15 #ifndef LLVM_LIB_IR_CONSTANTSCONTEXT_H 16 #define LLVM_LIB_IR_CONSTANTSCONTEXT_H 40 #define DEBUG_TYPE "ir" 54 void *
operator new(
size_t s) {
55 return User::operator
new(s, 1);
74 void *
operator new(
size_t s) {
75 return User::operator
new(s, 2);
94 void *
operator new(
size_t s) {
95 return User::operator
new(s, 3);
115 void *
operator new(
size_t s) {
116 return User::operator
new(s, 2);
137 void *
operator new(
size_t s) {
138 return User::operator
new(s, 3);
162 void *
operator new(
size_t s) {
163 return User::operator
new(s, 3);
178 Indices(IdxList.
begin(), IdxList.
end()) {
183 void *
operator new(
size_t s) {
184 return User::operator
new(s, 1);
194 return CE->
getOpcode() == Instruction::ExtractValue;
197 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
209 Indices(IdxList.
begin(), IdxList.
end()) {
215 void *
operator new(
size_t s) {
216 return User::operator
new(s, 2);
226 return CE->
getOpcode() == Instruction::InsertValue;
229 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
245 Type *DestTy,
unsigned Flags) {
252 Type *getSourceElementType()
const;
253 Type *getResultElementType()
const;
259 return CE->
getOpcode() == Instruction::GetElementPtr;
262 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
280 void *
operator new(
size_t s) {
281 return User::operator
new(s, 2);
288 return CE->
getOpcode() == Instruction::ICmp ||
292 return isa<ConstantExpr>(V) &&
classof(cast<ConstantExpr>(V));
379 : Operands(Operands) {}
383 assert(Storage.
empty() &&
"Expected empty storage");
384 for (
unsigned I = 0,
E = C->getNumOperands();
I !=
E; ++
I)
394 if (Operands.
size() != C->getNumOperands())
396 for (
unsigned I = 0,
E = Operands.
size();
I !=
E; ++
I)
397 if (Operands[
I] != C->getOperand(
I))
409 return new (Operands.
size()) ConstantClass(Ty, Operands);
422 FunctionType *FTy,
bool HasSideEffects,
bool IsAlignStack,
424 : AsmString(AsmString), Constraints(Constraints), FTy(FTy),
425 HasSideEffects(HasSideEffects), IsAlignStack(IsAlignStack),
426 AsmDialect(AsmDialect) {}
429 : AsmString(Asm->getAsmString()), Constraints(Asm->getConstraintString()),
430 FTy(Asm->getFunctionType()), HasSideEffects(Asm->hasSideEffects()),
431 IsAlignStack(Asm->isAlignStack()), AsmDialect(Asm->getDialect()) {}
450 return hash_combine(AsmString, Constraints, HasSideEffects, IsAlignStack,
458 return new InlineAsm(FTy, AsmString, Constraints, HasSideEffects,
459 IsAlignStack, AsmDialect);
472 unsigned short SubclassData = 0,
473 unsigned short SubclassOptionalData = 0,
475 Type *ExplicitTy =
nullptr)
476 : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData),
477 SubclassData(SubclassData), Ops(Ops), Indexes(Indexes),
478 ExplicitTy(ExplicitTy) {}
492 assert(Storage.
empty() &&
"Expected empty storage");
513 for (
unsigned I = 0,
E = Ops.
size();
I !=
E; ++
I)
522 return hash_combine(Opcode, SubclassOptionalData, SubclassData,
533 (Opcode >= Instruction::UnaryOpsBegin &&
534 Opcode < Instruction::UnaryOpsEnd))
536 if ((Opcode >= Instruction::BinaryOpsBegin &&
537 Opcode < Instruction::BinaryOpsEnd))
538 return new BinaryConstantExpr(Opcode, Ops[0], Ops[1],
539 SubclassOptionalData);
542 return new SelectConstantExpr(Ops[0], Ops[1], Ops[2]);
543 case Instruction::ExtractElement:
544 return new ExtractElementConstantExpr(Ops[0], Ops[1]);
545 case Instruction::InsertElement:
546 return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]);
547 case Instruction::ShuffleVector:
548 return new ShuffleVectorConstantExpr(Ops[0], Ops[1], Ops[2]);
549 case Instruction::InsertValue:
550 return new InsertValueConstantExpr(Ops[0], Ops[1], Indexes, Ty);
551 case Instruction::ExtractValue:
552 return new ExtractValueConstantExpr(Ops[0], Indexes, Ty);
553 case Instruction::GetElementPtr:
555 ExplicitTy ? ExplicitTy
556 : cast<PointerType>(Ops[0]->
getType()->getScalarType())
559 case Instruction::ICmp:
560 return new CompareConstantExpr(Ty, Instruction::ICmp, SubclassData,
562 case Instruction::FCmp:
563 return new CompareConstantExpr(Ty, Instruction::FCmp, SubclassData,
582 static inline ConstantClass *getEmptyKey() {
583 return ConstantClassInfo::getEmptyKey();
586 static inline ConstantClass *getTombstoneKey() {
587 return ConstantClassInfo::getTombstoneKey();
590 static unsigned getHashValue(
const ConstantClass *
CP) {
595 static bool isEqual(
const ConstantClass *LHS,
const ConstantClass *RHS) {
599 static unsigned getHashValue(
const LookupKey &Val) {
608 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
610 if (LHS.first != RHS->getType())
612 return LHS.second == RHS;
616 return isEqual(LHS.second, RHS);
637 ConstantClass *Result = V.create(Ty);
639 assert(Result->getType() == Ty &&
"Type specified is not correct!");
652 ConstantClass *Result =
nullptr;
656 Result = create(Ty, V, Lookup);
659 assert(Result &&
"Unexpected nullptr");
665 void remove(ConstantClass *
CP) {
667 assert(I != Map.
end() &&
"Constant not found in constant table!");
668 assert(*I ==
CP &&
"Didn't find correct element?");
674 Constant *To,
unsigned NumUpdated = 0,
675 unsigned OperandNo = ~0u) {
687 if (NumUpdated == 1) {
689 assert(CP->getOperand(OperandNo) != To &&
"I didn't contain From!");
690 CP->setOperand(OperandNo, To);
692 for (
unsigned I = 0,
E = CP->getNumOperands();
I !=
E; ++
I)
693 if (CP->getOperand(
I) ==
From)
694 CP->setOperand(
I, To);
707 #endif // LLVM_LIB_IR_CONSTANTSCONTEXT_H InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
const_iterator end(StringRef path)
Get end iterator over path.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
uint8_t SubclassOptionalData
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
bool operator==(const InlineAsm *Asm) const
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
ConstantInfo< InlineAsm >::TypeClass TypeClass
static bool classof(const ConstantExpr *CE)
void push_back(const T &Elt)
const std::string & getAsmString() const
typename ConstantInfo< llvm::ConstantExpr >::TypeClass TypeClass
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
bool erase(const ValueT &V)
friend struct ConstantExprKeyType
InlineAsmKeyType(StringRef AsmString, StringRef Constraints, FunctionType *FTy, bool HasSideEffects, bool IsAlignStack, InlineAsm::AsmDialect AsmDialect)
bool operator==(const InlineAsmKeyType &X) const
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
bool hasSideEffects() const
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant *> Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
Class to represent struct types.
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
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)
ArrayRef< Constant * > Operands
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
Class to represent function types.
A constant value that is initialized with an expression using other constant values.
UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
Type * getType() const
All values are typed, get the type of this value.
const SmallVector< unsigned, 4 > Indices
Indices - These identify the position for the insertion.
static bool isEqual(const Function &Caller, const Function &Callee)
Class to represent array types.
static bool classof(const Value *V)
std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
Value * getOperand(unsigned i) const
Class to represent pointers.
UnaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implemen...
ConstantExprKeyType(const ConstantExpr *CE, SmallVectorImpl< Constant *> &Storage)
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
static bool classof(const Value *V)
bool operator==(const ConstantClass *C) const
static GetElementPtrConstantExpr * Create(Type *SrcElementTy, Constant *C, ArrayRef< Constant *> IdxList, Type *DestTy, unsigned Flags)
InsertValueConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to im...
std::pair< iterator, bool > insert_as(const ValueT &V, const LookupKeyT &LookupKey)
Alternative version of insert that uses a different (and possibly less expensive) key type...
The instances of the Type class are immutable: once they are created, they are never changed...
typename ConstantInfo< llvm::ConstantExpr >::ValType ValType
ArrayRef< Constant * > Ops
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
ArrayRef< unsigned > Indexes
iterator find_as(const LookupKeyT &Val)
Alternative version of find() which allows a different, and possibly less expensive, key type.
bool operator==(const ConstantExpr *CE) const
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
ConstantExprKeyType(ArrayRef< Constant *> Operands, const ConstantExpr *CE)
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Constant Vector Declarations.
ConstantExprKeyType(unsigned Opcode, ArrayRef< Constant *> Ops, unsigned short SubclassData=0, unsigned short SubclassOptionalData=0, ArrayRef< unsigned > Indexes=None, Type *ExplicitTy=nullptr)
bool operator==(const ConstantExprKeyType &X) const
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
bool isAlignStack() const
ConstantAggrKeyType(const ConstantClass *C, SmallVectorImpl< Constant *> &Storage)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const std::string & getConstraintString() const
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
std::pair< unsigned, LookupKey > LookupKeyHashed
Key and hash together, so that we compute the hash only once and reuse it.
unsigned getNumOperands() const
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
BlockVerifier::State From
ConstantAggrKeyType(ArrayRef< Constant *> Operands)
InsertValueConstantExpr(Constant *Agg, Constant *Val, ArrayRef< unsigned > IdxList, Type *DestTy)
InlineAsmKeyType(const InlineAsm *Asm, SmallVectorImpl< Constant *> &)
ConstantAggrKeyType(ArrayRef< Constant *> Operands, const ConstantClass *)
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast:
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
ConstantClass * create(TypeClass *Ty) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags)
LLVM_NODISCARD bool empty() const
iterator find(const_arg_type_t< ValueT > V)
bool isCompare() const
Return true if this is a compare constant expression.
Compile-time customization of User operands.
FunctionType * getFunctionType() const
getFunctionType - InlineAsm's are always pointers to functions.
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices...
AsmDialect getDialect() const
InlineAsm * create(TypeClass *Ty) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ConstantExpr * create(TypeClass *Ty) const
static bool classof(const Value *V)
LLVM Value Representation.
ConstantInfo< ConstantExpr >::TypeClass TypeClass
typename ConstantInfo< ConstantClass >::TypeClass TypeClass
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...
VariadicOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
std::pair< TypeClass *, ValType > LookupKey
SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
bool operator==(const ConstantAggrKeyType &X) const
static bool classof(const ConstantExpr *CE)
static bool classof(const ConstantExpr *CE)
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.