Update for metadata changes in LLVM trunk.

This commit is contained in:
Frits van Bommel 2009-05-11 11:59:22 +02:00
parent 041a8c4bd3
commit 49a2924823
5 changed files with 38 additions and 10 deletions

View file

@ -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

View file

@ -202,16 +202,16 @@ namespace {
return false;
MDNode* node = dyn_cast<MDNode>(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<Constant>(node->getOperand(CD_Finalize));
Constant* hasDestructor = dyn_cast<Constant>(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<Constant>(node->getOperand(CD_CustomDelete));
Constant* hasCustomDelete = dyn_cast<Constant>(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();
}

View file

@ -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"

View file

@ -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<LLConstant>(irg->value);
mdVals[TD_Type] = llvm::UndefValue::get(DtoType(tid->tinfo));

View file

@ -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);