changeset 1506:76936858d1c6

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.
author Frits van Bommel <fvbommel wxs.nl>
date Sat, 20 Jun 2009 11:39:13 +0200
parents 1e5a14691e77
children f86fd3b77285
files gen/optimizer.cpp gen/runtime.cpp runtime/internal/lifetime.d
diffstat 3 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gen/optimizer.cpp	Thu Jun 18 15:44:18 2009 +0100
+++ b/gen/optimizer.cpp	Sat Jun 20 11:39:13 2009 +0200
@@ -135,6 +135,7 @@
         addPass(pm, createFunctionAttrsPass());
         addPass(pm, createTailCallEliminationPass());
         addPass(pm, createCFGSimplificationPass());
+        addPass(pm, createGVNPass());
     }
 
     // -inline
@@ -145,10 +146,13 @@
             // 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.
--- a/gen/runtime.cpp	Thu Jun 18 15:44:18 2009 +0100
+++ b/gen/runtime.cpp	Sat Jun 20 11:39:13 2009 +0200
@@ -329,7 +329,7 @@
         std::string fname("_d_allocclass");
         std::vector<const LLType*> 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);
     }
--- a/runtime/internal/lifetime.d	Thu Jun 18 15:44:18 2009 +0100
+++ b/runtime/internal/lifetime.d	Sat Jun 20 11:39:13 2009 +0200
@@ -107,7 +107,7 @@
 /**
  *
  */
-extern (C) Object _d_allocclass(ClassInfo ci)
+extern (C) void* _d_allocclass(ClassInfo ci)
 {
     void* p;
 
@@ -150,7 +150,7 @@
     //(cast(byte*) p)[0 .. ci.init.length] = ci.init[];
 
     debug(PRINTF) printf("initialization done\n");
-    return cast(Object) p;
+    return p;
 }
 
 /**