1 //===-- CodeGen/FunctionLiveVarInfo.h - LiveVar Analysis --------*- C++ -*-===//
3 // This is the interface for live variable info of a function that is required
4 // by any other part of the compiler
6 // After the analysis, getInSetOfBB or getOutSetofBB can be called to get
7 // live var info of a BB.
9 // The live var set before an instruction can be obtained in 2 ways:
11 // 1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info
12 // just after an instruction. (also exists getLiveVarSetBeforeInst(..))
14 // This function caluclates the LV info for a BB only once and caches that
15 // info. If the cache does not contain the LV info of the instruction, it
16 // calculates the LV info for the whole BB and caches them.
18 // Getting liveVar info this way uses more memory since, LV info should be
19 // cached. However, if you need LV info of nearly all the instructions of a
20 // BB, this is the best and simplest interfrace.
22 // 2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst)
23 // declared in LiveVarSet and traverse the instructions of a basic block in
24 // reverse (using const_reverse_iterator in the BB class).
26 //===----------------------------------------------------------------------===//
28 #ifndef FUNCTION_LIVE_VAR_INFO_H
29 #define FUNCTION_LIVE_VAR_INFO_H
31 #include "Support/hash_map"
32 #include "llvm/Pass.h"
33 #include "llvm/CodeGen/ValueSet.h"
38 class FunctionLiveVarInfo : public FunctionPass {
39 // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
40 // These sets are owned by this map and will be freed in releaseMemory().
41 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetBI;
43 // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst.
44 // These sets are just pointers to sets in MInst2LVSetBI or BBLiveVar.
45 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetAI;
47 // Stored Function that the data is computed with respect to
50 // --------- private methods -----------------------------------------
52 // constructs BBLiveVars and init Def and In sets
53 void constructBBs(const Function *F);
55 // do one backward pass over the CFG
56 bool doSingleBackwardPass(const Function *F, unsigned int iter);
58 // calculates live var sets for instructions in a BB
59 void calcLiveVarSetsForBB(const BasicBlock *BB);
62 // --------- Implement the FunctionPass interface ----------------------
64 // runOnFunction - Perform analysis, update internal data structures.
65 virtual bool runOnFunction(Function &F);
67 // releaseMemory - After LiveVariable analysis has been used, forget!
68 virtual void releaseMemory();
70 // getAnalysisUsage - Provide self!
71 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
75 // --------- Functions to access analysis results -------------------
78 const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
79 ValueSet &getOutSetOfBB(const BasicBlock *BB) ;
82 const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
83 ValueSet &getInSetOfBB(const BasicBlock *BB) ;
85 // gets the Live var set BEFORE an instruction.
86 // if BB is specified and the live var set has not yet been computed,
87 // it will be computed on demand.
88 const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
89 const BasicBlock *BB = 0);
91 // gets the Live var set AFTER an instruction
92 // if BB is specified and the live var set has not yet been computed,
93 // it will be computed on demand.
94 const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
95 const BasicBlock *BB = 0);