Skip to content

Commit c438603

Browse files
authored
[RISCV] Use cached SubtargetInfo in AsmPrinter (NFC) (#147269)
Avoids having to keep fetching to SubtargetInfo from machine function, if it's already cached in AsmPrinter.
1 parent e14e982 commit c438603

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ void RISCVAsmPrinter::emitNTLHint(const MachineInstr *MI) {
305305
}
306306

307307
void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
308-
RISCV_MC::verifyInstructionPredicates(MI->getOpcode(),
309-
getSubtargetInfo().getFeatureBits());
308+
RISCV_MC::verifyInstructionPredicates(MI->getOpcode(), STI->getFeatureBits());
310309

311310
emitNTLHint(MI);
312311

@@ -517,12 +516,9 @@ void RISCVAsmPrinter::emitSled(const MachineInstr *MI, SledKind Kind) {
517516
// Assuming we're using JAL to jump to .tmpN, then we only need
518517
// (68 - 4)/2 = 32 NOPs for RV64 and (44 - 4)/2 = 20 for RV32. However, there
519518
// is a chance that we'll use C.JAL instead, so an additional NOP is needed.
520-
const uint8_t NoopsInSledCount =
521-
MI->getParent()->getParent()->getSubtarget<RISCVSubtarget>().is64Bit()
522-
? 33
523-
: 21;
519+
const uint8_t NoopsInSledCount = STI->is64Bit() ? 33 : 21;
524520

525-
OutStreamer->emitCodeAlignment(Align(4), &getSubtargetInfo());
521+
OutStreamer->emitCodeAlignment(Align(4), STI);
526522
auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
527523
OutStreamer->emitLabel(CurSled);
528524
auto Target = OutContext.createTempSymbol();
@@ -1070,22 +1066,17 @@ bool RISCVAsmPrinter::lowerOperand(const MachineOperand &MO,
10701066
}
10711067

10721068
static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
1073-
MCInst &OutMI) {
1069+
MCInst &OutMI,
1070+
const RISCVSubtarget *STI) {
10741071
const RISCVVPseudosTable::PseudoInfo *RVV =
10751072
RISCVVPseudosTable::getPseudoInfo(MI->getOpcode());
10761073
if (!RVV)
10771074
return false;
10781075

10791076
OutMI.setOpcode(RVV->BaseInstr);
10801077

1081-
const MachineBasicBlock *MBB = MI->getParent();
1082-
assert(MBB && "MI expected to be in a basic block");
1083-
const MachineFunction *MF = MBB->getParent();
1084-
assert(MF && "MBB expected to be in a machine function");
1085-
1086-
const RISCVSubtarget &Subtarget = MF->getSubtarget<RISCVSubtarget>();
1087-
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
1088-
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
1078+
const TargetInstrInfo *TII = STI->getInstrInfo();
1079+
const TargetRegisterInfo *TRI = STI->getRegisterInfo();
10891080
assert(TRI && "TargetRegisterInfo expected");
10901081

10911082
const MCInstrDesc &MCID = MI->getDesc();
@@ -1182,7 +1173,7 @@ static bool lowerRISCVVMachineInstrToMCInst(const MachineInstr *MI,
11821173
}
11831174

11841175
bool RISCVAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) {
1185-
if (lowerRISCVVMachineInstrToMCInst(MI, OutMI))
1176+
if (lowerRISCVVMachineInstrToMCInst(MI, OutMI, STI))
11861177
return false;
11871178

11881179
OutMI.setOpcode(MI->getOpcode());

0 commit comments

Comments
 (0)