summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-05-14 21:21:52 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-05-14 21:21:52 +0000
commitcc9620ca29752214b1b9e2840b156ace7c6c2b7f (patch)
tree9da2da19c255ad2c2c757dd485458c4121088fdc /lib/Transforms/Instrumentation
parent93763c3e7d0ec1285653fb98a622fe7d5b7a8abb (diff)
downloadllvm-cc9620ca29752214b1b9e2840b156ace7c6c2b7f.tar.gz
llvm-cc9620ca29752214b1b9e2840b156ace7c6c2b7f.tar.bz2
llvm-cc9620ca29752214b1b9e2840b156ace7c6c2b7f.tar.xz
Clean up this pass somewhat:
Add better comments, including a better head-of-file comment. Prune #includes. Fix a FIXME that Chris put here by using doInitialization(). Use DEBUG() to print out debug msgs. Give names to basic blocks inserted by this pass. Expand tabs. Use InsertProfilingInitCall() from ProfilingUtils to insert the initialize call. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13581 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation')
-rw-r--r--lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp80
1 files changed, 38 insertions, 42 deletions
diff --git a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
index 8331781b07..5d53d230c9 100644
--- a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
+++ b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp
@@ -7,25 +7,23 @@
//
//===----------------------------------------------------------------------===//
//
-// Pass to instrument loops
-//
-// At every backedge, insert a counter for that backedge and a call function
+// This is the first-level instrumentation pass for the Reoptimizer. It
+// instrument the back-edges of loops by inserting a basic block
+// containing a call to llvm_first_trigger (the first-level trigger function),
+// and inserts an initialization call to the main() function.
//
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/Dominators.h"
#include "llvm/Support/CFG.h"
-#include "llvm/Constants.h"
-#include "llvm/iMemory.h"
-#include "llvm/GlobalVariable.h"
-#include "llvm/DerivedTypes.h"
#include "llvm/iOther.h"
-#include "llvm/iOperators.h"
+#include "llvm/Type.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
#include "llvm/Pass.h"
+#include "Support/Debug.h"
+#include "../ProfilingUtils.h"
namespace llvm {
@@ -45,6 +43,7 @@ namespace {
AU.addRequired<DominatorSet>();
}
private:
+ Function *inCountMth;
DominatorSet *DS;
void getBackEdgesVisit(BasicBlock *u,
std::map<BasicBlock *, Color > &color,
@@ -53,6 +52,7 @@ namespace {
void removeRedundant(BBMap &be);
void findAndInstrumentBackEdges(Function &F);
public:
+ bool doInitialization(Module &M);
bool runOnFunction(Function &F);
};
@@ -123,24 +123,19 @@ void InstLoops::findAndInstrumentBackEdges(Function &F){
removeRedundant(be);
- // FIXME: THIS IS HORRIBLY BROKEN. FunctionPass's cannot do this, except in
- // their initialize function!!
- Function *inCountMth =
- F.getParent()->getOrInsertFunction("llvm_first_trigger",
- Type::VoidTy, 0);
-
for(std::map<BasicBlock *, BasicBlock *>::iterator MI = be.begin(),
ME = be.end(); MI != ME; ++MI){
BasicBlock *u = MI->first;
BasicBlock *BB = MI->second;
- //std::cerr<<"Edge from: "<<BB->getName()<<"->"<<u->getName()<<"\n";
- //insert a new basic block: modify terminator accordingly!
- BasicBlock *newBB = new BasicBlock("", u->getParent());
+ // We have a back-edge from BB --> u.
+ DEBUG (std::cerr << "Instrumenting back-edge from " << BB->getName ()
+ << "-->" << u->getName () << "\n");
+ // Split the back-edge, inserting a new basic block on it, and modify the
+ // source BB's terminator accordingly.
+ BasicBlock *newBB = new BasicBlock("backEdgeInst", u->getParent());
BranchInst *ti = cast<BranchInst>(u->getTerminator());
- unsigned char index = 1;
- if(ti->getSuccessor(0) == BB){
- index = 0;
- }
+ unsigned char index = ((ti->getSuccessor(0) == BB) ? 0 : 1);
+
assert(ti->getNumSuccessors() > index && "Not enough successors!");
ti->setSuccessor(index, newBB);
@@ -148,36 +143,37 @@ void InstLoops::findAndInstrumentBackEdges(Function &F){
lt.push_back(new CallInst(inCountMth));
new BranchInst(BB, newBB);
- //now iterate over *vl, and set its Phi nodes right
+ // Now, set the sources of Phi nodes corresponding to the back-edge
+ // in BB to come from the instrumentation block instead.
for(BasicBlock::iterator BB2Inst = BB->begin(), BBend = BB->end();
- BB2Inst != BBend; ++BB2Inst){
-
- if (PHINode *phiInst = dyn_cast<PHINode>(BB2Inst)){
- int bbIndex = phiInst->getBasicBlockIndex(u);
- if(bbIndex>=0){
- phiInst->setIncomingBlock(bbIndex, newBB);
- }
+ BB2Inst != BBend; ++BB2Inst) {
+ if (PHINode *phiInst = dyn_cast<PHINode>(BB2Inst)) {
+ int bbIndex = phiInst->getBasicBlockIndex(u);
+ if (bbIndex>=0)
+ phiInst->setIncomingBlock(bbIndex, newBB);
}
}
}
}
-/// Entry point for FunctionPass that inserts calls to trigger function.
+bool InstLoops::doInitialization (Module &M) {
+ inCountMth = M.getOrInsertFunction("llvm_first_trigger", Type::VoidTy, 0);
+ return true; // Module was modified.
+}
+
+/// runOnFunction - Entry point for FunctionPass that inserts calls to
+/// trigger function.
///
bool InstLoops::runOnFunction(Function &F){
- DS = &getAnalysis<DominatorSet>();
- if(F.isExternal()) {
+ if (F.isExternal ())
return false;
- }
+
+ DS = &getAnalysis<DominatorSet> ();
+
// Add a call to reoptimizerInitialize() to beginning of function named main.
- if(F.getName() == "main"){
- std::vector<const Type*> argTypes; // Empty formal parameter list.
- const FunctionType *Fty = FunctionType::get(Type::VoidTy, argTypes, false);
- Function *initialMeth =
- F.getParent()->getOrInsertFunction("reoptimizerInitialize", Fty);
- assert(initialMeth && "Initialize method could not be inserted!");
- new CallInst(initialMeth, "", F.begin()->begin()); // Insert it.
- }
+ if (F.getName() == "main")
+ InsertProfilingInitCall (&F, "reoptimizerInitialize");
+
findAndInstrumentBackEdges(F);
return true; // Function was modified.
}