@@ -131,8 +131,12 @@ struct SBFMIPreEmitPeephole : public MachineFunctionPass {
131
131
const TargetRegisterInfo *TRI;
132
132
const SBFInstrInfo *TII;
133
133
const SBFSubtarget *SubTarget;
134
+ const CodeGenOptLevel OptLevel;
135
+ const bool DisablePeephole;
134
136
135
- SBFMIPreEmitPeephole () : MachineFunctionPass(ID) {
137
+ SBFMIPreEmitPeephole (CodeGenOptLevel OptLevel, bool DisablePeephole)
138
+ : MachineFunctionPass(ID), OptLevel(OptLevel),
139
+ DisablePeephole (DisablePeephole) {
136
140
initializeSBFMIPreEmitPeepholePass (*PassRegistry::getPassRegistry ());
137
141
}
138
142
@@ -147,15 +151,17 @@ struct SBFMIPreEmitPeephole : public MachineFunctionPass {
147
151
148
152
// Main entry point for this pass.
149
153
bool runOnMachineFunction (MachineFunction &MF) override {
150
- if (skipFunction (MF.getFunction ()))
151
- return false ;
152
-
153
154
initialize (MF);
154
155
155
156
bool PeepholeExecuted = false ;
156
157
if (SubTarget->getHasStaticSyscalls ())
157
158
PeepholeExecuted |= addReturn ();
158
159
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
+
159
165
PeepholeExecuted |= eliminateRedundantMov ();
160
166
161
167
return PeepholeExecuted;
@@ -194,10 +200,7 @@ bool SBFMIPreEmitPeephole::addReturn() {
194
200
195
201
MachineInstr &MI = MBB.back ();
196
202
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) {
201
204
BuildMI (&MBB, MI.getDebugLoc (), TII->get (SBF::RETURN_v3));
202
205
Added = true ;
203
206
}
@@ -250,9 +253,9 @@ INITIALIZE_PASS(SBFMIPreEmitPeephole, "sbf-mi-pemit-peephole",
250
253
" SBF PreEmit Peephole Optimization" , false , false )
251
254
252
255
char SBFMIPreEmitPeephole::ID = 0;
253
- FunctionPass* llvm::createSBFMIPreEmitPeepholePass ()
256
+ FunctionPass* llvm::createSBFMIPreEmitPeepholePass (CodeGenOptLevel OptLevel, bool DisablePeephole )
254
257
{
255
- return new SBFMIPreEmitPeephole ();
258
+ return new SBFMIPreEmitPeephole (OptLevel, DisablePeephole );
256
259
}
257
260
258
261
STATISTIC (TruncElemNum, " Number of truncation eliminated" );
0 commit comments