[llvm-commits] CVS: llvm-java/lib/Compiler/OperandStack.cpp Locals.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Wed Nov 24 12:32:28 PST 2004
Changes in directory llvm-java/lib/Compiler:
OperandStack.cpp updated: 1.3 -> 1.4
Locals.cpp updated: 1.2 -> 1.3
---
Log message:
Emit all allocas in the entry block so that mem2reg can eliminate
them.
---
Diffs of the changes: (+35 -9)
Index: llvm-java/lib/Compiler/OperandStack.cpp
diff -u llvm-java/lib/Compiler/OperandStack.cpp:1.3 llvm-java/lib/Compiler/OperandStack.cpp:1.4
--- llvm-java/lib/Compiler/OperandStack.cpp:1.3 Sun Nov 7 03:42:46 2004
+++ llvm-java/lib/Compiler/OperandStack.cpp Wed Nov 24 14:32:18 2004
@@ -13,7 +13,9 @@
//===----------------------------------------------------------------------===//
#include "OperandStack.h"
+#include <llvm/BasicBlock.h>
#include <llvm/DerivedTypes.h>
+#include <llvm/Function.h>
#include <llvm/Instructions.h>
#include <llvm/ADT/StringExtras.h>
@@ -30,10 +32,21 @@
valueTy == Type::ShortTy)
value = new CastInst(value, Type::IntTy, "int-extend", insertAtEnd);
- TheStack.push(new AllocaInst(value->getType(),
- NULL,
- "opStack" + utostr(TheStack.size()),
- insertAtEnd));
+ // Insert the alloca at the beginning of the entry block.
+ BasicBlock* entry = &insertAtEnd->getParent()->getEntryBlock();
+ if (entry->empty())
+ TheStack.push(new AllocaInst(
+ value->getType(),
+ NULL,
+ "opStack" + utostr(TheStack.size()),
+ entry));
+ else
+ TheStack.push(new AllocaInst(
+ value->getType(),
+ NULL,
+ "opStack" + utostr(TheStack.size()),
+ &entry->front()));
+
new StoreInst(value, TheStack.top(), insertAtEnd);
}
Index: llvm-java/lib/Compiler/Locals.cpp
diff -u llvm-java/lib/Compiler/Locals.cpp:1.2 llvm-java/lib/Compiler/Locals.cpp:1.3
--- llvm-java/lib/Compiler/Locals.cpp:1.2 Thu Oct 28 14:38:34 2004
+++ llvm-java/lib/Compiler/Locals.cpp Wed Nov 24 14:32:18 2004
@@ -13,7 +13,9 @@
//===----------------------------------------------------------------------===//
#include "Locals.h"
+#include <llvm/BasicBlock.h>
#include <llvm/DerivedTypes.h>
+#include <llvm/Function.h>
#include <llvm/Instructions.h>
#include <llvm/ADT/StringExtras.h>
@@ -28,11 +30,22 @@
void Locals::store(unsigned i, Value* value, BasicBlock* insertAtEnd)
{
if (!TheLocals[i] ||
- TheLocals[i]->getType()->getElementType() != value->getType())
- TheLocals[i] = new AllocaInst(value->getType(),
- NULL,
- "local" + utostr(i),
- insertAtEnd);
+ TheLocals[i]->getType()->getElementType() != value->getType()) {
+ // Insert the alloca at the beginning of the entry block.
+ BasicBlock* entry = &insertAtEnd->getParent()->getEntryBlock();
+ if (entry->empty())
+ TheLocals[i] = new AllocaInst(
+ value->getType(),
+ NULL,
+ "local" + utostr(i),
+ entry);
+ else
+ TheLocals[i] = new AllocaInst(
+ value->getType(),
+ NULL,
+ "local" + utostr(i),
+ &entry->front());
+ }
new StoreInst(value, TheLocals[i], insertAtEnd);
}
More information about the llvm-commits
mailing list