[llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Wed May 19 04:38:02 PDT 2004
Changes in directory reopt/lib/TraceToFunction:
TraceToFunction.cpp updated: 1.43 -> 1.44
---
Log message:
Rewrite threadFLIEdges() not to use RTTI so wastefully, and to skip
over most instructions.
---
Diffs of the changes: (+35 -38)
Index: reopt/lib/TraceToFunction/TraceToFunction.cpp
diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.43 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.44
--- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.43 Wed May 19 03:53:20 2004
+++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 04:37:04 2004
@@ -197,7 +197,7 @@
for (unsigned i = 0; i < BI->getNumSuccessors (); ++i) {
BasicBlock *BIT = BI->getSuccessor (i);
if (!T.contains (BIT))
- return BI;
+ return BI;
}
return NULL;
}
@@ -444,46 +444,43 @@
}
void TraceFunctionBuilder::threadFLIEdges (Function *F) {
- for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI)
- for (BasicBlock::iterator Inst = FI->begin (), BE = FI->end (); Inst != BE; ++Inst) {
- if (isa<PHINode> (Inst)) {
- // In a PHI node, replace references to FLI blocks with the
- // corresponding edge's source.
- for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) {
- Value *op = Inst->getOperand (OI);
- if (isa<BasicBlock> (op)) {
- BasicBlock *BB = cast<BasicBlock> (op);
- FLIMapTy::iterator It = FLIMap.find (BB);
- if (It != FLIMap.end ()) {
- DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI
- << " (FLI block " << BB->getName () << " --> <["
- << It->second.first->getName () << "], "
- << It->second.second->getName () << ">) of instruction: "
- << *Inst << "\n");
- Inst->setOperand (OI, It->second.first);
- }
- }
- }
- } else if (isa<BranchInst> (Inst)) {
- // If it's a branch, replace references to FLI blocks with the
- // corresponding edge's target.
- for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) {
- Value *op = Inst->getOperand (OI);
- if (isa<BasicBlock> (op)) {
- BasicBlock *BB = cast<BasicBlock> (op);
- FLIMapTy::iterator It = FLIMap.find (BB);
- if (It != FLIMap.end ()) {
- DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI
- << " (FLI block " << BB->getName () << " --> <"
- << It->second.first->getName () << ", ["
- << It->second.second->getName () << "]>) of instruction: "
- << *Inst << "\n");
- Inst->setOperand (OI, It->second.second);
- }
- }
+ for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) {
+ // Replace references to FLI blocks in PHI nodes with the
+ // corresponding edge's source.
+ for (BasicBlock::iterator Inst = FI->begin ();
+ PHINode *PN = dyn_cast<PHINode> (Inst); ++Inst)
+ for (unsigned i = 0, e = PN->getNumIncomingValues (); i != e; ++i) {
+ FLIMapTy::iterator It = FLIMap.find (PN->getIncomingBlock (i));
+ if (It != FLIMap.end ()) {
+ DEBUG (std::cerr << "threadFLIEdges: threading incoming block " << i
+ << " (FLI block " << It->first->getName () << " --> <["
+ << It->second.first->getName () << "], "
+ << It->second.second->getName () << ">) of PHI node: "
+ << *PN << "\n");
+ PN->setIncomingBlock (i, It->second.first);
}
}
+
+ // Look for a branch at the end of the basic block.
+ TerminatorInst *TI = FI->getTerminator ();
+ if (!TI) continue;
+ BranchInst *BI = dyn_cast<BranchInst> (TI);
+ if (!BI) continue;
+
+ // Replace references to FLI blocks in branches with the
+ // corresponding edge's target.
+ for (unsigned i = 0, e = BI->getNumSuccessors (); i != e; ++i) {
+ FLIMapTy::iterator It = FLIMap.find (BI->getSuccessor (i));
+ if (It != FLIMap.end ()) {
+ DEBUG (std::cerr << "threadFLIEdges: threading successor " << i
+ << " (FLI block " << It->first->getName () << " --> <"
+ << It->second.first->getName () << ", ["
+ << It->second.second->getName () << "]>) of branch: "
+ << *BI << "\n");
+ BI->setSuccessor (i, It->second.second);
+ }
}
+ }
}
/// buildFLIMap - Removes any FLI blocks which ended up in the trace, and
More information about the llvm-commits
mailing list