LLVM: lib/Bitcode/Writer/ValueEnumerator.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H

14#define LLVM_LIB_BITCODE_WRITER_VALUEENUMERATOR_H

15

21#include

22#include

23#include

24#include

25

26namespace llvm {

27

42

44public:

46

47

48 using ValueList = std::vector<std::pair<const Value *, unsigned>>;

49

50

51

53

55

56private:

58 TypeMapType TypeMap;

60

62 ValueMapType ValueMap;

64

66 ComdatSetType Comdats;

67

68 std::vector<const Metadata *> MDs;

69 std::vector<const Metadata *> FunctionMDs;

70

71

72 struct MDIndex {

73 unsigned F = 0;

74 unsigned ID = 0;

75

76 MDIndex() = default;

77 explicit MDIndex(unsigned F) : F(F) {}

78

79

80 bool hasDifferentFunction(unsigned NewF) const { return F && F != NewF; }

81

82

84 assert(ID && "Expected non-zero ID");

85 assert(ID <= MDs.size() && "Expected valid ID");

86 return MDs[ID - 1];

87 }

88 };

89

91 MetadataMapType MetadataMap;

92

93

94 struct MDRange {

95 unsigned First = 0;

96 unsigned Last = 0;

97

98

99 unsigned NumStrings = 0;

100

101 MDRange() = default;

103 };

104 SmallDenseMap<unsigned, MDRange, 1> FunctionMDInfo;

105

106 bool ShouldPreserveUseListOrder;

107

108 using AttributeGroupMapType = DenseMap<IndexAndAttrSet, unsigned>;

109 AttributeGroupMapType AttributeGroupMap;

110 std::vector AttributeGroups;

111

112 using AttributeListMapType = DenseMap<AttributeList, unsigned>;

113 AttributeListMapType AttributeListMap;

114 std::vector AttributeLists;

115

116

117

118 mutable DenseMap<const BasicBlock*, unsigned> GlobalBasicBlockIDs;

119

120 using InstructionMapType = DenseMap<const Instruction *, unsigned>;

121 InstructionMapType InstructionMap;

122 unsigned InstructionCount;

123

124

125

126 std::vector<const BasicBlock*> BasicBlocks;

127

128

129

130 unsigned NumModuleValues;

131

132

133

134 unsigned NumModuleMDs = 0;

135 unsigned NumMDStrings = 0;

136

137 unsigned FirstFuncConstantID;

138 unsigned FirstInstID;

139

140public:

144

145 void dump() const;

146 void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;

148 const char *Name) const;

149

151

154 assert(ID != 0 && "Metadata not in slotcalculator!");

155 return ID - 1;

156 }

157

159 return MetadataMap.lookup(MD).ID;

160 }

161

162 unsigned numMDs() const { return MDs.size(); }

163

165

168 assert(I != TypeMap.end() && "Type not in ValueEnumerator!");

169 return I->second-1;

170 }

171

174

176 if (PAL.isEmpty()) return 0;

178 assert(I != AttributeListMap.end() && "Attribute not in ValueEnumerator!");

179 return I->second;

180 }

181

183 if (!Group.second.hasAttributes())

184 return 0;

186 assert(I != AttributeGroupMap.end() && "Attribute not in ValueEnumerator!");

187 return I->second;

188 }

189

190

191

193 Start = FirstFuncConstantID;

194 End = FirstInstID;

195 }

196

198

199

200 bool hasMDs() const { return NumModuleMDs < MDs.size(); }

201

202

204 return ArrayRef(MDs).slice(NumModuleMDs, NumMDStrings);

205 }

206

207

209 return ArrayRef(MDs).slice(NumModuleMDs).slice(NumMDStrings);

210 }

211

213

215 return BasicBlocks;

216 }

217

218 const std::vector &getAttributeLists() const { return AttributeLists; }

219

221 return AttributeGroups;

222 }

223

224 const ComdatSetType &getComdats() const { return Comdats; }

226

227

228

229

231

232

233

235

238

239private:

240 void OptimizeConstants(unsigned CstStart, unsigned CstEnd);

241

242

243

244

245

246 void organizeMetadata();

247

248

250

251

252

253

254

255 void incorporateFunctionMetadata(const Function &F);

256

257

258

259

260

261

262

263

264 const MDNode *enumerateMetadataImpl(unsigned F, const Metadata *MD);

265

