LLVM  15.0.0git
BitCodes.h
Go to the documentation of this file.
1 //===- BitCodes.h - Enum values for the bitstream format --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header defines bitstream enum values.
10 //
11 // The enum values defined in this file should be considered permanent. If
12 // new features are added, they should have values added at the end of the
13 // respective lists.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_BITSTREAM_BITCODES_H
18 #define LLVM_BITSTREAM_BITCODES_H
19 
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/Support/DataTypes.h"
25 #include <cassert>
26 
27 namespace llvm {
28 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
29 /// This is actually a union of two different things:
30 /// 1. It could be a literal integer value ("the operand is always 17").
31 /// 2. It could be an encoding specification ("this operand encoded like so").
32 ///
34  uint64_t Val; // A literal value or data for an encoding.
35  bool IsLiteral : 1; // Indicate whether this is a literal value or not.
36  unsigned Enc : 3; // The encoding to use.
37 public:
38  enum Encoding {
39  Fixed = 1, // A fixed width field, Val specifies number of bits.
40  VBR = 2, // A VBR field where Val specifies the width of each chunk.
41  Array = 3, // A sequence of fields, next field species elt encoding.
42  Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._].
43  Blob = 5 // 32-bit aligned array of 8-bit characters.
44  };
45 
46  static bool isValidEncoding(uint64_t E) {
47  return E >= 1 && E <= 5;
48  }
49 
50  explicit BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {}
52  : Val(Data), IsLiteral(false), Enc(E) {}
53 
54  bool isLiteral() const { return IsLiteral; }
55  bool isEncoding() const { return !IsLiteral; }
56 
57  // Accessors for literals.
58  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
59 
60  // Accessors for encoding info.
61  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
64  return Val;
65  }
66 
67  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
68  static bool hasEncodingData(Encoding E) {
69  switch (E) {
70  case Fixed:
71  case VBR:
72  return true;
73  case Array:
74  case Char6:
75  case Blob:
76  return false;
77  }
78  report_fatal_error("Invalid encoding");
79  }
80 
81  /// isChar6 - Return true if this character is legal in the Char6 encoding.
82  static bool isChar6(char C) { return isAlnum(C) || C == '.' || C == '_'; }
83  static unsigned EncodeChar6(char C) {
84  if (C >= 'a' && C <= 'z') return C-'a';
85  if (C >= 'A' && C <= 'Z') return C-'A'+26;
86  if (C >= '0' && C <= '9') return C-'0'+26+26;
87  if (C == '.') return 62;
88  if (C == '_') return 63;
89  llvm_unreachable("Not a value Char6 character!");
90  }
91 
92  static char DecodeChar6(unsigned V) {
93  assert((V & ~63) == 0 && "Not a Char6 encoded character!");
94  return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
95  [V];
96  }
97 
98 };
99 
100 /// BitCodeAbbrev - This class represents an abbreviation record. An
101 /// abbreviation allows a complex record that has redundancy to be stored in a
102 /// specialized format instead of the fully-general, fully-vbr, format.
105 
106 public:
107  BitCodeAbbrev() = default;
108 
109  explicit BitCodeAbbrev(std::initializer_list<BitCodeAbbrevOp> OperandList)
110  : OperandList(OperandList) {}
111 
112  unsigned getNumOperandInfos() const {
113  return static_cast<unsigned>(OperandList.size());
114  }
115  const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
116  return OperandList[N];
117  }
118 
119  void Add(const BitCodeAbbrevOp &OpInfo) {
120  OperandList.push_back(OpInfo);
121  }
122 };
123 } // namespace llvm
124 
125 #endif
llvm::BitCodeAbbrev::getNumOperandInfos
unsigned getNumOperandInfos() const
Definition: BitCodes.h:112
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::BitCodeAbbrev::Add
void Add(const BitCodeAbbrevOp &OpInfo)
Definition: BitCodes.h:119
BitCodeEnums.h
llvm::BitCodeAbbrevOp::isChar6
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
Definition: BitCodes.h:82
llvm::BitCodeAbbrevOp::Fixed
@ Fixed
Definition: BitCodes.h:39
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::BitCodeAbbrevOp::hasEncodingData
static bool hasEncodingData(Encoding E)
Definition: BitCodes.h:68
ErrorHandling.h
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1909
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::BitCodeAbbrevOp::BitCodeAbbrevOp
BitCodeAbbrevOp(Encoding E, uint64_t Data=0)
Definition: BitCodes.h:51
llvm::BitCodeAbbrevOp::hasEncodingData
bool hasEncodingData() const
Definition: BitCodes.h:67
llvm::BitCodeAbbrevOp::Char6
@ Char6
Definition: BitCodes.h:42
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BitCodeAbbrev::BitCodeAbbrev
BitCodeAbbrev(std::initializer_list< BitCodeAbbrevOp > OperandList)
Definition: BitCodes.h:109
false
Definition: StackSlotColoring.cpp:141
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::BitCodeAbbrevOp::Blob
@ Blob
Definition: BitCodes.h:43
llvm::BitCodeAbbrevOp::getEncoding
Encoding getEncoding() const
Definition: BitCodes.h:61
llvm::BitCodeAbbrevOp::Encoding
Encoding
Definition: BitCodes.h:38
llvm::BitCodeAbbrevOp::isEncoding
bool isEncoding() const
Definition: BitCodes.h:55
llvm::BitCodeAbbrevOp::BitCodeAbbrevOp
BitCodeAbbrevOp(uint64_t V)
Definition: BitCodes.h:50
uint64_t
StringExtras.h
llvm::BitCodeAbbrevOp::VBR
@ VBR
Definition: BitCodes.h:40
llvm::BitCodeAbbrevOp::Array
@ Array
Definition: BitCodes.h:41
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::BitCodeAbbrevOp::getEncodingData
uint64_t getEncodingData() const
Definition: BitCodes.h:62
llvm::BitCodeAbbrevOp::isValidEncoding
static bool isValidEncoding(uint64_t E)
Definition: BitCodes.h:46
llvm::BitCodeAbbrev::getOperandInfo
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
Definition: BitCodes.h:115
llvm::BitCodeAbbrev::BitCodeAbbrev
BitCodeAbbrev()=default
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::BitCodeAbbrevOp::getLiteralValue
uint64_t getLiteralValue() const
Definition: BitCodes.h:58
llvm::BitCodeAbbrevOp
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
Definition: BitCodes.h:33
llvm::BitCodeAbbrevOp::isLiteral
bool isLiteral() const
Definition: BitCodes.h:54
llvm::BitCodeAbbrev
BitCodeAbbrev - This class represents an abbreviation record.
Definition: BitCodes.h:103
SmallVector.h
N
#define N
DataTypes.h
llvm::BitCodeAbbrevOp::EncodeChar6
static unsigned EncodeChar6(char C)
Definition: BitCodes.h:83
llvm::BitCodeAbbrevOp::DecodeChar6
static char DecodeChar6(unsigned V)
Definition: BitCodes.h:92