[llvm] r365240 - [CodeGen] Enhance `MachineInstrSpan` to allow the end of MBB to be used.
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 13:23:59 PDT 2019
Author: hliao
Date: Fri Jul 5 13:23:59 2019
New Revision: 365240
URL: http://llvm.org/viewvc/llvm-project?rev=365240&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/lib/CodeGen/InlineSpiller.cpp
llvm/trunk/lib/Target/AMDGPU/SILowerSGPRSpills.cpp
llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h?rev=365240&r1=365239&r2=365240&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h Fri Jul 5 13:23:59 2019
@@ -910,11 +910,11 @@ class MachineInstrSpan {
MachineBasicBlock::iterator I, B, E;
public:
- MachineInstrSpan(MachineBasicBlock::iterator I)
- : MBB(*I->getParent()),
- I(I),
- B(I == MBB.begin() ? MBB.end() : std::prev(I)),
- E(std::next(I)) {}
+ MachineInstrSpan(MachineBasicBlock::iterator I, MachineBasicBlock *BB)
+ : MBB(*BB), I(I), B(I == MBB.begin() ? MBB.end() : std::prev(I)),
+ E(std::next(I)) {
+ assert(I == BB->end() || I->getParent() == BB);
+ }
MachineBasicBlock::iterator begin() {
return B == MBB.end() ? MBB.begin() : std::next(B);
Modified: llvm/trunk/lib/CodeGen/InlineSpiller.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/InlineSpiller.cpp?rev=365240&r1=365239&r2=365240&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/InlineSpiller.cpp (original)
+++ llvm/trunk/lib/CodeGen/InlineSpiller.cpp Fri Jul 5 13:23:59 2019
@@ -833,7 +833,7 @@ foldMemoryOperand(ArrayRef<std::pair<Mac
if (FoldOps.empty())
return false;
- MachineInstrSpan MIS(MI);
+ MachineInstrSpan MIS(MI, MI->getParent());
MachineInstr *FoldMI =
LoadMI ? TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
@@ -907,7 +907,7 @@ void InlineSpiller::insertReload(unsigne
MachineBasicBlock::iterator MI) {
MachineBasicBlock &MBB = *MI->getParent();
- MachineInstrSpan MIS(MI);
+ MachineInstrSpan MIS(MI, &MBB);
TII.loadRegFromStackSlot(MBB, MI, NewVReg, StackSlot,
MRI.getRegClass(NewVReg), &TRI);
@@ -937,7 +937,7 @@ void InlineSpiller::insertSpill(unsigned
MachineBasicBlock::iterator MI) {
MachineBasicBlock &MBB = *MI->getParent();
- MachineInstrSpan MIS(MI);
+ MachineInstrSpan MIS(MI, &MBB);
bool IsRealSpill = true;
if (isFullUndefDef(*MI)) {
// Don't spill undef value.
Modified: llvm/trunk/lib/Target/AMDGPU/SILowerSGPRSpills.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SILowerSGPRSpills.cpp?rev=365240&r1=365239&r2=365240&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SILowerSGPRSpills.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SILowerSGPRSpills.cpp Fri Jul 5 13:23:59 2019
@@ -92,7 +92,7 @@ static void insertCSRSaves(MachineBasicB
// Insert the spill to the stack frame.
unsigned Reg = CS.getReg();
- MachineInstrSpan MIS(I);
+ MachineInstrSpan MIS(I, &SaveBlock);
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
TII.storeRegToStackSlot(SaveBlock, I, Reg, true, CS.getFrameIdx(), RC,
Modified: llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp?rev=365240&r1=365239&r2=365240&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp Fri Jul 5 13:23:59 2019
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -273,6 +274,38 @@ TEST(MachineInstrPrintingTest, DebugLocP
StringRef(OS.str()).endswith("filename:1:5"));
}
+TEST(MachineInstrSpan, DistanceBegin) {
+ auto MF = createMachineFunction();
+ auto MBB = MF->CreateMachineBasicBlock();
+
+ MCInstrDesc MCID = {0, 0, 0, 0, 0, 0,
+ 0, nullptr, nullptr, nullptr, 0, nullptr};
+
+ auto MII = MBB->begin();
+ MachineInstrSpan MIS(MII, MBB);
+ ASSERT_TRUE(MIS.empty());
+
+ auto MI = MF->CreateMachineInstr(MCID, DebugLoc());
+ MBB->insert(MII, MI);
+ ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1);
+}
+
+TEST(MachineInstrSpan, DistanceEnd) {
+ auto MF = createMachineFunction();
+ auto MBB = MF->CreateMachineBasicBlock();
+
+ MCInstrDesc MCID = {0, 0, 0, 0, 0, 0,
+ 0, nullptr, nullptr, nullptr, 0, nullptr};
+
+ auto MII = MBB->end();
+ MachineInstrSpan MIS(MII, MBB);
+ ASSERT_TRUE(MIS.empty());
+
+ auto MI = MF->CreateMachineInstr(MCID, DebugLoc());
+ MBB->insert(MII, MI);
+ ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1);
+}
+
static_assert(is_trivially_copyable<MCOperand>::value, "trivially copyable");
} // end namespace
More information about the llvm-commits
mailing list