15 #ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H
16 #define LLVM_LIB_IR_CONSTANTSCONTEXT_H
29 #define DEBUG_TYPE "ir"
36 void anchor()
override;
37 void *
operator new(size_t,
unsigned) =
delete;
40 void *
operator new(
size_t s) {
41 return User::operator
new(s, 1);
53 void anchor()
override;
54 void *
operator new(size_t,
unsigned) =
delete;
57 void *
operator new(
size_t s) {
58 return User::operator
new(s, 2);
74 void anchor()
override;
75 void *
operator new(size_t,
unsigned) =
delete;
78 void *
operator new(
size_t s) {
79 return User::operator
new(s, 3);
95 void anchor()
override;
96 void *
operator new(size_t,
unsigned) =
delete;
99 void *
operator new(
size_t s) {
100 return User::operator
new(s, 2);
116 void anchor()
override;
117 void *
operator new(size_t,
unsigned) =
delete;
120 void *
operator new(
size_t s) {
121 return User::operator
new(s, 3);
138 void anchor()
override;
139 void *
operator new(size_t,
unsigned) =
delete;
142 void *
operator new(
size_t s) {
143 return User::operator
new(s, 3);
163 void anchor()
override;
164 void *
operator new(size_t,
unsigned) =
delete;
167 void *
operator new(
size_t s) {
168 return User::operator
new(s, 1);
188 void anchor()
override;
189 void *
operator new(size_t,
unsigned) =
delete;
192 void *
operator new(
size_t s) {
193 return User::operator
new(s, 2);
214 void anchor()
override;
225 IdxList, DestTy,
Flags);
244 void anchor()
override;
245 void *
operator new(size_t,
unsigned) =
delete;
248 void *
operator new(
size_t s) {
249 return User::operator
new(s, 2);
343 : Operands(Operands) {}
346 assert(Storage.
empty() &&
"Expected empty storage");
347 for (
unsigned I = 0, E = C->getNumOperands();
I != E; ++
I)
356 if (
Operands.size() != C->getNumOperands())
358 for (
unsigned I = 0, E =
Operands.size();
I != E; ++
I)
383 : AsmString(AsmString), Constraints(Constraints),
384 HasSideEffects(HasSideEffects), IsAlignStack(IsAlignStack),
385 AsmDialect(AsmDialect) {}
432 :
Opcode(CE->getOpcode()),
438 :
Opcode(CE->getOpcode()),
442 assert(Storage.
empty() &&
"Expected empty storage");
463 for (
unsigned I = 0, E =
Ops.size();
I != E; ++
I)
483 if ((
Opcode >= Instruction::BinaryOpsBegin &&
484 Opcode < Instruction::BinaryOpsEnd))
492 case Instruction::InsertElement:
494 case Instruction::ShuffleVector:
496 case Instruction::InsertValue:
498 case Instruction::ExtractValue:
500 case Instruction::GetElementPtr:
503 : cast<PointerType>(
Ops[0]->
getType()->getScalarType())
506 case Instruction::ICmp:
509 case Instruction::FCmp:
516 template <
class ConstantClass>
class ConstantUniqueMap {
525 static inline ConstantClass *getEmptyKey() {
526 return ConstantClassInfo::getEmptyKey();
528 static inline ConstantClass *getTombstoneKey() {
529 return ConstantClassInfo::getTombstoneKey();
531 static unsigned getHashValue(
const ConstantClass *
CP) {
535 static bool isEqual(
const ConstantClass *LHS,
const ConstantClass *RHS) {
538 static unsigned getHashValue(
const LookupKey &Val) {
541 static bool isEqual(
const LookupKey &LHS,
const ConstantClass *RHS) {
542 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
544 if (LHS.first != RHS->getType())
546 return LHS.second == RHS;
568 ConstantClass *Result = V.create(Ty);
570 assert(Result->getType() == Ty &&
"Type specified is not correct!");
580 ConstantClass *Result =
nullptr;
582 auto I =
find(Lookup);
584 Result = create(Ty, V);
587 assert(Result &&
"Unexpected nullptr");
601 void remove(ConstantClass *
CP) {
603 assert(I != Map.
end() &&
"Constant not found in constant table!");
604 assert(I->first ==
CP &&
"Didn't find correct element?");
609 ConstantClass *
CP,
Value *From,
610 Constant *To,
unsigned NumUpdated = 0,
611 unsigned OperandNo = ~0u) {
620 if (NumUpdated == 1) {
621 assert(OperandNo < CP->getNumOperands() &&
"Invalid index");
622 assert(CP->getOperand(OperandNo) != To &&
"I didn't contain From!");
623 CP->setOperand(OperandNo, To);
625 for (
unsigned I = 0, E = CP->getNumOperands(); I != E; ++
I)
626 if (CP->getOperand(I) == From)
627 CP->setOperand(I, To);
InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
ConstantInfo< ConstantExpr >::TypeClass TypeClass
void push_back(const T &Elt)
ConstantAggrKeyType< ConstantArray > ValType
const_iterator end(StringRef path)
Get end iterator over path.
AsmDialect getDialect() const
ConstantInfo< InlineAsm >::TypeClass TypeClass
uint8_t SubclassOptionalData
void insert(ConstantClass *CP)
Insert the constant into its proper slot.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
ConstantExprKeyType(unsigned Opcode, ArrayRef< Constant * > Ops, unsigned short SubclassData=0, unsigned short SubclassOptionalData=0, ArrayRef< unsigned > Indexes=None, Type *ExplicitTy=nullptr)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getNumOperands() const
bool operator==(const InlineAsmKeyType &X) const
const std::string & getAsmString() const
ConstantAggrKeyType(ArrayRef< Constant * > Operands, const ConstantClass *)
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
const_iterator begin(StringRef path)
Get begin iterator over path.
const std::string & getConstraintString() const
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
ConstantInfo< ConstantClass >::TypeClass TypeClass
ConstantExprKeyType(const ConstantExpr *CE, SmallVectorImpl< Constant * > &Storage)
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CompareConstantExpr(Type *ty, Instruction::OtherOps opc, unsigned short pred, Constant *LHS, Constant *RHS)
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
MapTy::iterator find(LookupKey Lookup)
Find the constant by lookup key.
InlineAsmKeyType(StringRef AsmString, StringRef Constraints, bool HasSideEffects, bool IsAlignStack, InlineAsm::AsmDialect AsmDialect)
ArrayRef< Constant * > Operands
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
ConstantExprKeyType(ArrayRef< Constant * > Operands, const ConstantExpr *CE)
const SmallVector< unsigned, 4 > Indices
Indices - These identify the position for the insertion.
bool operator==(const ConstantAggrKeyType &X) const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
std::pair< TypeClass *, ValType > LookupKey
ArrayType - Class to represent array types.
bool operator==(const ConstantExprKeyType &X) const
MapTy::iterator map_begin()
size_t size() const
size - Get the array size.
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
PointerType - Class to represent pointers.
UnaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implemen...
static GetElementPtrConstantExpr * Create(Constant *C, ArrayRef< Constant * > IdxList, Type *DestTy, unsigned Flags)
bool erase(const KeyT &Val)
ConstantExprKeyType ValType
InsertValueConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to im...
ConstantAggrKeyType(const ConstantClass *C, SmallVectorImpl< Constant * > &Storage)
bool hasSideEffects() const
InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl< Constant * > &)
The instances of the Type class are immutable: once they are created, they are never changed...
ConstantClass * create(TypeClass *Ty) const
ArrayRef< Constant * > Ops
This is an important base class in LLVM.
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
ArrayRef< unsigned > Indexes
static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode)
bool operator==(const ConstantExpr *CE) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
Value * getOperand(unsigned i) const
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
ConstantVector - Constant Vector Declarations.
unsigned getPredicate() const
getPredicate - Return the ICMP or FCMP predicate value.
ArrayRef< unsigned > getIndices() const
getIndices - Assert that this is an insertvalue or exactvalue expression and return the list of indic...
ConstantAggrKeyType< ConstantStruct > ValType
SelectConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
InlineAsm::AsmDialect AsmDialect
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool isCompare() const
Return true if this is a compare constant expression.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
InsertValueConstantExpr(Constant *Agg, Constant *Val, ArrayRef< unsigned > IdxList, Type *DestTy)
ConstantExpr * create(TypeClass *Ty) const
Type * getType() const
All values are typed, get the type of this value.
InlineAsm * create(TypeClass *Ty) const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
static GetElementPtrConstantExpr * Create(Type *SrcElementTy, Constant *C, ArrayRef< Constant * > IdxList, Type *DestTy, unsigned Flags)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
VectorType - Class to represent vector types.
ConstantArray - Constant Array Declarations.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
bool operator==(const ConstantClass *C) const
ConstantAggrKeyType(ArrayRef< Constant * > Operands)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags)
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
Type * getSourceElementType() const
DenseMap< ConstantClass *, char, MapInfo > MapTy
ConstantAggrKeyType< ConstantVector > ValType
iterator find(const KeyT &Val)
Compile-time customization of User operands.
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive, key type.
ConstantInfo< ConstantClass >::TypeClass TypeClass
LLVM Value Representation.
MapTy::iterator map_end()
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
StringRef - Represent a constant reference to a string, i.e.
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
bool operator==(const InlineAsm *Asm) const
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
bool isAlignStack() const
ConstantInfo< ConstantClass >::ValType ValType