-/* 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
-
-// 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;
+#ifndef FUNCTION_LIVE_VAR_INFO_H
+#define FUNCTION_LIVE_VAR_INFO_H
#include "llvm/Pass.h"
+#include "llvm/CodeGen/ValueSet.h"
+
class BBLiveVar;
class MachineInstr;
-class LiveVarSet;
-
-class MethodLiveVarInfo : public MethodPass {
- // A map between the BasicBlock and BBLiveVar
- std::map<const BasicBlock *, BBLiveVar *> BB2BBLVMap;
+class FunctionLiveVarInfo : public FunctionPass {
// Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
- std::map<const MachineInstr *, const LiveVarSet *> MInst2LVSetBI;
+ std::map<const MachineInstr *, const ValueSet *> MInst2LVSetBI;
// Machine Instr to LiveVarSet Map for providing LVset AFTER each inst
- std::map<const MachineInstr *, const LiveVarSet *> MInst2LVSetAI;
+ 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(const Method *M);
+ void constructBBs(const Function *F);
// do one backward pass over the CFG
- bool doSingleBackwardPass(const Method *M);
+ 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
-
- MethodLiveVarInfo(AnalysisID id = ID) { assert(id == ID); }
- ~MethodLiveVarInfo() { releaseMemory(); }
-
- // --------- Implement the MethodPass interface ----------------------
+ // --------- Implement the FunctionPass interface ----------------------
- // runOnMethod - Perform analysis, update internal data structures.
- virtual bool runOnMethod(Method *M);
+ // runOnFunction - Perform analysis, update internal data structures.
+ virtual bool runOnFunction(Function &F);
// releaseMemory - After LiveVariable analysis has been used, forget!
virtual void releaseMemory();
- // getAnalysisUsageInfo - Provide self!
- virtual void getAnalysisUsageInfo(AnalysisSet &Required,
- AnalysisSet &Destroyed,
- AnalysisSet &Provided) {
- Provided.push_back(ID);
+ // getAnalysisUsage - Provide self!
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
}
// --------- Functions to access analysis results -------------------
// gets OutSet of a BB
- const LiveVarSet *getOutSetOfBB(const BasicBlock *BB) const;
+ const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
// gets InSet of a BB
- const LiveVarSet *getInSetOfBB(const BasicBlock *BB) const;
+ const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
// gets the Live var set BEFORE an instruction
- const LiveVarSet *getLiveVarSetBeforeMInst(const MachineInstr *MI,
- const BasicBlock *BB);
+ const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
+ const BasicBlock *BB);
// gets the Live var set AFTER an instruction
- const LiveVarSet *getLiveVarSetAfterMInst(const MachineInstr *MI,
- const BasicBlock *BB);
+ const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
+ const BasicBlock *BB);
};
#endif