Skip to content

Commit 2fb1519

Browse files
committed
[RISCV] Simplify interface of RISCVAsmPrinter::lowerToMCInst [nfc]
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 b062aad commit 2fb1519

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 14 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,16 @@ 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+
assert(!F.getFnAttribute("patchable-function-entry")
336+
.getValueAsString()
337+
.getAsInteger(10, Num) &&
338+
"Enforced by the verified");
339+
emitNops(Num);
340+
return;
341+
}
338342
LowerPATCHABLE_FUNCTION_ENTER(MI);
339343
return;
340344
}
@@ -347,8 +351,8 @@ void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
347351
}
348352

349353
MCInst OutInst;
350-
if (!lowerToMCInst(MI, OutInst))
351-
EmitToStreamer(*OutStreamer, OutInst);
354+
lowerToMCInst(MI, OutInst);
355+
EmitToStreamer(*OutStreamer, OutInst);
352356
}
353357

354358
bool RISCVAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
@@ -1174,9 +1178,9 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
11741178
return true;
11751179
}
11761180

1177-
bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
1181+
void RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
11781182
if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
1179-
return false;
1183+
return;
11801184

11811185
OutMI.setOpcode(MI->getOpcode());
11821186

@@ -1185,23 +1189,6 @@ bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
11851189
if (lowerOperand(MO, MCOp))
11861190
OutMI.addOperand(MCOp);
11871191
}
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;
12051192
}
12061193

12071194
void RISCVAsmPrinter::emitMachineConstantPoolValue(

0 commit comments

Comments
 (0)