aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/CodeGen/MachineInstrTest.cpp
diff options
context:
space:
mode:
authorMichael Liao <michael.hliao@gmail.com>2019-07-05 20:23:59 +0000
committerMichael Liao <michael.hliao@gmail.com>2019-07-05 20:23:59 +0000
commit8d6ea2d48c87d9ada06c384de3e255a2f6706ac3 (patch)
treeef858aca72a281fe5a4cc1b2c756dab52de1bf73 /llvm/unittests/CodeGen/MachineInstrTest.cpp
parent009225374a410888a4c1ed28549a650c516550f0 (diff)
downloadllvm-8d6ea2d48c87d9ada06c384de3e255a2f6706ac3.zip
llvm-8d6ea2d48c87d9ada06c384de3e255a2f6706ac3.tar.gz
llvm-8d6ea2d48c87d9ada06c384de3e255a2f6706ac3.tar.bz2
[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 llvm-svn: 365240
Diffstat (limited to 'llvm/unittests/CodeGen/MachineInstrTest.cpp')
-rw-r--r--llvm/unittests/CodeGen/MachineInstrTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp
index 21b5eb6..0f86968 100644
--- a/llvm/unittests/CodeGen/MachineInstrTest.cpp
+++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp
@@ -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, DebugLocPrinting) {
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