diff options
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/LiveVar/BBLiveVar.cpp | 18 | ||||
| -rw-r--r-- | llvm/lib/Analysis/LiveVar/BBLiveVar.h | 11 | ||||
| -rw-r--r-- | llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp | 47 | 
3 files changed, 43 insertions, 33 deletions
| diff --git a/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp b/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp index 54de63e58ff..4b07ebc6323 100644 --- a/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp +++ b/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp @@ -18,8 +18,9 @@ using std::cerr;  static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar")); -BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) { -  BBLiveVar *Result = new BBLiveVar(BB, POID); +BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, +                                 unsigned POID) { +  BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);    BB.addAnnotation(Result);    return Result;  } @@ -34,8 +35,8 @@ void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {  } -BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id) -  : Annotation(AID), BB(bb), POID(id) { +BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id) +  : Annotation(AID), BB(bb), MBB(mbb), POID(id) {    InSetChanged = OutSetChanged = false;    calcDefUseSets(); @@ -49,15 +50,12 @@ BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)  //-----------------------------------------------------------------------------  void BBLiveVar::calcDefUseSets() { -  // get the iterator for machine instructions -  const MachineBasicBlock &MIVec = MachineBasicBlock::get(&BB); -    // iterate over all the machine instructions in BB -  for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(), -         MIE = MIVec.rend(); MII != MIE; ++MII) { +  for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(), +         MIE = MBB.rend(); MII != MIE; ++MII) {      const MachineInstr *MI = *MII; -    if (DEBUG_LV >= LV_DEBUG_Verbose) {                            // debug msg +    if (DEBUG_LV >= LV_DEBUG_Verbose) {        cerr << " *Iterating over machine instr ";        MI->dump();        cerr << "\n"; diff --git a/llvm/lib/Analysis/LiveVar/BBLiveVar.h b/llvm/lib/Analysis/LiveVar/BBLiveVar.h index 0eed3375ab7..eada3a7f086 100644 --- a/llvm/lib/Analysis/LiveVar/BBLiveVar.h +++ b/llvm/lib/Analysis/LiveVar/BBLiveVar.h @@ -13,6 +13,7 @@  #include <map>  class BasicBlock;  class Value; +class MachineBasicBlock;  enum LiveVarDebugLevel_t {    LV_DEBUG_None, @@ -25,9 +26,10 @@ extern LiveVarDebugLevel_t DEBUG_LV;  class BBLiveVar : public Annotation {    const BasicBlock &BB;         // pointer to BasicBlock +  MachineBasicBlock &MBB;       // Pointer to MachineBasicBlock    unsigned POID;                // Post-Order ID -  ValueSet DefSet;              // Def set (with no preceding uses) for LV analysis +  ValueSet DefSet;           // Def set (with no preceding uses) for LV analysis    ValueSet InSet, OutSet;       // In & Out for LV analysis    bool InSetChanged, OutSetChanged;   // set if the InSet/OutSet is modified @@ -49,16 +51,19 @@ class BBLiveVar : public Annotation {    void calcDefUseSets();         // calculates the Def & Use sets for this BB -  BBLiveVar(const BasicBlock &BB, unsigned POID); +  BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);    ~BBLiveVar() {}                // make dtor private   public: -  static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID); +  static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB, +                               unsigned POID);    static BBLiveVar *GetFromBB(const BasicBlock &BB);    static void RemoveFromBB(const BasicBlock &BB);    inline bool isInSetChanged() const  { return InSetChanged; }        inline bool isOutSetChanged() const { return OutSetChanged; } +  MachineBasicBlock &getMachineBasicBlock() const { return MBB; } +    inline unsigned getPOId() const { return POID; }    bool applyTransferFunc();      // calcultes the In in terms of Out  diff --git a/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp index 198afed537c..962afa44a18 100644 --- a/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp +++ b/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp @@ -8,7 +8,7 @@  #include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"  #include "BBLiveVar.h"  #include "llvm/CodeGen/MachineInstr.h" -#include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/CodeGen/MachineFunction.h"  #include "llvm/Support/CFG.h"  #include "Support/PostOrderIterator.h"  #include "Support/SetOperations.h" @@ -71,31 +71,36 @@ bool FunctionLiveVarInfo::runOnFunction(Function &F) {  // constructs BBLiveVars and init Def and In sets  //----------------------------------------------------------------------------- -void FunctionLiveVarInfo::constructBBs(const Function *M) { -  unsigned int POId = 0;                // Reverse Depth-first Order ID -   -  for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M); -      BBI != BBE; ++BBI, ++POId) {  -    const BasicBlock &BB = **BBI;        // get the current BB  +void FunctionLiveVarInfo::constructBBs(const Function *F) { +  unsigned POId = 0;                // Reverse Depth-first Order ID +  std::map<const BasicBlock*, unsigned> PONumbering; + +  for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M); +      BBI != BBE; ++BBI) +    PONumbering[*BBI] = POId++; +  MachineFunction &MF = MachineFunction::get(F); +  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { +    const BasicBlock &BB = *I->getBasicBlock();        // get the current BB       if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n"; -    // create a new BBLiveVar -    BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);   +    BBLiveVar *LVBB; +    std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB); +    if (POI != PONumbering.end()) { +      // create a new BBLiveVar +      LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);   +    } else { +      // The PO iterator does not discover unreachable blocks, but the random +      // iterator later may access these blocks.  We must make sure to +      // initialize unreachable blocks as well.  However, LV info is not correct +      // for those blocks (they are not analyzed) +      // +      LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId); +    }      if (DEBUG_LV)        LVBB->printAllSets();    } - -  // Since the PO iterator does not discover unreachable blocks, -  // go over the random iterator and init those blocks as well. -  // However, LV info is not correct for those blocks (they are not -  // analyzed) -  // -  for (Function::const_iterator BBRI = M->begin(), BBRE = M->end(); -       BBRI != BBRE; ++BBRI, ++POId) -    if (!BBLiveVar::GetFromBB(*BBRI))                 // Not yet processed? -      BBLiveVar::CreateOnBB(*BBRI, POId);  } @@ -240,7 +245,9 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {  //-----------------------------------------------------------------------------  void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { -  const MachineBasicBlock &MIVec = MachineBasicBlock::get(BB); +  BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB); +  assert(BBLV && "BBLiveVar annotation doesn't exist?"); +  const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();    if (DEBUG_LV >= LV_DEBUG_Instr)      std::cerr << "\n======For BB " << BB->getName() | 

