Skip to content

Commit f71f959

Browse files
committed
[SOL] Always add return for SBPFv3 (#150)
* [SOL] Always add return for SBPFv3 * Add test and simplify condition
1 parent 57d0d02 commit f71f959

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

llvm/lib/Target/SBF/SBF.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ FunctionPass *createSBFISelDag(SBFTargetMachine &TM);
2828
FunctionPass *createSBFMISimplifyPatchablePass();
2929
FunctionPass *createSBFMIPeepholePass();
3030
FunctionPass *createSBFMIPeepholeTruncElimPass();
31-
FunctionPass *createSBFMIPreEmitPeepholePass();
31+
FunctionPass *createSBFMIPreEmitPeepholePass(CodeGenOptLevel OptLevel,
32+
bool DisablePeephole);
3233
FunctionPass *createSBFMIPreEmitCheckingPass();
3334

3435
InstructionSelector *createSBFInstructionSelector(const SBFTargetMachine &,

llvm/lib/Target/SBF/SBFMIPeephole.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ struct SBFMIPreEmitPeephole : public MachineFunctionPass {
131131
const TargetRegisterInfo *TRI;
132132
const SBFInstrInfo *TII;
133133
const SBFSubtarget *SubTarget;
134+
const CodeGenOptLevel OptLevel;
135+
const bool DisablePeephole;
134136

135-
SBFMIPreEmitPeephole() : MachineFunctionPass(ID) {
137+
SBFMIPreEmitPeephole(CodeGenOptLevel OptLevel, bool DisablePeephole)
138+
: MachineFunctionPass(ID), OptLevel(OptLevel),
139+
DisablePeephole(DisablePeephole) {
136140
initializeSBFMIPreEmitPeepholePass(*PassRegistry::getPassRegistry());
137141
}
138142

@@ -147,15 +151,17 @@ struct SBFMIPreEmitPeephole : public MachineFunctionPass {
147151

148152
// Main entry point for this pass.
149153
bool runOnMachineFunction(MachineFunction &MF) override {
150-
if (skipFunction(MF.getFunction()))
151-
return false;
152-
153154
initialize(MF);
154155

155156
bool PeepholeExecuted = false;
156157
if (SubTarget->getHasStaticSyscalls())
157158
PeepholeExecuted |= addReturn();
158159

160+
// We shall not skip adding the return to SBPFv3 functions
161+
if (skipFunction(MF.getFunction()) || OptLevel == CodeGenOptLevel::None ||
162+
DisablePeephole)
163+
return PeepholeExecuted;
164+
159165
PeepholeExecuted |= eliminateRedundantMov();
160166

161167
return PeepholeExecuted;
@@ -194,10 +200,7 @@ bool SBFMIPreEmitPeephole::addReturn() {
194200

195201
MachineInstr &MI = MBB.back();
196202
unsigned Opcode = MI.getOpcode();
197-
if (Opcode == SBF::JAL ||
198-
Opcode == SBF::JALX ||
199-
Opcode == SBF::JALX_v2 ||
200-
Opcode == SBF::SYSCALL_v3) {
203+
if (Opcode != SBF::RETURN_v3) {
201204
BuildMI(&MBB, MI.getDebugLoc(), TII->get(SBF::RETURN_v3));
202205
Added = true;
203206
}
@@ -250,9 +253,9 @@ INITIALIZE_PASS(SBFMIPreEmitPeephole, "sbf-mi-pemit-peephole",
250253
"SBF PreEmit Peephole Optimization", false, false)
251254

252255
char SBFMIPreEmitPeephole::ID = 0;
253-
FunctionPass* llvm::createSBFMIPreEmitPeepholePass()
256+
FunctionPass* llvm::createSBFMIPreEmitPeepholePass(CodeGenOptLevel OptLevel, bool DisablePeephole)
254257
{
255-
return new SBFMIPreEmitPeephole();
258+
return new SBFMIPreEmitPeephole(OptLevel, DisablePeephole);
256259
}
257260

258261
STATISTIC(TruncElemNum, "Number of truncation eliminated");

llvm/lib/Target/SBF/SBFTargetMachine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,5 @@ void SBFPassConfig::addMachineSSAOptimization() {
168168

169169
void SBFPassConfig::addPreEmitPass() {
170170
addPass(createSBFMIPreEmitCheckingPass());
171-
if (getOptLevel() != CodeGenOptLevel::None)
172-
if (!DisableMIPeephole)
173-
addPass(createSBFMIPreEmitPeepholePass());
171+
addPass(createSBFMIPreEmitPeepholePass(getOptLevel(), DisableMIPeephole));
174172
}

llvm/test/CodeGen/SBF/unreachable_return.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
; RUN: llc -O2 -march=sbf -mcpu=v3 < %s | FileCheck %s
2+
; RUN: llc -O0 -march=sbf -mcpu=v3 < %s | FileCheck %s
23

34
declare void @dummy_func(i8, ptr, ptr, ptr, ptr, ptr, ptr)
45

0 commit comments

Comments
 (0)