36 #define DEBUG_TYPE "machine-ssaupdater" 46 : InsertedPHIs(NewPHI),
TII(MF.getSubtarget().getInstrInfo()),
47 MRI(&MF.getRegInfo()) {}
80 return GetValueAtEndOfBlockInternal(BB);
85 SmallVectorImpl<std::pair<MachineBasicBlock *, unsigned>> &PredValues) {
94 for (
unsigned i = 0, e = PredValues.size(); i != e; ++i)
96 while (I != BB->
end() && I->isPHI()) {
98 for (
unsigned i = 1, e = I->getNumOperands(); i != e; i += 2) {
99 unsigned SrcReg = I->getOperand(i).getReg();
101 if (AVals[SrcBB] != SrcReg) {
107 return I->getOperand(0).getReg();
148 return GetValueAtEndOfBlockInternal(BB);
162 unsigned SingularValue = 0;
164 bool isFirstPred =
true;
168 unsigned PredVal = GetValueAtEndOfBlockInternal(PredBB);
169 PredValues.
push_back(std::make_pair(PredBB, PredVal));
173 SingularValue = PredVal;
175 }
else if (PredVal != SingularValue)
180 if (SingularValue != 0)
181 return SingularValue;
194 for (
unsigned i = 0, e = PredValues.
size(); i != e; ++i)
205 if (InsertedPHIs) InsertedPHIs->
push_back(InsertedPHI);
227 if (UseMI->
isPHI()) {
229 NewVR = GetValueAtEndOfBlockInternal(SourceBB);
262 : PHI(P), idx(PHI->getNumOperands()) {}
265 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
275 static inline PHI_iterator
PHI_begin(
PhiT *PHI) {
return PHI_iterator(PHI); }
278 return PHI_iterator(PHI,
true);
297 Updater->VRC, Updater->MRI,
308 Updater->VRC, Updater->MRI,
330 return InstrIsPHI(Updater->MRI->
getVRegDef(Val));
357 if (
unsigned V = AvailableVals[BB])
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
MachineBasicBlock * getMBB() const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
This class represents lattice values for constants.
PHI_iterator & operator++()
static MachineInstrBuilder InsertNewDef(unsigned Opcode, MachineBasicBlock *BB, MachineBasicBlock::iterator I, const TargetRegisterClass *RC, MachineRegisterInfo *MRI, const TargetInstrInfo *TII)
InsertNewDef - Insert an empty PHI or IMPLICIT_DEF instruction which define a value of the given regi...
void push_back(const T &Elt)
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned getReg() const
getReg - Returns the register number.
static PHI_iterator PHI_begin(PhiT *PHI)
void RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
ValT GetValue(BlkT *BB)
GetValue - Check to see if AvailableVals has an entry for the specified BB and if so...
MachineSSAUpdater - This class updates SSA form for a set of virtual registers defined in multiple bl...
static unsigned LookForIdenticalPHI(MachineBasicBlock *BB, SmallVectorImpl< std::pair< MachineBasicBlock *, unsigned >> &PredValues)
unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr *> *NewPHI=nullptr)
MachineSSAUpdater constructor.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineBasicBlock::succ_iterator BlkSucc_iterator
PHI_iterator(MachineInstr *P, bool)
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
static MachineInstr * ValueIsNewPHI(unsigned Val, MachineSSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i...
void Initialize(unsigned V)
Initialize - Reset this object to get ready for a new set of SSA updates.
TargetInstrInfo - Interface to description of machine instruction set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned const MachineRegisterInfo * MRI
unsigned isConstantValuePHI() const
If the specified instruction is a PHI that always merges together the same virtual register...
bool operator!=(const PHI_iterator &x) const
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::vector< MachineBasicBlock * >::iterator pred_iterator
succ_iterator succ_begin()
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
pred_iterator pred_begin()
static void AddPHIOperand(MachineInstr *PHI, unsigned Val, MachineBasicBlock *Pred)
AddPHIOperand - Add the specified value as an operand of the PHI for the specified predecessor block...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static MachineBasicBlock * findCorrespondingPred(const MachineInstr *MI, MachineOperand *U)
static unsigned CreateEmptyPHI(MachineBasicBlock *BB, unsigned NumPreds, MachineSSAUpdater *Updater)
CreateEmptyPHI - Create a PHI instruction that defines a new register.
bool operator==(const PHI_iterator &x) const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static MachineInstr * ValueIsPHI(unsigned Val, MachineSSAUpdater *Updater)
ValueIsPHI - Check if the instruction that defines the specified register is a PHI instruction...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static PHI_iterator PHI_end(PhiT *PHI)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static unsigned GetUndefVal(MachineBasicBlock *BB, MachineSSAUpdater *Updater)
GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block...
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
unsigned GetValueInMiddleOfBlock(MachineBasicBlock *BB)
GetValueInMiddleOfBlock - Construct SSA form, materializing a value that is live in the middle of the...
void AddAvailableValue(MachineBasicBlock *BB, unsigned V)
AddAvailableValue - Indicate that a rewritten value is available at the end of the specified block wi...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
DenseMap< MachineBasicBlock *, unsigned > AvailableValsTy
unsigned getIncomingValue()
static void FindPredecessorBlocks(MachineBasicBlock *BB, SmallVectorImpl< MachineBasicBlock *> *Preds)
FindPredecessorBlocks - Put the predecessors of BB into the Preds vector.
static MachineInstr * InstrIsPHI(MachineInstr *I)
InstrIsPHI - Check if an instruction is a PHI.
MachineBasicBlock * getIncomingBlock()
static unsigned GetPHIValue(MachineInstr *PHI)
GetPHIValue - For the specified PHI instruction, return the register that it defines.
bool operator==(uint64_t V1, const APInt &V2)
static AvailableValsTy & getAvailableVals(void *AV)
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
const MachineOperand & getOperand(unsigned i) const
PHI_iterator(MachineInstr *P)
std::vector< MachineBasicBlock * >::iterator succ_iterator
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...