[vmkit-commits] [vmkit] r89158 - /vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Tue Nov 17 14:44:06 PST 2009
Author: geoffray
Date: Tue Nov 17 16:44:06 2009
New Revision: 89158
URL: http://llvm.org/viewvc/llvm-project?rev=89158&view=rev
Log:
Remove useless allocas in J3 optimizer.
Modified:
vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp
Modified: vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp?rev=89158&r1=89157&r2=89158&view=diff
==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/LowerConstantCalls.cpp Tue Nov 17 16:44:06 2009
@@ -154,6 +154,49 @@
}
}
}
+
+ // Remove useless Alloca's, usually used for stacks or temporary values.
+ // The optimizers may have rendered them useless.
+ if (AllocaInst* AI = dyn_cast<AllocaInst>(I)) {
+ bool ToDelete = true;
+ for (Value::use_iterator UI = AI->use_begin(), UE = AI->use_end();
+ UI != UE; ++UI) {
+ if (dyn_cast<StoreInst>(UI)) continue;
+ if (BitCastInst* BI = dyn_cast<BitCastInst>(UI)) {
+ if (BI->hasOneUse()) {
+ CallSite Call = CallSite::get(*(BI->use_begin()));
+ Instruction* CI = Call.getInstruction();
+ if (CI && Call.getCalledFunction() == module->llvm_gc_gcroot)
+ continue;
+ }
+ }
+
+ ToDelete = false;
+ break;
+ }
+
+ if (ToDelete) {
+ Changed = true;
+ for (Value::use_iterator UI = AI->use_begin(), UE = AI->use_end();
+ UI != UE;) {
+ Value* Temp = *UI;
+ ++UI;
+ if (StoreInst* SI = dyn_cast<StoreInst>(Temp)) {
+ if (dyn_cast<Instruction>(II) == SI) ++II;
+ SI->eraseFromParent();
+ }
+ if (BitCastInst* BI = dyn_cast<BitCastInst>(Temp)) {
+ CallSite Call = CallSite::get(*(BI->use_begin()));
+ Instruction* CI = Call.getInstruction();
+ if (dyn_cast<Instruction>(II) == CI) ++II;
+ CI->eraseFromParent();
+ if (dyn_cast<Instruction>(II) == BI) ++II;
+ BI->eraseFromParent();
+ }
+ }
+ AI->eraseFromParent();
+ }
+ }
CallSite Call = CallSite::get(I);
Instruction* CI = Call.getInstruction();
More information about the vmkit-commits
mailing list