LLVM API Documentation
00001 //===-- CodeGen/FunctionLiveVarInfo.h - LiveVar Analysis --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This is the interface for live variable info of a function that is required 00011 // by any other part of the compiler 00012 // 00013 // After the analysis, getInSetOfBB or getOutSetofBB can be called to get 00014 // live var info of a BB. 00015 // 00016 // The live var set before an instruction can be obtained in 2 ways: 00017 // 00018 // 1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info 00019 // just after an instruction. (also exists getLiveVarSetBeforeInst(..)) 00020 // 00021 // This function caluclates the LV info for a BB only once and caches that 00022 // info. If the cache does not contain the LV info of the instruction, it 00023 // calculates the LV info for the whole BB and caches them. 00024 // 00025 // Getting liveVar info this way uses more memory since, LV info should be 00026 // cached. However, if you need LV info of nearly all the instructions of a 00027 // BB, this is the best and simplest interfrace. 00028 // 00029 // 2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst) 00030 // declared in LiveVarSet and traverse the instructions of a basic block in 00031 // reverse (using const_reverse_iterator in the BB class). 00032 // 00033 //===----------------------------------------------------------------------===// 00034 00035 #ifndef FUNCTION_LIVE_VAR_INFO_H 00036 #define FUNCTION_LIVE_VAR_INFO_H 00037 00038 #include "llvm/ADT/hash_map" 00039 #include "llvm/Pass.h" 00040 #include "llvm/CodeGen/ValueSet.h" 00041 00042 namespace llvm { 00043 00044 class BBLiveVar; 00045 class MachineInstr; 00046 00047 class FunctionLiveVarInfo : public FunctionPass { 00048 // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst 00049 // These sets are owned by this map and will be freed in releaseMemory(). 00050 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetBI; 00051 00052 // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst. 00053 // These sets are just pointers to sets in MInst2LVSetBI or BBLiveVar. 00054 hash_map<const MachineInstr *, ValueSet *> MInst2LVSetAI; 00055 00056 hash_map<const BasicBlock*, BBLiveVar*> BBLiveVarInfo; 00057 00058 // Stored Function that the data is computed with respect to 00059 const Function *M; 00060 00061 // --------- private methods ----------------------------------------- 00062 00063 // constructs BBLiveVars and init Def and In sets 00064 void constructBBs(const Function *F); 00065 00066 // do one backward pass over the CFG 00067 bool doSingleBackwardPass(const Function *F, unsigned int iter); 00068 00069 // calculates live var sets for instructions in a BB 00070 void calcLiveVarSetsForBB(const BasicBlock *BB); 00071 00072 public: 00073 // --------- Implement the FunctionPass interface ---------------------- 00074 00075 // runOnFunction - Perform analysis, update internal data structures. 00076 virtual bool runOnFunction(Function &F); 00077 00078 // releaseMemory - After LiveVariable analysis has been used, forget! 00079 virtual void releaseMemory(); 00080 00081 // getAnalysisUsage - Provide self! 00082 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 00083 AU.setPreservesAll(); 00084 } 00085 00086 // --------- Functions to access analysis results ------------------- 00087 00088 // get OutSet of a BB 00089 const ValueSet &getOutSetOfBB(const BasicBlock *BB) const; 00090 ValueSet &getOutSetOfBB(const BasicBlock *BB) ; 00091 00092 // get InSet of a BB 00093 const ValueSet &getInSetOfBB(const BasicBlock *BB) const; 00094 ValueSet &getInSetOfBB(const BasicBlock *BB) ; 00095 00096 // gets the Live var set BEFORE an instruction. 00097 // if BB is specified and the live var set has not yet been computed, 00098 // it will be computed on demand. 00099 const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI, 00100 const BasicBlock *BB = 0); 00101 00102 // gets the Live var set AFTER an instruction 00103 // if BB is specified and the live var set has not yet been computed, 00104 // it will be computed on demand. 00105 const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI, 00106 const BasicBlock *BB = 0); 00107 }; 00108 00109 } // End llvm namespace 00110 00111 #endif