comparison gen/typinf.cpp @ 1284:5851c18e4c6d

Add metadata for TypeInfo -> llvm::Type mapping. Disabled for LLVM versions before the introduction of metadata.
author Frits van Bommel <fvbommel wxs.nl>
date Sat, 02 May 2009 11:58:50 +0200
parents 450897f5aae9
children 875afb7a93b6
comparison
equal deleted inserted replaced
1283:450897f5aae9 1284:5851c18e4c6d
38 #include "gen/llvmhelpers.h" 38 #include "gen/llvmhelpers.h"
39 #include "gen/arrays.h" 39 #include "gen/arrays.h"
40 #include "gen/structs.h" 40 #include "gen/structs.h"
41 #include "gen/classes.h" 41 #include "gen/classes.h"
42 #include "gen/linkage.h" 42 #include "gen/linkage.h"
43 #include "gen/metadata.h"
43 44
44 #include "ir/irvar.h" 45 #include "ir/irvar.h"
45 46
46 /******************************************* 47 /*******************************************
47 * Get a canonicalized form of the TypeInfo for use with the internal 48 * Get a canonicalized form of the TypeInfo for use with the internal
282 if (!irg->value) 283 if (!irg->value)
283 irg->value = new llvm::GlobalVariable(irg->type.get(), true, 284 irg->value = new llvm::GlobalVariable(irg->type.get(), true,
284 TYPEINFO_LINKAGE_TYPE, NULL, mangle, gIR->module); 285 TYPEINFO_LINKAGE_TYPE, NULL, mangle, gIR->module);
285 286
286 tid->ir.irGlobal = irg; 287 tid->ir.irGlobal = irg;
288
289 #ifdef USE_METADATA
290 // Add some metadata for use by optimization passes.
291 static std::string prefix = "llvm.ldc.typeinfo.";
292 std::string metaname = prefix + mangle;
293 LLGlobalVariable* meta = gIR->module->getGlobalVariable(metaname);
294 // Don't generate metadata for non-concrete types
295 // (such as tuple types, slice types, typeof(expr), etc.)
296 if (!meta && tid->tinfo->toBasetype()->ty < Terror) {
297 LLConstant* mdVals[] = {
298 llvm::cast<LLConstant>(irg->value),
299 llvm::UndefValue::get(DtoType(tid->tinfo))
300 };
301 llvm::MDNode* metadata =
302 llvm::MDNode::get(mdVals, sizeof(mdVals) / sizeof(mdVals[0]));
303 new llvm::GlobalVariable(metadata->getType(), true,
304 METADATA_LINKAGE_TYPE, metadata, metaname, gIR->module);
305 }
306 #endif
287 307
288 DtoDeclareTypeInfo(tid); 308 DtoDeclareTypeInfo(tid);
289 } 309 }
290 310
291 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) 311 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)