266 unsigned getMetadataFunctionID(const Function *F) const;

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

284 void EnumerateMetadata(unsigned F, const Metadata *MD);

285

286

287 void EnumerateFunctionLocalMetadata(const Function &F,

290 void EnumerateFunctionLocalListMetadata(const Function &F,

292 void EnumerateFunctionLocalListMetadata(unsigned F, const DIArgList *Arglist);

293 void EnumerateNamedMDNode(const NamedMDNode *NMD);

294 void EnumerateValue(const Value *V);

295 void EnumerateType(Type *T);

296 void EnumerateOperandType(const Value *V);

297 void EnumerateAttributes(AttributeList PAL);

298

300 void EnumerateNamedMetadata(const Module &M);

301};

302

303}

304

305#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file contains the simple types necessary to represent the attributes associated with functions a...

This file defines the DenseMap class.

Machine Check Debug Module

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

LLVM Basic Block Representation.

List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.

DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator

A Module instance is used to store all the information related to an LLVM module.

The instances of the Type class are immutable: once they are created, they are never changed.

UniqueVector - This class produces a sequential ID number (base 1) for each unique entry that is adde...

std::vector< std::pair< const Value *, unsigned > > ValueList

Definition ValueEnumerator.h:48

unsigned getTypeID(Type *T) const

Definition ValueEnumerator.h:166

unsigned getMetadataID(const Metadata *MD) const

Definition ValueEnumerator.h:152

UseListOrderStack UseListOrders

Definition ValueEnumerator.h:54

void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const

ArrayRef< const Metadata * > getNonMDStrings() const

Get the non-MDString metadata for this block.

Definition ValueEnumerator.h:208

unsigned getInstructionID(const Instruction *I) const

unsigned getAttributeListID(AttributeList PAL) const

Definition ValueEnumerator.h:175

void incorporateFunction(const Function &F)

incorporateFunction/purgeFunction - If you'd like to deal with a function, use these two methods to g...

void getFunctionConstantRange(unsigned &Start, unsigned &End) const

getFunctionConstantRange - Return the range of values that corresponds to function-local constants.

Definition ValueEnumerator.h:192

unsigned getAttributeGroupID(IndexAndAttrSet Group) const

Definition ValueEnumerator.h:182

bool hasMDs() const

Check whether the current block has any metadata to emit.

Definition ValueEnumerator.h:200

ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder)

unsigned getComdatID(const Comdat *C) const

uint64_t computeBitsRequiredForTypeIndices() const

ValueEnumerator(const ValueEnumerator &)=delete

unsigned getValueID(const Value *V) const

unsigned getMetadataOrNullID(const Metadata *MD) const

Definition ValueEnumerator.h:158

const std::vector< IndexAndAttrSet > & getAttributeGroups() const

Definition ValueEnumerator.h:220

const ValueList & getValues() const

Definition ValueEnumerator.h:197

unsigned getGlobalBasicBlockID(const BasicBlock *BB) const

getGlobalBasicBlockID - This returns the function-specific ID for the specified basic block.

void setInstructionID(const Instruction *I)

const std::vector< const BasicBlock * > & getBasicBlocks() const

Definition ValueEnumerator.h:214

unsigned numMDs() const

Definition ValueEnumerator.h:162

const std::vector< AttributeList > & getAttributeLists() const

Definition ValueEnumerator.h:218

ValueEnumerator & operator=(const ValueEnumerator &)=delete

bool shouldPreserveUseListOrder() const

Definition ValueEnumerator.h:164

const ComdatSetType & getComdats() const

Definition ValueEnumerator.h:224

std::vector< Type * > TypeList

Definition ValueEnumerator.h:45

ArrayRef< const Metadata * > getMDStrings() const

Get the MDString metadata for this block.

Definition ValueEnumerator.h:203

std::pair< unsigned, AttributeSet > IndexAndAttrSet

Attribute groups as encoded in bitcode are almost AttributeSets, but they include the AttributeList i...

Definition ValueEnumerator.h:52

const TypeList & getTypes() const

Definition ValueEnumerator.h:212

This class provides a symbol table of name/value pairs.

LLVM Value Representation.

This class implements an extremely fast bulk output stream that can only output to a stream.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)

std::vector< UseListOrder > UseListOrderStack

@ First

Helpers to iterate all locations in the MemoryEffectsBase class.

ArrayRef(const T &OneElt) -> ArrayRef< T >