[llvm-commits] CVS: llvm/lib/Reoptimizer/SSAPRE/RuntimeLICM.cpp
Tanya Brethour
tbrethou at cs.uiuc.edu
Fri Jun 6 16:22:01 PDT 2003
Changes in directory llvm/lib/Reoptimizer/SSAPRE:
RuntimeLICM.cpp added (r1.1)
---
Log message:
Simple runtime LICM on traces.
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/SSAPRE/RuntimeLICM.cpp
diff -c /dev/null llvm/lib/Reoptimizer/SSAPRE/RuntimeLICM.cpp:1.1
*** /dev/null Fri Jun 6 16:21:13 2003
--- llvm/lib/Reoptimizer/SSAPRE/RuntimeLICM.cpp Fri Jun 6 16:21:03 2003
***************
*** 0 ****
--- 1,70 ----
+ //===-- RuntimeLICM.cpp - Runtime LICM on traces ----------------------------=//
+ //
+ // Implements the loop invariant code motion optmization for traces.
+ // Only moves LI instructions to the prologe if all operands are not
+ // defined in the trace.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/BasicBlock.h"
+ #include "llvm/Instruction.h"
+ #include "llvm/iMemory.h"
+ #include "llvm/iPHINode.h"
+ #include "llvm/Reoptimizer/BinInterface/LLVMTrace.h"
+
+ #include <iostream>
+ #include <vector>
+ #include <set>
+
+ using std::vector;
+ using std::set;
+
+ void RuntimeLICM(vector<BasicBlock *> &trace, LLVMTrace <race) {
+
+ //Put the trace in a set for faster searching
+ std::set<BasicBlock*> traceSet(trace.begin(), trace.end());
+
+ //Keep track of the number of LI expressions we find
+ unsigned numLIC = 0;
+
+ //loop over all the basic blocks in my trace
+ for(vector<BasicBlock *>::iterator T = trace.begin(), End = trace.end();
+ T != End; ++T) {
+
+ //loop over all the instructions in the basic block
+ BasicBlock *BB = (*T);
+ for(BasicBlock::iterator i = BB->begin(), e = BB->end(); i != e; ++i) {
+
+ //Keep track of instructions status. Assume invariant until proven
+ //otherwise
+ bool isLoopInvariant = true;
+
+ //Check if its a load, a phi, a terminator, or if it can write to mem
+ //If any of these are true, we can not move it
+ if (!isa<LoadInst>(*i) && !i->mayWriteToMemory() &&
+ !i->isTerminator() && !isa<PHINode>(*i)) {
+
+ //loop over the operands and see where they are defined
+ //if all operands are defined out of the trace, its loop invariant
+ for(User::op_iterator z = i->op_begin(), ze = i->op_end();
+ z != ze; ++z) {
+ Value *V = *z;
+ if(Instruction* def = dyn_cast<Instruction>(V)) {
+ BasicBlock *parent = def->getParent();
+ if(traceSet.count(parent))
+ isLoopInvariant = false;
+ }
+ }
+
+ if(isLoopInvariant) {
+ std::cerr << "Loop Invariant Instruction: " << i << "\n";
+ //move to header block
+ ltrace.moveInstrToSec(&(*i), 0);
+ ++numLIC;
+ }
+ }
+ }
+ }
+
+ std::cerr << "Number Loop Invariant: " << numLIC << "\n";
+ }
More information about the llvm-commits
mailing list