* Eliminate the Provided set. All Passes now finally just automatically
[oota-llvm.git] / include / llvm / CodeGen / FunctionLiveVarInfo.h
index a1470fe485cf20bdc9f6bf96bbb1b10931817237..b120cc0a1b0bae4e193d4834a5c29d3dd8a76ae2 100644 (file)
@@ -1,15 +1,15 @@
-/* Title:   MethodLiveVarInfo.h             -*- C++ -*-
+/* Title:   FunctionLiveVarInfo.h             -*- C++ -*-
    Author:  Ruchira Sasanka
    Date:    Jun 30, 01
    Purpose: 
 
-   This is the interface for live variable info of a method that is required 
+   This is the interface for live variable info of a function that is required 
    by any other part of the compiler
 
    It must be called like:
 
-       MethodLiveVarInfo MLVI( Mehtod *);  // initializes data structures
-       MLVI.analyze();                     // do the actural live variable anal
+       FunctionLiveVarInfo FLVI(Function *);  // initializes data structures
+       FLVI.analyze();                     // do the actural live variable anal
 
  After the analysis, getInSetOfBB or getOutSetofBB can be called to get 
  live var info of a BB.
 */
 
 
-#ifndef METH_LIVE_VAR_INFO_H
-#define METH_LIVE_VAR_INFO_H
+#ifndef FUNCTION_LIVE_VAR_INFO_H
+#define FUNCTION_LIVE_VAR_INFO_H
 
-// set DEBUG_LV for printing out debug messages
-// if DEBUG_LV is 1 normal output messages
-// if DEBUG_LV is 2 extensive debug info for each instr
+#include "llvm/Pass.h"
+#include "llvm/Analysis/LiveVar/ValueSet.h"
 
-static const int DEBUG_LV = 0;
-
-#include "BBLiveVar.h"
-
-class MethodLiveVarInfo {
-
-  // Live var anal is done on this method - set by constructor
-  const Method *const Meth;   
-
-  // A map betwn the BasicBlock and BBLiveVar
-  BBToBBLiveVarMapType BB2BBLVMap;  
+class BBLiveVar;
+class MachineInstr;
 
+class FunctionLiveVarInfo : public FunctionPass {
   // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
-  MInstToLiveVarSetMapType MInst2LVSetBI; 
+  std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI; 
 
   // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
-  MInstToLiveVarSetMapType MInst2LVSetAI; 
-
-  // True if the analyze() method has been called. This is checked when
-  // getInSet/OutSet is called to prevent calling those methods before analyze
-  bool HasAnalyzed;
+  std::map<const MachineInstr *, const ValueSet *> MInst2LVSetAI; 
 
+  // Stored Function that the data is computed with respect to
+  const Function *M;
 
   // --------- private methods -----------------------------------------
 
   // constructs BBLiveVars and init Def and In sets
-  void constructBBs();      
+  void constructBBs(const Function *F);
     
   // do one backward pass over the CFG
-  bool  doSingleBackwardPass(); 
+  bool doSingleBackwardPass(const Function *F, unsigned int iter); 
 
   // calculates live var sets for instructions in a BB
   void calcLiveVarSetsForBB(const BasicBlock *BB);
   
+public:
+  static AnalysisID ID;    // We are an analysis, we must have an ID
 
- public:
-  MethodLiveVarInfo(const Method *Meth);
-  ~MethodLiveVarInfo();
+  // --------- Implement the FunctionPass interface ----------------------
 
-  // performs a liver var analysis of a single method
-  void analyze();            
+  // runOnFunction - Perform analysis, update internal data structures.
+  virtual bool runOnFunction(Function &F);
 
-  // gets OutSet of a BB
-  inline const LiveVarSet *getOutSetOfBB( const BasicBlock *BB) const { 
-    assert( HasAnalyzed && "call analyze() before calling this" );
-    return BB2BBLVMap.find(BB)->second->getOutSet();
+  // releaseMemory - After LiveVariable analysis has been used, forget!
+  virtual void releaseMemory();
+
+  // getAnalysisUsage - Provide self!
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.setPreservesAll();
   }
 
+  // --------- Functions to access analysis results -------------------
+
+  // gets OutSet of a BB
+  const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
+
   // gets InSet of a BB
-  inline const LiveVarSet *getInSetOfBB( const BasicBlock *BB)  const { 
-    assert(HasAnalyzed && "call analyze() before calling this" );
-    return BB2BBLVMap.find(BB)->second->getInSet();
-  }
+  const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
 
   // gets the Live var set BEFORE an instruction
-  const LiveVarSet * getLiveVarSetBeforeMInst(const MachineInstr *Inst,
-                                             const BasicBlock *CurBB);
+  const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
+                                           const BasicBlock *BB);
 
   // gets the Live var set AFTER an instruction
-  const LiveVarSet * getLiveVarSetAfterMInst(const MachineInstr *MInst,
-                                            const BasicBlock *CurBB);
-
+  const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
+                                          const BasicBlock *BB);
 };
 
 #endif