Add metadata for TypeInfo -> llvm::Type mapping.

Disabled for LLVM versions before the introduction of metadata.
This commit is contained in:
Frits van Bommel
2009-05-02 11:58:50 +02:00
parent 6c91185a77
commit a9c518d82b
2 changed files with 31 additions and 0 deletions

11
gen/metadata.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef LDC_GEN_METADATA_H
#define LDC_GEN_METADATA_H
#include "gen/llvm-version.h"
#if LLVM_REV >= 68420
# define USE_METADATA
# define METADATA_LINKAGE_TYPE llvm::GlobalValue::WeakODRLinkage
#endif
#endif

View File

@@ -40,6 +40,7 @@
#include "gen/structs.h"
#include "gen/classes.h"
#include "gen/linkage.h"
#include "gen/metadata.h"
#include "ir/irvar.h"
@@ -285,6 +286,25 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
tid->ir.irGlobal = irg;
#ifdef USE_METADATA
// Add some metadata for use by optimization passes.
static std::string prefix = "llvm.ldc.typeinfo.";
std::string metaname = prefix + mangle;
LLGlobalVariable* meta = gIR->module->getGlobalVariable(metaname);
// Don't generate metadata for non-concrete types
// (such as tuple types, slice types, typeof(expr), etc.)
if (!meta && tid->tinfo->toBasetype()->ty < Terror) {
LLConstant* mdVals[] = {
llvm::cast<LLConstant>(irg->value),
llvm::UndefValue::get(DtoType(tid->tinfo))
};
llvm::MDNode* metadata =
llvm::MDNode::get(mdVals, sizeof(mdVals) / sizeof(mdVals[0]));
new llvm::GlobalVariable(metadata->getType(), true,
METADATA_LINKAGE_TYPE, metadata, metaname, gIR->module);
}
#endif
DtoDeclareTypeInfo(tid);
}