[X86] Move getting module flag into `runOnMachineFunction` to reduce compile-time...
authorPhoebe Wang <phoebe.wang@intel.com>
Fri, 5 Aug 2022 08:36:33 +0000 (01:36 -0700)
committerPhoebe Wang <phoebe.wang@intel.com>
Fri, 5 Aug 2022 08:58:17 +0000 (01:58 -0700)
Reviewed By: nikic

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

llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.h
llvm/lib/Target/X86/X86MCInstLower.cpp

index c205395..3fc0eec 100644 (file)
@@ -66,6 +66,9 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   EmitFPOData =
       Subtarget->isTargetWin32() && MF.getMMI().getModule()->getCodeViewFlag();
 
+  IndCSPrefix =
+      MF.getMMI().getModule()->getModuleFlag("indirect_branch_cs_prefix");
+
   SetupMachineFunction(MF);
 
   if (Subtarget->isTargetCOFF()) {
@@ -86,6 +89,8 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   EmitFPOData = false;
 
+  IndCSPrefix = false;
+
   // We didn't modify anything.
   return false;
 }
index d53c26b..043c4b8 100644 (file)
@@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
   std::unique_ptr<MCCodeEmitter> CodeEmitter;
   bool EmitFPOData = false;
   bool ShouldEmitWeakSwiftAsyncExtendedFramePointerFlags = false;
+  bool IndCSPrefix = false;
 
   // This utility class tracks the length of a stackmap instruction's 'shadow'.
   // It is used by the X86AsmPrinter to ensure that the stackmap shadow
index bfbded8..e611664 100644 (file)
@@ -2449,9 +2449,6 @@ void X86AsmPrinter::emitInstruction(const MachineInstr *MI) {
   if (OutStreamer->isVerboseAsm())
     addConstantComments(MI, *OutStreamer);
 
-  bool IndCS =
-      MF->getMMI().getModule()->getModuleFlag("indirect_branch_cs_prefix");
-
   switch (MI->getOpcode()) {
   case TargetOpcode::DBG_VALUE:
     llvm_unreachable("Should be handled target independently");
@@ -2501,7 +2498,7 @@ void X86AsmPrinter::emitInstruction(const MachineInstr *MI) {
   }
 
   case X86::TAILJMPd64:
-    if (IndCS && MI->hasRegisterImplicitUseOperand(X86::R11))
+    if (IndCSPrefix && MI->hasRegisterImplicitUseOperand(X86::R11))
       EmitAndCountInstruction(MCInstBuilder(X86::CS_PREFIX));
     LLVM_FALLTHROUGH;
   case X86::TAILJMPr:
@@ -2684,7 +2681,7 @@ void X86AsmPrinter::emitInstruction(const MachineInstr *MI) {
                                 .addReg(X86::NoRegister));
     return;
   case X86::CALL64pcrel32:
-    if (IndCS && MI->hasRegisterImplicitUseOperand(X86::R11))
+    if (IndCSPrefix && MI->hasRegisterImplicitUseOperand(X86::R11))
       EmitAndCountInstruction(MCInstBuilder(X86::CS_PREFIX));
     break;
   }