diff options
Diffstat (limited to 'contrib/llvm/lib/IR/Module.cpp')
-rw-r--r-- | contrib/llvm/lib/IR/Module.cpp | 103 |
1 files changed, 44 insertions, 59 deletions
diff --git a/contrib/llvm/lib/IR/Module.cpp b/contrib/llvm/lib/IR/Module.cpp index 1911f84..c230a50 100644 --- a/contrib/llvm/lib/IR/Module.cpp +++ b/contrib/llvm/lib/IR/Module.cpp @@ -1,4 +1,4 @@ -//===-- Module.cpp - Implement the Module class ---------------------------===// +//===- Module.cpp - Implement the Module class ----------------------------===// // // The LLVM Compiler Infrastructure // @@ -13,25 +13,44 @@ #include "llvm/IR/Module.h" #include "SymbolTableListTraitsImpl.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/Comdat.h" #include "llvm/IR/Constants.h" -#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" #include "llvm/IR/GVMaterializer.h" -#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalIFunc.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" +#include "llvm/IR/SymbolTableListTraits.h" +#include "llvm/IR/Type.h" #include "llvm/IR/TypeFinder.h" -#include "llvm/Support/Dwarf.h" +#include "llvm/IR/Value.h" +#include "llvm/IR/ValueSymbolTable.h" +#include "llvm/Pass.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/RandomNumberGenerator.h" #include <algorithm> -#include <cstdarg> -#include <cstdlib> +#include <cassert> +#include <cstdint> +#include <memory> +#include <utility> +#include <vector> using namespace llvm; @@ -69,7 +88,7 @@ Module::~Module() { delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab); } -RandomNumberGenerator *Module::createRNG(const Pass* P) const { +std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const { SmallString<32> Salt(P->getPassName()); // This RNG is guaranteed to produce the same random stream only @@ -84,7 +103,7 @@ RandomNumberGenerator *Module::createRNG(const Pass* P) const { // store salt metadata from the Module constructor. Salt += sys::path::filename(getModuleIdentifier()); - return new RandomNumberGenerator(Salt); + return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt)); } /// getNamedValue - Return the first global value in the module with @@ -120,9 +139,8 @@ void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const { // it. This is nice because it allows most passes to get away with not handling // the symbol table directly for this common task. // -Constant *Module::getOrInsertFunction(StringRef Name, - FunctionType *Ty, - AttributeSet AttributeList) { +Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty, + AttributeList AttributeList) { // See if we have a definition for the specified function already. GlobalValue *F = getNamedValue(Name); if (!F) { @@ -145,49 +163,7 @@ Constant *Module::getOrInsertFunction(StringRef Name, Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty) { - return getOrInsertFunction(Name, Ty, AttributeSet()); -} - -// getOrInsertFunction - Look up the specified function in the module symbol -// table. If it does not exist, add a prototype for the function and return it. -// This version of the method takes a null terminated list of function -// arguments, which makes it easier for clients to use. -// -Constant *Module::getOrInsertFunction(StringRef Name, - AttributeSet AttributeList, - Type *RetTy, ...) { - va_list Args; - va_start(Args, RetTy); - - // Build the list of argument types... - std::vector<Type*> ArgTys; - while (Type *ArgTy = va_arg(Args, Type*)) - ArgTys.push_back(ArgTy); - - va_end(Args); - - // Build the function type and chain to the other getOrInsertFunction... - return getOrInsertFunction(Name, - FunctionType::get(RetTy, ArgTys, false), - AttributeList); -} - -Constant *Module::getOrInsertFunction(StringRef Name, - Type *RetTy, ...) { - va_list Args; - va_start(Args, RetTy); - - // Build the list of argument types... - std::vector<Type*> ArgTys; - while (Type *ArgTy = va_arg(Args, Type*)) - ArgTys.push_back(ArgTy); - - va_end(Args); - - // Build the function type and chain to the other getOrInsertFunction... - return getOrInsertFunction(Name, - FunctionType::get(RetTy, ArgTys, false), - AttributeSet()); + return getOrInsertFunction(Name, Ty, AttributeList()); } // getFunction - Look up the specified function in the module symbol table. @@ -208,7 +184,8 @@ Function *Module::getFunction(StringRef Name) const { /// If AllowLocal is set to true, this function will return types that /// have an local. By default, these types are not returned. /// -GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) { +GlobalVariable *Module::getGlobalVariable(StringRef Name, + bool AllowLocal) const { if (GlobalVariable *Result = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name))) if (AllowLocal || !Result->hasLocalLinkage()) @@ -465,6 +442,14 @@ void Module::dropAllReferences() { GIF.dropAllReferences(); } +unsigned Module::getNumberRegisterParameters() const { + auto *Val = + cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters")); + if (!Val) + return 0; + return cast<ConstantInt>(Val->getValue())->getZExtValue(); +} + unsigned Module::getDwarfVersion() const { auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version")); if (!Val) @@ -496,7 +481,7 @@ PICLevel::Level Module::getPICLevel() const { } void Module::setPICLevel(PICLevel::Level PL) { - addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL); + addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL); } PIELevel::Level Module::getPIELevel() const { @@ -510,7 +495,7 @@ PIELevel::Level Module::getPIELevel() const { } void Module::setPIELevel(PIELevel::Level PL) { - addModuleFlag(ModFlagBehavior::Error, "PIE Level", PL); + addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL); } void Module::setProfileSummary(Metadata *M) { |