30 #define DEBUG_TYPE "machine-ssaupdater"
39 : AV(nullptr), InsertedPHIs(NewPHI) {
75 return GetValueAtEndOfBlockInternal(BB);
80 SmallVectorImpl<std::pair<MachineBasicBlock*, unsigned> > &PredValues) {
89 for (
unsigned i = 0, e = PredValues.size();
i != e; ++
i)
90 AVals[PredValues[
i].first] = PredValues[
i].second;
91 while (I != BB->
end() && I->isPHI()) {
93 for (
unsigned i = 1, e = I->getNumOperands();
i != e;
i += 2) {
94 unsigned SrcReg = I->getOperand(
i).getReg();
96 if (AVals[SrcBB] != SrcReg) {
102 return I->getOperand(0).getReg();
144 return GetValueAtEndOfBlockInternal(BB);
158 unsigned SingularValue = 0;
160 bool isFirstPred =
true;
164 unsigned PredVal = GetValueAtEndOfBlockInternal(PredBB);
165 PredValues.
push_back(std::make_pair(PredBB, PredVal));
169 SingularValue = PredVal;
171 }
else if (PredVal != SingularValue)
176 if (SingularValue != 0)
177 return SingularValue;
190 for (
unsigned i = 0, e = PredValues.
size();
i != e; ++
i)
191 InsertedPHI.
addReg(PredValues[
i].second).
addMBB(PredValues[i].first);
201 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
203 DEBUG(
dbgs() <<
" Inserted PHI: " << *InsertedPHI <<
"\n");
223 if (UseMI->
isPHI()) {
225 NewVR = GetValueAtEndOfBlockInternal(SourceBB);
257 : PHI(P), idx(PHI->getNumOperands()) {}
260 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
264 return PHI->getOperand(idx+1).getMBB();
267 static inline PHI_iterator
PHI_begin(
PhiT *PHI) {
return PHI_iterator(PHI); }
269 return PHI_iterator(PHI,
true);
288 Updater->VRC, Updater->MRI,
299 Updater->VRC, Updater->MRI,
322 return InstrIsPHI(Updater->MRI->
getVRegDef(Val));
349 if (
unsigned V = AvailableVals[BB])
353 return Impl.GetValue(BB);
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
bool operator==(const PHI_iterator &x) const
MachineBasicBlock * getMBB() const
PHI_iterator & operator++()
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
static PHI_iterator PHI_begin(PhiT *PHI)
void RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
static void FindPredecessorBlocks(MachineBasicBlock *BB, SmallVectorImpl< MachineBasicBlock * > *Preds)
FindPredecessorBlocks - Put the predecessors of BB into the Preds vector.
MachineSSAUpdater - This class updates SSA form for a set of virtual registers defined in multiple bl...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
const HexagonInstrInfo * TII
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
std::vector< MachineBasicBlock * >::iterator succ_iterator
PHI_iterator(MachineInstr *P, bool)
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool operator!=(const PHI_iterator &x) const
static MachineInstr * ValueIsNewPHI(unsigned Val, MachineSSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i...
std::vector< MachineBasicBlock * >::iterator pred_iterator
void Initialize(unsigned V)
Initialize - Reset this object to get ready for a new set of SSA updates.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
const MachineBasicBlock * getParent() const
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
MachineInstrBuilder & UseMI
const MachineOperand & getOperand(unsigned i) const
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.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
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.
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.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
MachineBasicBlock::succ_iterator BlkSucc_iterator
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)
static unsigned LookForIdenticalPHI(MachineBasicBlock *BB, SmallVectorImpl< std::pair< MachineBasicBlock *, unsigned > > &PredValues)
Representation of each machine instruction.
static unsigned GetUndefVal(MachineBasicBlock *BB, MachineSSAUpdater *Updater)
GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
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...
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
DenseMap< MachineBasicBlock *, unsigned > AvailableValsTy
unsigned getReg() const
getReg - Returns the register number.
unsigned getIncomingValue()
unsigned isConstantValuePHI() const
If the specified instruction is a PHI that always merges together the same virtual register...
virtual const TargetInstrInfo * getInstrInfo() const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
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 & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
PHI_iterator(MachineInstr *P)
MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr * > *InsertedPHIs=nullptr)
MachineSSAUpdater constructor.