-/* 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.
}
See buildInterferenceGraph() for the above example.
-
-
*/
-#ifndef METH_LIVE_VAR_INFO_H
-#define METH_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
-
-static const int DEBUG_LV = 0;
-
-#include "LiveVarSet.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/Instruction.h"
-#include "llvm/Method.h"
-
-#include "LiveVarMap.h"
-#include "BBLiveVar.h"
-
+#ifndef FUNCTION_LIVE_VAR_INFO_H
+#define FUNCTION_LIVE_VAR_INFO_H
-class MethodLiveVarInfo
-{
- private:
+#include "llvm/Pass.h"
+#include "llvm/CodeGen/ValueSet.h"
- // 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 *const BB);
+ void calcLiveVarSetsForBB(const BasicBlock *BB);
+public:
+ // --------- Implement the FunctionPass interface ----------------------
+
+ // runOnFunction - Perform analysis, update internal data structures.
+ virtual bool runOnFunction(Function &F);
- public:
- MethodLiveVarInfo(const Method *const Meth); // constructor
+ // releaseMemory - After LiveVariable analysis has been used, forget!
+ virtual void releaseMemory();
- ~MethodLiveVarInfo(); // destructor
+ // getAnalysisUsage - Provide self!
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
- // performs a liver var analysis of a single method
- void analyze();
+ // --------- Functions to access analysis results -------------------
// gets OutSet of a BB
- inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB) const {
- assert( HasAnalyzed && "call analyze() before calling this" );
- return ( (* (BB2BBLVMap.find(BB)) ).second ) ->getOutSet();
- }
+ const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
// gets InSet of a BB
- inline const LiveVarSet *getInSetOfBB( const BasicBlock *const 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 *const Inst,
- const BasicBlock *const CurBB);
+ const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
+ const BasicBlock *BB);
// gets the Live var set AFTER an instruction
- const LiveVarSet * getLiveVarSetAfterMInst(const MachineInstr *const MInst,
- const BasicBlock *const CurBB);
-
-
-
-
+ const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
+ const BasicBlock *BB);
};
-
-
-
-
#endif
-
-
-
-