LLVM API Documentation
00001 //===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ---*- 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 a BasicBlock annotation class that is used by live var analysis to 00011 // hold data flow information for a basic block. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LIVE_VAR_BB_H 00016 #define LIVE_VAR_BB_H 00017 00018 #include "llvm/CodeGen/ValueSet.h" 00019 #include "llvm/ADT/hash_map" 00020 00021 namespace llvm { 00022 00023 class BasicBlock; 00024 class Value; 00025 class MachineBasicBlock; 00026 00027 enum LiveVarDebugLevel_t { 00028 LV_DEBUG_None, 00029 LV_DEBUG_Normal, 00030 LV_DEBUG_Instr, 00031 LV_DEBUG_Verbose 00032 }; 00033 00034 extern LiveVarDebugLevel_t DEBUG_LV; 00035 00036 class BBLiveVar { 00037 const BasicBlock &BB; // pointer to BasicBlock 00038 const MachineBasicBlock &MBB; // Pointer to MachineBasicBlock 00039 unsigned POID; // Post-Order ID 00040 00041 ValueSet DefSet; // Def set (with no preceding uses) for LV analysis 00042 ValueSet InSet, OutSet; // In & Out for LV analysis 00043 bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified 00044 00045 // map that contains PredBB -> Phi arguments 00046 // coming in on that edge. such uses have to be 00047 // treated differently from ordinary uses. 00048 hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap; 00049 00050 // method to propagate an InSet to OutSet of a predecessor 00051 bool setPropagate(ValueSet *OutSetOfPred, 00052 const ValueSet *InSetOfThisBB, 00053 const BasicBlock *PredBB); 00054 00055 // To add an operand which is a def 00056 void addDef(const Value *Op); 00057 00058 // To add an operand which is a use 00059 void addUse(const Value *Op); 00060 00061 void calcDefUseSets(); // calculates the Def & Use sets for this BB 00062 public: 00063 00064 BBLiveVar(const BasicBlock &BB, const MachineBasicBlock &MBB, unsigned POID); 00065 00066 inline bool isInSetChanged() const { return InSetChanged; } 00067 inline bool isOutSetChanged() const { return OutSetChanged; } 00068 00069 const MachineBasicBlock &getMachineBasicBlock() const { return MBB; } 00070 00071 inline unsigned getPOId() const { return POID; } 00072 00073 bool applyTransferFunc(); // calcultes the In in terms of Out 00074 00075 // calculates Out set using In sets of the predecessors 00076 bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo); 00077 00078 inline const ValueSet &getOutSet() const { return OutSet; } 00079 inline ValueSet &getOutSet() { return OutSet; } 00080 00081 inline const ValueSet &getInSet() const { return InSet; } 00082 inline ValueSet &getInSet() { return InSet; } 00083 00084 void printAllSets() const; // for printing Def/In/Out sets 00085 void printInOutSets() const; // for printing In/Out sets 00086 }; 00087 00088 } // End llvm namespace 00089 00090 #endif