Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Feb 23, 2025

SPIRVInstrInfo.h is a CodeGen layer file, it should not be used in MC layer files.

This required adding a new enum for MCInst flags and a conversion from MachineInstr's AsmPrinter flags in SPIRVMCInstLower.

SPIRVInstrInfo.h is a CodeGen layer file, it should not be used in
MC layer files.

This required adding a new enum for MCInst flags and a conversion
from MachineInstr's AsmPrinter flags in SPIRVMCInstLower.
@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2025

@llvm/pr-subscribers-backend-spir-v

Author: Craig Topper (topperc)

Changes

SPIRVInstrInfo.h is a CodeGen layer file, it should not be used in MC layer files.

This required adding a new enum for MCInst flags and a conversion from MachineInstr's AsmPrinter flags in SPIRVMCInstLower.


Full diff: https://github.com/llvm/llvm-project/pull/128443.diff

3 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h (+5)
  • (modified) llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp (+2-1)
diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
index 2437fbb820a36..d009244a92259 100644
--- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
+++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.h
@@ -222,6 +222,11 @@ struct ExtendedBuiltin {
   InstructionSet::InstructionSet Set;
   uint32_t Number;
 };
+
+enum InstFlags {
+  // It is a half type
+  INST_PRINTER_WIDTH16 = 1
+};
 } // namespace SPIRV
 
 using CapabilityList = SmallVector<SPIRV::Capability::Capability, 8>;
diff --git a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp
index 10f4ea99fab32..3eb090f4857d8 100644
--- a/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp
@@ -13,7 +13,6 @@
 #include "SPIRVInstPrinter.h"
 #include "SPIRV.h"
 #include "SPIRVBaseInfo.h"
-#include "SPIRVInstrInfo.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/CodeGen/Register.h"
 #include "llvm/MC/MCAsmInfo.h"
@@ -51,7 +50,7 @@ void SPIRVInstPrinter::printRemainingVariableOps(const MCInst *MI,
 void SPIRVInstPrinter::printOpConstantVarOps(const MCInst *MI,
                                              unsigned StartIndex,
                                              raw_ostream &O) {
-  unsigned IsBitwidth16 = MI->getFlags() & SPIRV::ASM_PRINTER_WIDTH16;
+  unsigned IsBitwidth16 = MI->getFlags() & SPIRV::INST_PRINTER_WIDTH16;
   const unsigned NumVarOps = MI->getNumOperands() - StartIndex;
 
   assert((NumVarOps == 1 || NumVarOps == 2) &&
diff --git a/llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp b/llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp
index afa550d6dd424..bc074aa2799b1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp
@@ -24,7 +24,8 @@ void SPIRVMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI,
                              SPIRV::ModuleAnalysisInfo *MAI) const {
   OutMI.setOpcode(MI->getOpcode());
   // Propagate previously set flags
-  OutMI.setFlags(MI->getAsmPrinterFlags());
+  if (MI->getAsmPrinterFlags() & SPIRV::ASM_PRINTER_WIDTH16)
+    OutMI.setFlags(SPIRV::INST_PRINTER_WIDTH16);
   const MachineFunction *MF = MI->getMF();
   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
     const MachineOperand &MO = MI->getOperand(i);

@topperc topperc merged commit 7f6f186 into llvm:main Feb 24, 2025
14 checks passed
@topperc topperc deleted the pr/spirv-instrinfo branch February 24, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants