X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FModule.cpp;h=5dbed69ca6cfd8d211e65de0e3ede88f68f48644;hb=a3610962a91043142353e0011c0a420708537bdb;hp=739f8888f96a46283b8584334eb5fbe18891566e;hpb=aab87fe0ec98072580586850ed00bac3d00df6c0;p=oota-llvm.git diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 739f8888f96..5dbed69ca6c 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -17,12 +17,13 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/GVMaterializer.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/GVMaterializer.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/LLVMContext.h" -#include "llvm/Support/LeakDetector.h" +#include "llvm/IR/LeakDetector.h" +#include "llvm/Support/Dwarf.h" #include #include #include @@ -43,7 +44,7 @@ template class llvm::SymbolTableListTraits; // Module::Module(StringRef MID, LLVMContext &C) - : Context(C), Materializer(NULL), ModuleID(MID), DL("") { + : Context(C), Materializer(), ModuleID(MID), DL("") { ValSymTab = new ValueSymbolTable(); NamedMDSymTab = new StringMap(); Context.addModule(this); @@ -95,7 +96,7 @@ Constant *Module::getOrInsertFunction(StringRef Name, AttributeSet AttributeList) { // See if we have a definition for the specified function already. GlobalValue *F = getNamedValue(Name); - if (F == 0) { + if (!F) { // Nope, add it Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); if (!New->isIntrinsic()) // Intrinsics get attrs set on construction @@ -104,16 +105,6 @@ Constant *Module::getOrInsertFunction(StringRef Name, return New; // Return the new prototype. } - // Okay, the function exists. Does it have externally visible linkage? - if (F->hasLocalLinkage()) { - // Clear the function's name. - F->setName(""); - // Retry, now there won't be a conflict. - Constant *NewF = getOrInsertFunction(Name, Ty); - F->setName(Name); - return NewF; - } - // If the function exists but has the wrong type, return a bitcast to the // right type. if (F->getType() != PointerType::getUnqual(Ty)) @@ -193,7 +184,7 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) { dyn_cast_or_null(getNamedValue(Name))) if (AllowLocal || !Result->hasLocalLinkage()) return Result; - return 0; + return nullptr; } /// getOrInsertGlobal - Look up the specified global in the module symbol table. @@ -205,11 +196,11 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) { Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) { // See if we have a definition for the specified global already. GlobalVariable *GV = dyn_cast_or_null(getNamedValue(Name)); - if (GV == 0) { + if (!GV) { // Nope, add it GlobalVariable *New = new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage, - 0, Name); + nullptr, Name); return New; // Return the new declaration. } @@ -271,8 +262,7 @@ getModuleFlagsMetadata(SmallVectorImpl &Flags) const { const NamedMDNode *ModFlags = getModuleFlagsMetadata(); if (!ModFlags) return; - for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) { - MDNode *Flag = ModFlags->getOperand(i); + for (const MDNode *Flag : ModFlags->operands()) { if (Flag->getNumOperands() >= 3 && isa(Flag->getOperand(0)) && isa(Flag->getOperand(1))) { // Check the operands of the MDNode before accessing the operands. @@ -291,12 +281,11 @@ getModuleFlagsMetadata(SmallVectorImpl &Flags) const { Value *Module::getModuleFlag(StringRef Key) const { SmallVector ModuleFlags; getModuleFlagsMetadata(ModuleFlags); - for (unsigned I = 0, E = ModuleFlags.size(); I < E; ++I) { - const ModuleFlagEntry &MFE = ModuleFlags[I]; + for (const ModuleFlagEntry &MFE : ModuleFlags) { if (Key == MFE.Key->getString()) return MFE.Val; } - return 0; + return nullptr; } /// getModuleFlagsMetadata - Returns the NamedMDNode in the module that @@ -339,17 +328,21 @@ void Module::addModuleFlag(MDNode *Node) { } void Module::setDataLayout(StringRef Desc) { + DL.reset(Desc); + if (Desc.empty()) { DataLayoutStr = ""; } else { - DL.init(Desc); DataLayoutStr = DL.getStringRepresentation(); + // DataLayoutStr is now equivalent to Desc, but since the representation + // is not unique, they may not be identical. } } void Module::setDataLayout(const DataLayout *Other) { if (!Other) { DataLayoutStr = ""; + DL.reset(""); } else { DL = *Other; DataLayoutStr = DL.getStringRepresentation(); @@ -358,7 +351,7 @@ void Module::setDataLayout(const DataLayout *Other) { const DataLayout *Module::getDataLayout() const { if (DataLayoutStr.empty()) - return 0; + return nullptr; return &DL; } @@ -437,3 +430,10 @@ void Module::dropAllReferences() { for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I) I->dropAllReferences(); } + +unsigned Module::getDwarfVersion() const { + Value *Val = getModuleFlag("Dwarf Version"); + if (!Val) + return dwarf::DWARF_VERSION; + return cast(Val)->getZExtValue(); +}