LLVM API Documentation
00001 //===-- MachineSSAUpdater.h - Unstructured SSA Update Tool ------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the MachineSSAUpdater class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CODEGEN_MACHINESSAUPDATER_H 00015 #define LLVM_CODEGEN_MACHINESSAUPDATER_H 00016 00017 #include "llvm/Support/Allocator.h" 00018 #include "llvm/Support/Compiler.h" 00019 00020 namespace llvm { 00021 class MachineBasicBlock; 00022 class MachineFunction; 00023 class MachineInstr; 00024 class MachineOperand; 00025 class MachineRegisterInfo; 00026 class TargetInstrInfo; 00027 class TargetRegisterClass; 00028 template<typename T> class SmallVectorImpl; 00029 template<typename T> class SSAUpdaterTraits; 00030 00031 /// MachineSSAUpdater - This class updates SSA form for a set of virtual 00032 /// registers defined in multiple blocks. This is used when code duplication 00033 /// or another unstructured transformation wants to rewrite a set of uses of one 00034 /// vreg with uses of a set of vregs. 00035 class MachineSSAUpdater { 00036 friend class SSAUpdaterTraits<MachineSSAUpdater>; 00037 00038 private: 00039 /// AvailableVals - This keeps track of which value to use on a per-block 00040 /// basis. When we insert PHI nodes, we keep track of them here. 00041 //typedef DenseMap<MachineBasicBlock*, unsigned > AvailableValsTy; 00042 void *AV; 00043 00044 /// VR - Current virtual register whose uses are being updated. 00045 unsigned VR; 00046 00047 /// VRC - Register class of the current virtual register. 00048 const TargetRegisterClass *VRC; 00049 00050 /// InsertedPHIs - If this is non-null, the MachineSSAUpdater adds all PHI 00051 /// nodes that it creates to the vector. 00052 SmallVectorImpl<MachineInstr*> *InsertedPHIs; 00053 00054 const TargetInstrInfo *TII; 00055 MachineRegisterInfo *MRI; 00056 public: 00057 /// MachineSSAUpdater constructor. If InsertedPHIs is specified, it will be 00058 /// filled in with all PHI Nodes created by rewriting. 00059 explicit MachineSSAUpdater(MachineFunction &MF, 00060 SmallVectorImpl<MachineInstr*> *InsertedPHIs = nullptr); 00061 ~MachineSSAUpdater(); 00062 00063 /// Initialize - Reset this object to get ready for a new set of SSA 00064 /// updates. 00065 void Initialize(unsigned V); 00066 00067 /// AddAvailableValue - Indicate that a rewritten value is available at the 00068 /// end of the specified block with the specified value. 00069 void AddAvailableValue(MachineBasicBlock *BB, unsigned V); 00070 00071 /// HasValueForBlock - Return true if the MachineSSAUpdater already has a 00072 /// value for the specified block. 00073 bool HasValueForBlock(MachineBasicBlock *BB) const; 00074 00075 /// GetValueAtEndOfBlock - Construct SSA form, materializing a value that is 00076 /// live at the end of the specified block. 00077 unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB); 00078 00079 /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that 00080 /// is live in the middle of the specified block. 00081 /// 00082 /// GetValueInMiddleOfBlock is the same as GetValueAtEndOfBlock except in one 00083 /// important case: if there is a definition of the rewritten value after the 00084 /// 'use' in BB. Consider code like this: 00085 /// 00086 /// X1 = ... 00087 /// SomeBB: 00088 /// use(X) 00089 /// X2 = ... 00090 /// br Cond, SomeBB, OutBB 00091 /// 00092 /// In this case, there are two values (X1 and X2) added to the AvailableVals 00093 /// set by the client of the rewriter, and those values are both live out of 00094 /// their respective blocks. However, the use of X happens in the *middle* of 00095 /// a block. Because of this, we need to insert a new PHI node in SomeBB to 00096 /// merge the appropriate values, and this value isn't live out of the block. 00097 /// 00098 unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB); 00099 00100 /// RewriteUse - Rewrite a use of the symbolic value. This handles PHI nodes, 00101 /// which use their value in the corresponding predecessor. Note that this 00102 /// will not work if the use is supposed to be rewritten to a value defined in 00103 /// the same block as the use, but above it. Any 'AddAvailableValue's added 00104 /// for the use's block will be considered to be below it. 00105 void RewriteUse(MachineOperand &U); 00106 00107 private: 00108 unsigned GetValueAtEndOfBlockInternal(MachineBasicBlock *BB); 00109 00110 void operator=(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION; 00111 MachineSSAUpdater(const MachineSSAUpdater&) LLVM_DELETED_FUNCTION; 00112 }; 00113 00114 } // End llvm namespace 00115 00116 #endif