Go to the documentation of this file.
35 #define DEBUG_TYPE "machine-ssaupdater"
45 : InsertedPHIs(NewPHI),
TII(MF.getSubtarget().getInstrInfo()),
46 MRI(&MF.getRegInfo()) {}
82 return GetValueAtEndOfBlockInternal(
BB);
87 SmallVectorImpl<std::pair<MachineBasicBlock *, Register>> &PredValues) {
96 for (
unsigned i = 0,
e = PredValues.size();
i !=
e; ++
i)
97 AVals[PredValues[
i].first] = PredValues[
i].second;
98 while (
I !=
BB->end() &&
I->isPHI()) {
100 for (
unsigned i = 1,
e =
I->getNumOperands();
i !=
e;
i += 2) {
103 if (AVals[SrcBB] != SrcReg) {
109 return I->getOperand(0).getReg();
150 return GetValueAtEndOfBlockInternal(
BB);
153 if (
BB->pred_empty()) {
156 BB,
BB->getFirstTerminator(),
166 bool isFirstPred =
true;
168 Register PredVal = GetValueAtEndOfBlockInternal(PredBB);
169 PredValues.push_back(std::make_pair(PredBB, PredVal));
173 SingularValue = PredVal;
175 }
else if (PredVal != SingularValue)
181 return SingularValue;
194 for (
unsigned i = 0,
e = PredValues.size();
i !=
e; ++
i)
195 InsertedPHI.
addReg(PredValues[
i].second).
addMBB(PredValues[
i].first);
205 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
208 return InsertedPHI.
getReg(0);
214 for (
unsigned i = 1,
e =
MI->getNumOperands();
i !=
e;
i += 2) {
215 if (&
MI->getOperand(
i) == U)
216 return MI->getOperand(
i+1).getMBB();
229 NewVR = GetValueAtEndOfBlockInternal(SourceBB);
262 : PHI(
P), idx(PHI->getNumOperands()) {}
275 static inline PHI_iterator
PHI_begin(
PhiT *PHI) {
return PHI_iterator(PHI); }
278 return PHI_iterator(PHI,
true);
294 BB,
BB->getFirstNonPHI(),
295 Updater->VRC, Updater->MRI,
306 Updater->VRC, Updater->MRI,
328 return InstrIsPHI(Updater->MRI->
getVRegDef(Val));
359 return Impl.GetValue(
BB);
static Register GetUndefVal(MachineBasicBlock *BB, MachineSSAUpdater *Updater)
GetUndefVal - Create an IMPLICIT_DEF instruction with a new register.
MachineInstrBuilder & UseMI
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
static PHI_iterator PHI_end(PhiT *PHI)
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned isConstantValuePHI() const
If the specified instruction is a PHI that always merges together the same virtual register,...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
static Register LookForIdenticalPHI(MachineBasicBlock *BB, SmallVectorImpl< std::pair< MachineBasicBlock *, Register >> &PredValues)
MachineBasicBlock::succ_iterator BlkSucc_iterator
bool operator!=(const PHI_iterator &x) const
static void FindPredecessorBlocks(MachineBasicBlock *BB, SmallVectorImpl< MachineBasicBlock * > *Preds)
FindPredecessorBlocks - Put the predecessors of BB into the Preds vector.
static MachineBasicBlock * findCorrespondingPred(const MachineInstr *MI, MachineOperand *U)
MachineBasicBlock * getIncomingBlock()
static Register CreateEmptyPHI(MachineBasicBlock *BB, unsigned NumPreds, MachineSSAUpdater *Updater)
CreateEmptyPHI - Create a PHI instruction that defines a new register.
PHI_iterator & operator++()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static MachineInstr * InstrIsPHI(MachineInstr *I)
InstrIsPHI - Check if an instruction is a PHI.
TargetInstrInfo - Interface to description of machine instruction set.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineOperand & getOperand(unsigned i) const
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
static MachineInstr * ValueIsNewPHI(Register Val, MachineSSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i....
bool operator==(const PHI_iterator &x) const
static Register GetPHIValue(MachineInstr *PHI)
GetPHIValue - For the specified PHI instruction, return the register that it defines.
PHI_iterator(MachineInstr *P)
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
Register getReg(unsigned Idx) const
Get the register for the operand index.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
std::vector< MachineBasicBlock * >::iterator succ_iterator
MachineSSAUpdater(MachineFunction &MF, SmallVectorImpl< MachineInstr * > *NewPHI=nullptr)
MachineSSAUpdater constructor.
Representation of each machine instruction.
bool HasValueForBlock(MachineBasicBlock *BB) const
HasValueForBlock - Return true if the MachineSSAUpdater already has a value for the specified block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool operator==(uint64_t V1, const APInt &V2)
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Register getReg() const
getReg - Returns the register number.
static PHI_iterator PHI_begin(PhiT *PHI)
MachineBasicBlock * getMBB() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
const MachineBasicBlock * getParent() const
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
unsigned getIncomingValue()
Register GetValueAtEndOfBlock(MachineBasicBlock *BB)
GetValueAtEndOfBlock - Construct SSA form, materializing a value that is live at the end of the speci...
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 RewriteUse(MachineOperand &U)
RewriteUse - Rewrite a use of the symbolic value.
static MachineInstr * ValueIsPHI(Register Val, MachineSSAUpdater *Updater)
ValueIsPHI - Check if the instruction that defines the specified register is a PHI instruction.
MachineSSAUpdater - This class updates SSA form for a set of virtual registers defined in multiple bl...
PHI_iterator(MachineInstr *P, bool)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void setReg(Register Reg)
Change the register this operand corresponds to.
unsigned getNumOperands() const
Retuns the total number of operands.
static AvailableValsTy & getAvailableVals(void *AV)
static void AddPHIOperand(MachineInstr *PHI, Register Val, MachineBasicBlock *Pred)
AddPHIOperand - Add the specified value as an operand of the PHI for the specified predecessor block.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
void AddAvailableValue(MachineBasicBlock *BB, Register V)
AddAvailableValue - Indicate that a rewritten value is available at the end of the specified block wi...
void Initialize(Register V)
Initialize - Reset this object to get ready for a new set of SSA updates.
Register GetValueInMiddleOfBlock(MachineBasicBlock *BB)
GetValueInMiddleOfBlock - Construct SSA form, materializing a value that is live in the middle of the...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
DenseMap< MachineBasicBlock *, Register > AvailableValsTy