49 : Context(C), Materializer(), ModuleID(MID),
DL(
"") {
52 Context.addModule(
this);
56 Context.removeModule(
this);
152 va_start(Args, RetTy);
155 std::vector<Type*> ArgTys;
156 while (
Type *ArgTy = va_arg(Args,
Type*))
157 ArgTys.push_back(ArgTy);
170 va_start(Args, RetTy);
173 std::vector<Type*> ArgTys;
174 while (
Type *ArgTy = va_arg(Args,
Type*))
175 ArgTys.push_back(ArgTy);
206 if (AllowLocal || !Result->hasLocalLinkage())
267 NMD->setParent(
this);
277 NamedMDList.
erase(NMD);
281 if (
ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
282 uint64_t Val = Behavior->getLimitedValue();
295 if (!ModFlags)
return;
299 if (
Flag->getNumOperands() >= 3 &&
301 dyn_cast_or_null<MDString>(
Flag->getOperand(1))) {
317 if (Key == MFE.Key->getString())
359 "Invalid number of operands for module flag!");
360 assert(mdconst::hasa<ConstantInt>(Node->
getOperand(0)) &&
362 "Invalid operand types for module flag!");
378 assert(!Materializer &&
379 "Module already has a GVMaterializer. Call MaterializeAllPermanently"
380 " to clear it out before setting another one.");
381 Materializer.reset(GVM);
386 return Materializer->isDematerializable(GV);
392 return std::error_code();
394 return Materializer->materialize(GV);
399 return Materializer->dematerialize(GV);
404 return std::error_code();
405 return Materializer->materializeModule(
this);
412 Materializer.reset();
413 return std::error_code();
418 return std::error_code();
419 return Materializer->materializeMetadata();
431 return Materializer->getIdentifiedStructTypes();
433 std::vector<StructType *>
Ret;
435 SrcStructTypes.
run(*
this,
true);
436 Ret.assign(SrcStructTypes.
begin(), SrcStructTypes.
end());
452 GV.dropAllReferences();
455 GA.dropAllReferences();
459 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Dwarf Version"));
462 return cast<ConstantInt>(Val->getValue())->getZExtValue();
466 auto &Entry = *ComdatSymTab.
insert(std::make_pair(Name,
Comdat())).first;
467 Entry.second.Name = &Entry;
468 return &Entry.second;
472 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIC Level"));
478 cast<ConstantInt>(Val->getValue())->getZExtValue());
Pass interface - Implemented by all 'passes'.
StringRef getName() const
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
This class provides a symbol table of name/value pairs.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
std::error_code materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
RandomNumberGenerator * createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
void dematerialize(GlobalValue *GV)
If the GlobalValue is read in, and if the GVMaterializer supports it, release the memory for the func...
static MDString * get(LLVMContext &Context, StringRef Str)
unsigned getNumOperands() const
Return number of MDNode operands.
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
void addOperand(MDNode *M)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
virtual const char * getPassName() const
getPassName - Return a nice clean name for a pass.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Externally visible function.
void setDataLayout(StringRef Desc)
Set the data layout.
std::vector< StructType * > getIdentifiedStructTypes() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
void push_back(NodeTy *val)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
std::error_code materializeAllPermanently()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
std::error_code materializeAll()
Make sure all GlobalValues in this Module are fully read.
FunctionType - Class to represent function types.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
iterator_range< op_iterator > operands()
PointerType - Class to represent pointers.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
getMDKindNames - Populate client supplied SmallVector with the name for custom metadata IDs registere...
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
StringRef filename(StringRef path)
Get filename.
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
bool isDematerializable(const GlobalValue *GV) const
Returns true if this GV was loaded from this Module's GVMaterializer and the GVMaterializer knows how...
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
This is an important base class in LLVM.
std::error_code materializeMetadata()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
iterator erase(iterator where)
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
const MDOperand & getOperand(unsigned I) const
static PointerType * getUnqual(Type *ElementType)
PointerType::getUnqual - This constructs a pointer to an object of the specified type in the generic ...
This is the shared class of boolean and integer constants.
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
void run(const Module &M, bool onlyNamed)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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...
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
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.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
A random number generator.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static const uint16_t * lookup(unsigned opcode, unsigned domain)
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
static IntegerType * getInt32Ty(LLVMContext &C)
~Module()
The module destructor. This will dropAllReferences.
void setAttributes(AttributeSet attrs)
Set the attribute list for this Function.
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
void push_back(const NodeTy &val)
iterator_range< alias_iterator > aliases()