Skip to content

Commit 13fe673

Browse files
committed
[RISCV] Move NTLH hint emission into RISCVAsmPrinter.cpp.
Rather than having a separate pass to add the hint instructions, emit them directly into the streamer during asm printing. Reviewed By: BeMg, kito-cheng Differential Revision: https://reviews.llvm.org/D149511
1 parent 4ca1932 commit 13fe673

File tree

9 files changed

+36
-151
lines changed

9 files changed

+36
-151
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ add_llvm_target(RISCVCodeGen
2626
RISCVExpandPseudoInsts.cpp
2727
RISCVFrameLowering.cpp
2828
RISCVGatherScatterLowering.cpp
29-
RISCVInsertNTLHInsts.cpp
3029
RISCVInsertVSETVLI.cpp
3130
RISCVInstrInfo.cpp
3231
RISCVISelDAGToDAG.cpp

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ void initializeRISCVPreRAExpandPseudoPass(PassRegistry &);
6262
FunctionPass *createRISCVExpandAtomicPseudoPass();
6363
void initializeRISCVExpandAtomicPseudoPass(PassRegistry &);
6464

65-
FunctionPass *createRISCVInsertNTLHInstsPass();
66-
void initializeRISCVInsertNTLHInstsPass(PassRegistry &);
67-
6865
FunctionPass *createRISCVInsertVSETVLIPass();
6966
void initializeRISCVInsertVSETVLIPass(PassRegistry &);
7067

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class RISCVAsmPrinter : public AsmPrinter {
8585

8686
private:
8787
void emitAttributes();
88+
89+
void emitNTLHint(const MachineInstr *MI);
8890
};
8991
}
9092

@@ -100,10 +102,44 @@ void RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst) {
100102
// instructions) auto-generated.
101103
#include "RISCVGenMCPseudoLowering.inc"
102104

105+
// If the target supports Zihintnthl and the instruction has a nontemporal
106+
// MachineMemOperand, emit an NTLH hint instruction before it.
107+
void RISCVAsmPrinter::emitNTLHint(const MachineInstr *MI) {
108+
if (!STI->hasStdExtZihintntl())
109+
return;
110+
111+
if (MI->memoperands_empty())
112+
return;
113+
114+
MachineMemOperand *MMO = *(MI->memoperands_begin());
115+
if (!MMO->isNonTemporal())
116+
return;
117+
118+
unsigned NontemporalMode = 0;
119+
if (MMO->getFlags() & MONontemporalBit0)
120+
NontemporalMode += 0b1;
121+
if (MMO->getFlags() & MONontemporalBit1)
122+
NontemporalMode += 0b10;
123+
124+
MCInst Hint;
125+
if (STI->hasStdExtCOrZca() && STI->enableRVCHintInstrs())
126+
Hint.setOpcode(RISCV::C_ADD_HINT);
127+
else
128+
Hint.setOpcode(RISCV::ADD);
129+
130+
Hint.addOperand(MCOperand::createReg(RISCV::X0));
131+
Hint.addOperand(MCOperand::createReg(RISCV::X0));
132+
Hint.addOperand(MCOperand::createReg(RISCV::X2 + NontemporalMode));
133+
134+
EmitToStreamer(*OutStreamer, Hint);
135+
}
136+
103137
void RISCVAsmPrinter::emitInstruction(const MachineInstr *MI) {
104138
RISCV_MC::verifyInstructionPredicates(MI->getOpcode(),
105139
getSubtargetInfo().getFeatureBits());
106140

141+
emitNTLHint(MI);
142+
107143
// Do any auto-generated pseudo lowerings.
108144
if (emitPseudoExpansionLowering(*OutStreamer, MI))
109145
return;

llvm/lib/Target/RISCV/RISCVInsertNTLHInsts.cpp

Lines changed: 0 additions & 108 deletions
This file was deleted.

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,6 @@ include "RISCVInstrInfoZfa.td"
19111911
include "RISCVInstrInfoZfh.td"
19121912
include "RISCVInstrInfoZicbo.td"
19131913
include "RISCVInstrInfoZicond.td"
1914-
include "RISCVInstrInfoZihintntl.td"
19151914

19161915
//===----------------------------------------------------------------------===//
19171916
// Vendor extensions

llvm/lib/Target/RISCV/RISCVInstrInfoZihintntl.td

Lines changed: 0 additions & 34 deletions
This file was deleted.

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTarget() {
8383
initializeRISCVOptWInstrsPass(*PR);
8484
initializeRISCVPreRAExpandPseudoPass(*PR);
8585
initializeRISCVExpandPseudoPass(*PR);
86-
initializeRISCVInsertNTLHInstsPass(*PR);
8786
initializeRISCVInsertVSETVLIPass(*PR);
8887
initializeRISCVDAGToDAGISelPass(*PR);
8988
initializeRISCVInitUndefPass(*PR);
@@ -349,7 +348,6 @@ void RISCVPassConfig::addPreEmitPass() {
349348

350349
void RISCVPassConfig::addPreEmitPass2() {
351350
addPass(createRISCVExpandPseudoPass());
352-
addPass(createRISCVInsertNTLHInstsPass());
353351

354352
// Schedule the expansion of AMOs at the last possible moment, avoiding the
355353
// possibility for other passes to break the requirements for forward

llvm/test/CodeGen/RISCV/O0-pipeline.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
; CHECK-NEXT: Machine Optimization Remark Emitter
6565
; CHECK-NEXT: Stack Frame Layout Analysis
6666
; CHECK-NEXT: RISC-V pseudo instruction expansion pass
67-
; CHECK-NEXT: RISC-V insert NTLH instruction pass
6867
; CHECK-NEXT: RISC-V atomic pseudo instruction expansion pass
6968
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
7069
; CHECK-NEXT: Machine Optimization Remark Emitter

llvm/test/CodeGen/RISCV/O3-pipeline.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@
177177
; CHECK-NEXT: Machine Optimization Remark Emitter
178178
; CHECK-NEXT: Stack Frame Layout Analysis
179179
; CHECK-NEXT: RISC-V pseudo instruction expansion pass
180-
; CHECK-NEXT: RISC-V insert NTLH instruction pass
181180
; CHECK-NEXT: RISC-V atomic pseudo instruction expansion pass
182181
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
183182
; CHECK-NEXT: Machine Optimization Remark Emitter

0 commit comments

Comments
 (0)