From 49a29248233424f707b29d3715e56dc377443c6c Mon Sep 17 00:00:00 2001 From: Frits van Bommel Date: Mon, 11 May 2009 11:59:22 +0200 Subject: [PATCH] Update for metadata changes in LLVM trunk. --- gen/metadata.h | 27 +++++++++++++++++++++++++++ gen/passes/GarbageCollect2Stack.cpp | 16 +++++++++------- gen/passes/StripMetaData.cpp | 1 - gen/typinf.cpp | 2 +- ir/irclass.cpp | 2 +- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/gen/metadata.h b/gen/metadata.h index 551ce5a5..6050b978 100644 --- a/gen/metadata.h +++ b/gen/metadata.h @@ -6,6 +6,33 @@ #if LLVM_REV >= 68420 // Yay, we have metadata! +// The metadata interface is still in flux... +#if LLVM_REV >= 71407 + // MDNode was moved into its own header, and contains Value*s + #include "llvm/MDNode.h" + typedef llvm::Value MDNodeField; + + // Use getNumElements() and getElement() to access elements. + inline unsigned MD_GetNumElements(llvm::MDNode* N) { + return N->getNumElements(); + } + inline MDNodeField* MD_GetElement(llvm::MDNode* N, unsigned i) { + return N->getElement(i); + } +#else + // MDNode is in Constants.h, and contains Constant*s + #include "llvm/Constants.h" + typedef llvm::Constant MDNodeField; + + // Use getNumOperands() and getOperand() to access elements. + inline unsigned MD_GetNumElements(llvm::MDNode* N) { + return N->getNumOperands(); + } + inline MDNodeField* MD_GetElement(llvm::MDNode* N, unsigned i) { + return N->getOperand(i); + } +#endif + #define USE_METADATA #define METADATA_LINKAGE_TYPE llvm::GlobalValue::WeakODRLinkage diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 3445509e..976ae673 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -202,16 +202,16 @@ namespace { return false; MDNode* node = dyn_cast(global->getInitializer()); - if (!node || node->getNumOperands() != CD_NumFields) + if (!node || MD_GetNumElements(node) != CD_NumFields) return false; // Inserting destructor calls is not implemented yet, so classes // with destructors are ignored for now. - Constant* hasDestructor = dyn_cast(node->getOperand(CD_Finalize)); + Constant* hasDestructor = dyn_cast(MD_GetElement(node, CD_Finalize)); // We can't stack-allocate if the class has a custom deallocator // (Custom allocators don't get turned into this runtime call, so // those can be ignored) - Constant* hasCustomDelete = dyn_cast(node->getOperand(CD_CustomDelete)); + Constant* hasCustomDelete = dyn_cast(MD_GetElement(node, CD_CustomDelete)); if (hasDestructor == NULL || hasCustomDelete == NULL) return false; @@ -219,7 +219,7 @@ namespace { != ConstantInt::getFalse()) return false; - Ty = node->getOperand(CD_BodyType)->getType(); + Ty = MD_GetElement(node, CD_BodyType)->getType(); return true; } @@ -366,6 +366,8 @@ bool GarbageCollect2Stack::runOnFunction(Function &F) { IRBuilder<> Builder(BB, Inst); Value* newVal = info->promote(CS, Builder, A); + DEBUG(DOUT << "Promoted to: " << *newVal); + // Make sure the type is the same as it was before, and replace all // uses of the runtime call with the alloca. if (newVal->getType() != Inst->getType()) @@ -395,11 +397,11 @@ const Type* Analysis::getTypeFor(Value* typeinfo) const { if (!node) return NULL; - if (node->getNumOperands() != TD_NumFields || - (TD_Confirm >= 0 && node->getOperand(TD_Confirm)->stripPointerCasts() != ti_global)) + if (MD_GetNumElements(node) != TD_NumFields || + (TD_Confirm >= 0 && MD_GetElement(node, TD_Confirm)->stripPointerCasts() != ti_global)) return NULL; - return node->getOperand(TD_Type)->getType(); + return MD_GetElement(node, TD_Type)->getType(); } diff --git a/gen/passes/StripMetaData.cpp b/gen/passes/StripMetaData.cpp index f5cd1ad6..ba12a86f 100644 --- a/gen/passes/StripMetaData.cpp +++ b/gen/passes/StripMetaData.cpp @@ -30,7 +30,6 @@ #include "llvm/Pass.h" #include "llvm/Module.h" -#include "llvm/Constants.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" diff --git a/gen/typinf.cpp b/gen/typinf.cpp index fad45739..4a817bc5 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -294,7 +294,7 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid) // (such as tuple types, slice types, typeof(expr), etc.) if (!meta && tid->tinfo->toBasetype()->ty < Terror) { // Construct the fields - LLConstant* mdVals[TD_NumFields]; + MDNodeField* mdVals[TD_NumFields]; if (TD_Confirm >= 0) mdVals[TD_Confirm] = llvm::cast(irg->value); mdVals[TD_Type] = llvm::UndefValue::get(DtoType(tid->tinfo)); diff --git a/ir/irclass.cpp b/ir/irclass.cpp index 1a6c4be2..624b06cf 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -82,7 +82,7 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol() bool hasDestructor = (classdecl->dtor != NULL); bool hasCustomDelete = (classdecl->aggDelete != NULL); // Construct the fields - LLConstant* mdVals[CD_NumFields]; + MDNodeField* mdVals[CD_NumFields]; mdVals[CD_BodyType] = llvm::UndefValue::get(bodyType); mdVals[CD_Finalize] = LLConstantInt::get(LLType::Int1Ty, hasDestructor); mdVals[CD_CustomDelete] = LLConstantInt::get(LLType::Int1Ty, hasCustomDelete);