LLVM  6.0.0svn
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/SmallPtrSet.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/Comdat.h"
24 #include "llvm/IR/Constants.h"
25 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Function.h"
29 #include "llvm/IR/GVMaterializer.h"
30 #include "llvm/IR/GlobalAlias.h"
31 #include "llvm/IR/GlobalIFunc.h"
32 #include "llvm/IR/GlobalValue.h"
33 #include "llvm/IR/GlobalVariable.h"
34 #include "llvm/IR/LLVMContext.h"
35 #include "llvm/IR/Metadata.h"
37 #include "llvm/IR/Type.h"
38 #include "llvm/IR/TypeFinder.h"
39 #include "llvm/IR/Value.h"
41 #include "llvm/Pass.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/CodeGen.h"
44 #include "llvm/Support/Error.h"
46 #include "llvm/Support/Path.h"
48 #include <algorithm>
49 #include <cassert>
50 #include <cstdint>
51 #include <memory>
52 #include <utility>
53 #include <vector>
54 
55 using namespace llvm;
56 
57 //===----------------------------------------------------------------------===//
58 // Methods to implement the globals and functions lists.
59 //
60 
61 // Explicit instantiations of SymbolTableListTraits since some of the methods
62 // are not in the public header file.
67 
68 //===----------------------------------------------------------------------===//
69 // Primitive Module methods.
70 //
71 
73  : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") {
74  ValSymTab = new ValueSymbolTable();
75  NamedMDSymTab = new StringMap<NamedMDNode *>();
76  Context.addModule(this);
77 }
78 
80  Context.removeModule(this);
82  GlobalList.clear();
83  FunctionList.clear();
84  AliasList.clear();
85  IFuncList.clear();
86  NamedMDList.clear();
87  delete ValSymTab;
88  delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
89 }
90 
91 std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
92  SmallString<32> Salt(P->getPassName());
93 
94  // This RNG is guaranteed to produce the same random stream only
95  // when the Module ID and thus the input filename is the same. This
96  // might be problematic if the input filename extension changes
97  // (e.g. from .c to .bc or .ll).
98  //
99  // We could store this salt in NamedMetadata, but this would make
100  // the parameter non-const. This would unfortunately make this
101  // interface unusable by any Machine passes, since they only have a
102  // const reference to their IR Module. Alternatively we can always
103  // store salt metadata from the Module constructor.
105 
106  return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt));
107 }
108 
109 /// getNamedValue - Return the first global value in the module with
110 /// the specified name, of arbitrary type. This method returns null
111 /// if a global with the specified name is not found.
113  return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
114 }
115 
116 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
117 /// This ID is uniqued across modules in the current LLVMContext.
119  return Context.getMDKindID(Name);
120 }
121 
122 /// getMDKindNames - Populate client supplied SmallVector with the name for
123 /// custom metadata IDs registered in this LLVMContext. ID #0 is not used,
124 /// so it is filled in as an empty string.
126  return Context.getMDKindNames(Result);
127 }
128 
130  return Context.getOperandBundleTags(Result);
131 }
132 
133 //===----------------------------------------------------------------------===//
134 // Methods for easy access to the functions in the module.
135 //
136 
137 // getOrInsertFunction - Look up the specified function in the module symbol
138 // table. If it does not exist, add a prototype for the function and return
139 // it. This is nice because it allows most passes to get away with not handling
140 // the symbol table directly for this common task.
141 //
144  // See if we have a definition for the specified function already.
145  GlobalValue *F = getNamedValue(Name);
146  if (!F) {
147  // Nope, add it
149  if (!New->isIntrinsic()) // Intrinsics get attrs set on construction
150  New->setAttributes(AttributeList);
151  FunctionList.push_back(New);
152  return New; // Return the new prototype.
153  }
154 
155  // If the function exists but has the wrong type, return a bitcast to the
156  // right type.
157  if (F->getType() != PointerType::getUnqual(Ty))
159 
160  // Otherwise, we just found the existing function or a prototype.
161  return F;
162 }
163 
165  FunctionType *Ty) {
166  return getOrInsertFunction(Name, Ty, AttributeList());
167 }
168 
169 // getFunction - Look up the specified function in the module symbol table.
170 // If it does not exist, return null.
171 //
173  return dyn_cast_or_null<Function>(getNamedValue(Name));
174 }
175 
176 //===----------------------------------------------------------------------===//
177 // Methods for easy access to the global variables in the module.
178 //
179 
180 /// getGlobalVariable - Look up the specified global variable in the module
181 /// symbol table. If it does not exist, return null. The type argument
182 /// should be the underlying type of the global, i.e., it should not have
183 /// the top-level PointerType, which represents the address of the global.
184 /// If AllowLocal is set to true, this function will return types that
185 /// have an local. By default, these types are not returned.
186 ///
188  bool AllowLocal) const {
189  if (GlobalVariable *Result =
190  dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
191  if (AllowLocal || !Result->hasLocalLinkage())
192  return Result;
193  return nullptr;
194 }
195 
196 /// getOrInsertGlobal - Look up the specified global in the module symbol table.
197 /// 1. If it does not exist, add a declaration of the global and return it.
198 /// 2. Else, the global exists but has the wrong type: return the function
199 /// with a constantexpr cast to the right type.
200 /// 3. Finally, if the existing global is the correct declaration, return the
201 /// existing global.
203  // See if we have a definition for the specified global already.
204  GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
205  if (!GV) {
206  // Nope, add it
207  GlobalVariable *New =
208  new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
209  nullptr, Name);
210  return New; // Return the new declaration.
211  }
212 
213  // If the variable exists but has the wrong type, return a bitcast to the
214  // right type.
215  Type *GVTy = GV->getType();
217  if (GVTy != PTy)
218  return ConstantExpr::getBitCast(GV, PTy);
219 
220  // Otherwise, we just found the existing function or a prototype.
221  return GV;
222 }
223 
224 //===----------------------------------------------------------------------===//
225 // Methods for easy access to the global variables in the module.
226 //
227 
228 // getNamedAlias - Look up the specified global in the module symbol table.
229 // If it does not exist, return null.
230 //
232  return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
233 }
234 
236  return dyn_cast_or_null<GlobalIFunc>(getNamedValue(Name));
237 }
238 
239 /// getNamedMetadata - Return the first NamedMDNode in the module with the
240 /// specified name. This method returns null if a NamedMDNode with the
241 /// specified name is not found.
243  SmallString<256> NameData;
244  StringRef NameRef = Name.toStringRef(NameData);
245  return static_cast<StringMap<NamedMDNode*> *>(NamedMDSymTab)->lookup(NameRef);
246 }
247 
248 /// getOrInsertNamedMetadata - Return the first named MDNode in the module
249 /// with the specified name. This method returns a new NamedMDNode if a
250 /// NamedMDNode with the specified name is not found.
252  NamedMDNode *&NMD =
253  (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name];
254  if (!NMD) {
255  NMD = new NamedMDNode(Name);
256  NMD->setParent(this);
257  NamedMDList.push_back(NMD);
258  }
259  return NMD;
260 }
261 
262 /// eraseNamedMetadata - Remove the given NamedMDNode from this module and
263 /// delete it.
265  static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
266  NamedMDList.erase(NMD->getIterator());
267 }
268 
270  if (ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
271  uint64_t Val = Behavior->getLimitedValue();
272  if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
273  MFB = static_cast<ModFlagBehavior>(Val);
274  return true;
275  }
276  }
277  return false;
278 }
279 
280 /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
281 void Module::
283  const NamedMDNode *ModFlags = getModuleFlagsMetadata();
284  if (!ModFlags) return;
285 
286  for (const MDNode *Flag : ModFlags->operands()) {
287  ModFlagBehavior MFB;
288  if (Flag->getNumOperands() >= 3 &&
289  isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
290  dyn_cast_or_null<MDString>(Flag->getOperand(1))) {
291  // Check the operands of the MDNode before accessing the operands.
292  // The verifier will actually catch these failures.
293  MDString *Key = cast<MDString>(Flag->getOperand(1));
294  Metadata *Val = Flag->getOperand(2);
295  Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
296  }
297  }
298 }
299 
300 /// Return the corresponding value if Key appears in module flags, otherwise
301 /// return null.
304  getModuleFlagsMetadata(ModuleFlags);
305  for (const ModuleFlagEntry &MFE : ModuleFlags) {
306  if (Key == MFE.Key->getString())
307  return MFE.Val;
308  }
309  return nullptr;
310 }
311 
312 /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
313 /// represents module-level flags. This method returns null if there are no
314 /// module-level flags.
316  return getNamedMetadata("llvm.module.flags");
317 }
318 
319 /// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
320 /// represents module-level flags. If module-level flags aren't found, it
321 /// creates the named metadata that contains them.
323  return getOrInsertNamedMetadata("llvm.module.flags");
324 }
325 
326 /// addModuleFlag - Add a module-level flag to the module-level flags
327 /// metadata. It will create the module-level flags named metadata if it doesn't
328 /// already exist.
330  Metadata *Val) {
331  Type *Int32Ty = Type::getInt32Ty(Context);
332  Metadata *Ops[3] = {
333  ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
334  MDString::get(Context, Key), Val};
336 }
338  Constant *Val) {
339  addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
340 }
342  uint32_t Val) {
343  Type *Int32Ty = Type::getInt32Ty(Context);
344  addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
345 }
347  assert(Node->getNumOperands() == 3 &&
348  "Invalid number of operands for module flag!");
349  assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
350  isa<MDString>(Node->getOperand(1)) &&
351  "Invalid operand types for module flag!");
353 }
354 
356  DL.reset(Desc);
357 }
358 
359 void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
360 
361 const DataLayout &Module::getDataLayout() const { return DL; }
362 
364  return cast<DICompileUnit>(CUs->getOperand(Idx));
365 }
367  return cast<DICompileUnit>(CUs->getOperand(Idx));
368 }
369 
370 void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
371  while (CUs && (Idx < CUs->getNumOperands()) &&
372  ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
373  ++Idx;
374 }
375 
376 //===----------------------------------------------------------------------===//
377 // Methods to control the materialization of GlobalValues in the Module.
378 //
380  assert(!Materializer &&
381  "Module already has a GVMaterializer. Call materializeAll"
382  " to clear it out before setting another one.");
383  Materializer.reset(GVM);
384 }
385 
387  if (!Materializer)
388  return Error::success();
389 
390  return Materializer->materialize(GV);
391 }
392 
394  if (!Materializer)
395  return Error::success();
396  std::unique_ptr<GVMaterializer> M = std::move(Materializer);
397  return M->materializeModule();
398 }
399 
401  if (!Materializer)
402  return Error::success();
403  return Materializer->materializeMetadata();
404 }
405 
406 //===----------------------------------------------------------------------===//
407 // Other module related stuff.
408 //
409 
410 std::vector<StructType *> Module::getIdentifiedStructTypes() const {
411  // If we have a materializer, it is possible that some unread function
412  // uses a type that is currently not visible to a TypeFinder, so ask
413  // the materializer which types it created.
414  if (Materializer)
415  return Materializer->getIdentifiedStructTypes();
416 
417  std::vector<StructType *> Ret;
418  TypeFinder SrcStructTypes;
419  SrcStructTypes.run(*this, true);
420  Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
421  return Ret;
422 }
423 
424 // dropAllReferences() - This function causes all the subelements to "let go"
425 // of all references that they are maintaining. This allows one to 'delete' a
426 // whole module at a time, even though there may be circular references... first
427 // all references are dropped, and all use counts go to zero. Then everything
428 // is deleted for real. Note that no operations are valid on an object that
429 // has "dropped all references", except operator delete.
430 //
432  for (Function &F : *this)
433  F.dropAllReferences();
434 
435  for (GlobalVariable &GV : globals())
436  GV.dropAllReferences();
437 
438  for (GlobalAlias &GA : aliases())
439  GA.dropAllReferences();
440 
441  for (GlobalIFunc &GIF : ifuncs())
442  GIF.dropAllReferences();
443 }
444 
446  auto *Val =
447  cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
448  if (!Val)
449  return 0;
450  return cast<ConstantInt>(Val->getValue())->getZExtValue();
451 }
452 
453 unsigned Module::getDwarfVersion() const {
454  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
455  if (!Val)
456  return 0;
457  return cast<ConstantInt>(Val->getValue())->getZExtValue();
458 }
459 
460 unsigned Module::getCodeViewFlag() const {
461  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
462  if (!Val)
463  return 0;
464  return cast<ConstantInt>(Val->getValue())->getZExtValue();
465 }
466 
468  auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
469  Entry.second.Name = &Entry;
470  return &Entry.second;
471 }
472 
474  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
475 
476  if (!Val)
477  return PICLevel::NotPIC;
478 
479  return static_cast<PICLevel::Level>(
480  cast<ConstantInt>(Val->getValue())->getZExtValue());
481 }
482 
484  addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL);
485 }
486 
488  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
489 
490  if (!Val)
491  return PIELevel::Default;
492 
493  return static_cast<PIELevel::Level>(
494  cast<ConstantInt>(Val->getValue())->getZExtValue());
495 }
496 
498  addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
499 }
500 
502  addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
503 }
504 
506  return getModuleFlag("ProfileSummary");
507 }
508 
509 void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
510  OwnedMemoryBuffer = std::move(MB);
511 }
512 
514  const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
515  const char *Name = CompilerUsed ? "llvm.compiler.used" : "llvm.used";
516  GlobalVariable *GV = M.getGlobalVariable(Name);
517  if (!GV || !GV->hasInitializer())
518  return GV;
519 
520  const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
521  for (Value *Op : Init->operands()) {
522  GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
523  Set.insert(G);
524  }
525  return GV;
526 }
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:172
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
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:393
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Definition: DataLayout.cpp:177
LLVMContext & Context
iterator erase(iterator where)
Definition: ilist.h:280
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Compute iterated dominance frontiers using a linear time algorithm.
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:142
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:315
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:446
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
Definition: Module.h:542
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
Definition: Module.cpp:379
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:463
void addOperand(MDNode *M)
Definition: Metadata.cpp:1079
DICompileUnit * operator->() const
Definition: Module.cpp:366
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:617
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Definition: Module.cpp:251
Externally visible function.
Definition: GlobalValue.h:49
void setDataLayout(StringRef Desc)
Set the data layout.
Definition: Module.cpp:355
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
Definition: Module.h:368
Metadata node.
Definition: Metadata.h:862
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1067
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:67
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:345
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:231
A tuple of MDNodes.
Definition: Metadata.h:1316
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:361
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:264
This file contains the simple types necessary to represent the attributes associated with functions a...
Metadata * getProfileSummary()
Returns profile summary metadata.
Definition: Module.cpp:505
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
Class to represent function types.
Definition: DerivedTypes.h:103
#define F(x, y, z)
Definition: MD5.cpp:55
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
Definition: Module.cpp:242
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:112
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
Definition: Module.cpp:431
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:408
iterator_range< op_iterator > operands()
Definition: Metadata.h:1408
const char * Name
Class to represent pointers.
Definition: DerivedTypes.h:467
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Definition: Module.cpp:460
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
Definition: Module.cpp:129
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1678
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1164
#define P(N)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Definition: Module.cpp:72
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
Definition: Module.cpp:487
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:68
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
Definition: Module.cpp:202
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:302
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:111
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:372
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:329
op_range operands()
Definition: User.h:222
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:467
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:208
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Definition: Module.cpp:453
std::vector< StructType * > getIdentifiedStructTypes() const
Definition: Module.cpp:410
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:513
static ErrorSuccess success()
Create a success value.
Definition: Error.h:311
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
Definition: DerivedTypes.h:482
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:864
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:269
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
Definition: Module.cpp:322
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
Definition: Function.cpp:325
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:560
iterator end()
Definition: TypeFinder.h:51
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:200
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:370
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:224
ConstantArray - Constant Array Declarations.
Definition: Constants.h:405
void push_back(pointer val)
Definition: ilist.h:326
StringRef getName() const
Definition: Metadata.cpp:1090
DICompileUnit * operator*() const
Definition: Module.cpp:363
A random number generator.
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
void setProfileSummary(Metadata *M)
Attach profile summary metadata to this module.
Definition: Module.cpp:501
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:575
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
void clear()
Definition: ilist.h:322
std::unique_ptr< RandomNumberGenerator > createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
Definition: Module.cpp:91
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:386
~Module()
The module destructor. This will dropAllReferences.
Definition: Module.cpp:79
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
Definition: Module.cpp:497
iterator_range< ifunc_iterator > ifuncs()
Definition: Module.h:619
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Definition: Module.cpp:509
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:125
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Definition: Module.cpp:118
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:445
bool hasInitializer() const
Definitions have initializers, declarations don&#39;t.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
iterator begin()
Definition: TypeFinder.h:50
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
Definition: Module.cpp:483
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
Definition: Module.cpp:473
iterator_range< global_iterator > globals()
Definition: Module.h:561
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:602
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:128
T Max(T a, T b)
Definition: FuzzerDefs.h:91
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:235
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:400
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:260
IntegerType * Int32Ty
iterator_range< alias_iterator > aliases()
Definition: Module.h:601