LLVM  8.0.1
Module.cpp
Go to the documentation of this file.
1 //===- Module.cpp - Implement the Module class ----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Module class for the IR library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/IR/Module.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/Twine.h"
23 #include "llvm/IR/Attributes.h"
24 #include "llvm/IR/Comdat.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/GVMaterializer.h"
31 #include "llvm/IR/GlobalAlias.h"
32 #include "llvm/IR/GlobalIFunc.h"
33 #include "llvm/IR/GlobalValue.h"
34 #include "llvm/IR/GlobalVariable.h"
35 #include "llvm/IR/LLVMContext.h"
36 #include "llvm/IR/Metadata.h"
38 #include "llvm/IR/Type.h"
39 #include "llvm/IR/TypeFinder.h"
40 #include "llvm/IR/Value.h"
42 #include "llvm/Pass.h"
43 #include "llvm/Support/Casting.h"
44 #include "llvm/Support/CodeGen.h"
45 #include "llvm/Support/Error.h"
47 #include "llvm/Support/Path.h"
50 #include <algorithm>
51 #include <cassert>
52 #include <cstdint>
53 #include <memory>
54 #include <utility>
55 #include <vector>
56 
57 using namespace llvm;
58 
59 //===----------------------------------------------------------------------===//
60 // Methods to implement the globals and functions lists.
61 //
62 
63 // Explicit instantiations of SymbolTableListTraits since some of the methods
64 // are not in the public header file.
69 
70 //===----------------------------------------------------------------------===//
71 // Primitive Module methods.
72 //
73 
75  : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") {
76  ValSymTab = new ValueSymbolTable();
77  NamedMDSymTab = new StringMap<NamedMDNode *>();
78  Context.addModule(this);
79 }
80 
82  Context.removeModule(this);
84  GlobalList.clear();
85  FunctionList.clear();
86  AliasList.clear();
87  IFuncList.clear();
88  NamedMDList.clear();
89  delete ValSymTab;
90  delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
91 }
92 
93 std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
94  SmallString<32> Salt(P->getPassName());
95 
96  // This RNG is guaranteed to produce the same random stream only
97  // when the Module ID and thus the input filename is the same. This
98  // might be problematic if the input filename extension changes
99  // (e.g. from .c to .bc or .ll).
100  //
101  // We could store this salt in NamedMetadata, but this would make
102  // the parameter non-const. This would unfortunately make this
103  // interface unusable by any Machine passes, since they only have a
104  // const reference to their IR Module. Alternatively we can always
105  // store salt metadata from the Module constructor.
107 
108  return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt));
109 }
110 
111 /// getNamedValue - Return the first global value in the module with
112 /// the specified name, of arbitrary type. This method returns null
113 /// if a global with the specified name is not found.
115  return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
116 }
117 
118 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
119 /// This ID is uniqued across modules in the current LLVMContext.
121  return Context.getMDKindID(Name);
122 }
123 
124 /// getMDKindNames - Populate client supplied SmallVector with the name for
125 /// custom metadata IDs registered in this LLVMContext. ID #0 is not used,
126 /// so it is filled in as an empty string.
128  return Context.getMDKindNames(Result);
129 }
130 
132  return Context.getOperandBundleTags(Result);
133 }
134 
135 //===----------------------------------------------------------------------===//
136 // Methods for easy access to the functions in the module.
137 //
138 
139 // getOrInsertFunction - Look up the specified function in the module symbol
140 // table. If it does not exist, add a prototype for the function and return
141 // it. This is nice because it allows most passes to get away with not handling
142 // the symbol table directly for this common task.
143 //
146  // See if we have a definition for the specified function already.
147  GlobalValue *F = getNamedValue(Name);
148  if (!F) {
149  // Nope, add it
152  if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
153  New->setAttributes(AttributeList);
154  FunctionList.push_back(New);
155  return New; // Return the new prototype.
156  }
157 
158  // If the function exists but has the wrong type, return a bitcast to the
159  // right type.
160  auto *PTy = PointerType::get(Ty, F->getAddressSpace());
161  if (F->getType() != PTy)
162  return ConstantExpr::getBitCast(F, PTy);
163 
164  // Otherwise, we just found the existing function or a prototype.
165  return F;
166 }
167 
169  FunctionType *Ty) {
170  return getOrInsertFunction(Name, Ty, AttributeList());
171 }
172 
173 // getFunction - Look up the specified function in the module symbol table.
174 // If it does not exist, return null.
175 //
177  return dyn_cast_or_null<Function>(getNamedValue(Name));
178 }
179 
180 //===----------------------------------------------------------------------===//
181 // Methods for easy access to the global variables in the module.
182 //
183 
184 /// getGlobalVariable - Look up the specified global variable in the module
185 /// symbol table. If it does not exist, return null. The type argument
186 /// should be the underlying type of the global, i.e., it should not have
187 /// the top-level PointerType, which represents the address of the global.
188 /// If AllowLocal is set to true, this function will return types that
189 /// have an local. By default, these types are not returned.
190 ///
192  bool AllowLocal) const {
193  if (GlobalVariable *Result =
194  dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
195  if (AllowLocal || !Result->hasLocalLinkage())
196  return Result;
197  return nullptr;
198 }
199 
200 /// getOrInsertGlobal - Look up the specified global in the module symbol table.
201 /// 1. If it does not exist, add a declaration of the global and return it.
202 /// 2. Else, the global exists but has the wrong type: return the function
203 /// with a constantexpr cast to the right type.
204 /// 3. Finally, if the existing global is the correct declaration, return the
205 /// existing global.
207  StringRef Name, Type *Ty,
208  function_ref<GlobalVariable *()> CreateGlobalCallback) {
209  // See if we have a definition for the specified global already.
210  GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
211  if (!GV)
212  GV = CreateGlobalCallback();
213  assert(GV && "The CreateGlobalCallback is expected to create a global");
214 
215  // If the variable exists but has the wrong type, return a bitcast to the
216  // right type.
217  Type *GVTy = GV->getType();
219  if (GVTy != PTy)
220  return ConstantExpr::getBitCast(GV, PTy);
221 
222  // Otherwise, we just found the existing function or a prototype.
223  return GV;
224 }
225 
226 // Overload to construct a global variable using its constructor's defaults.
228  return getOrInsertGlobal(Name, Ty, [&] {
229  return new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
230  nullptr, Name);
231  });
232 }
233 
234 //===----------------------------------------------------------------------===//
235 // Methods for easy access to the global variables in the module.
236 //
237 
238 // getNamedAlias - Look up the specified global in the module symbol table.
239 // If it does not exist, return null.
240 //
242  return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
243 }
244 
246  return dyn_cast_or_null<GlobalIFunc>(getNamedValue(Name));
247 }
248 
249 /// getNamedMetadata - Return the first NamedMDNode in the module with the
250 /// specified name. This method returns null if a NamedMDNode with the
251 /// specified name is not found.
253  SmallString<256> NameData;
254  StringRef NameRef = Name.toStringRef(NameData);
255  return static_cast<StringMap<NamedMDNode*> *>(NamedMDSymTab)->lookup(NameRef);
256 }
257 
258 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
259 /// with the specified name. This method returns a new NamedMDNode if a
260 /// NamedMDNode with the specified name is not found.
262  NamedMDNode *&NMD =
263  (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name];
264  if (!NMD) {
265  NMD = new NamedMDNode(Name);
266  NMD->setParent(this);
267  NamedMDList.push_back(NMD);
268  }
269  return NMD;
270 }
271 
272 /// eraseNamedMetadata - Remove the given NamedMDNode from this module and
273 /// delete it.
275  static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
276  NamedMDList.erase(NMD->getIterator());
277 }
278 
280  if (ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
281  uint64_t Val = Behavior->getLimitedValue();
282  if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
283  MFB = static_cast<ModFlagBehavior>(Val);
284  return true;
285  }
286  }
287  return false;
288 }
289 
290 /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
291 void Module::
293  const NamedMDNode *ModFlags = getModuleFlagsMetadata();
294  if (!ModFlags) return;
295 
296  for (const MDNode *Flag : ModFlags->operands()) {
297  ModFlagBehavior MFB;
298  if (Flag->getNumOperands() >= 3 &&
299  isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
300  dyn_cast_or_null<MDString>(Flag->getOperand(1))) {
301  // Check the operands of the MDNode before accessing the operands.
302  // The verifier will actually catch these failures.
303  MDString *Key = cast<MDString>(Flag->getOperand(1));
304  Metadata *Val = Flag->getOperand(2);
305  Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
306  }
307  }
308 }
309 
310 /// Return the corresponding value if Key appears in module flags, otherwise
311 /// return null.
314  getModuleFlagsMetadata(ModuleFlags);
315  for (const ModuleFlagEntry &MFE : ModuleFlags) {
316  if (Key == MFE.Key->getString())
317  return MFE.Val;
318  }
319  return nullptr;
320 }
321 
322 /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
323 /// represents module-level flags. This method returns null if there are no
324 /// module-level flags.
326  return getNamedMetadata("llvm.module.flags");
327 }
328 
329 /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
330 /// represents module-level flags. If module-level flags aren't found, it
331 /// creates the named metadata that contains them.
333  return getOrInsertNamedMetadata("llvm.module.flags");
334 }
335 
336 /// addModuleFlag - Add a module-level flag to the module-level flags
337 /// metadata. It will create the module-level flags named metadata if it doesn't
338 /// already exist.
340  Metadata *Val) {
341  Type *Int32Ty = Type::getInt32Ty(Context);
342  Metadata *Ops[3] = {
343  ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
344  MDString::get(Context, Key), Val};
346 }
348  Constant *Val) {
349  addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
350 }
352  uint32_t Val) {
353  Type *Int32Ty = Type::getInt32Ty(Context);
354  addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
355 }
357  assert(Node->getNumOperands() == 3 &&
358  "Invalid number of operands for module flag!");
359  assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
360  isa<MDString>(Node->getOperand(1)) &&
361  "Invalid operand types for module flag!");
363 }
364 
366  DL.reset(Desc);
367 }
368 
369 void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
370 
371 const DataLayout &Module::getDataLayout() const { return DL; }
372 
374  return cast<DICompileUnit>(CUs->getOperand(Idx));
375 }
377  return cast<DICompileUnit>(CUs->getOperand(Idx));
378 }
379 
380 void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
381  while (CUs && (Idx < CUs->getNumOperands()) &&
382  ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
383  ++Idx;
384 }
385 
386 //===----------------------------------------------------------------------===//
387 // Methods to control the materialization of GlobalValues in the Module.
388 //
390  assert(!Materializer &&
391  "Module already has a GVMaterializer. Call materializeAll"
392  " to clear it out before setting another one.");
393  Materializer.reset(GVM);
394 }
395 
397  if (!Materializer)
398  return Error::success();
399 
400  return Materializer->materialize(GV);
401 }
402 
404  if (!Materializer)
405  return Error::success();
406  std::unique_ptr<GVMaterializer> M = std::move(Materializer);
407  return M->materializeModule();
408 }
409 
411  if (!Materializer)
412  return Error::success();
413  return Materializer->materializeMetadata();
414 }
415 
416 //===----------------------------------------------------------------------===//
417 // Other module related stuff.
418 //
419 
420 std::vector<StructType *> Module::getIdentifiedStructTypes() const {
421  // If we have a materializer, it is possible that some unread function
422  // uses a type that is currently not visible to a TypeFinder, so ask
423  // the materializer which types it created.
424  if (Materializer)
425  return Materializer->getIdentifiedStructTypes();
426 
427  std::vector<StructType *> Ret;
428  TypeFinder SrcStructTypes;
429  SrcStructTypes.run(*this, true);
430  Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
431  return Ret;
432 }
433 
434 // dropAllReferences() - This function causes all the subelements to "let go"
435 // of all references that they are maintaining. This allows one to 'delete' a
436 // whole module at a time, even though there may be circular references... first
437 // all references are dropped, and all use counts go to zero. Then everything
438 // is deleted for real. Note that no operations are valid on an object that
439 // has "dropped all references", except operator delete.
440 //
442  for (Function &F : *this)
443  F.dropAllReferences();
444 
445  for (GlobalVariable &GV : globals())
446  GV.dropAllReferences();
447 
448  for (GlobalAlias &GA : aliases())
449  GA.dropAllReferences();
450 
451  for (GlobalIFunc &GIF : ifuncs())
452  GIF.dropAllReferences();
453 }
454 
456  auto *Val =
457  cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
458  if (!Val)
459  return 0;
460  return cast<ConstantInt>(Val->getValue())->getZExtValue();
461 }
462 
463 unsigned Module::getDwarfVersion() const {
464  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
465  if (!Val)
466  return 0;
467  return cast<ConstantInt>(Val->getValue())->getZExtValue();
468 }
469 
470 unsigned Module::getCodeViewFlag() const {
471  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
472  if (!Val)
473  return 0;
474  return cast<ConstantInt>(Val->getValue())->getZExtValue();
475 }
476 
478  unsigned NumInstrs = 0;
479  for (Function &F : FunctionList)
480  NumInstrs += F.getInstructionCount();
481  return NumInstrs;
482 }
483 
485  auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
486  Entry.second.Name = &Entry;
487  return &Entry.second;
488 }
489 
491  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
492 
493  if (!Val)
494  return PICLevel::NotPIC;
495 
496  return static_cast<PICLevel::Level>(
497  cast<ConstantInt>(Val->getValue())->getZExtValue());
498 }
499 
501  addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL);
502 }
503 
505  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
506 
507  if (!Val)
508  return PIELevel::Default;
509 
510  return static_cast<PIELevel::Level>(
511  cast<ConstantInt>(Val->getValue())->getZExtValue());
512 }
513 
515  addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
516 }
517 
519  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Code Model"));
520 
521  if (!Val)
522  return None;
523 
524  return static_cast<CodeModel::Model>(
525  cast<ConstantInt>(Val->getValue())->getZExtValue());
526 }
527 
529  // Linking object files with different code models is undefined behavior
530  // because the compiler would have to generate additional code (to span
531  // longer jumps) if a larger code model is used with a smaller one.
532  // Therefore we will treat attempts to mix code models as an error.
533  addModuleFlag(ModFlagBehavior::Error, "Code Model", CL);
534 }
535 
537  addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
538 }
539 
541  return getModuleFlag("ProfileSummary");
542 }
543 
544 void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
545  OwnedMemoryBuffer = std::move(MB);
546 }
547 
549  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("RtLibUseGOT"));
550  return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
551 }
552 
554  addModuleFlag(ModFlagBehavior::Max, "RtLibUseGOT", 1);
555 }
556 
558  SmallVector<unsigned, 3> Entries;
559  Entries.push_back(V.getMajor());
560  if (auto Minor = V.getMinor()) {
561  Entries.push_back(*Minor);
562  if (auto Subminor = V.getSubminor())
563  Entries.push_back(*Subminor);
564  // Ignore the 'build' component as it can't be represented in the object
565  // file.
566  }
568  ConstantDataArray::get(Context, Entries));
569 }
570 
572  auto *CM = dyn_cast_or_null<ConstantAsMetadata>(getModuleFlag("SDK Version"));
573  if (!CM)
574  return {};
575  auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
576  if (!Arr)
577  return {};
578  auto getVersionComponent = [&](unsigned Index) -> Optional<unsigned> {
579  if (Index >= Arr->getNumElements())
580  return None;
581  return (unsigned)Arr->getElementAsInteger(Index);
582  };
583  auto Major = getVersionComponent(0);
584  if (!Major)
585  return {};
586  VersionTuple Result = VersionTuple(*Major);
587  if (auto Minor = getVersionComponent(1)) {
588  Result = VersionTuple(*Major, *Minor);
589  if (auto Subminor = getVersionComponent(2)) {
590  Result = VersionTuple(*Major, *Minor, *Subminor);
591  }
592  }
593  return Result;
594 }
595 
597  const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
598  const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
599  GlobalVariable *GV = M.getGlobalVariable(Name);
600  if (!GV || !GV->hasInitializer())
601  return GV;
602 
603  const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
604  for (Value *Op : Init->operands()) {
605  GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
606  Set.insert(G);
607  }
608  return GV;
609 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
uint64_t CallInst * C
bool isIntrinsic() const
isIntrinsic - Returns true if the function&#39;s name starts with "llvm.".
Definition: Function.h:199
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This class provides a symbol table of name/value pairs.
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
Definition: Module.cpp:403
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:180
LLVMContext & Context
iterator erase(iterator where)
Definition: ilist.h:267
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:144
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:325
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:454
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
Definition: Module.h:565
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
Definition: Module.cpp:389
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:453
void addOperand(MDNode *M)
Definition: Metadata.cpp:1087
DICompileUnit * operator->() const
Definition: Module.cpp:376
This file contains the declarations for metadata subclasses.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Definition: Type.cpp:630
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:261
Externally visible function.
Definition: GlobalValue.h:49
void setDataLayout(StringRef Desc)
Set the data layout.
Definition: Module.cpp:365
Optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
Definition: Module.cpp:518
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition: Module.h:387
Metadata node.
Definition: Metadata.h:864
F(f)
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1069
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:503
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:75
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:241
A tuple of MDNodes.
Definition: Metadata.h:1326
amdgpu Simplify well known AMD library false Value Value const Twine & Name
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:371
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
getMDKindNames - Populate client supplied SmallVector with the name for custom metadata IDs registere...
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
Definition: Module.cpp:274
unsigned getInstructionCount()
Returns the number of non-debug IR instructions in the module.
Definition: Module.cpp:477
This file contains the simple types necessary to represent the attributes associated with functions a...
Metadata * getProfileSummary()
Returns profile summary metadata.
Definition: Module.cpp:540
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
Key
PAL metadata keys.
Class to represent function types.
Definition: DerivedTypes.h:103
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
Definition: Module.cpp:553
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:252
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:114
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
Definition: Module.cpp:441
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:410
iterator_range< op_iterator > operands()
Definition: Metadata.h:1418
Class to represent pointers.
Definition: DerivedTypes.h:467
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Definition: Module.cpp:470
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:118
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
Definition: Module.cpp:131
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1773
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1166
#define P(N)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Definition: Module.cpp:74
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition: Module.cpp:504
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:312
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
getOperandBundleTags - Populate client supplied SmallVector with the bundle tags registered in this L...
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
Definition: Module.h:113
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:371
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:68
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:339
unsigned getAddressSpace() const
Definition: Globals.cpp:111
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
Definition: Module.cpp:528
op_range operands()
Definition: User.h:238
self_iterator getIterator()
Definition: ilist_node.h:82
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:484
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:210
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Definition: Module.cpp:463
Optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:71
std::vector< StructType * > getIdentifiedStructTypes() const
Definition: Module.cpp:420
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallPtrSetImpl< GlobalValue *> &Set, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition: Module.cpp:596
static ErrorSuccess success()
Create a success value.
Definition: Error.h:327
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
void run(const Module &M, bool onlyNamed)
Definition: TypeFinder.cpp:32
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Module.h This file contains the declarations for the Module class.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
Definition: Module.cpp:279
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:332
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:346
unsigned getProgramAddressSpace() const
Definition: DataLayout.h:260
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:622
iterator end()
Definition: TypeFinder.h:51
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:227
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:366
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:176
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
ConstantArray - Constant Array Declarations.
Definition: Constants.h:414
void push_back(pointer val)
Definition: ilist.h:313
StringRef getName() const
Definition: Metadata.cpp:1098
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
Definition: Module.cpp:548
DICompileUnit * operator*() const
Definition: Module.cpp:373
A random number generator.
void setProfileSummary(Metadata *M)
Attach profile summary metadata to this module.
Definition: Module.cpp:536
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:27
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
Definition: Module.cpp:206
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:590
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
void clear()
Definition: ilist.h:309
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
Definition: Module.cpp:557
std::unique_ptr< RandomNumberGenerator > createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
Definition: Module.cpp:93
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:396
~Module()
The module destructor. This will dropAllReferences.
Definition: Module.cpp:81
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
Definition: Module.cpp:514
iterator_range< ifunc_iterator > ifuncs()
Definition: Module.h:642
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Definition: Module.cpp:544
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
Definition: Module.cpp:127
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition: Module.cpp:120
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
Definition: Module.cpp:455
bool hasInitializer() const
Definitions have initializers, declarations don&#39;t.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
iterator begin()
Definition: TypeFinder.h:50
Defines the llvm::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Definition: Constants.h:703
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
Definition: Module.cpp:500
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition: Module.cpp:490
iterator_range< global_iterator > globals()
Definition: Module.h:584
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:604
Optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
Definition: VersionTuple.h:78
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
Definition: Module.cpp:571
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1075
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:245
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
Definition: TypeFinder.h:31
Root of the metadata hierarchy.
Definition: Metadata.h:58
llvm::Error materializeMetadata()
Definition: Module.cpp:410
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:274
IntegerType * Int32Ty
iterator_range< alias_iterator > aliases()
Definition: Module.h:624