1 //===-- CodeGen/FunctionLiveVarInfo.h - LiveVar Analysis --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the interface for live variable info of a function that is required
11 // by any other part of the compiler
13 // After the analysis, getInSetOfBB or getOutSetofBB can be called to get
14 // live var info of a BB.
16 // The live var set before an instruction can be obtained in 2 ways:
18 // 1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info
19 // just after an instruction. (also exists getLiveVarSetBeforeInst(..))
21 // This function caluclates the LV info for a BB only once and caches that
22 // info. If the cache does not contain the LV info of the instruction, it
23 // calculates the LV info for the whole BB and caches them.
25 // Getting liveVar info this way uses more memory since, LV info should be
26 // cached. However, if you need LV info of nearly all the instructions of a
27 // BB, this is the best and simplest interfrace.
29 // 2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst)
30 // declared in LiveVarSet and traverse the instructions of a basic block in
31 // reverse (using const_reverse_iterator in the BB class).
33 //===----------------------------------------------------------------------===//
35 #ifndef FUNCTION_LIVE_VAR_INFO_H
36 #define FUNCTION_LIVE_VAR_INFO_H
38 #include "Support/hash_map"
39 #include "llvm/Pass.h"
40 #include "llvm/CodeGen/ValueSet.h"
45 class FunctionLiveVarInfo : public FunctionPass {
46 // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
47 // These sets are owned by this map and will be freed in releaseMemory().
48 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetBI;
50 // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst.
51 // These sets are just pointers to sets in MInst2LVSetBI or BBLiveVar.
52 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetAI;
54 // Stored Function that the data is computed with respect to
57 // --------- private methods -----------------------------------------
59 // constructs BBLiveVars and init Def and In sets
60 void constructBBs(const Function *F);
62 // do one backward pass over the CFG
63 bool doSingleBackwardPass(const Function *F, unsigned int iter);
65 // calculates live var sets for instructions in a BB
66 void calcLiveVarSetsForBB(const BasicBlock *BB);
69 // --------- Implement the FunctionPass interface ----------------------
71 // runOnFunction - Perform analysis, update internal data structures.
72 virtual bool runOnFunction(Function &F);
74 // releaseMemory - After LiveVariable analysis has been used, forget!
75 virtual void releaseMemory();
77 // getAnalysisUsage - Provide self!
78 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
82 // --------- Functions to access analysis results -------------------
85 const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
86 ValueSet &getOutSetOfBB(const BasicBlock *BB) ;
89 const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
90 ValueSet &getInSetOfBB(const BasicBlock *BB) ;
92 // gets the Live var set BEFORE an instruction.
93 // if BB is specified and the live var set has not yet been computed,
94 // it will be computed on demand.
95 const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
96 const BasicBlock *BB = 0);
98 // gets the Live var set AFTER an instruction
99 // if BB is specified and the live var set has not yet been computed,
100 // it will be computed on demand.
101 const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
102 const BasicBlock *BB = 0);