[llvm] 2bc019d - [RISCV] Simplify interface of RISCVAsmPrinter::lowerToMCInst [nfc] (#156482)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 14:56:30 PDT 2025
Author: Philip Reames
Date: 2025-09-02T14:56:26-07:00
New Revision: 2bc019d8d02afee096f1c0c19cb2828b526aef94
URL: https://github.com/llvm/llvm-project/commit/2bc019d8d02afee096f1c0c19cb2828b526aef94
DIFF: https://github.com/llvm/llvm-project/commit/2bc019d8d02afee096f1c0c19cb2828b526aef94.diff
LOG: [RISCV] Simplify interface of RISCVAsmPrinter::lowerToMCInst [nfc] (#156482)
The only case which returns true is just pypassing this routine for
custom logic. Given the caller *already* has to special case this to
even fall into this routine, let's just put the logic in one place.
Note that the code had a guard for a malformed attribute which is
unreachable, and was converted into an assert. The verifier enforces
that the function attribute is well formed if present.
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 83566b1c57782..66ca43604670f 100644
--- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -126,7 +126,7 @@ class RISCVAsmPrinter : public AsmPrinter {
void LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI);
void emitSled(const MachineInstr *MI, SledKind Kind);
- bool lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
+ void lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
};
}
@@ -329,12 +329,17 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
case TargetOpcode::STATEPOINT:
return LowerSTATEPOINT(*OutStreamer, SM, *MI);
case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
- // patchable-function-entry is handled in lowerToMCInst
- // Therefore, we break out of the switch statement if we encounter it here.
const Function &F = MI->getParent()->getParent()->getFunction();
- if (F.hasFnAttribute("patchable-function-entry"))
- break;
-
+ if (F.hasFnAttribute("patchable-function-entry")) {
+ unsigned Num;
+ [[maybe_unused]] bool Result =
+ F.getFnAttribute("patchable-function-entry")
+ .getValueAsString()
+ .getAsInteger(10, Num);
+ assert(!Result && "Enforced by the verifier");
+ emitNops(Num);
+ return;
+ }
LowerPATCHABLE_FUNCTION_ENTER(MI);
return;
}
@@ -347,8 +352,8 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
}
MCInst OutInst;
- if (!lowerToMCInst(MI, OutInst))
- EmitToStreamer(*OutStreamer, OutInst);
+ lowerToMCInst(MI, OutInst);
+ EmitToStreamer(*OutStreamer, OutInst);
}
bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -1174,9 +1179,9 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
return true;
}
-bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
+void RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
- return false;
+ return;
OutMI.setOpcode(MI->getOpcode());
@@ -1185,23 +1190,6 @@ bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
if (lowerOperand(MO, MCOp))
OutMI.addOperand(MCOp);
}
-
- switch (OutMI.getOpcode()) {
- case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
- const Function &F = MI->getParent()->getParent()->getFunction();
- if (F.hasFnAttribute("patchable-function-entry")) {
- unsigned Num;
- if (F.getFnAttribute("patchable-function-entry")
- .getValueAsString()
- .getAsInteger(10, Num))
- return false;
- emitNops(Num);
- return true;
- }
- break;
- }
- }
- return false;
}
void RISCVAsmPrinter::emitMachineConstantPoolValue(
More information about the llvm-commits
mailing list