+LiveRangeEdit::Remat LiveRangeEdit::canRematerializeAt(VNInfo *ParentVNI,
+ SlotIndex UseIdx,
+ bool cheapAsAMove,
+ LiveIntervals &lis) {
+ assert(scannedRemattable_ && "Call anyRematerializable first");
+ Remat RM = { 0, 0 };
+
+ // We could remat an undefined value as IMPLICIT_DEF, but all that should have
+ // been taken care of earlier.
+ if (!(RM.ParentVNI = parent_.getVNInfoAt(UseIdx)))
+ return RM;
+
+ // Use scanRemattable info.
+ if (!remattable_.count(RM.ParentVNI))
+ return RM;
+
+ // No defining instruction.
+ MachineInstr *OrigMI = lis.getInstructionFromIndex(RM.ParentVNI->def);
+ assert(OrigMI && "Defining instruction for remattable value disappeared");
+
+ // If only cheap remats were requested, bail out early.
+ if (cheapAsAMove && !OrigMI->getDesc().isAsCheapAsAMove())
+ return RM;
+
+ // Verify that all used registers are available with the same values.
+ if (!allUsesAvailableAt(OrigMI, RM.ParentVNI->def, UseIdx, lis))
+ return RM;
+
+ RM.OrigMI = OrigMI;
+ return RM;
+}
+
+SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MI,
+ unsigned DestReg,
+ const Remat &RM,
+ LiveIntervals &lis,
+ const TargetInstrInfo &tii,
+ const TargetRegisterInfo &tri) {
+ assert(RM.OrigMI && "Invalid remat");
+ tii.reMaterialize(MBB, MI, DestReg, 0, RM.OrigMI, tri);
+ return lis.InsertMachineInstrInMaps(--MI).getDefIndex();
+}
+