[llvm] ca72b0a - [CodeGen] Use the TII hook for Noop insertion in BBSections (NFC)

Daniel Hoekwater via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 12:40:27 PDT 2023


Author: Daniel Hoekwater
Date: 2023-08-18T19:40:11Z
New Revision: ca72b0a70923ebb59a114ce497794d58f31457a3

URL: https://github.com/llvm/llvm-project/commit/ca72b0a70923ebb59a114ce497794d58f31457a3
DIFF: https://github.com/llvm/llvm-project/commit/ca72b0a70923ebb59a114ce497794d58f31457a3.diff

LOG: [CodeGen] Use the TII hook for Noop insertion in BBSections (NFC)

Refactor BasicBlockSections to use the target-specific noop insertion
hook from TargetInstrInfo instead of building it ourselves. Using the
TII hook is both cleaner and makes it easier to extend BBSections to
non-X86 targets.

Differential Revision: https://reviews.llvm.org/D158303

Added: 
    

Modified: 
    llvm/lib/CodeGen/BasicBlockSections.cpp
    llvm/lib/Target/X86/X86InstrInfo.cpp
    llvm/lib/Target/X86/X86InstrInfo.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp
index 6967ca5160c015..76fe1d96dbccf1 100644
--- a/llvm/lib/CodeGen/BasicBlockSections.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -285,9 +285,7 @@ void llvm::avoidZeroOffsetLandingPad(MachineFunction &MF) {
       MachineBasicBlock::iterator MI = MBB.begin();
       while (!MI->isEHLabel())
         ++MI;
-      MCInst Nop = MF.getSubtarget().getInstrInfo()->getNop();
-      BuildMI(MBB, MI, DebugLoc(),
-              MF.getSubtarget().getInstrInfo()->get(Nop.getOpcode()));
+      MF.getSubtarget().getInstrInfo()->insertNoop(MBB, MI);
     }
   }
 }

diff  --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 41d3a3e89fe9a0..09b951befac9f4 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -8443,6 +8443,12 @@ void X86InstrInfo::setExecutionDomain(MachineInstr &MI, unsigned Domain) const {
   MI.setDesc(get(table[Domain - 1]));
 }
 
+void X86InstrInfo::insertNoop(MachineBasicBlock &MBB,
+                              MachineBasicBlock::iterator MI) const {
+  DebugLoc DL;
+  BuildMI(MBB, MI, DL, get(X86::NOOP));
+}
+
 /// Return the noop instruction to use for a noop.
 MCInst X86InstrInfo::getNop() const {
   MCInst Nop;

diff  --git a/llvm/lib/Target/X86/X86InstrInfo.h b/llvm/lib/Target/X86/X86InstrInfo.h
index 82554032ebd661..9a072c6569fe97 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.h
+++ b/llvm/lib/Target/X86/X86InstrInfo.h
@@ -457,6 +457,9 @@ class X86InstrInfo final : public X86GenInstrInfo {
                                int64_t Offset2,
                                unsigned NumLoads) const override;
 
+  void insertNoop(MachineBasicBlock &MBB,
+                  MachineBasicBlock::iterator MI) const override;
+
   MCInst getNop() const override;
 
   bool


        


More information about the llvm-commits mailing list