From: David van Moolenbroek Date: Wed, 11 Nov 2015 04:38:27 +0000 (+0100) Subject: passes: updates for LLVM 3.6.1 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=bdb565187c0f1a04513dd488df843317b27f86c8;p=minix.git passes: updates for LLVM 3.6.1 This patch also takes the first step to remove backward compatibility code from the passes. We only support the in-tree LLVM version. Change-Id: I7836e524404afba151d1a8bfa539b505e1dbdb8e --- diff --git a/minix/llvm/include/magic_common.h b/minix/llvm/include/magic_common.h index 7a3d22dcd..d3e653a6d 100644 --- a/minix/llvm/include/magic_common.h +++ b/minix/llvm/include/magic_common.h @@ -65,7 +65,7 @@ /* 0=disabled, 1=force no debug output, 2=force no output (for perf. testing).*/ #define MAGIC_CHECK_LEVEL 1 /* 2=extra checks, 1=standard checks, 0=no checks (for perf. testing). */ -#define MAGIC_FLATTEN_FUNCTION_ARGS 1 +#define MAGIC_FLATTEN_FUNCTION_ARGS 0 /* XXX was 1 but header was not included, seems to break on variadic functions */ #define MAGIC_CHECK_INVARIANTS 1 #define MAGIC_SHRINK_TYPE_STR 1 #define MAGIC_MAX_NAME_LEN 64 diff --git a/minix/llvm/passes/Makefile.inc b/minix/llvm/passes/Makefile.inc index 7661894ff..7b80f9f7a 100644 --- a/minix/llvm/passes/Makefile.inc +++ b/minix/llvm/passes/Makefile.inc @@ -5,7 +5,7 @@ # LLVMPREFIX?=../../../../../obj_llvm.i386/Release+Asserts -CFLAGS += -D__MINIX -D_MINIX_SYSTEM +CFLAGS += -D__MINIX -D_MINIX_SYSTEM -DDEBUG_TYPE=\""$PASSNAME"\" INCLUDES += -I../../include QUIET=@ diff --git a/minix/llvm/passes/asr/ASRPass.cpp b/minix/llvm/passes/asr/ASRPass.cpp index 22439aad3..dc70a4a82 100644 --- a/minix/llvm/passes/asr/ASRPass.cpp +++ b/minix/llvm/passes/asr/ASRPass.cpp @@ -3,7 +3,7 @@ #include #include -#define MAGIC_IS_MAGIC_FUNC(M, F) (!(F)->getSection().compare(MAGIC_STATIC_FUNCTIONS_SECTION)) +#define MAGIC_IS_MAGIC_FUNC(M, F) (!StringRef((F)->getSection()).compare(MAGIC_STATIC_FUNCTIONS_SECTION)) using namespace llvm; @@ -392,7 +392,7 @@ bool ASRPass::runOnModule(Module &M) { * (last found allocation instruction will be at the front), and remove it from the basic block. * */ int hasAddressTaken = 0; - for (Value::use_iterator UI = allocaInst->use_begin(), E = allocaInst->use_end(); UI != E; ++UI) { + for (Value::user_iterator UI = allocaInst->user_begin(), E = allocaInst->user_end(); UI != E; ++UI) { /* Loop through all the Uses of this allocation function. */ @@ -555,7 +555,7 @@ bool ASRPass::runOnModule(Module &M) { assert(ret); if(stackframe_caller_padding && max_offset > 0) { - std::vector Users(F->use_begin(), F->use_end()); + std::vector Users(F->user_begin(), F->user_end()); while (!Users.empty()) { User *U = Users.back(); Users.pop_back(); diff --git a/minix/llvm/passes/include/common/pass_common.h b/minix/llvm/passes/include/common/pass_common.h index 6590621af..1c2c00633 100644 --- a/minix/llvm/passes/include/common/pass_common.h +++ b/minix/llvm/passes/include/common/pass_common.h @@ -31,7 +31,7 @@ #define DATA_LAYOUT_TY DataLayout #define ATTRIBUTE_SET_RET_IDX ATTRIBUTE_SET_TY::ReturnIndex #define ATTRIBUTE_SET_FN_IDX ATTRIBUTE_SET_TY::FunctionIndex -#include +#include #if LLVM_VERSION == 32 #include #include @@ -145,15 +145,17 @@ class PassUtil { public: static void writeTypeSymbolic(raw_string_ostream &OS, TYPECONST Type *type, const Module *M); static const std::string getTypeDescription(TYPECONST Type* type); - static Value *findDbgGlobalDeclare(GlobalVariable *V); - static Value *findDbgSubprogramDeclare(const Function *F); + static MDNode *findDbgGlobalDeclare(GlobalVariable *V); + static MDNode *findDbgSubprogramDeclare(const Function *F); static void getDbgLocationInfoRelPath(const std::string &baseDir, const std::string &filename, const std::string &directory, std::string &relPath); static void getDbgLocationInfo(DIDescriptor &DID, const std::string &baseDir, std::string *filename, std::string *directory, std::string *relPath); static bool getInstrDbgLocationInfo(Instruction *I, const std::string &baseDir, std::string *filename, std::string *directory, std::string *relPath, unsigned int *lineNum, bool expand=true); static unsigned getDbgSubrangeNumElements(const DISubrange &subrange); static bool isDbgVectorTy(const DIType &type); static DIType getDITypeDerivedFrom(const DIDerivedType &type); + static DIType getDITypeFromRef(const DITypeRef &ref); static bool isOpaqueTy(TYPECONST Type *type); + static bool isPrimitiveTy(TYPECONST Type *type); static Constant* getGetElementPtrConstant(Constant *constant, std::vector &indexes); static GetElementPtrInst* createGetElementPtrInstruction(Value *ptr, std::vector &indexes, const Twine &NameStr="", Instruction *InsertBefore=0); static GetElementPtrInst* createGetElementPtrInstruction(Value *ptr, std::vector &indexes, const Twine &NameStr="", BasicBlock *InsertAtEnd=0); @@ -210,7 +212,7 @@ inline const std::string PassUtil::getTypeDescription(TYPECONST Type* type) { return string; } -inline Value *PassUtil::findDbgGlobalDeclare(GlobalVariable *V) { +inline MDNode *PassUtil::findDbgGlobalDeclare(GlobalVariable *V) { #if LLVM_VERSION >= 30 const Module *M = V->getParent(); NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.cu"); @@ -244,7 +246,7 @@ inline Value *PassUtil::findDbgGlobalDeclare(GlobalVariable *V) { #endif } -inline Value *PassUtil::findDbgSubprogramDeclare(const Function *V) { +inline MDNode *PassUtil::findDbgSubprogramDeclare(const Function *V) { #if LLVM_VERSION >= 30 const Module *M = V->getParent(); NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.cu"); @@ -428,6 +430,20 @@ inline DIType PassUtil::getDITypeDerivedFrom(const DIDerivedType &type) { #endif } +inline DIType PassUtil::getDITypeFromRef(const DITypeRef &ref) { + static DITypeIdentifierMap TypeIdentifierMap; + static bool TypeMapInitialized = false; + if (!TypeMapInitialized) { + /* TODO: generate the type identifier map only once! */ + assert(PassUtil::M && "Set module first!"); + if (NamedMDNode *CU_Nodes = PassUtil::M->getNamedMetadata("llvm.dbg.cu")) { + TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes); + TypeMapInitialized = true; + } + } + return ref.resolve(TypeIdentifierMap); +} + inline bool PassUtil::isOpaqueTy(TYPECONST Type *type) { #if LLVM_VERSION >= 30 return type->isStructTy() && (((TYPECONST StructType*)type)->isOpaque() || type->getNumContainedTypes() == 0); @@ -436,6 +452,10 @@ inline bool PassUtil::isOpaqueTy(TYPECONST Type *type) { #endif } +inline bool PassUtil::isPrimitiveTy(TYPECONST Type *type) { + return type->isVoidTy() || type->isFloatingPointTy() || type->isLabelTy() || type->isMetadataTy() || type->isX86_MMXTy(); +} + inline Constant* PassUtil::getGetElementPtrConstant(Constant *constant, std::vector &indexes) { #if LLVM_VERSION >= 30 ArrayRef ref(indexes); diff --git a/minix/llvm/passes/include/magic/MagicPass.h b/minix/llvm/passes/include/magic/MagicPass.h index 38a65e2e3..bfd795884 100644 --- a/minix/llvm/passes/include/magic/MagicPass.h +++ b/minix/llvm/passes/include/magic/MagicPass.h @@ -4,7 +4,6 @@ #include #include -#include #include #include #include diff --git a/minix/llvm/passes/include/magic/support/Backports.h b/minix/llvm/passes/include/magic/support/Backports.h deleted file mode 100644 index 96b9e0b84..000000000 --- a/minix/llvm/passes/include/magic/support/Backports.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef BACKPORTS_H -#define BACKPORTS_H - -#include - -using namespace llvm; - -namespace llvm { - -class Backports { - public: - - //From DbgInfoPrinter.cpp (LLVM 2.9) - static Value *findDbgGlobalDeclare(GlobalVariable *V); - static Value *findDbgSubprogramDeclare(Function *V); - static const DbgDeclareInst *findDbgDeclare(const Value *V); - - //From Local.cpp (LLVM 2.9) - static DbgDeclareInst *FindAllocaDbgDeclare(Value *V); -}; - -} - -#endif diff --git a/minix/llvm/passes/include/magic/support/EDIType.h b/minix/llvm/passes/include/magic/support/EDIType.h index a47fb69c4..98e9ea897 100644 --- a/minix/llvm/passes/include/magic/support/EDIType.h +++ b/minix/llvm/passes/include/magic/support/EDIType.h @@ -37,6 +37,7 @@ class EDIType { const DIDerivedType& getMember(unsigned i) const; bool isUnionOrStructTy(bool isStruct=true, bool isUnion=true) const; bool hasInnerPointers() const; + unsigned int getTypeArrayNum() const; DIArray getTypeArray() const; const EDIType* getTopStructType(unsigned index) const; @@ -262,7 +263,7 @@ inline bool EDIType::isPointerTy() const { } inline bool EDIType::isOpaqueTy() const { - return (isCompositeType() && getTypeArray().getNumElements() == 0); + return (isCompositeType() && getTypeArrayNum() == 0); } inline void EDIType::writeTypeSymbolic(raw_string_ostream &OS, TYPECONST Type *type, const Module *M) { diff --git a/minix/llvm/passes/include/magic/support/MagicDebugFunction.h b/minix/llvm/passes/include/magic/support/MagicDebugFunction.h index 2f1161685..6f980fe5c 100644 --- a/minix/llvm/passes/include/magic/support/MagicDebugFunction.h +++ b/minix/llvm/passes/include/magic/support/MagicDebugFunction.h @@ -122,7 +122,7 @@ inline void MagicDebugFunction::fixCalls(Module &M, const std::string &baseDir) bool ret = MagicDebugFunction::inlineHookCalls(debugFunction, hooks, flags, argsMapping, trailingArgs); assert(ret && "Unable to inline the calls to the hook functions."); - std::vector Users(function->use_begin(), function->use_end()); + std::vector Users(function->user_begin(), function->user_end()); std::vector EqPointers; while (!Users.empty()) { User *U = Users.back(); @@ -153,11 +153,11 @@ inline void MagicDebugFunction::fixCalls(Module &M, const std::string &baseDir) MagicUtil::replaceCallInst(I, newInst, 1); } } else if (GlobalValue * GV = dyn_cast(U)) { - Users.insert(Users.end(), GV->use_begin(), GV->use_end()); + Users.insert(Users.end(), GV->user_begin(), GV->user_end()); EqPointers.push_back(GV); } else if (ConstantExpr * CE = dyn_cast(U)) { if (CE->isCast()) { - Users.insert(Users.end(), CE->use_begin(), CE->use_end()); + Users.insert(Users.end(), CE->user_begin(), CE->user_end()); EqPointers.push_back(CE); } } diff --git a/minix/llvm/passes/include/magic/support/MagicMmapCtlFunction.h b/minix/llvm/passes/include/magic/support/MagicMmapCtlFunction.h index e21184d08..de24eaa3b 100644 --- a/minix/llvm/passes/include/magic/support/MagicMmapCtlFunction.h +++ b/minix/llvm/passes/include/magic/support/MagicMmapCtlFunction.h @@ -88,7 +88,7 @@ inline Function* MagicMmapCtlFunction::getFunction() const { /* This assumes in-band metadata of 1 page before every mmapped region. */ inline void MagicMmapCtlFunction::fixCalls(Module &M, Function *magicGetPageSizeFunc) const { - std::vector Users(function->use_begin(), function->use_end()); + std::vector Users(function->user_begin(), function->user_end()); while (!Users.empty()) { User *U = Users.back(); Users.pop_back(); diff --git a/minix/llvm/passes/include/magic/support/SmartType.h b/minix/llvm/passes/include/magic/support/SmartType.h index be5c6aecb..b979581fe 100644 --- a/minix/llvm/passes/include/magic/support/SmartType.h +++ b/minix/llvm/passes/include/magic/support/SmartType.h @@ -2,7 +2,6 @@ #define SMART_TYPE_H #include -#include #include #include #include @@ -144,7 +143,7 @@ inline bool SmartType::isPrimitiveTy() const { assert(type->isStructTy()); return true; } - return isTy(type->isPrimitiveType(), aEDIType.isPrimitiveType(), "isPrimitiveTy"); + return isTy(PassUtil::isPrimitiveTy(type), aEDIType.isPrimitiveType(), "isPrimitiveTy"); } inline bool SmartType::isAggregateType() const { diff --git a/minix/llvm/passes/include/pass.h b/minix/llvm/passes/include/pass.h index 25db98f88..b5a8ecfed 100644 --- a/minix/llvm/passes/include/pass.h +++ b/minix/llvm/passes/include/pass.h @@ -14,12 +14,11 @@ #include #include -#include -#include +#include #include #include -#include +#include #include #include diff --git a/minix/llvm/passes/include/sectionify/SectionifyPass.h b/minix/llvm/passes/include/sectionify/SectionifyPass.h index 2d764f7c9..d859f74c8 100644 --- a/minix/llvm/passes/include/sectionify/SectionifyPass.h +++ b/minix/llvm/passes/include/sectionify/SectionifyPass.h @@ -2,7 +2,6 @@ #define SECTIONIFY_PASS_H -#define DEBUG_TYPE "sectionify" #include using namespace llvm; @@ -25,8 +24,8 @@ class SectionifyPass : public ModulePass { std::vector dataRegexList; std::string moduleName; - bool sectionifyFromRegex(GlobalValue *value, Regex *regex, std::string §ion); - bool sectionify(GlobalValue *value, std::vector ®exList, std::map ®exMap); + bool sectionifyFromRegex(GlobalObject *value, Regex *regex, std::string §ion); + bool sectionify(GlobalObject *value, std::vector ®exList, std::map ®exMap); void parseAndInitRegexMap(cl::list &stringListOpt, std::vector ®exList, std::map ®exMap, std::string regexType); bool initRegexMap(std::map ®exMap, std::vector ®exList, std::map &stringMap, std::vector &stringList, std::string regexType); bool parseStringMapOpt(std::map &map, std::vector &keyList, std::vector &stringList); diff --git a/minix/llvm/passes/magic/MagicPass.cpp b/minix/llvm/passes/magic/MagicPass.cpp index f8ae89e3b..2c00f4d0e 100644 --- a/minix/llvm/passes/magic/MagicPass.cpp +++ b/minix/llvm/passes/magic/MagicPass.cpp @@ -977,7 +977,7 @@ bool MagicPass::runOnModule(Module &M) { while(!magicMemFunctions.empty()) { MagicMemFunction magicMemFunction = magicMemFunctions.front(); magicMemFunctions.erase(magicMemFunctions.begin()); - std::vector Users(magicMemFunction.getFunction()->use_begin(), magicMemFunction.getFunction()->use_end()); + std::vector Users(magicMemFunction.getFunction()->user_begin(), magicMemFunction.getFunction()->user_end()); std::vector EqPointers; while (!Users.empty()) { int annotation; @@ -1139,11 +1139,11 @@ bool MagicPass::runOnModule(Module &M) { } } } else if (GlobalValue *GV = dyn_cast(U)) { - Users.insert(Users.end(), GV->use_begin(), GV->use_end()); + Users.insert(Users.end(), GV->user_begin(), GV->user_end()); EqPointers.push_back(GV); } else if (ConstantExpr *CE = dyn_cast(U)) { if (CE->isCast()) { - Users.insert(Users.end(), CE->use_begin(), CE->use_end()); + Users.insert(Users.end(), CE->user_begin(), CE->user_end()); EqPointers.push_back(CE); } } @@ -1962,7 +1962,7 @@ void MagicPass::findPointerVariables(Function* function, Value *value, std::vect DEBUG_VALUE(" ************************************************************ findPointerVariables: Unknown value: ", value); RETURN_IF(true); } - for (Value::use_iterator i = value->use_begin(), e = value->use_end(); i != e; ++i) { + for (Value::user_iterator i = value->user_begin(), e = value->user_end(); i != e; ++i) { User *user = *i; Instruction *instruction = dyn_cast(user); if(!instruction || instruction->getParent()->getParent() != function) { @@ -2789,7 +2789,7 @@ void MagicPass::fillStackInstrumentedFunctions(std::vector &stackIntr } } stackIntrumentedFuncs.push_back(deepestLLFunction); - for (Value::use_iterator i = deepestLLFunction->use_begin(), e = deepestLLFunction->use_end(); i != e; ++i) { + for (Value::user_iterator i = deepestLLFunction->user_begin(), e = deepestLLFunction->user_end(); i != e; ++i) { User *user = *i; if(Instruction *I = dyn_cast(user)) { fillStackInstrumentedFunctions(stackIntrumentedFuncs, I->getParent()->getParent()); @@ -2944,7 +2944,7 @@ bool MagicPass::isMagicGV(Module &M, GlobalVariable *GV) if (GV->isThreadLocal() && (GV->getName().startswith(MAGIC_PREFIX_STR) || GV->getName().startswith("rcu"))) { return true; } - if (!GV->getSection().compare(MAGIC_LLVM_METADATA_SECTION)) { + if (!StringRef(GV->getSection()).compare(MAGIC_LLVM_METADATA_SECTION)) { return true; } if (GV->getName().startswith("__start") || GV->getName().startswith("__stop") || GV->getName().startswith("llvm.")) { diff --git a/minix/llvm/passes/magic/Makefile b/minix/llvm/passes/magic/Makefile index 9d89f58e6..ee5b101dc 100644 --- a/minix/llvm/passes/magic/Makefile +++ b/minix/llvm/passes/magic/Makefile @@ -1,6 +1,6 @@ PASSNAME = magic -OBJS = support/Backports.o support/EDIType.o support/TypeUtil.o support/BitFieldAggregation.o support/SmartType.o support/VariableRefs.o support/MagicUtil.o MagicPass.o +OBJS = support/EDIType.o support/TypeUtil.o support/BitFieldAggregation.o support/SmartType.o support/VariableRefs.o support/MagicUtil.o MagicPass.o HEADERS = $(wildcard ../include/magic/support/*.h) include ../Makefile.inc diff --git a/minix/llvm/passes/magic/support/Backports.cpp b/minix/llvm/passes/magic/support/Backports.cpp deleted file mode 100644 index 748ae5071..000000000 --- a/minix/llvm/passes/magic/support/Backports.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include - -#include -#include -#include - -using namespace llvm; - -namespace llvm { - -//===----------------------------------------------------------------------===// -// Public static methods -//===----------------------------------------------------------------------===// - -/// Find the debug info descriptor corresponding to this global variable. -Value *Backports::findDbgGlobalDeclare(GlobalVariable *V) { - return PassUtil::findDbgGlobalDeclare(V); -} - -/// Find the debug info descriptor corresponding to this function. -Value *Backports::findDbgSubprogramDeclare(Function *V) { - return PassUtil::findDbgSubprogramDeclare(V); -} - -/// Finds the llvm.dbg.declare intrinsic corresponding to this value if any. -/// It looks through pointer casts too. -const DbgDeclareInst *Backports::findDbgDeclare(const Value *V) { - V = V->stripPointerCasts(); - - if (!isa(V) && !isa(V)) - return 0; - - const Function *F = NULL; - if (const Instruction *I = dyn_cast(V)) - F = I->getParent()->getParent(); - else if (const Argument *A = dyn_cast(V)) - F = A->getParent(); - - for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) - for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end(); - BI != BE; ++BI) - if (const DbgDeclareInst *DDI = dyn_cast(BI)) - if (DDI->getAddress() == V) - return DDI; - - return 0; -} - -/// FindAllocaDbgDeclare - Finds the llvm.dbg.declare intrinsic describing the -/// alloca 'V', if any. -DbgDeclareInst *Backports::FindAllocaDbgDeclare(Value *V) { -#if LLVM_VERSION >= 33 - if (MDNode *DebugNode = MDNode::getIfExists(V->getContext(), V)) - for (Value::use_iterator UI = DebugNode->use_begin(), - E = DebugNode->use_end(); UI != E; ++UI) - if (DbgDeclareInst *DDI = dyn_cast(*UI)) - return DDI; - - return 0; -#else - -/// -/// There is an unfixed bug (http://llvm.org/bugs/show_bug.cgi?id=10887) -/// that drops debug information references for local variables at linking time. -/// This is way the method FindAllocaDbgDeclare() will always return NULL and -/// we need to resort to some ugly workaround. -/// - AllocaInst *AI = dyn_cast(V); - if(!AI) { - return NULL; - } - BasicBlock *varParent = AI->getParent(); - Function *varFunc = varParent->getParent(); - if(!AI->hasName() || !AI->getName().compare("retval")) { - return NULL; - } - StringRef varName = AI->getName(); - bool isInlinedVar = false; - bool isScopedVar = false; - DIType aDIType, aAddrDIType, tmpDIType; - DbgDeclareInst *DDI = NULL, *addrDDI = NULL; - SmallVector< StringRef, 8 > vector; - varName.split(vector, "."); - if(vector.size() >= 2 && vector[1][0] == 'i') { - isInlinedVar = true; - varName = vector[0]; - } - if(!isInlinedVar) { - //for non-inlined variables we have to look in the first bb first. - for(BasicBlock::iterator i=varParent->begin(), e=varParent->end();i!=e;i++) { - if(DbgDeclareInst *DI = dyn_cast(i)) { - MDNode *node = DI->getVariable(); - assert(node); - DIVariable DIV(node); - if(!DIV.getName().compare(varName)) { - aDIType = DIV.getType(); - DDI = DI; - break; - } - StringRef addrVarName(DIV.getName().str() + "_addr"); - if(!addrVarName.compare(varName)) { - aAddrDIType = DIV.getType(); - addrDDI = DI; - break; - } - } - } - if(!DDI && !addrDDI) { - //not found? probably a scoped variable, look anywhere else. - isScopedVar = true; - } - } - if(isInlinedVar || isScopedVar) { - //for inlined/scoped variables we have to look everywhere in the function and name clashing could also occur. - bool isDuplicate = false; - for (inst_iterator it = inst_begin(varFunc), et = inst_end(varFunc); it != et; ++it) { - Instruction *inst = &(*it); - if(DbgDeclareInst *DI = dyn_cast(inst)) { - MDNode *node = DI->getVariable(); - assert(node); - DIVariable DIV(node); - StringRef addrVarName(DIV.getName().str() + "_addr"); - if(!DIV.getName().compare(varName) || !addrVarName.compare(varName)) { - tmpDIType = DIV.getType(); - EDIType tmpEDIType(tmpDIType); - if(!SmartType::isTypeConsistent(AI->getAllocatedType(), &tmpEDIType)) { - continue; - } - bool skipDIType = false; - if(DDI) { - EDIType aEDIType(aDIType); - skipDIType = true; - if(!aEDIType.equals(&tmpEDIType)) { - isDuplicate = true; - } - } - if(addrDDI) { - EDIType aAddrEDIType(aAddrDIType); - skipDIType = true; - if(!aAddrEDIType.equals(&tmpEDIType)) { - isDuplicate = true; - } - } - if(!skipDIType && !DIV.getName().compare(varName)) { - aDIType = tmpDIType; - DDI = DI; - continue; - } - if(!skipDIType && !addrVarName.compare(varName)) { - aAddrDIType = tmpDIType; - addrDDI = DI; - continue; - } - } - } - } - if(isDuplicate) { - //name clashing problem with inline/scoped variables, pretend nothing was found - DDI = NULL; - addrDDI = NULL; - } - } - if(!DDI && !addrDDI) { - return (DbgDeclareInst*)-1; - } - assert((DDI && !addrDDI) || (!DDI && addrDDI)); - DDI = DDI ? DDI : addrDDI; - return DDI; -#endif -} - -} diff --git a/minix/llvm/passes/magic/support/EDIType.cpp b/minix/llvm/passes/magic/support/EDIType.cpp index bea74a14d..7b993b908 100644 --- a/minix/llvm/passes/magic/support/EDIType.cpp +++ b/minix/llvm/passes/magic/support/EDIType.cpp @@ -56,11 +56,16 @@ const EDIType& EDIType::getContainedType(unsigned i, bool norm) const { } return subType; } - DIArray aDIArray = getTypeArray(); - unsigned numContainedTypes = aDIArray.getNumElements(); - assert(i < numContainedTypes); - EDIType tmpType((const DIType) aDIArray.getElement(i), norm); - subType = tmpType; + if (isFunctionTy()) { + DITypeArray DTA = ((const DISubroutineType)aDIType).getTypeArray(); + subType = PassUtil::getDITypeFromRef(DTA.getElement(i)); + } else { + DIArray aDIArray = getTypeArray(); + unsigned numContainedTypes = aDIArray.getNumElements(); + assert(i < numContainedTypes); + EDIType tmpType((const DIType) aDIArray.getElement(i), norm); + subType = tmpType; + } return subType; } @@ -72,9 +77,7 @@ unsigned EDIType::getNumContainedTypes() const { if(isDerivedType() || isArrayOrVectorTy) { return 1; } - DIArray aDIArray = getTypeArray(); - unsigned numContainedTypes = aDIArray.getNumElements(); - return numContainedTypes; + return getTypeArrayNum(); } const DIDerivedType& EDIType::getMember(unsigned i) const { @@ -128,11 +131,23 @@ bool EDIType::hasInnerPointers() const { return false; } +unsigned int EDIType::getTypeArrayNum() const { + EDIType_assert(isCompositeType()); + /* This function is used from isOpaqueTy(), so do not use isFunctionTy() here. */ + if (getTag() == dwarf::DW_TAG_subroutine_type) { + DITypeArray DTA = ((const DISubroutineType)aDIType).getTypeArray(); + return DTA.getNumElements(); + } else { + return getTypeArray().getNumElements(); + } +} + DIArray EDIType::getTypeArray() const { static std::set nonOpaqueEmptyTypes; static std::set::iterator nonOpaqueEmptyTypesIt; EDIType_assert(isCompositeType()); - DIArray aDIArray = ((const DICompositeType)aDIType).getTypeArray(); + EDIType_assert(getTag() != dwarf::DW_TAG_subroutine_type); /* as above, no isFunctionTy() */ + DIArray aDIArray = ((const DICompositeType)aDIType).getElements(); if(aDIArray.getNumElements() == 0 && checkOpaqueTypes && myNames.size() > 0) { const EDIType *aType = NULL; std::string name; @@ -144,7 +159,7 @@ DIArray EDIType::getTypeArray() const { } } if(aType) { - aDIArray = ((const DICompositeType *)aType->getDIType())->getTypeArray(); + aDIArray = ((const DICompositeType *)aType->getDIType())->getElements(); nonOpaqueEmptyTypesIt = nonOpaqueEmptyTypes.find(name); if(nonOpaqueEmptyTypesIt == nonOpaqueEmptyTypes.end()) { EDITypeLog("Found a non-opaque composite type with 0 members! Name is: " << name); @@ -390,9 +405,8 @@ bool EDIType::equals(const EDIType *other) const { std::string EDIType::lookupTypedefName(std::string &typedefName) { static std::string noName; - for (DebugInfoFinder::iterator I = DIFinder.type_begin(), - E = DIFinder.type_end(); I != E; ++I) { - DIType aDIType(*I); + for (const DIType aDITypeIt : DIFinder.types()) { + DIType aDIType(aDITypeIt); if(aDIType.getTag() == dwarf::DW_TAG_typedef && aDIType.getName().compare(typedefName)) { while(aDIType.getTag() == dwarf::DW_TAG_typedef) { aDIType = PassUtil::getDITypeDerivedFrom((const DIDerivedType)aDIType); @@ -426,9 +440,7 @@ std::string EDIType::lookupUnionMemberName(TYPECONST Type* type) { const EDIType* EDIType::getStructEDITypeByName(std::string &typeName) { static EDIType aEDIType; assert(module); - for (DebugInfoFinder::iterator I = DIFinder.type_begin(), - E = DIFinder.type_end(); I != E; ++I) { - const DIType aDIType(*I); + for (const DIType aDIType : DIFinder.types()) { //skip zero-element stuct types, necessary to avoid infinite recursion during opaque type lookup //xxx opaque type lookup should not be necessary but is there a bug in the frontend that leaves certain concrete types unnecessarily opaque? const EDIType tmpEDIType(aDIType, NORMALIZE, DO_NOT_CHECK_OPAQUE_TYPES); diff --git a/minix/llvm/passes/magic/support/MagicUtil.cpp b/minix/llvm/passes/magic/support/MagicUtil.cpp index 7c38871dc..688a06a62 100644 --- a/minix/llvm/passes/magic/support/MagicUtil.cpp +++ b/minix/llvm/passes/magic/support/MagicUtil.cpp @@ -27,9 +27,9 @@ unsigned getModuleHash(DIDescriptor DID, const std::string &baseDir, StringRef e StringRef MagicUtil::getGVSourceName(Module &M, GlobalVariable *GV, DIGlobalVariable **DIGVP, const std::string &baseDir) { static DIGlobalVariable Var; - Value *DIGV = Backports::findDbgGlobalDeclare(GV); + MDNode *DIGV = PassUtil::findDbgGlobalDeclare(GV); if(DIGV) { - Var = DIGlobalVariable(cast(DIGV)); + Var = DIGlobalVariable(DIGV); if(DIGVP) *DIGVP = &Var; if(GV->getLinkage() == GlobalValue::InternalLinkage){ /* static variable */ @@ -50,9 +50,9 @@ StringRef MagicUtil::getGVSourceName(Module &M, GlobalVariable *GV, DIGlobalVari Module::GlobalListType &globalList = M.getGlobalList(); for (Module::global_iterator it = globalList.begin(); it != globalList.end(); ++it) { GlobalVariable *OtherGV = &(*it); - Value *OtherDIGV = Backports::findDbgGlobalDeclare(OtherGV); + MDNode *OtherDIGV = PassUtil::findDbgGlobalDeclare(OtherGV); if(OtherDIGV) { - DIGlobalVariable OtherVar(cast(OtherDIGV)); + DIGlobalVariable OtherVar(OtherDIGV); DIScope otherScope = OtherVar.getContext(); if(otherScope.isLexicalBlock()){ @@ -101,7 +101,7 @@ StringRef MagicUtil::getGVSourceName(Module &M, GlobalVariable *GV, DIGlobalVari StringRef MagicUtil::getLVSourceName(Module &M, AllocaInst *V, DIVariable **DIVP) { static DIVariable Var; - const DbgDeclareInst *DDI = Backports::FindAllocaDbgDeclare(V); + const DbgDeclareInst *DDI = FindAllocaDbgDeclare(V); if(DDI && DDI != (const DbgDeclareInst *) -1){ Var = DIVariable(cast(DDI->getVariable())); if(DIVP) *DIVP = &Var; @@ -136,9 +136,9 @@ StringRef MagicUtil::getLVSourceName(Module &M, AllocaInst *V, DIVariable **DIVP StringRef MagicUtil::getFunctionSourceName(Module &M, Function *F, DISubprogram **DISP, const std::string &baseDir) { static DISubprogram Func; - Value *DIF = Backports::findDbgSubprogramDeclare(F); + MDNode *DIF = PassUtil::findDbgSubprogramDeclare(F); if(DIF) { - Func = DISubprogram(cast(DIF)); + Func = DISubprogram(DIF); if(DISP) *DISP = &Func; if(F->getLinkage() == GlobalValue::InternalLinkage){ std::stringstream stm; @@ -709,9 +709,8 @@ bool MagicUtil::hasAddressTaken(const GlobalValue *GV, bool includeMembers) { std::vector sourceUsers; sourceUsers.push_back(GV); if(includeMembers && isa(GV)) { - for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end(); - UI != E; ++UI) { - const User *U = *UI; + for (const Use &UI : GV->uses()) { + const User *U = UI.getUser(); const ConstantExpr *constantExpr = dyn_cast(U); if(isa(U)) { sourceUsers.push_back(U); @@ -723,16 +722,15 @@ bool MagicUtil::hasAddressTaken(const GlobalValue *GV, bool includeMembers) { } for(unsigned i=0;iuse_begin(), E = sourceUsers[i]->use_end(); - UI != E; ++UI) { - const User *U = *UI; + for (const Use &UI : sourceUsers[i]->uses()) { + const User *U = UI.getUser(); if (const StoreInst *SI = dyn_cast(U)) { if (SI->getOperand(0) == sourceUsers[i] || SI->isVolatile()) return true; // Storing addr of sourceUsers[i]. } else if (isa(U) || isa(U)) { // Make sure we are calling the function, not passing the address. ImmutableCallSite CS(cast(U)); - if (!CS.isCallee(UI)) + if (!CS.isCallee(&UI)) return true; } else if (const LoadInst *LI = dyn_cast(U)) { if (LI->isVolatile()) @@ -764,7 +762,7 @@ bool MagicUtil::lookupValueSet(const GlobalVariable *GV, std::vector &value GV->removeDeadConstantUsers(); std::set set; - for (Value::const_use_iterator UI = GV->use_begin(), E = GV->use_end(); + for (Value::const_user_iterator UI = GV->user_begin(), E = GV->user_end(); UI != E; ++UI) { const User *U = *UI; if (const StoreInst *SI = dyn_cast(U)) { @@ -811,7 +809,7 @@ Value* MagicUtil::getStringOwner(GlobalVariable *GV) std::vector sourceUsers; sourceUsers.push_back(GV); - for (Value::use_iterator UI = GV->use_begin(), E = GV->use_end(); + for (Value::user_iterator UI = GV->user_begin(), E = GV->user_end(); UI != E; ++UI) { User *U = *UI; ConstantExpr *constantExpr = dyn_cast(U); @@ -825,7 +823,7 @@ Value* MagicUtil::getStringOwner(GlobalVariable *GV) Value *stringOwner = NULL; for(unsigned i=0;iuse_begin(), E = sourceUsers[i]->use_end(); + for (Value::user_iterator UI = sourceUsers[i]->user_begin(), E = sourceUsers[i]->user_end(); UI != E; ++UI) { User *U = *UI; Value *V = U; diff --git a/minix/llvm/passes/magic/support/SmartType.cpp b/minix/llvm/passes/magic/support/SmartType.cpp index 281f204d6..0d8c49db2 100644 --- a/minix/llvm/passes/magic/support/SmartType.cpp +++ b/minix/llvm/passes/magic/support/SmartType.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -341,12 +342,12 @@ const SmartType* SmartType::getSmartTypeFromGV(Module &M, GlobalVariable *GV, DI if(GV->getName().startswith(".str")) { return NULL; } - Value *DIGV = Backports::findDbgGlobalDeclare(GV); + MDNode *DIGV = PassUtil::findDbgGlobalDeclare(GV); if (!DIGV) { return NULL; } - DIGlobalVariable Var(cast(DIGV)); - DIType aDIType = Var.getType(); + DIGlobalVariable Var(DIGV); + DIType aDIType = PassUtil::getDITypeFromRef(Var.getType()); const SmartType* retSmartType = new SmartType(GV->getType()->getElementType(), &aDIType); if(DIG) { *DIG = Var; @@ -355,7 +356,7 @@ const SmartType* SmartType::getSmartTypeFromGV(Module &M, GlobalVariable *GV, DI } const SmartType* SmartType::getSmartTypeFromLV(Module &M, AllocaInst *AI, DIVariable *DIV) { - const DbgDeclareInst *DDI = Backports::FindAllocaDbgDeclare(AI); + const DbgDeclareInst *DDI = FindAllocaDbgDeclare(AI); if (!DDI) { return NULL; } @@ -363,7 +364,7 @@ const SmartType* SmartType::getSmartTypeFromLV(Module &M, AllocaInst *AI, DIVari return (const SmartType*)-1; } DIVariable Var(cast(DDI->getVariable())); - DIType aDIType = Var.getType(); + DIType aDIType = PassUtil::getDITypeFromRef(Var.getType()); if(DIV) { *DIV = Var; } @@ -372,11 +373,11 @@ const SmartType* SmartType::getSmartTypeFromLV(Module &M, AllocaInst *AI, DIVari } const SmartType* SmartType::getSmartTypeFromFunction(Module &M, Function *F, DISubprogram *DIS) { - Value *DIF = Backports::findDbgSubprogramDeclare(F); + MDNode *DIF = PassUtil::findDbgSubprogramDeclare(F); if (!DIF) { return NULL; } - DISubprogram Sub(cast(DIF)); + DISubprogram Sub(DIF); DIType aDIType = Sub.getType(); const SmartType* retSmartType = new SmartType(F->getType()->getElementType(), &aDIType); if(DIS) { diff --git a/minix/llvm/passes/sectionify/SectionifyPass.cpp b/minix/llvm/passes/sectionify/SectionifyPass.cpp index e9a4bad7c..abda50938 100644 --- a/minix/llvm/passes/sectionify/SectionifyPass.cpp +++ b/minix/llvm/passes/sectionify/SectionifyPass.cpp @@ -127,7 +127,7 @@ bool SectionifyPass::runOnModule(Module &M) { return sectionified; } -bool SectionifyPass::sectionifyFromRegex(GlobalValue *value, Regex *regex, std::string §ion) +bool SectionifyPass::sectionifyFromRegex(GlobalObject *value, Regex *regex, std::string §ion) { bool returnValue = false; @@ -142,7 +142,7 @@ bool SectionifyPass::sectionifyFromRegex(GlobalValue *value, Regex *regex, std:: DEBUG(errs() << "Sectionified " << valueStrPrefix << (isa(value) ? "Function " : "GlobalVariable ") << value->getName() << " with section " << trgSection << "\n"); value->setSection(trgSection); if (value->hasCommonLinkage()) { - value->setLinkage(GlobalValue::WeakAnyLinkage); + value->setLinkage(GlobalObject::WeakAnyLinkage); } returnValue = true; } @@ -167,7 +167,7 @@ bool SectionifyPass::sectionifyFromRegex(GlobalValue *value, Regex *regex, std:: return returnValue; } -bool SectionifyPass::sectionify(GlobalValue *value, std::vector ®exList, std::map ®exMap) +bool SectionifyPass::sectionify(GlobalObject *value, std::vector ®exList, std::map ®exMap) { std::map::iterator regexMapIt; for (std::vector::iterator it = regexList.begin(); it != regexList.end(); ++it) {