Skip to content

[RISCV] Set Feature32Bit/Feature64Bit based on triple for -mcpu=help. #127031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Feb 13, 2025

llvm-mc keeps going after printing help text and creates an assembler. If we don't set one of the XLen sized feature bits we trip a fatal error in RISCVFeatures::validate.

llvm-mc should probably be fixed, but I don't know if its the only tool with this issue.

llvm-mc keeps going after printing help text and creates an assembler.
If we don't set one of the XLen sized feature bits we trip a fatal error
in RISCVFeatures::validate.

llvm-mc should probably be fixed, but I don't know if its the only tool
with this issue.
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

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

Author: Craig Topper (topperc)

Changes

llvm-mc keeps going after printing help text and creates an assembler. If we don't set one of the XLen sized feature bits we trip a fatal error in RISCVFeatures::validate.

llvm-mc should probably be fixed, but I don't know if its the only tool with this issue.


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

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp (+16-1)
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
index 2853881780aa8..269f2e24bdf6b 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp
@@ -89,7 +89,22 @@ static MCSubtargetInfo *createRISCVMCSubtargetInfo(const Triple &TT,
   if (CPU.empty() || CPU == "generic")
     CPU = TT.isArch64Bit() ? "generic-rv64" : "generic-rv32";
 
-  return createRISCVMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
+  MCSubtargetInfo *X =
+      createRISCVMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
+
+  // If the CPU is "help" fill in 64 or 32 bit feature so we can pass
+  // RISCVFeatures::validate.
+  // FIXME: Why does llvm-mc still expect a source file with -mcpu=help?
+  if (CPU == "help") {
+    llvm::FeatureBitset Features = X->getFeatureBits();
+    if (TT.isArch64Bit())
+      Features.set(RISCV::Feature64Bit);
+    else
+      Features.set(RISCV::Feature32Bit);
+    X->setFeatureBits(Features);
+  }
+
+  return X;
 }
 
 static MCInstPrinter *createRISCVMCInstPrinter(const Triple &T,

@topperc topperc changed the title [RISCV] Set Feature32Bit/Feature64Bit base on triple for -mcpu=help. [RISCV] Set Feature32Bit/Feature64Bit based on triple for -mcpu=help. Feb 13, 2025
@topperc topperc merged commit e750c7e into llvm:main Feb 13, 2025
10 checks passed
@topperc topperc deleted the pr/mcpu-help branch February 13, 2025 17:07
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…llvm#127031)

llvm-mc keeps going after printing help text and creates an assembler.
If we don't set one of the XLen sized feature bits we trip a fatal error
in RISCVFeatures::validate.

llvm-mc should probably be fixed, but I don't know if its the only tool
with this issue.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
…llvm#127031)

llvm-mc keeps going after printing help text and creates an assembler.
If we don't set one of the XLen sized feature bits we trip a fatal error
in RISCVFeatures::validate.

llvm-mc should probably be fixed, but I don't know if its the only tool
with this issue.
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.

3 participants