LLVMContextImpl.h 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file declares LLVMContextImpl, the opaque implementation
  10. // of LLVMContext.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
  14. #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
  15. #include "ConstantsContext.h"
  16. #include "llvm/ADT/APFloat.h"
  17. #include "llvm/ADT/APInt.h"
  18. #include "llvm/ADT/ArrayRef.h"
  19. #include "llvm/ADT/DenseMap.h"
  20. #include "llvm/ADT/DenseMapInfo.h"
  21. #include "llvm/ADT/DenseSet.h"
  22. #include "llvm/ADT/FoldingSet.h"
  23. #include "llvm/ADT/Hashing.h"
  24. #include "llvm/ADT/Optional.h"
  25. #include "llvm/ADT/STLExtras.h"
  26. #include "llvm/ADT/SmallPtrSet.h"
  27. #include "llvm/ADT/SmallVector.h"
  28. #include "llvm/ADT/StringMap.h"
  29. #include "llvm/BinaryFormat/Dwarf.h"
  30. #include "llvm/IR/Constants.h"
  31. #include "llvm/IR/DebugInfoMetadata.h"
  32. #include "llvm/IR/DerivedTypes.h"
  33. #include "llvm/IR/LLVMContext.h"
  34. #include "llvm/IR/Metadata.h"
  35. #include "llvm/IR/Module.h"
  36. #include "llvm/IR/TrackingMDRef.h"
  37. #include "llvm/IR/Type.h"
  38. #include "llvm/IR/Value.h"
  39. #include "llvm/Support/Allocator.h"
  40. #include "llvm/Support/Casting.h"
  41. #include "llvm/Support/StringSaver.h"
  42. #include <algorithm>
  43. #include <cassert>
  44. #include <cstddef>
  45. #include <cstdint>
  46. #include <memory>
  47. #include <string>
  48. #include <utility>
  49. #include <vector>
  50. namespace llvm {
  51. class AttributeImpl;
  52. class AttributeListImpl;
  53. class AttributeSetNode;
  54. class BasicBlock;
  55. struct DiagnosticHandler;
  56. class ElementCount;
  57. class Function;
  58. class GlobalObject;
  59. class GlobalValue;
  60. class InlineAsm;
  61. class LLVMRemarkStreamer;
  62. class OptPassGate;
  63. namespace remarks {
  64. class RemarkStreamer;
  65. }
  66. template <typename T> class StringMapEntry;
  67. class StringRef;
  68. class ValueHandleBase;
  69. using DenseMapAPIntKeyInfo = DenseMapInfo<APInt>;
  70. struct DenseMapAPFloatKeyInfo {
  71. static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
  72. static inline APFloat getTombstoneKey() {
  73. return APFloat(APFloat::Bogus(), 2);
  74. }
  75. static unsigned getHashValue(const APFloat &Key) {
  76. return static_cast<unsigned>(hash_value(Key));
  77. }
  78. static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
  79. return LHS.bitwiseIsEqual(RHS);
  80. }
  81. };
  82. struct AnonStructTypeKeyInfo {
  83. struct KeyTy {
  84. ArrayRef<Type *> ETypes;
  85. bool isPacked;
  86. KeyTy(const ArrayRef<Type *> &E, bool P) : ETypes(E), isPacked(P) {}
  87. KeyTy(const StructType *ST)
  88. : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
  89. bool operator==(const KeyTy &that) const {
  90. if (isPacked != that.isPacked)
  91. return false;
  92. if (ETypes != that.ETypes)
  93. return false;
  94. return true;
  95. }
  96. bool operator!=(const KeyTy &that) const { return !this->operator==(that); }
  97. };
  98. static inline StructType *getEmptyKey() {
  99. return DenseMapInfo<StructType *>::getEmptyKey();
  100. }
  101. static inline StructType *getTombstoneKey() {
  102. return DenseMapInfo<StructType *>::getTombstoneKey();
  103. }
  104. static unsigned getHashValue(const KeyTy &Key) {
  105. return hash_combine(
  106. hash_combine_range(Key.ETypes.begin(), Key.ETypes.end()), Key.isPacked);
  107. }
  108. static unsigned getHashValue(const StructType *ST) {
  109. return getHashValue(KeyTy(ST));
  110. }
  111. static bool isEqual(const KeyTy &LHS, const StructType *RHS) {
  112. if (RHS == getEmptyKey() || RHS == getTombstoneKey())
  113. return false;
  114. return LHS == KeyTy(RHS);
  115. }
  116. static bool isEqual(const StructType *LHS, const StructType *RHS) {
  117. return LHS == RHS;
  118. }
  119. };
  120. struct FunctionTypeKeyInfo {
  121. struct KeyTy {
  122. const Type *ReturnType;
  123. ArrayRef<Type *> Params;
  124. bool isVarArg;
  125. KeyTy(const Type *R, const ArrayRef<Type *> &P, bool V)
  126. : ReturnType(R), Params(P), isVarArg(V) {}
  127. KeyTy(const FunctionType *FT)
  128. : ReturnType(FT->getReturnType()), Params(FT->params()),
  129. isVarArg(FT->isVarArg()) {}
  130. bool operator==(const KeyTy &that) const {
  131. if (ReturnType != that.ReturnType)
  132. return false;
  133. if (isVarArg != that.isVarArg)
  134. return false;
  135. if (Params != that.Params)
  136. return false;
  137. return true;
  138. }
  139. bool operator!=(const KeyTy &that) const { return !this->operator==(that); }
  140. };
  141. static inline FunctionType *getEmptyKey() {
  142. return DenseMapInfo<FunctionType *>::getEmptyKey();
  143. }
  144. static inline FunctionType *getTombstoneKey() {
  145. return DenseMapInfo<FunctionType *>::getTombstoneKey();
  146. }
  147. static unsigned getHashValue(const KeyTy &Key) {
  148. return hash_combine(
  149. Key.ReturnType,
  150. hash_combine_range(Key.Params.begin(), Key.Params.end()), Key.isVarArg);
  151. }
  152. static unsigned getHashValue(const FunctionType *FT) {
  153. return getHashValue(KeyTy(FT));
  154. }
  155. static bool isEqual(const KeyTy &LHS, const FunctionType *RHS) {
  156. if (RHS == getEmptyKey() || RHS == getTombstoneKey())
  157. return false;
  158. return LHS == KeyTy(RHS);
  159. }
  160. static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
  161. return LHS == RHS;
  162. }
  163. };
  164. /// Structure for hashing arbitrary MDNode operands.
  165. class MDNodeOpsKey {
  166. ArrayRef<Metadata *> RawOps;
  167. ArrayRef<MDOperand> Ops;
  168. unsigned Hash;
  169. protected:
  170. MDNodeOpsKey(ArrayRef<Metadata *> Ops)
  171. : RawOps(Ops), Hash(calculateHash(Ops)) {}
  172. template <class NodeTy>
  173. MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
  174. : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
  175. template <class NodeTy>
  176. bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
  177. if (getHash() != RHS->getHash())
  178. return false;
  179. assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
  180. return RawOps.empty() ? compareOps(Ops, RHS, Offset)
  181. : compareOps(RawOps, RHS, Offset);
  182. }
  183. static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
  184. private:
  185. template <class T>
  186. static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
  187. if (Ops.size() != RHS->getNumOperands() - Offset)
  188. return false;
  189. return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
  190. }
  191. static unsigned calculateHash(ArrayRef<Metadata *> Ops);
  192. public:
  193. unsigned getHash() const { return Hash; }
  194. };
  195. template <class NodeTy> struct MDNodeKeyImpl;
  196. /// Configuration point for MDNodeInfo::isEqual().
  197. template <class NodeTy> struct MDNodeSubsetEqualImpl {
  198. using KeyTy = MDNodeKeyImpl<NodeTy>;
  199. static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
  200. return false;
  201. }
  202. static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
  203. return false;
  204. }
  205. };
  206. /// DenseMapInfo for MDTuple.
  207. ///
  208. /// Note that we don't need the is-function-local bit, since that's implicit in
  209. /// the operands.
  210. template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
  211. MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
  212. MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
  213. bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
  214. unsigned getHashValue() const { return getHash(); }
  215. static unsigned calculateHash(MDTuple *N) {
  216. return MDNodeOpsKey::calculateHash(N);
  217. }
  218. };
  219. /// DenseMapInfo for DILocation.
  220. template <> struct MDNodeKeyImpl<DILocation> {
  221. unsigned Line;
  222. unsigned Column;
  223. Metadata *Scope;
  224. Metadata *InlinedAt;
  225. bool ImplicitCode;
  226. MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
  227. Metadata *InlinedAt, bool ImplicitCode)
  228. : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
  229. ImplicitCode(ImplicitCode) {}
  230. MDNodeKeyImpl(const DILocation *L)
  231. : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
  232. InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
  233. bool isKeyOf(const DILocation *RHS) const {
  234. return Line == RHS->getLine() && Column == RHS->getColumn() &&
  235. Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
  236. ImplicitCode == RHS->isImplicitCode();
  237. }
  238. unsigned getHashValue() const {
  239. return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
  240. }
  241. };
  242. /// DenseMapInfo for GenericDINode.
  243. template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
  244. unsigned Tag;
  245. MDString *Header;
  246. MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
  247. : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
  248. MDNodeKeyImpl(const GenericDINode *N)
  249. : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
  250. bool isKeyOf(const GenericDINode *RHS) const {
  251. return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
  252. compareOps(RHS, 1);
  253. }
  254. unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
  255. static unsigned calculateHash(GenericDINode *N) {
  256. return MDNodeOpsKey::calculateHash(N, 1);
  257. }
  258. };
  259. template <> struct MDNodeKeyImpl<DISubrange> {
  260. Metadata *CountNode;
  261. Metadata *LowerBound;
  262. Metadata *UpperBound;
  263. Metadata *Stride;
  264. MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound,
  265. Metadata *Stride)
  266. : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound),
  267. Stride(Stride) {}
  268. MDNodeKeyImpl(const DISubrange *N)
  269. : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()),
  270. UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {}
  271. bool isKeyOf(const DISubrange *RHS) const {
  272. auto BoundsEqual = [=](Metadata *Node1, Metadata *Node2) -> bool {
  273. if (Node1 == Node2)
  274. return true;
  275. ConstantAsMetadata *MD1 = dyn_cast_or_null<ConstantAsMetadata>(Node1);
  276. ConstantAsMetadata *MD2 = dyn_cast_or_null<ConstantAsMetadata>(Node2);
  277. if (MD1 && MD2) {
  278. ConstantInt *CV1 = cast<ConstantInt>(MD1->getValue());
  279. ConstantInt *CV2 = cast<ConstantInt>(MD2->getValue());
  280. if (CV1->getSExtValue() == CV2->getSExtValue())
  281. return true;
  282. }
  283. return false;
  284. };
  285. return BoundsEqual(CountNode, RHS->getRawCountNode()) &&
  286. BoundsEqual(LowerBound, RHS->getRawLowerBound()) &&
  287. BoundsEqual(UpperBound, RHS->getRawUpperBound()) &&
  288. BoundsEqual(Stride, RHS->getRawStride());
  289. }
  290. unsigned getHashValue() const {
  291. if (CountNode)
  292. if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
  293. return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
  294. LowerBound, UpperBound, Stride);
  295. return hash_combine(CountNode, LowerBound, UpperBound, Stride);
  296. }
  297. };
  298. template <> struct MDNodeKeyImpl<DIGenericSubrange> {
  299. Metadata *CountNode;
  300. Metadata *LowerBound;
  301. Metadata *UpperBound;
  302. Metadata *Stride;
  303. MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound,
  304. Metadata *Stride)
  305. : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound),
  306. Stride(Stride) {}
  307. MDNodeKeyImpl(const DIGenericSubrange *N)
  308. : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()),
  309. UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {}
  310. bool isKeyOf(const DIGenericSubrange *RHS) const {
  311. return (CountNode == RHS->getRawCountNode()) &&
  312. (LowerBound == RHS->getRawLowerBound()) &&
  313. (UpperBound == RHS->getRawUpperBound()) &&
  314. (Stride == RHS->getRawStride());
  315. }
  316. unsigned getHashValue() const {
  317. auto *MD = dyn_cast_or_null<ConstantAsMetadata>(CountNode);
  318. if (CountNode && MD)
  319. return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
  320. LowerBound, UpperBound, Stride);
  321. return hash_combine(CountNode, LowerBound, UpperBound, Stride);
  322. }
  323. };
  324. template <> struct MDNodeKeyImpl<DIEnumerator> {
  325. APInt Value;
  326. MDString *Name;
  327. bool IsUnsigned;
  328. MDNodeKeyImpl(APInt Value, bool IsUnsigned, MDString *Name)
  329. : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
  330. MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
  331. : Value(APInt(64, Value, !IsUnsigned)), Name(Name),
  332. IsUnsigned(IsUnsigned) {}
  333. MDNodeKeyImpl(const DIEnumerator *N)
  334. : Value(N->getValue()), Name(N->getRawName()),
  335. IsUnsigned(N->isUnsigned()) {}
  336. bool isKeyOf(const DIEnumerator *RHS) const {
  337. return Value.getBitWidth() == RHS->getValue().getBitWidth() &&
  338. Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
  339. Name == RHS->getRawName();
  340. }
  341. unsigned getHashValue() const { return hash_combine(Value, Name); }
  342. };
  343. template <> struct MDNodeKeyImpl<DIBasicType> {
  344. unsigned Tag;
  345. MDString *Name;
  346. uint64_t SizeInBits;
  347. uint32_t AlignInBits;
  348. unsigned Encoding;
  349. unsigned Flags;
  350. MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
  351. uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
  352. : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
  353. Encoding(Encoding), Flags(Flags) {}
  354. MDNodeKeyImpl(const DIBasicType *N)
  355. : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
  356. AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()),
  357. Flags(N->getFlags()) {}
  358. bool isKeyOf(const DIBasicType *RHS) const {
  359. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  360. SizeInBits == RHS->getSizeInBits() &&
  361. AlignInBits == RHS->getAlignInBits() &&
  362. Encoding == RHS->getEncoding() && Flags == RHS->getFlags();
  363. }
  364. unsigned getHashValue() const {
  365. return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
  366. }
  367. };
  368. template <> struct MDNodeKeyImpl<DIStringType> {
  369. unsigned Tag;
  370. MDString *Name;
  371. Metadata *StringLength;
  372. Metadata *StringLengthExp;
  373. Metadata *StringLocationExp;
  374. uint64_t SizeInBits;
  375. uint32_t AlignInBits;
  376. unsigned Encoding;
  377. MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *StringLength,
  378. Metadata *StringLengthExp, Metadata *StringLocationExp,
  379. uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding)
  380. : Tag(Tag), Name(Name), StringLength(StringLength),
  381. StringLengthExp(StringLengthExp), StringLocationExp(StringLocationExp),
  382. SizeInBits(SizeInBits), AlignInBits(AlignInBits), Encoding(Encoding) {}
  383. MDNodeKeyImpl(const DIStringType *N)
  384. : Tag(N->getTag()), Name(N->getRawName()),
  385. StringLength(N->getRawStringLength()),
  386. StringLengthExp(N->getRawStringLengthExp()),
  387. StringLocationExp(N->getRawStringLocationExp()),
  388. SizeInBits(N->getSizeInBits()), AlignInBits(N->getAlignInBits()),
  389. Encoding(N->getEncoding()) {}
  390. bool isKeyOf(const DIStringType *RHS) const {
  391. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  392. SizeInBits == RHS->getSizeInBits() &&
  393. AlignInBits == RHS->getAlignInBits() &&
  394. Encoding == RHS->getEncoding();
  395. }
  396. unsigned getHashValue() const { return hash_combine(Tag, Name, Encoding); }
  397. };
  398. template <> struct MDNodeKeyImpl<DIDerivedType> {
  399. unsigned Tag;
  400. MDString *Name;
  401. Metadata *File;
  402. unsigned Line;
  403. Metadata *Scope;
  404. Metadata *BaseType;
  405. uint64_t SizeInBits;
  406. uint64_t OffsetInBits;
  407. uint32_t AlignInBits;
  408. Optional<unsigned> DWARFAddressSpace;
  409. unsigned Flags;
  410. Metadata *ExtraData;
  411. Metadata *Annotations;
  412. MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
  413. Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
  414. uint32_t AlignInBits, uint64_t OffsetInBits,
  415. Optional<unsigned> DWARFAddressSpace, unsigned Flags,
  416. Metadata *ExtraData, Metadata *Annotations)
  417. : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
  418. BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
  419. AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
  420. Flags(Flags), ExtraData(ExtraData), Annotations(Annotations) {}
  421. MDNodeKeyImpl(const DIDerivedType *N)
  422. : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
  423. Line(N->getLine()), Scope(N->getRawScope()),
  424. BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
  425. OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
  426. DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
  427. ExtraData(N->getRawExtraData()), Annotations(N->getRawAnnotations()) {}
  428. bool isKeyOf(const DIDerivedType *RHS) const {
  429. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  430. File == RHS->getRawFile() && Line == RHS->getLine() &&
  431. Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
  432. SizeInBits == RHS->getSizeInBits() &&
  433. AlignInBits == RHS->getAlignInBits() &&
  434. OffsetInBits == RHS->getOffsetInBits() &&
  435. DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
  436. Flags == RHS->getFlags() && ExtraData == RHS->getRawExtraData() &&
  437. Annotations == RHS->getRawAnnotations();
  438. }
  439. unsigned getHashValue() const {
  440. // If this is a member inside an ODR type, only hash the type and the name.
  441. // Otherwise the hash will be stronger than
  442. // MDNodeSubsetEqualImpl::isODRMember().
  443. if (Tag == dwarf::DW_TAG_member && Name)
  444. if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
  445. if (CT->getRawIdentifier())
  446. return hash_combine(Name, Scope);
  447. // Intentionally computes the hash on a subset of the operands for
  448. // performance reason. The subset has to be significant enough to avoid
  449. // collision "most of the time". There is no correctness issue in case of
  450. // collision because of the full check above.
  451. return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
  452. }
  453. };
  454. template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
  455. using KeyTy = MDNodeKeyImpl<DIDerivedType>;
  456. static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
  457. return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
  458. }
  459. static bool isSubsetEqual(const DIDerivedType *LHS,
  460. const DIDerivedType *RHS) {
  461. return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
  462. RHS);
  463. }
  464. /// Subprograms compare equal if they declare the same function in an ODR
  465. /// type.
  466. static bool isODRMember(unsigned Tag, const Metadata *Scope,
  467. const MDString *Name, const DIDerivedType *RHS) {
  468. // Check whether the LHS is eligible.
  469. if (Tag != dwarf::DW_TAG_member || !Name)
  470. return false;
  471. auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
  472. if (!CT || !CT->getRawIdentifier())
  473. return false;
  474. // Compare to the RHS.
  475. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  476. Scope == RHS->getRawScope();
  477. }
  478. };
  479. template <> struct MDNodeKeyImpl<DICompositeType> {
  480. unsigned Tag;
  481. MDString *Name;
  482. Metadata *File;
  483. unsigned Line;
  484. Metadata *Scope;
  485. Metadata *BaseType;
  486. uint64_t SizeInBits;
  487. uint64_t OffsetInBits;
  488. uint32_t AlignInBits;
  489. unsigned Flags;
  490. Metadata *Elements;
  491. unsigned RuntimeLang;
  492. Metadata *VTableHolder;
  493. Metadata *TemplateParams;
  494. MDString *Identifier;
  495. Metadata *Discriminator;
  496. Metadata *DataLocation;
  497. Metadata *Associated;
  498. Metadata *Allocated;
  499. Metadata *Rank;
  500. Metadata *Annotations;
  501. MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
  502. Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
  503. uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
  504. Metadata *Elements, unsigned RuntimeLang,
  505. Metadata *VTableHolder, Metadata *TemplateParams,
  506. MDString *Identifier, Metadata *Discriminator,
  507. Metadata *DataLocation, Metadata *Associated,
  508. Metadata *Allocated, Metadata *Rank, Metadata *Annotations)
  509. : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
  510. BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
  511. AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
  512. RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
  513. TemplateParams(TemplateParams), Identifier(Identifier),
  514. Discriminator(Discriminator), DataLocation(DataLocation),
  515. Associated(Associated), Allocated(Allocated), Rank(Rank),
  516. Annotations(Annotations) {}
  517. MDNodeKeyImpl(const DICompositeType *N)
  518. : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
  519. Line(N->getLine()), Scope(N->getRawScope()),
  520. BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
  521. OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
  522. Flags(N->getFlags()), Elements(N->getRawElements()),
  523. RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
  524. TemplateParams(N->getRawTemplateParams()),
  525. Identifier(N->getRawIdentifier()),
  526. Discriminator(N->getRawDiscriminator()),
  527. DataLocation(N->getRawDataLocation()),
  528. Associated(N->getRawAssociated()), Allocated(N->getRawAllocated()),
  529. Rank(N->getRawRank()), Annotations(N->getRawAnnotations()) {}
  530. bool isKeyOf(const DICompositeType *RHS) const {
  531. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  532. File == RHS->getRawFile() && Line == RHS->getLine() &&
  533. Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
  534. SizeInBits == RHS->getSizeInBits() &&
  535. AlignInBits == RHS->getAlignInBits() &&
  536. OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
  537. Elements == RHS->getRawElements() &&
  538. RuntimeLang == RHS->getRuntimeLang() &&
  539. VTableHolder == RHS->getRawVTableHolder() &&
  540. TemplateParams == RHS->getRawTemplateParams() &&
  541. Identifier == RHS->getRawIdentifier() &&
  542. Discriminator == RHS->getRawDiscriminator() &&
  543. DataLocation == RHS->getRawDataLocation() &&
  544. Associated == RHS->getRawAssociated() &&
  545. Allocated == RHS->getRawAllocated() && Rank == RHS->getRawRank() &&
  546. Annotations == RHS->getRawAnnotations();
  547. }
  548. unsigned getHashValue() const {
  549. // Intentionally computes the hash on a subset of the operands for
  550. // performance reason. The subset has to be significant enough to avoid
  551. // collision "most of the time". There is no correctness issue in case of
  552. // collision because of the full check above.
  553. return hash_combine(Name, File, Line, BaseType, Scope, Elements,
  554. TemplateParams, Annotations);
  555. }
  556. };
  557. template <> struct MDNodeKeyImpl<DISubroutineType> {
  558. unsigned Flags;
  559. uint8_t CC;
  560. Metadata *TypeArray;
  561. MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
  562. : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
  563. MDNodeKeyImpl(const DISubroutineType *N)
  564. : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
  565. bool isKeyOf(const DISubroutineType *RHS) const {
  566. return Flags == RHS->getFlags() && CC == RHS->getCC() &&
  567. TypeArray == RHS->getRawTypeArray();
  568. }
  569. unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
  570. };
  571. template <> struct MDNodeKeyImpl<DIFile> {
  572. MDString *Filename;
  573. MDString *Directory;
  574. Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
  575. Optional<MDString *> Source;
  576. MDNodeKeyImpl(MDString *Filename, MDString *Directory,
  577. Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
  578. Optional<MDString *> Source)
  579. : Filename(Filename), Directory(Directory), Checksum(Checksum),
  580. Source(Source) {}
  581. MDNodeKeyImpl(const DIFile *N)
  582. : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
  583. Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
  584. bool isKeyOf(const DIFile *RHS) const {
  585. return Filename == RHS->getRawFilename() &&
  586. Directory == RHS->getRawDirectory() &&
  587. Checksum == RHS->getRawChecksum() && Source == RHS->getRawSource();
  588. }
  589. unsigned getHashValue() const {
  590. return hash_combine(Filename, Directory, Checksum ? Checksum->Kind : 0,
  591. Checksum ? Checksum->Value : nullptr,
  592. Source.getValueOr(nullptr));
  593. }
  594. };
  595. template <> struct MDNodeKeyImpl<DISubprogram> {
  596. Metadata *Scope;
  597. MDString *Name;
  598. MDString *LinkageName;
  599. Metadata *File;
  600. unsigned Line;
  601. Metadata *Type;
  602. unsigned ScopeLine;
  603. Metadata *ContainingType;
  604. unsigned VirtualIndex;
  605. int ThisAdjustment;
  606. unsigned Flags;
  607. unsigned SPFlags;
  608. Metadata *Unit;
  609. Metadata *TemplateParams;
  610. Metadata *Declaration;
  611. Metadata *RetainedNodes;
  612. Metadata *ThrownTypes;
  613. Metadata *Annotations;
  614. MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
  615. Metadata *File, unsigned Line, Metadata *Type,
  616. unsigned ScopeLine, Metadata *ContainingType,
  617. unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
  618. unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
  619. Metadata *Declaration, Metadata *RetainedNodes,
  620. Metadata *ThrownTypes, Metadata *Annotations)
  621. : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
  622. Line(Line), Type(Type), ScopeLine(ScopeLine),
  623. ContainingType(ContainingType), VirtualIndex(VirtualIndex),
  624. ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
  625. Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
  626. RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes),
  627. Annotations(Annotations) {}
  628. MDNodeKeyImpl(const DISubprogram *N)
  629. : Scope(N->getRawScope()), Name(N->getRawName()),
  630. LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
  631. Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()),
  632. ContainingType(N->getRawContainingType()),
  633. VirtualIndex(N->getVirtualIndex()),
  634. ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
  635. SPFlags(N->getSPFlags()), Unit(N->getRawUnit()),
  636. TemplateParams(N->getRawTemplateParams()),
  637. Declaration(N->getRawDeclaration()),
  638. RetainedNodes(N->getRawRetainedNodes()),
  639. ThrownTypes(N->getRawThrownTypes()),
  640. Annotations(N->getRawAnnotations()) {}
  641. bool isKeyOf(const DISubprogram *RHS) const {
  642. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  643. LinkageName == RHS->getRawLinkageName() &&
  644. File == RHS->getRawFile() && Line == RHS->getLine() &&
  645. Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() &&
  646. ContainingType == RHS->getRawContainingType() &&
  647. VirtualIndex == RHS->getVirtualIndex() &&
  648. ThisAdjustment == RHS->getThisAdjustment() &&
  649. Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() &&
  650. Unit == RHS->getUnit() &&
  651. TemplateParams == RHS->getRawTemplateParams() &&
  652. Declaration == RHS->getRawDeclaration() &&
  653. RetainedNodes == RHS->getRawRetainedNodes() &&
  654. ThrownTypes == RHS->getRawThrownTypes() &&
  655. Annotations == RHS->getRawAnnotations();
  656. }
  657. bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
  658. unsigned getHashValue() const {
  659. // If this is a declaration inside an ODR type, only hash the type and the
  660. // name. Otherwise the hash will be stronger than
  661. // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
  662. if (!isDefinition() && LinkageName)
  663. if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
  664. if (CT->getRawIdentifier())
  665. return hash_combine(LinkageName, Scope);
  666. // Intentionally computes the hash on a subset of the operands for
  667. // performance reason. The subset has to be significant enough to avoid
  668. // collision "most of the time". There is no correctness issue in case of
  669. // collision because of the full check above.
  670. return hash_combine(Name, Scope, File, Type, Line);
  671. }
  672. };
  673. template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
  674. using KeyTy = MDNodeKeyImpl<DISubprogram>;
  675. static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
  676. return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope,
  677. LHS.LinkageName, LHS.TemplateParams, RHS);
  678. }
  679. static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
  680. return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
  681. LHS->getRawLinkageName(),
  682. LHS->getRawTemplateParams(), RHS);
  683. }
  684. /// Subprograms compare equal if they declare the same function in an ODR
  685. /// type.
  686. static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
  687. const MDString *LinkageName,
  688. const Metadata *TemplateParams,
  689. const DISubprogram *RHS) {
  690. // Check whether the LHS is eligible.
  691. if (IsDefinition || !Scope || !LinkageName)
  692. return false;
  693. auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
  694. if (!CT || !CT->getRawIdentifier())
  695. return false;
  696. // Compare to the RHS.
  697. // FIXME: We need to compare template parameters here to avoid incorrect
  698. // collisions in mapMetadata when RF_ReuseAndMutateDistinctMDs and a
  699. // ODR-DISubprogram has a non-ODR template parameter (i.e., a
  700. // DICompositeType that does not have an identifier). Eventually we should
  701. // decouple ODR logic from uniquing logic.
  702. return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
  703. LinkageName == RHS->getRawLinkageName() &&
  704. TemplateParams == RHS->getRawTemplateParams();
  705. }
  706. };
  707. template <> struct MDNodeKeyImpl<DILexicalBlock> {
  708. Metadata *Scope;
  709. Metadata *File;
  710. unsigned Line;
  711. unsigned Column;
  712. MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
  713. : Scope(Scope), File(File), Line(Line), Column(Column) {}
  714. MDNodeKeyImpl(const DILexicalBlock *N)
  715. : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
  716. Column(N->getColumn()) {}
  717. bool isKeyOf(const DILexicalBlock *RHS) const {
  718. return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
  719. Line == RHS->getLine() && Column == RHS->getColumn();
  720. }
  721. unsigned getHashValue() const {
  722. return hash_combine(Scope, File, Line, Column);
  723. }
  724. };
  725. template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
  726. Metadata *Scope;
  727. Metadata *File;
  728. unsigned Discriminator;
  729. MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
  730. : Scope(Scope), File(File), Discriminator(Discriminator) {}
  731. MDNodeKeyImpl(const DILexicalBlockFile *N)
  732. : Scope(N->getRawScope()), File(N->getRawFile()),
  733. Discriminator(N->getDiscriminator()) {}
  734. bool isKeyOf(const DILexicalBlockFile *RHS) const {
  735. return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
  736. Discriminator == RHS->getDiscriminator();
  737. }
  738. unsigned getHashValue() const {
  739. return hash_combine(Scope, File, Discriminator);
  740. }
  741. };
  742. template <> struct MDNodeKeyImpl<DINamespace> {
  743. Metadata *Scope;
  744. MDString *Name;
  745. bool ExportSymbols;
  746. MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
  747. : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
  748. MDNodeKeyImpl(const DINamespace *N)
  749. : Scope(N->getRawScope()), Name(N->getRawName()),
  750. ExportSymbols(N->getExportSymbols()) {}
  751. bool isKeyOf(const DINamespace *RHS) const {
  752. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  753. ExportSymbols == RHS->getExportSymbols();
  754. }
  755. unsigned getHashValue() const { return hash_combine(Scope, Name); }
  756. };
  757. template <> struct MDNodeKeyImpl<DICommonBlock> {
  758. Metadata *Scope;
  759. Metadata *Decl;
  760. MDString *Name;
  761. Metadata *File;
  762. unsigned LineNo;
  763. MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name, Metadata *File,
  764. unsigned LineNo)
  765. : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {}
  766. MDNodeKeyImpl(const DICommonBlock *N)
  767. : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()),
  768. File(N->getRawFile()), LineNo(N->getLineNo()) {}
  769. bool isKeyOf(const DICommonBlock *RHS) const {
  770. return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() &&
  771. Name == RHS->getRawName() && File == RHS->getRawFile() &&
  772. LineNo == RHS->getLineNo();
  773. }
  774. unsigned getHashValue() const {
  775. return hash_combine(Scope, Decl, Name, File, LineNo);
  776. }
  777. };
  778. template <> struct MDNodeKeyImpl<DIModule> {
  779. Metadata *File;
  780. Metadata *Scope;
  781. MDString *Name;
  782. MDString *ConfigurationMacros;
  783. MDString *IncludePath;
  784. MDString *APINotesFile;
  785. unsigned LineNo;
  786. bool IsDecl;
  787. MDNodeKeyImpl(Metadata *File, Metadata *Scope, MDString *Name,
  788. MDString *ConfigurationMacros, MDString *IncludePath,
  789. MDString *APINotesFile, unsigned LineNo, bool IsDecl)
  790. : File(File), Scope(Scope), Name(Name),
  791. ConfigurationMacros(ConfigurationMacros), IncludePath(IncludePath),
  792. APINotesFile(APINotesFile), LineNo(LineNo), IsDecl(IsDecl) {}
  793. MDNodeKeyImpl(const DIModule *N)
  794. : File(N->getRawFile()), Scope(N->getRawScope()), Name(N->getRawName()),
  795. ConfigurationMacros(N->getRawConfigurationMacros()),
  796. IncludePath(N->getRawIncludePath()),
  797. APINotesFile(N->getRawAPINotesFile()), LineNo(N->getLineNo()),
  798. IsDecl(N->getIsDecl()) {}
  799. bool isKeyOf(const DIModule *RHS) const {
  800. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  801. ConfigurationMacros == RHS->getRawConfigurationMacros() &&
  802. IncludePath == RHS->getRawIncludePath() &&
  803. APINotesFile == RHS->getRawAPINotesFile() &&
  804. File == RHS->getRawFile() && LineNo == RHS->getLineNo() &&
  805. IsDecl == RHS->getIsDecl();
  806. }
  807. unsigned getHashValue() const {
  808. return hash_combine(Scope, Name, ConfigurationMacros, IncludePath);
  809. }
  810. };
  811. template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
  812. MDString *Name;
  813. Metadata *Type;
  814. bool IsDefault;
  815. MDNodeKeyImpl(MDString *Name, Metadata *Type, bool IsDefault)
  816. : Name(Name), Type(Type), IsDefault(IsDefault) {}
  817. MDNodeKeyImpl(const DITemplateTypeParameter *N)
  818. : Name(N->getRawName()), Type(N->getRawType()),
  819. IsDefault(N->isDefault()) {}
  820. bool isKeyOf(const DITemplateTypeParameter *RHS) const {
  821. return Name == RHS->getRawName() && Type == RHS->getRawType() &&
  822. IsDefault == RHS->isDefault();
  823. }
  824. unsigned getHashValue() const { return hash_combine(Name, Type, IsDefault); }
  825. };
  826. template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
  827. unsigned Tag;
  828. MDString *Name;
  829. Metadata *Type;
  830. bool IsDefault;
  831. Metadata *Value;
  832. MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, bool IsDefault,
  833. Metadata *Value)
  834. : Tag(Tag), Name(Name), Type(Type), IsDefault(IsDefault), Value(Value) {}
  835. MDNodeKeyImpl(const DITemplateValueParameter *N)
  836. : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
  837. IsDefault(N->isDefault()), Value(N->getValue()) {}
  838. bool isKeyOf(const DITemplateValueParameter *RHS) const {
  839. return Tag == RHS->getTag() && Name == RHS->getRawName() &&
  840. Type == RHS->getRawType() && IsDefault == RHS->isDefault() &&
  841. Value == RHS->getValue();
  842. }
  843. unsigned getHashValue() const {
  844. return hash_combine(Tag, Name, Type, IsDefault, Value);
  845. }
  846. };
  847. template <> struct MDNodeKeyImpl<DIGlobalVariable> {
  848. Metadata *Scope;
  849. MDString *Name;
  850. MDString *LinkageName;
  851. Metadata *File;
  852. unsigned Line;
  853. Metadata *Type;
  854. bool IsLocalToUnit;
  855. bool IsDefinition;
  856. Metadata *StaticDataMemberDeclaration;
  857. Metadata *TemplateParams;
  858. uint32_t AlignInBits;
  859. Metadata *Annotations;
  860. MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
  861. Metadata *File, unsigned Line, Metadata *Type,
  862. bool IsLocalToUnit, bool IsDefinition,
  863. Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
  864. uint32_t AlignInBits, Metadata *Annotations)
  865. : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
  866. Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
  867. IsDefinition(IsDefinition),
  868. StaticDataMemberDeclaration(StaticDataMemberDeclaration),
  869. TemplateParams(TemplateParams), AlignInBits(AlignInBits),
  870. Annotations(Annotations) {}
  871. MDNodeKeyImpl(const DIGlobalVariable *N)
  872. : Scope(N->getRawScope()), Name(N->getRawName()),
  873. LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
  874. Line(N->getLine()), Type(N->getRawType()),
  875. IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
  876. StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
  877. TemplateParams(N->getRawTemplateParams()),
  878. AlignInBits(N->getAlignInBits()), Annotations(N->getRawAnnotations()) {}
  879. bool isKeyOf(const DIGlobalVariable *RHS) const {
  880. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  881. LinkageName == RHS->getRawLinkageName() &&
  882. File == RHS->getRawFile() && Line == RHS->getLine() &&
  883. Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
  884. IsDefinition == RHS->isDefinition() &&
  885. StaticDataMemberDeclaration ==
  886. RHS->getRawStaticDataMemberDeclaration() &&
  887. TemplateParams == RHS->getRawTemplateParams() &&
  888. AlignInBits == RHS->getAlignInBits() &&
  889. Annotations == RHS->getRawAnnotations();
  890. }
  891. unsigned getHashValue() const {
  892. // We do not use AlignInBits in hashing function here on purpose:
  893. // in most cases this param for local variable is zero (for function param
  894. // it is always zero). This leads to lots of hash collisions and errors on
  895. // cases with lots of similar variables.
  896. // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
  897. // generated IR is random for each run and test fails with Align included.
  898. // TODO: make hashing work fine with such situations
  899. return hash_combine(Scope, Name, LinkageName, File, Line, Type,
  900. IsLocalToUnit, IsDefinition, /* AlignInBits, */
  901. StaticDataMemberDeclaration, Annotations);
  902. }
  903. };
  904. template <> struct MDNodeKeyImpl<DILocalVariable> {
  905. Metadata *Scope;
  906. MDString *Name;
  907. Metadata *File;
  908. unsigned Line;
  909. Metadata *Type;
  910. unsigned Arg;
  911. unsigned Flags;
  912. uint32_t AlignInBits;
  913. Metadata *Annotations;
  914. MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
  915. Metadata *Type, unsigned Arg, unsigned Flags,
  916. uint32_t AlignInBits, Metadata *Annotations)
  917. : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
  918. Flags(Flags), AlignInBits(AlignInBits), Annotations(Annotations) {}
  919. MDNodeKeyImpl(const DILocalVariable *N)
  920. : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
  921. Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
  922. Flags(N->getFlags()), AlignInBits(N->getAlignInBits()),
  923. Annotations(N->getRawAnnotations()) {}
  924. bool isKeyOf(const DILocalVariable *RHS) const {
  925. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  926. File == RHS->getRawFile() && Line == RHS->getLine() &&
  927. Type == RHS->getRawType() && Arg == RHS->getArg() &&
  928. Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits() &&
  929. Annotations == RHS->getRawAnnotations();
  930. }
  931. unsigned getHashValue() const {
  932. // We do not use AlignInBits in hashing function here on purpose:
  933. // in most cases this param for local variable is zero (for function param
  934. // it is always zero). This leads to lots of hash collisions and errors on
  935. // cases with lots of similar variables.
  936. // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
  937. // generated IR is random for each run and test fails with Align included.
  938. // TODO: make hashing work fine with such situations
  939. return hash_combine(Scope, Name, File, Line, Type, Arg, Flags, Annotations);
  940. }
  941. };
  942. template <> struct MDNodeKeyImpl<DILabel> {
  943. Metadata *Scope;
  944. MDString *Name;
  945. Metadata *File;
  946. unsigned Line;
  947. MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
  948. : Scope(Scope), Name(Name), File(File), Line(Line) {}
  949. MDNodeKeyImpl(const DILabel *N)
  950. : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
  951. Line(N->getLine()) {}
  952. bool isKeyOf(const DILabel *RHS) const {
  953. return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
  954. File == RHS->getRawFile() && Line == RHS->getLine();
  955. }
  956. /// Using name and line to get hash value. It should already be mostly unique.
  957. unsigned getHashValue() const { return hash_combine(Scope, Name, Line); }
  958. };
  959. template <> struct MDNodeKeyImpl<DIExpression> {
  960. ArrayRef<uint64_t> Elements;
  961. MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
  962. MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
  963. bool isKeyOf(const DIExpression *RHS) const {
  964. return Elements == RHS->getElements();
  965. }
  966. unsigned getHashValue() const {
  967. return hash_combine_range(Elements.begin(), Elements.end());
  968. }
  969. };
  970. template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
  971. Metadata *Variable;
  972. Metadata *Expression;
  973. MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
  974. : Variable(Variable), Expression(Expression) {}
  975. MDNodeKeyImpl(const DIGlobalVariableExpression *N)
  976. : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
  977. bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
  978. return Variable == RHS->getRawVariable() &&
  979. Expression == RHS->getRawExpression();
  980. }
  981. unsigned getHashValue() const { return hash_combine(Variable, Expression); }
  982. };
  983. template <> struct MDNodeKeyImpl<DIObjCProperty> {
  984. MDString *Name;
  985. Metadata *File;
  986. unsigned Line;
  987. MDString *GetterName;
  988. MDString *SetterName;
  989. unsigned Attributes;
  990. Metadata *Type;
  991. MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
  992. MDString *GetterName, MDString *SetterName, unsigned Attributes,
  993. Metadata *Type)
  994. : Name(Name), File(File), Line(Line), GetterName(GetterName),
  995. SetterName(SetterName), Attributes(Attributes), Type(Type) {}
  996. MDNodeKeyImpl(const DIObjCProperty *N)
  997. : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
  998. GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
  999. Attributes(N->getAttributes()), Type(N->getRawType()) {}
  1000. bool isKeyOf(const DIObjCProperty *RHS) const {
  1001. return Name == RHS->getRawName() && File == RHS->getRawFile() &&
  1002. Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
  1003. SetterName == RHS->getRawSetterName() &&
  1004. Attributes == RHS->getAttributes() && Type == RHS->getRawType();
  1005. }
  1006. unsigned getHashValue() const {
  1007. return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
  1008. Type);
  1009. }
  1010. };
  1011. template <> struct MDNodeKeyImpl<DIImportedEntity> {
  1012. unsigned Tag;
  1013. Metadata *Scope;
  1014. Metadata *Entity;
  1015. Metadata *File;
  1016. unsigned Line;
  1017. MDString *Name;
  1018. Metadata *Elements;
  1019. MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
  1020. unsigned Line, MDString *Name, Metadata *Elements)
  1021. : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
  1022. Name(Name), Elements(Elements) {}
  1023. MDNodeKeyImpl(const DIImportedEntity *N)
  1024. : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
  1025. File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()),
  1026. Elements(N->getRawElements()) {}
  1027. bool isKeyOf(const DIImportedEntity *RHS) const {
  1028. return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
  1029. Entity == RHS->getRawEntity() && File == RHS->getFile() &&
  1030. Line == RHS->getLine() && Name == RHS->getRawName() &&
  1031. Elements == RHS->getRawElements();
  1032. }
  1033. unsigned getHashValue() const {
  1034. return hash_combine(Tag, Scope, Entity, File, Line, Name, Elements);
  1035. }
  1036. };
  1037. template <> struct MDNodeKeyImpl<DIMacro> {
  1038. unsigned MIType;
  1039. unsigned Line;
  1040. MDString *Name;
  1041. MDString *Value;
  1042. MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
  1043. : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
  1044. MDNodeKeyImpl(const DIMacro *N)
  1045. : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
  1046. Value(N->getRawValue()) {}
  1047. bool isKeyOf(const DIMacro *RHS) const {
  1048. return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
  1049. Name == RHS->getRawName() && Value == RHS->getRawValue();
  1050. }
  1051. unsigned getHashValue() const {
  1052. return hash_combine(MIType, Line, Name, Value);
  1053. }
  1054. };
  1055. template <> struct MDNodeKeyImpl<DIMacroFile> {
  1056. unsigned MIType;
  1057. unsigned Line;
  1058. Metadata *File;
  1059. Metadata *Elements;
  1060. MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
  1061. Metadata *Elements)
  1062. : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
  1063. MDNodeKeyImpl(const DIMacroFile *N)
  1064. : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
  1065. Elements(N->getRawElements()) {}
  1066. bool isKeyOf(const DIMacroFile *RHS) const {
  1067. return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
  1068. File == RHS->getRawFile() && Elements == RHS->getRawElements();
  1069. }
  1070. unsigned getHashValue() const {
  1071. return hash_combine(MIType, Line, File, Elements);
  1072. }
  1073. };
  1074. template <> struct MDNodeKeyImpl<DIArgList> {
  1075. ArrayRef<ValueAsMetadata *> Args;
  1076. MDNodeKeyImpl(ArrayRef<ValueAsMetadata *> Args) : Args(Args) {}
  1077. MDNodeKeyImpl(const DIArgList *N) : Args(N->getArgs()) {}
  1078. bool isKeyOf(const DIArgList *RHS) const { return Args == RHS->getArgs(); }
  1079. unsigned getHashValue() const {
  1080. return hash_combine_range(Args.begin(), Args.end());
  1081. }
  1082. };
  1083. /// DenseMapInfo for MDNode subclasses.
  1084. template <class NodeTy> struct MDNodeInfo {
  1085. using KeyTy = MDNodeKeyImpl<NodeTy>;
  1086. using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
  1087. static inline NodeTy *getEmptyKey() {
  1088. return DenseMapInfo<NodeTy *>::getEmptyKey();
  1089. }
  1090. static inline NodeTy *getTombstoneKey() {
  1091. return DenseMapInfo<NodeTy *>::getTombstoneKey();
  1092. }
  1093. static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
  1094. static unsigned getHashValue(const NodeTy *N) {
  1095. return KeyTy(N).getHashValue();
  1096. }
  1097. static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
  1098. if (RHS == getEmptyKey() || RHS == getTombstoneKey())
  1099. return false;
  1100. return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
  1101. }
  1102. static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
  1103. if (LHS == RHS)
  1104. return true;
  1105. if (RHS == getEmptyKey() || RHS == getTombstoneKey())
  1106. return false;
  1107. return SubsetEqualTy::isSubsetEqual(LHS, RHS);
  1108. }
  1109. };
  1110. #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
  1111. #include "llvm/IR/Metadata.def"
  1112. /// Multimap-like storage for metadata attachments.
  1113. class MDAttachments {
  1114. public:
  1115. struct Attachment {
  1116. unsigned MDKind;
  1117. TrackingMDNodeRef Node;
  1118. };
  1119. private:
  1120. SmallVector<Attachment, 1> Attachments;
  1121. public:
  1122. bool empty() const { return Attachments.empty(); }
  1123. size_t size() const { return Attachments.size(); }
  1124. /// Returns the first attachment with the given ID or nullptr if no such
  1125. /// attachment exists.
  1126. MDNode *lookup(unsigned ID) const;
  1127. /// Appends all attachments with the given ID to \c Result in insertion order.
  1128. /// If the global has no attachments with the given ID, or if ID is invalid,
  1129. /// leaves Result unchanged.
  1130. void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
  1131. /// Appends all attachments for the global to \c Result, sorting by attachment
  1132. /// ID. Attachments with the same ID appear in insertion order. This function
  1133. /// does \em not clear \c Result.
  1134. void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
  1135. /// Set an attachment to a particular node.
  1136. ///
  1137. /// Set the \c ID attachment to \c MD, replacing the current attachments at \c
  1138. /// ID (if anyway).
  1139. void set(unsigned ID, MDNode *MD);
  1140. /// Adds an attachment to a particular node.
  1141. void insert(unsigned ID, MDNode &MD);
  1142. /// Remove attachments with the given ID.
  1143. ///
  1144. /// Remove the attachments at \c ID, if any.
  1145. bool erase(unsigned ID);
  1146. /// Erase matching attachments.
  1147. ///
  1148. /// Erases all attachments matching the \c shouldRemove predicate.
  1149. template <class PredTy> void remove_if(PredTy shouldRemove) {
  1150. llvm::erase_if(Attachments, shouldRemove);
  1151. }
  1152. };
  1153. class LLVMContextImpl {
  1154. public:
  1155. /// OwnedModules - The set of modules instantiated in this context, and which
  1156. /// will be automatically deleted if this context is deleted.
  1157. SmallPtrSet<Module *, 4> OwnedModules;
  1158. /// The main remark streamer used by all the other streamers (e.g. IR, MIR,
  1159. /// frontends, etc.). This should only be used by the specific streamers, and
  1160. /// never directly.
  1161. std::unique_ptr<remarks::RemarkStreamer> MainRemarkStreamer;
  1162. std::unique_ptr<DiagnosticHandler> DiagHandler;
  1163. bool RespectDiagnosticFilters = false;
  1164. bool DiagnosticsHotnessRequested = false;
  1165. /// The minimum hotness value a diagnostic needs in order to be included in
  1166. /// optimization diagnostics.
  1167. ///
  1168. /// The threshold is an Optional value, which maps to one of the 3 states:
  1169. /// 1). 0 => threshold disabled. All emarks will be printed.
  1170. /// 2). positive int => manual threshold by user. Remarks with hotness exceed
  1171. /// threshold will be printed.
  1172. /// 3). None => 'auto' threshold by user. The actual value is not
  1173. /// available at command line, but will be synced with
  1174. /// hotness threhold from profile summary during
  1175. /// compilation.
  1176. ///
  1177. /// State 1 and 2 are considered as terminal states. State transition is
  1178. /// only allowed from 3 to 2, when the threshold is first synced with profile
  1179. /// summary. This ensures that the threshold is set only once and stays
  1180. /// constant.
  1181. ///
  1182. /// If threshold option is not specified, it is disabled (0) by default.
  1183. Optional<uint64_t> DiagnosticsHotnessThreshold = 0;
  1184. /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter.
  1185. std::unique_ptr<LLVMRemarkStreamer> LLVMRS;
  1186. LLVMContext::YieldCallbackTy YieldCallback = nullptr;
  1187. void *YieldOpaqueHandle = nullptr;
  1188. using IntMapTy =
  1189. DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
  1190. IntMapTy IntConstants;
  1191. using FPMapTy =
  1192. DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
  1193. FPMapTy FPConstants;
  1194. FoldingSet<AttributeImpl> AttrsSet;
  1195. FoldingSet<AttributeListImpl> AttrsLists;
  1196. FoldingSet<AttributeSetNode> AttrsSetNodes;
  1197. StringMap<MDString, BumpPtrAllocator> MDStringCache;
  1198. DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
  1199. DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
  1200. DenseMap<const Value *, ValueName *> ValueNames;
  1201. #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
  1202. DenseSet<CLASS *, CLASS##Info> CLASS##s;
  1203. #include "llvm/IR/Metadata.def"
  1204. // Optional map for looking up composite types by identifier.
  1205. Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
  1206. // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
  1207. // aren't in the MDNodeSet, but they're still shared between objects, so no
  1208. // one object can destroy them. Keep track of them here so we can delete
  1209. // them on context teardown.
  1210. std::vector<MDNode *> DistinctMDNodes;
  1211. DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
  1212. using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
  1213. ArrayConstantsTy ArrayConstants;
  1214. using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
  1215. StructConstantsTy StructConstants;
  1216. using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
  1217. VectorConstantsTy VectorConstants;
  1218. DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
  1219. DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
  1220. DenseMap<Type *, std::unique_ptr<PoisonValue>> PVConstants;
  1221. StringMap<std::unique_ptr<ConstantDataSequential>> CDSConstants;
  1222. DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
  1223. BlockAddresses;
  1224. DenseMap<const GlobalValue *, DSOLocalEquivalent *> DSOLocalEquivalents;
  1225. DenseMap<const GlobalValue *, NoCFIValue *> NoCFIValues;
  1226. ConstantUniqueMap<ConstantExpr> ExprConstants;
  1227. ConstantUniqueMap<InlineAsm> InlineAsms;
  1228. ConstantInt *TheTrueVal = nullptr;
  1229. ConstantInt *TheFalseVal = nullptr;
  1230. std::unique_ptr<ConstantTokenNone> TheNoneToken;
  1231. // Basic type instances.
  1232. Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy,
  1233. TokenTy;
  1234. Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy;
  1235. IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
  1236. BumpPtrAllocator Alloc;
  1237. UniqueStringSaver Saver{Alloc};
  1238. DenseMap<unsigned, IntegerType *> IntegerTypes;
  1239. using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
  1240. FunctionTypeSet FunctionTypes;
  1241. using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
  1242. StructTypeSet AnonStructTypes;
  1243. StringMap<StructType *> NamedStructTypes;
  1244. unsigned NamedStructTypesUniqueID = 0;
  1245. DenseMap<std::pair<Type *, uint64_t>, ArrayType *> ArrayTypes;
  1246. DenseMap<std::pair<Type *, ElementCount>, VectorType *> VectorTypes;
  1247. DenseMap<Type *, PointerType *> PointerTypes; // Pointers in AddrSpace = 0
  1248. DenseMap<std::pair<Type *, unsigned>, PointerType *> ASPointerTypes;
  1249. /// ValueHandles - This map keeps track of all of the value handles that are
  1250. /// watching a Value*. The Value::HasValueHandle bit is used to know
  1251. /// whether or not a value has an entry in this map.
  1252. using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
  1253. ValueHandlesTy ValueHandles;
  1254. /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
  1255. StringMap<unsigned> CustomMDKindNames;
  1256. /// Collection of metadata used in this context.
  1257. DenseMap<const Value *, MDAttachments> ValueMetadata;
  1258. /// Collection of per-GlobalObject sections used in this context.
  1259. DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
  1260. /// Collection of per-GlobalValue partitions used in this context.
  1261. DenseMap<const GlobalValue *, StringRef> GlobalValuePartitions;
  1262. /// DiscriminatorTable - This table maps file:line locations to an
  1263. /// integer representing the next DWARF path discriminator to assign to
  1264. /// instructions in different blocks at the same location.
  1265. DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
  1266. /// A set of interned tags for operand bundles. The StringMap maps
  1267. /// bundle tags to their IDs.
  1268. ///
  1269. /// \see LLVMContext::getOperandBundleTagID
  1270. StringMap<uint32_t> BundleTagCache;
  1271. StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
  1272. void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
  1273. uint32_t getOperandBundleTagID(StringRef Tag) const;
  1274. /// A set of interned synchronization scopes. The StringMap maps
  1275. /// synchronization scope names to their respective synchronization scope IDs.
  1276. StringMap<SyncScope::ID> SSC;
  1277. /// getOrInsertSyncScopeID - Maps synchronization scope name to
  1278. /// synchronization scope ID. Every synchronization scope registered with
  1279. /// LLVMContext has unique ID except pre-defined ones.
  1280. SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
  1281. /// getSyncScopeNames - Populates client supplied SmallVector with
  1282. /// synchronization scope names registered with LLVMContext. Synchronization
  1283. /// scope names are ordered by increasing synchronization scope IDs.
  1284. void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
  1285. /// Maintain the GC name for each function.
  1286. ///
  1287. /// This saves allocating an additional word in Function for programs which
  1288. /// do not use GC (i.e., most programs) at the cost of increased overhead for
  1289. /// clients which do use GC.
  1290. DenseMap<const Function *, std::string> GCNames;
  1291. /// Flag to indicate if Value (other than GlobalValue) retains their name or
  1292. /// not.
  1293. bool DiscardValueNames = false;
  1294. LLVMContextImpl(LLVMContext &C);
  1295. ~LLVMContextImpl();
  1296. /// Destroy the ConstantArrays if they are not used.
  1297. void dropTriviallyDeadConstantArrays();
  1298. mutable OptPassGate *OPG = nullptr;
  1299. /// Access the object which can disable optional passes and individual
  1300. /// optimizations at compile time.
  1301. OptPassGate &getOptPassGate() const;
  1302. /// Set the object which can disable optional passes and individual
  1303. /// optimizations at compile time.
  1304. ///
  1305. /// The lifetime of the object must be guaranteed to extend as long as the
  1306. /// LLVMContext is used by compilation.
  1307. void setOptPassGate(OptPassGate &);
  1308. // TODO: clean up the following after we no longer support non-opaque pointer
  1309. // types.
  1310. bool getOpaquePointers();
  1311. void setOpaquePointers(bool OP);
  1312. private:
  1313. Optional<bool> OpaquePointers;
  1314. };
  1315. } // end namespace llvm
  1316. #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H