aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp')
-rw-r--r--llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
index b4232875383c..088195994edd 100644
--- a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
+++ b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
@@ -31,9 +31,11 @@
#include "BPFCORE.h"
#include "BPFInstrInfo.h"
#include "BPFTargetMachine.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/Support/Debug.h"
+#include <set>
using namespace llvm;
@@ -52,9 +54,12 @@ struct BPFMISimplifyPatchable : public MachineFunctionPass {
}
private:
+ std::set<MachineInstr *> SkipInsts;
+
// Initialize class variables.
void initialize(MachineFunction &MFParm);
+ bool isLoadInst(unsigned Opcode);
bool removeLD();
void processCandidate(MachineRegisterInfo *MRI, MachineBasicBlock &MBB,
MachineInstr &MI, Register &SrcReg, Register &DstReg,
@@ -88,6 +93,12 @@ void BPFMISimplifyPatchable::initialize(MachineFunction &MFParm) {
LLVM_DEBUG(dbgs() << "*** BPF simplify patchable insts pass ***\n\n");
}
+bool BPFMISimplifyPatchable::isLoadInst(unsigned Opcode) {
+ return Opcode == BPF::LDD || Opcode == BPF::LDW || Opcode == BPF::LDH ||
+ Opcode == BPF::LDB || Opcode == BPF::LDW32 || Opcode == BPF::LDH32 ||
+ Opcode == BPF::LDB32;
+}
+
void BPFMISimplifyPatchable::checkADDrr(MachineRegisterInfo *MRI,
MachineOperand *RelocOp, const GlobalValue *GVal) {
const MachineInstr *Inst = RelocOp->getParent();
@@ -229,6 +240,11 @@ void BPFMISimplifyPatchable::processDstReg(MachineRegisterInfo *MRI,
void BPFMISimplifyPatchable::processInst(MachineRegisterInfo *MRI,
MachineInstr *Inst, MachineOperand *RelocOp, const GlobalValue *GVal) {
unsigned Opcode = Inst->getOpcode();
+ if (isLoadInst(Opcode)) {
+ SkipInsts.insert(Inst);
+ return;
+ }
+
if (Opcode == BPF::ADD_rr)
checkADDrr(MRI, RelocOp, GVal);
else if (Opcode == BPF::SLL_rr)
@@ -253,10 +269,10 @@ bool BPFMISimplifyPatchable::removeLD() {
}
// Ensure the register format is LOAD <reg>, <reg>, 0
- if (MI.getOpcode() != BPF::LDD && MI.getOpcode() != BPF::LDW &&
- MI.getOpcode() != BPF::LDH && MI.getOpcode() != BPF::LDB &&
- MI.getOpcode() != BPF::LDW32 && MI.getOpcode() != BPF::LDH32 &&
- MI.getOpcode() != BPF::LDB32)
+ if (!isLoadInst(MI.getOpcode()))
+ continue;
+
+ if (SkipInsts.find(&MI) != SkipInsts.end())
continue;
if (!MI.getOperand(0).isReg() || !MI.getOperand(1).isReg())