From 465f15eda026d33da8f754516d9a0dc2a91d2c3c Mon Sep 17 00:00:00 2001 From: Frits van Bommel Date: Sat, 20 Jun 2009 11:39:13 +0200 Subject: [PATCH] Return `void*` from _d_allocclass so LLVM doesn't do weird things with it... This allows `-instcombine` followed by `-gvn` to do devirtualization, so add `-gvn` in strategic places in the default pass order. --- gen/optimizer.cpp | 10 +++++++--- gen/runtime.cpp | 2 +- runtime/internal/lifetime.d | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index ac8765aa..bfb471eb 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -135,6 +135,7 @@ static void addPassesForOptLevel(PassManager& pm) { addPass(pm, createFunctionAttrsPass()); addPass(pm, createTailCallEliminationPass()); addPass(pm, createCFGSimplificationPass()); + addPass(pm, createGVNPass()); } // -inline @@ -145,10 +146,13 @@ static void addPassesForOptLevel(PassManager& pm) { // Run some optimizations to clean up after inlining. addPass(pm, createScalarReplAggregatesPass()); addPass(pm, createInstructionCombiningPass()); + // -instcombine + gvn == devirtualization :) + addPass(pm, createGVNPass()); - // Inline again, to catch things like foreach delegates - // passed to inlined opApply's where the function wasn't - // known during the first inliner pass. + // Inline again, to catch things like now nonvirtual + // function calls, foreach delegates passed to inlined + // opApply's, etc. where the actual function being called + // wasn't known during the first inliner pass. addPass(pm, createFunctionInliningPass()); // Run clean-up again. diff --git a/gen/runtime.cpp b/gen/runtime.cpp index f13414f8..ce86dec0 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -329,7 +329,7 @@ static void LLVM_D_BuildRuntimeModule() std::string fname("_d_allocclass"); std::vector types; types.push_back(classInfoTy); - const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); + const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M) ->setAttributes(Attr_NoAlias); } diff --git a/runtime/internal/lifetime.d b/runtime/internal/lifetime.d index 206a2568..be78f9ce 100644 --- a/runtime/internal/lifetime.d +++ b/runtime/internal/lifetime.d @@ -107,7 +107,7 @@ private /** * */ -extern (C) Object _d_allocclass(ClassInfo ci) +extern (C) void* _d_allocclass(ClassInfo ci) { void* p; @@ -150,7 +150,7 @@ extern (C) Object _d_allocclass(ClassInfo ci) //(cast(byte*) p)[0 .. ci.init.length] = ci.init[]; debug(PRINTF) printf("initialization done\n"); - return cast(Object) p; + return p; } /**