[llvm] 9778802 - [RISCV] Make it explicit that attributes use the MCSubtargetInfo from TargetMachine. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 11:32:04 PST 2023


Author: Craig Topper
Date: 2023-01-18T11:31:45-08:00
New Revision: 9778802cb0f62d9e8588117b0a444d3d5c874250

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

LOG: [RISCV] Make it explicit that attributes use the MCSubtargetInfo from TargetMachine. NFC

The MCSTI variable is initialized to TM.getMCSubtargetInfo(), but is
re-assigned in every call to runOnMachineFunction. emitAttributes is
called before any call to runOnMachineFunction, but it's not
immediately obvious.

This patch removes the MCSTI variable, and instead queries
TM.getMCSubtargetInfo() at the time emitAttributes is called.

Reviewed By: reames

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

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
index c3157585d26f9..0edb81ce5ec9b 100644
--- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -46,13 +46,12 @@ STATISTIC(RISCVNumInstrsCompressed,
 
 namespace {
 class RISCVAsmPrinter : public AsmPrinter {
-  const MCSubtargetInfo *MCSTI;
   const RISCVSubtarget *STI;
 
 public:
   explicit RISCVAsmPrinter(TargetMachine &TM,
                            std::unique_ptr<MCStreamer> Streamer)
-      : AsmPrinter(TM, std::move(Streamer)), MCSTI(TM.getMCSubtargetInfo()) {}
+      : AsmPrinter(TM, std::move(Streamer)) {}
 
   StringRef getPassName() const override { return "RISCV Assembly Printer"; }
 
@@ -189,12 +188,6 @@ bool RISCVAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
 }
 
 bool RISCVAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
-  // Set the current MCSubtargetInfo to a copy which has the correct
-  // feature bits for the current MachineFunction
-  MCSubtargetInfo &NewSTI =
-    OutStreamer->getContext().getSubtargetCopy(*TM.getMCSubtargetInfo());
-  NewSTI.setFeatureBits(MF.getSubtarget().getFeatureBits());
-  MCSTI = &NewSTI;
   STI = &MF.getSubtarget<RISCVSubtarget>();
 
   SetupMachineFunction(MF);
@@ -224,7 +217,10 @@ void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
 void RISCVAsmPrinter::emitAttributes() {
   RISCVTargetStreamer &RTS =
       static_cast<RISCVTargetStreamer &>(*OutStreamer->getTargetStreamer());
-  RTS.emitTargetAttributes(*MCSTI);
+  // Use MCSubtargetInfo from TargetMachine. Individual functions may have
+  // attributes that 
diff er from other functions in the module and we have no
+  // way to know which function is correct.
+  RTS.emitTargetAttributes(*TM.getMCSubtargetInfo());
 }
 
 void RISCVAsmPrinter::emitFunctionEntryLabel() {


        


More information about the llvm-commits mailing list