Skip to content

Commit 2bc019d

Browse files
authored
[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.
1 parent 5b4819e commit 2bc019d

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class RISCVAsmPrinter : public AsmPrinter {
126126
void LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI);
127127
void emitSled(const MachineInstr *MI, SledKind Kind);
128128

129-
bool lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
129+
void lowerToMCInst(const MachineInstr *MI, MCInst &OutMI);
130130
};
131131
}
132132

@@ -329,12 +329,17 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
329329
case TargetOpcode::STATEPOINT:
330330
return LowerSTATEPOINT(*OutStreamer, SM, *MI);
331331
case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
332-
// patchable-function-entry is handled in lowerToMCInst
333-
// Therefore, we break out of the switch statement if we encounter it here.
334332
const Function &F = MI->getParent()->getParent()->getFunction();
335-
if (F.hasFnAttribute("patchable-function-entry"))
336-
break;
337-
333+
if (F.hasFnAttribute("patchable-function-entry")) {
334+
unsigned Num;
335+
[[maybe_unused]] bool Result =
336+
F.getFnAttribute("patchable-function-entry")
337+
.getValueAsString()
338+
.getAsInteger(10, Num);
339+
assert(!Result && "Enforced by the verifier");
340+
emitNops(Num);
341+
return;
342+
}
338343
LowerPATCHABLE_FUNCTION_ENTER(MI);
339344
return;
340345
}
@@ -347,8 +352,8 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
347352
}
348353

349354
MCInst OutInst;
350-
if (!lowerToMCInst(MI, OutInst))
351-
EmitToStreamer(*OutStreamer, OutInst);
355+
lowerToMCInst(MI, OutInst);
356+
EmitToStreamer(*OutStreamer, OutInst);
352357
}
353358

354359
bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -1174,9 +1179,9 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
11741179
return true;
11751180
}
11761181

1177-
bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
1182+
void RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
11781183
if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
1179-
return false;
1184+
return;
11801185

11811186
OutMI.setOpcode(MI->getOpcode());
11821187

@@ -1185,23 +1190,6 @@ bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
11851190
if (lowerOperand(MO, MCOp))
11861191
OutMI.addOperand(MCOp);
11871192
}
1188-
1189-
switch (OutMI.getOpcode()) {
1190-
case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
1191-
const Function &F = MI->getParent()->getParent()->getFunction();
1192-
if (F.hasFnAttribute("patchable-function-entry")) {
1193-
unsigned Num;
1194-
if (F.getFnAttribute("patchable-function-entry")
1195-
.getValueAsString()
1196-
.getAsInteger(10, Num))
1197-
return false;
1198-
emitNops(Num);
1199-
return true;
1200-
}
1201-
break;
1202-
}
1203-
}
1204-
return false;
12051193
}
12061194

12071195
void RISCVAsmPrinter::emitMachineConstantPoolValue(

0 commit comments

Comments
 (0)