File indexing completed on 2026-05-10 08:44:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_IR_VALUESYMBOLTABLE_H
0014 #define LLVM_IR_VALUESYMBOLTABLE_H
0015
0016 #include "llvm/ADT/StringMap.h"
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/IR/Value.h"
0019 #include <cstdint>
0020
0021 namespace llvm {
0022
0023 class Argument;
0024 class BasicBlock;
0025 class Function;
0026 class GlobalAlias;
0027 class GlobalIFunc;
0028 class GlobalVariable;
0029 class Instruction;
0030 template <bool ExtraIteratorBits> struct ilist_iterator_bits;
0031 template <class ParentTy> struct ilist_parent;
0032 template <unsigned InternalLen> class SmallString;
0033 template <typename ValueSubClass, typename ... Args> class SymbolTableListTraits;
0034
0035
0036
0037
0038
0039 class ValueSymbolTable {
0040 friend class SymbolTableListTraits<Argument>;
0041 friend class SymbolTableListTraits<BasicBlock>;
0042 friend class SymbolTableListTraits<Function>;
0043 friend class SymbolTableListTraits<GlobalAlias>;
0044 friend class SymbolTableListTraits<GlobalIFunc>;
0045 friend class SymbolTableListTraits<GlobalVariable>;
0046 friend class SymbolTableListTraits<Instruction, ilist_iterator_bits<true>,
0047 ilist_parent<BasicBlock>>;
0048 friend class Value;
0049
0050
0051
0052 public:
0053
0054 using ValueMap = StringMap<Value*>;
0055
0056
0057 using iterator = ValueMap::iterator;
0058
0059
0060 using const_iterator = ValueMap::const_iterator;
0061
0062
0063
0064
0065
0066 ValueSymbolTable(int MaxNameSize = -1) : vmap(0), MaxNameSize(MaxNameSize) {}
0067 ~ValueSymbolTable();
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 Value *lookup(StringRef Name) const {
0078 if (MaxNameSize > -1 && Name.size() > (unsigned)MaxNameSize)
0079 Name = Name.substr(0, std::max(1u, (unsigned)MaxNameSize));
0080
0081 return vmap.lookup(Name);
0082 }
0083
0084
0085
0086 inline bool empty() const { return vmap.empty(); }
0087
0088
0089 inline unsigned size() const { return unsigned(vmap.size()); }
0090
0091
0092
0093
0094 void dump() const;
0095
0096
0097
0098
0099
0100
0101 inline iterator begin() { return vmap.begin(); }
0102
0103
0104 inline const_iterator begin() const { return vmap.begin(); }
0105
0106
0107 inline iterator end() { return vmap.end(); }
0108
0109
0110 inline const_iterator end() const { return vmap.end(); }
0111
0112
0113
0114
0115 private:
0116 ValueName *makeUniqueName(Value *V, SmallString<256> &UniqueName);
0117
0118
0119
0120
0121
0122 void reinsertValue(Value *V);
0123
0124
0125
0126
0127 ValueName *createValueName(StringRef Name, Value *V);
0128
0129
0130
0131
0132 void removeValueName(ValueName *V);
0133
0134
0135
0136
0137
0138 ValueMap vmap;
0139 int MaxNameSize;
0140
0141 mutable uint32_t LastUnique = 0;
0142
0143
0144 };
0145
0146 }
0147
0148 #endif