From: Brian Gaeke Date: Tue, 12 Aug 2003 22:00:24 +0000 (+0000) Subject: Give std::map the short name BBMap, because X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=aee2fdf0690f1e074a5193bb73005f10abba8d4b;p=oota-llvm.git Give std::map the short name BBMap, because it's used 7 different times. Rename `getBackEdges' to `findAndInstrumentBackEdges', for clarity. Remove some excess whitespace and commented-out code. Use shorter forms of CallInst ctors. Do not make `reopt_threshold' visible to the LLVM program, and do not pass it to the call to `reoptimizerInitialize'. Don't pass the GlobalVariable representing it to any of our helper methods. `reopt_threshold' is an internal parameter of the reoptimizer, which InstLoops does not need to know about. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7794 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp index 91b4e203fc2..a74d5c75b1e 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/InstLoops.cpp @@ -29,6 +29,7 @@ enum Color{ }; namespace{ + typedef std::map BBMap; struct InstLoops : public FunctionPass { virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); @@ -38,15 +39,14 @@ namespace{ void getBackEdgesVisit(BasicBlock *u, std::map &color, std::map &d, - int &time, Value *threshold, - std::map &be); - void removeRedundant(std::map &be); - void getBackEdges(Function &F, Value *threshold); + int &time, BBMap &be); + void removeRedundant(BBMap &be); + void findAndInstrumentBackEdges(Function &F); public: bool runOnFunction(Function &F); }; - RegisterOpt X("instloops", "Instrument backedges for profiling"); + RegisterOpt X("instloops", "Instrument backedges for profiling"); } // createInstLoopsPass - Create a new pass to add path profiling @@ -61,20 +61,17 @@ Pass *createInstLoopsPass() { void InstLoops::getBackEdgesVisit(BasicBlock *u, std::map &color, std::map &d, - int &time, Value *threshold, - std::map &be) { - + int &time, BBMap &be) { color[u]=GREY; time++; d[u]=time; for(BasicBlock::succ_iterator vl = succ_begin(u), ve = succ_end(u); vl != ve; ++vl){ - BasicBlock *BB = *vl; if(color[BB]!=GREY && color[BB]!=BLACK){ - getBackEdgesVisit(BB, color, d, time, threshold, be); + getBackEdgesVisit(BB, color, d, time, be); } //now checking for d and f vals @@ -91,26 +88,17 @@ void InstLoops::getBackEdgesVisit(BasicBlock *u, //look at all BEs, and remove all BEs that are dominated by other BE's in the //set -void InstLoops::removeRedundant(std::map &be){ +void InstLoops::removeRedundant(BBMap &be) { std::vector toDelete; for(std::map::iterator MI = be.begin(), - ME = be.end(); MI != ME; ++MI){ - //std::cerr<first->getName()<<"\t->\t"<second->getName()<<"\n"; - //std::cerr<first; - //std::cerr<second; - for(std::map::iterator MMI = be.begin(), - MME = be.end(); MMI != MME; ++MMI){ - if(DS->properlyDominates(MI->first, MMI->first)){ + ME = be.end(); MI != ME; ++MI) + for(BBMap::iterator MMI = be.begin(), MME = be.end(); MMI != MME; ++MMI) + if(DS->properlyDominates(MI->first, MMI->first)) toDelete.push_back(MMI->first); - //std::cerr<first->getName()<<"\t Dominates\t"<first->getName(); - } - } - } - + // Remove all the back-edges we found from be. for(std::vector::iterator VI = toDelete.begin(), - VE = toDelete.end(); VI != VE; ++VI){ + VE = toDelete.end(); VI != VE; ++VI) be.erase(*VI); - } } //getting the backedges in a graph @@ -124,12 +112,12 @@ void InstLoops::removeRedundant(std::map &be){ //have been visited //So we have a back edge when we meet a successor of //a node with smaller time, and GREY color -void InstLoops::getBackEdges(Function &F, Value *threshold){ +void InstLoops::findAndInstrumentBackEdges(Function &F){ std::map color; std::map d; - std::map be; + BBMap be; int time=0; - getBackEdgesVisit(F.begin(), color, d, time, threshold, be); + getBackEdgesVisit(F.begin(), color, d, time, be); removeRedundant(be); @@ -159,7 +147,7 @@ void InstLoops::getBackEdges(Function &F, Value *threshold){ assert(inCountMth && "Initial method could not be inserted!"); - Instruction *call = new CallInst(inCountMth, ""); + Instruction *call = new CallInst(inCountMth); lt.push_back(call); lt.push_back(new BranchInst(BB)); @@ -177,46 +165,22 @@ void InstLoops::getBackEdges(Function &F, Value *threshold){ } } -//Per function pass for inserting counters and call function +/// Entry point for FunctionPass that inserts calls to trigger function. +/// bool InstLoops::runOnFunction(Function &F){ - - static GlobalVariable *threshold = NULL; - static bool insertedThreshold = false; - DS = &getAnalysis(); - if(F.isExternal()) { return false; } - - if(!insertedThreshold){ - threshold = new GlobalVariable(Type::IntTy, false, - GlobalValue::ExternalLinkage, 0, - "reopt_threshold"); - - F.getParent()->getGlobalList().push_back(threshold); - insertedThreshold = true; - } - + // Add a call to reoptimizerInitialize() to beginning of function named main. if(F.getName() == "main"){ - //intialize threshold - std::vector initialize_args; - initialize_args.push_back(PointerType::get(Type::IntTy)); - - const FunctionType *Fty = FunctionType::get(Type::VoidTy, initialize_args, - false); - Function *initialMeth = F.getParent()->getOrInsertFunction("reoptimizerInitialize", Fty); + std::vector 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!"); - - std::vector trargs; - trargs.push_back(threshold); - - new CallInst(initialMeth, trargs, "", F.begin()->begin()); + new CallInst(initialMeth, "", F.begin()->begin()); // Insert it. } - - assert(threshold && "GlobalVariable threshold not defined!"); - - getBackEdges(F, threshold); - - return true; + findAndInstrumentBackEdges(F); + return true; // Function was modified. }