[llvm-commits] CVS: llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Apr 1 14:29:05 PST 2004
Changes in directory llvm/lib/Transforms/Utils:
DemoteRegToStack.cpp updated: 1.10 -> 1.11
---
Log message:
Fix PR310: http://llvm.cs.uiuc.edu/PR310 and TailDup/2004-04-01-DemoteRegToStack.llx
---
Diffs of the changes: (+12 -5)
Index: llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
diff -u llvm/lib/Transforms/Utils/DemoteRegToStack.cpp:1.10 llvm/lib/Transforms/Utils/DemoteRegToStack.cpp:1.11
--- llvm/lib/Transforms/Utils/DemoteRegToStack.cpp:1.10 Tue Mar 16 17:23:11 2004
+++ llvm/lib/Transforms/Utils/DemoteRegToStack.cpp Thu Apr 1 14:28:45 2004
@@ -19,6 +19,7 @@
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
+#include <map>
using namespace llvm;
/// DemoteRegToStack - This function takes a virtual register computed by an
@@ -45,13 +46,19 @@
// to the incoming value.
//
// Note that if there are multiple edges from a basic block to this PHI
- // node that we'll insert multiple loads. Since DemoteRegToStack requires
- // a mem2reg pass after it (to produce reasonable code), we don't care.
+ // node that we cannot multiple loads. The problem is that the resultant
+ // PHI node will have multiple values (from each load) coming in from the
+ // same block, which is illegal SSA form. For this reason, we keep track
+ // and reuse loads we insert.
+ std::map<BasicBlock*, Value*> Loads;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (PN->getIncomingValue(i) == &I) {
- // Insert the load into the predecessor block
- Value *V = new LoadInst(Slot, I.getName()+".reload",
- PN->getIncomingBlock(i)->getTerminator());
+ Value *&V = Loads[PN->getIncomingBlock(i)];
+ if (V == 0) {
+ // Insert the load into the predecessor block
+ V = new LoadInst(Slot, I.getName()+".reload",
+ PN->getIncomingBlock(i)->getTerminator());
+ }
PN->setIncomingValue(i, V);
}
More information about the llvm-commits
mailing list