diff options
author | Marco Elver <elver@google.com> | 2022-09-06 15:49:08 +0200 |
---|---|---|
committer | Marco Elver <elver@google.com> | 2022-09-07 11:22:50 +0200 |
commit | da695de628d6507924f49b8088c812eeb908b2ee (patch) | |
tree | ecf86bb53f143cf40e99e302d855f833a78c9910 /llvm/unittests/CodeGen/MachineInstrTest.cpp | |
parent | 4c58b00801add008e1f2bd0774d9a0d7297c3f93 (diff) | |
download | llvm-da695de628d6507924f49b8088c812eeb908b2ee.zip llvm-da695de628d6507924f49b8088c812eeb908b2ee.tar.gz llvm-da695de628d6507924f49b8088c812eeb908b2ee.tar.bz2 |
[MachineInstrBuilder] Introduce MIMetadata to simplify metadata propagation
In many places DebugLoc and PCSections metadata are just copied along to
propagate them through MachineInstrs. Simplify doing so by bundling them
up in a MIMetadata class that replaces the DebugLoc argument to most
BuildMI() variants.
The DebugLoc-only constructors allow implicit construction, so that
existing usage of `BuildMI(.., DL, ..)` works as before, and the rest of
the codebase using BuildMI() does not require changes.
NFC.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D130883
Diffstat (limited to 'llvm/unittests/CodeGen/MachineInstrTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/MachineInstrTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index 5552151..6488f24 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/TargetFrameLowering.h" @@ -25,6 +26,7 @@ #include "llvm/Support/TargetSelect.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" using namespace llvm; @@ -442,6 +444,34 @@ TEST(MachineInstrDebugValue, AddDebugValueOperand) { } } +MATCHER_P(HasMIMetadata, MIMD, "") { + return arg->getDebugLoc() == MIMD.getDL() && + arg->getPCSections() == MIMD.getPCSections(); +} + +TEST(MachineInstrBuilder, BuildMI) { + LLVMContext Ctx; + MDNode *PCS = MDNode::getDistinct(Ctx, None); + MDNode *DI = MDNode::getDistinct(Ctx, None); + DebugLoc DL(DI); + MIMetadata MIMD(DL, PCS); + EXPECT_EQ(MIMD.getDL(), DL); + EXPECT_EQ(MIMD.getPCSections(), PCS); + // Check common BuildMI() overloads propagate MIMetadata. + Module Mod("Module", Ctx); + auto MF = createMachineFunction(Ctx, Mod); + auto MBB = MF->CreateMachineBasicBlock(); + MCInstrDesc MCID = {0, 0, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr}; + EXPECT_THAT(BuildMI(*MF, MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MF, MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MBB, MBB->end(), MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MBB, MBB->end(), MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MBB, MBB->instr_end(), MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MBB, *MBB->begin(), MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(*MBB, &*MBB->begin(), MIMD, MCID), HasMIMetadata(MIMD)); + EXPECT_THAT(BuildMI(MBB, MIMD, MCID), HasMIMetadata(MIMD)); +} + static_assert(std::is_trivially_copyable<MCOperand>::value, "trivially copyable"); |