llvm.org GIT mirror llvm / 0d22b74
[CodeGen] Enhance `MachineInstrSpan` to allow the end of MBB to be used. Summary: - Explicitly specify the parent MBB to allow the end iterator to be used. Reviewers: aprantl, MatzeB, craig.topper, qcolombet Subscribers: arsenm, jvesely, nhaehnle, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64261 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365240 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Liao 4 months ago
4 changed file(s) with 42 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
909909 MachineBasicBlock::iterator I, B, E;
910910
911911 public:
912 MachineInstrSpan(MachineBasicBlock::iterator I)
913 : MBB(*I->getParent()),
914 I(I),
915 B(I == MBB.begin() ? MBB.end() : std::prev(I)),
916 E(std::next(I)) {}
912 MachineInstrSpan(MachineBasicBlock::iterator I, MachineBasicBlock *BB)
913 : MBB(*BB), I(I), B(I == MBB.begin() ? MBB.end() : std::prev(I)),
914 E(std::next(I)) {
915 assert(I == BB->end() || I->getParent() == BB);
916 }
917917
918918 MachineBasicBlock::iterator begin() {
919919 return B == MBB.end() ? MBB.begin() : std::next(B);
832832 if (FoldOps.empty())
833833 return false;
834834
835 MachineInstrSpan MIS(MI);
835 MachineInstrSpan MIS(MI, MI->getParent());
836836
837837 MachineInstr *FoldMI =
838838 LoadMI ? TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
906906 MachineBasicBlock::iterator MI) {
907907 MachineBasicBlock &MBB = *MI->getParent();
908908
909 MachineInstrSpan MIS(MI);
909 MachineInstrSpan MIS(MI, &MBB);
910910 TII.loadRegFromStackSlot(MBB, MI, NewVReg, StackSlot,
911911 MRI.getRegClass(NewVReg), &TRI);
912912
936936 MachineBasicBlock::iterator MI) {
937937 MachineBasicBlock &MBB = *MI->getParent();
938938
939 MachineInstrSpan MIS(MI);
939 MachineInstrSpan MIS(MI, &MBB);
940940 bool IsRealSpill = true;
941941 if (isFullUndefDef(*MI)) {
942942 // Don't spill undef value.
9191 // Insert the spill to the stack frame.
9292 unsigned Reg = CS.getReg();
9393
94 MachineInstrSpan MIS(I);
94 MachineInstrSpan MIS(I, &SaveBlock);
9595 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
9696
9797 TII.storeRegToStackSlot(SaveBlock, I, Reg, true, CS.getFrameIdx(), RC,
55 //
66 //===----------------------------------------------------------------------===//
77
8 #include "llvm/CodeGen/MachineBasicBlock.h"
89 #include "llvm/CodeGen/MachineInstr.h"
910 #include "llvm/CodeGen/MachineFunction.h"
1011 #include "llvm/CodeGen/MachineModuleInfo.h"
272273 StringRef(OS.str()).endswith("filename:1:5"));
273274 }
274275
276 TEST(MachineInstrSpan, DistanceBegin) {
277 auto MF = createMachineFunction();
278 auto MBB = MF->CreateMachineBasicBlock();
279
280 MCInstrDesc MCID = {0, 0, 0, 0, 0, 0,
281 0, nullptr, nullptr, nullptr, 0, nullptr};
282
283 auto MII = MBB->begin();
284 MachineInstrSpan MIS(MII, MBB);
285 ASSERT_TRUE(MIS.empty());
286
287 auto MI = MF->CreateMachineInstr(MCID, DebugLoc());
288 MBB->insert(MII, MI);
289 ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1);
290 }
291
292 TEST(MachineInstrSpan, DistanceEnd) {
293 auto MF = createMachineFunction();
294 auto MBB = MF->CreateMachineBasicBlock();
295
296 MCInstrDesc MCID = {0, 0, 0, 0, 0, 0,
297 0, nullptr, nullptr, nullptr, 0, nullptr};
298
299 auto MII = MBB->end();
300 MachineInstrSpan MIS(MII, MBB);
301 ASSERT_TRUE(MIS.empty());
302
303 auto MI = MF->CreateMachineInstr(MCID, DebugLoc());
304 MBB->insert(MII, MI);
305 ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1);
306 }
307
275308 static_assert(is_trivially_copyable::value, "trivially copyable");
276309
277310 } // end namespace