15 #ifndef LLVM_CONSTANTSCONTEXT_H
16 #define LLVM_CONSTANTSCONTEXT_H
29 template<
class ValType>
35 virtual void anchor();
39 void *
operator new(
size_t s) {
40 return User::operator
new(s, 1);
52 virtual void anchor();
56 void *
operator new(
size_t s) {
57 return User::operator
new(s, 2);
73 virtual void anchor();
77 void *
operator new(
size_t s) {
78 return User::operator
new(s, 3);
94 virtual void anchor();
98 void *
operator new(
size_t s) {
99 return User::operator
new(s, 2);
115 virtual void anchor();
119 void *
operator new(
size_t s) {
120 return User::operator
new(s, 3);
137 virtual void anchor();
141 void *
operator new(
size_t s) {
142 return User::operator
new(s, 3);
162 virtual void anchor();
166 void *
operator new(
size_t s) {
167 return User::operator
new(s, 1);
188 virtual void anchor();
192 void *
operator new(
size_t s) {
193 return User::operator
new(s, 2);
215 virtual void anchor();
236 virtual void anchor();
240 void *
operator new(
size_t s) {
241 return User::operator
new(s, 2);
319 unsigned short flags = 0,
320 unsigned short optionalflags = 0,
322 : opcode(opc), subclassoptionaldata(optionalflags), subclassdata(flags),
330 return this->opcode == that.
opcode &&
337 if (this->opcode != that.
opcode)
return this->opcode < that.
opcode;
343 if (this->indices != that.
indices)
return this->indices < that.
indices;
348 return !(*
this == that);
354 StringRef Constraints,
bool hasSideEffects,
386 return !(*
this == that);
397 template<
typename T,
typename Alloc>
399 static unsigned uses(
const std::vector<T, Alloc>& v) {
411 template<
class ConstantClass,
class TypeClass,
class ValType>
412 struct ConstantCreator {
413 static ConstantClass *
create(TypeClass *Ty,
const ValType &V) {
418 template<
class ConstantClass,
class TypeClass>
419 struct ConstantArrayCreator {
421 return new(V.
size()) ConstantClass(Ty, V);
425 template<
class ConstantClass>
436 unsigned short pred = 0) {
439 if ((V.
opcode >= Instruction::BinaryOpsBegin &&
440 V.
opcode < Instruction::BinaryOpsEnd))
448 if (V.
opcode == Instruction::InsertElement)
451 if (V.
opcode == Instruction::ShuffleVector)
454 if (V.
opcode == Instruction::InsertValue)
457 if (V.
opcode == Instruction::ExtractValue)
459 if (V.
opcode == Instruction::GetElementPtr) {
468 if (V.
opcode == Instruction::ICmp)
471 if (V.
opcode == Instruction::FCmp)
482 std::vector<Constant*> Operands;
485 Operands.push_back(cast<Constant>(CE->
getOperand(i)));
513 template<
class ValType,
class ValRefType,
class TypeClass,
class ConstantClass,
514 bool HasLargeKey =
false >
515 class ConstantUniqueMap {
517 typedef std::pair<TypeClass*, ValType>
MapKey;
518 typedef std::map<MapKey, ConstantClass *>
MapTy;
519 typedef std::map<ConstantClass *, typename MapTy::iterator>
InverseMapTy;
533 typename MapTy::iterator
map_begin() {
return Map.begin(); }
534 typename MapTy::iterator
map_end() {
return Map.end(); }
537 for (
typename MapTy::iterator
I=Map.begin(), E=Map.end();
552 std::pair<typename MapTy::iterator, bool> IP = Map.insert(InsertVal);
558 typename MapTy::iterator FindExistingElement(ConstantClass *CP) {
560 typename InverseMapTy::iterator IMI = InverseMap.find(CP);
561 assert(IMI != InverseMap.end() && IMI->second != Map.end() &&
562 IMI->second->second == CP &&
563 "InverseMap corrupt!");
567 typename MapTy::iterator
I =
568 Map.find(
MapKey(static_cast<TypeClass*>(CP->getType()),
569 ConstantKeyData<ConstantClass>::getValType(CP)));
570 if (I == Map.end() || I->second != CP) {
573 for (I = Map.begin(); I != Map.end() && I->second != CP; ++
I)
579 ConstantClass *Create(TypeClass *Ty, ValRefType V,
580 typename MapTy::iterator I) {
581 ConstantClass* Result =
584 assert(Result->getType() == Ty &&
"Type specified is not correct!");
585 I = Map.insert(I, std::make_pair(
MapKey(Ty, V), Result));
588 InverseMap.insert(std::make_pair(Result, I));
598 ConstantClass* Result = 0;
600 typename MapTy::iterator I = Map.find(Lookup);
607 Result = Create(Ty, V, I);
613 void remove(ConstantClass *CP) {
614 typename MapTy::iterator I = FindExistingElement(CP);
615 assert(I != Map.end() &&
"Constant not found in constant table!");
616 assert(I->second == CP &&
"Didn't find correct element?");
619 InverseMap.erase(CP);
629 typename MapTy::iterator OldI = FindExistingElement(C);
630 assert(OldI != Map.end() &&
"Constant not found in constant table!");
631 assert(OldI->second == C &&
"Didn't find correct element?");
639 assert(I->second == C &&
"Bad inversemap entry!");
645 DEBUG(
dbgs() <<
"Constant.cpp: ConstantUniqueMap\n");
650 template<
class TypeClass,
class ConstantClass>
660 static inline ConstantClass* getEmptyKey() {
661 return ConstantClassInfo::getEmptyKey();
663 static inline ConstantClass* getTombstoneKey() {
664 return ConstantClassInfo::getTombstoneKey();
666 static unsigned getHashValue(
const ConstantClass *CP) {
668 CPOperands.
reserve(CP->getNumOperands());
669 for (
unsigned I = 0, E = CP->getNumOperands(); I < E; ++
I)
671 return getHashValue(
LookupKey(CP->getType(), CPOperands));
673 static bool isEqual(
const ConstantClass *LHS,
const ConstantClass *RHS) {
676 static unsigned getHashValue(
const LookupKey &Val) {
680 static bool isEqual(
const LookupKey &LHS,
const ConstantClass *RHS) {
681 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
683 if (LHS.first != RHS->getType()
684 || LHS.second.size() != RHS->getNumOperands())
686 for (
unsigned I = 0, E = RHS->getNumOperands(); I < E; ++
I) {
687 if (LHS.second[I] != RHS->getOperand(I))
720 ConstantClass* Result =
723 assert(Result->getType() == Ty &&
"Type specified is not correct!");
734 ConstantClass* Result = 0;
743 Result = Create(Ty, V, I);
760 void remove(ConstantClass *CP) {
762 assert(I != Map.
end() &&
"Constant not found in constant table!");
763 assert(I->first == CP &&
"Didn't find correct element?");
768 DEBUG(
dbgs() <<
"Constant.cpp: ConstantUniqueMap\n");
InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
AsmDialect getDialect() const
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
unsigned getNumOperands() const
static ValType getValType(ConstantClass *C)
std::pair< TypeClass *, ValType > MapKey
const std::string & getAsmString() const
MapTy::iterator map_end()
std::pair< TypeClass *, Operands > LookupKey
const_iterator begin(StringRef path)
Get begin iterator over path.
SmallVector< unsigned, 4 > indices
const std::string & getConstraintString() const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type cast(const Y &Val)
static ValType getValType(ConstantExpr *CE)
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
MapTy::iterator map_end()
std::map< ConstantClass *, typename MapTy::iterator > InverseMapTy
static ConstantClass * create(TypeClass *Ty, const ValType &V)
bool operator==(const ExprMapKeyType &that) const
DenseMap< ConstantClass *, char, MapInfo > MapTy
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
#define llvm_unreachable(msg)
ExprMapKeyType(unsigned opc, ArrayRef< Constant * > ops, unsigned short flags=0, unsigned short optionalflags=0, ArrayRef< unsigned > inds=None)
iterator find_as(const LookupKeyT &Val)
CompareConstantExpr(Type *ty, Instruction::OtherOps opc, unsigned short pred, Constant *LHS, Constant *RHS)
static unsigned uses(const std::vector< T, Alloc > &v)
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
bool operator!=(const ExprMapKeyType &that) const
uint8_t subclassoptionaldata
ArrayRef< Constant * > Operands
bool operator<(const ExprMapKeyType &that) const
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty)
const SmallVector< unsigned, 4 > Indices
Indices - These identify the position for the insertion.
InlineAsm::AsmDialect asm_dialect
size_t size() const
size - Get the array size.
InlineAsmKeyType(StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack, InlineAsm::AsmDialect asmDialect)
bool operator!=(const InlineAsmKeyType &that) const
static GetElementPtrConstantExpr * Create(Constant *C, ArrayRef< Constant * > IdxList, Type *DestTy, unsigned Flags)
MapTy::iterator InsertOrGetItem(std::pair< MapKey, ConstantClass * > &InsertVal, bool &Exists)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
bool operator==(const InlineAsmKeyType &that) const
bool hasSideEffects() const
LLVM Constant Representation.
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
hash_code hash_combine(const T1 &arg1, const T2 &arg2, const T3 &arg3, const T4 &arg4, const T5 &arg5, const T6 &arg6)
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode)
static InlineAsm * create(PointerType *Ty, const InlineAsmKeyType &Key)
Value * getOperand(unsigned i) const
unsigned getPredicate() const
ArrayRef< unsigned > getIndices() const
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
static ValType getValType(InlineAsm *Asm)
unsigned char SubclassOptionalData
bool isCompare() const
Return true if this is a compare constant expression.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
ConstantClass * getOrCreate(TypeClass *Ty, ValRefType V)
MapTy::iterator map_begin()
std::map< MapKey, ConstantClass * > MapTy
bool erase(const KeyT &Val)
std::vector< Constant * > operands
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
#define LLVM_DELETED_FUNCTION
ConstantClass * getOrCreate(TypeClass *Ty, Operands V)
InsertValueConstantExpr(Constant *Agg, Constant *Val, const SmallVector< unsigned, 4 > &IdxList, Type *DestTy)
MapTy::iterator map_begin()
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.
DenseMapIterator< KeyT, ValueT, KeyInfoT > iterator
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)
Transparently provide more efficient getOperand methods.
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags)
unsigned getRawSubclassOptionalData() const
static ConstantClass * create(TypeClass *Ty, ArrayRef< Constant * > V)
MapTy::iterator find(LookupKey Lookup)
Find the constant by lookup key.
bool operator<(const InlineAsmKeyType &that) const
void insert(ConstantClass *CP)
Insert the constant into its proper slot.
void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I)
LLVM Value Representation.
static unsigned uses(Constant *const &v)
SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
bool isAlignStack() const
iterator find(const KeyT &Val)
static ConstantExpr * create(Type *Ty, const ExprMapKeyType &V, unsigned short pred=0)