10b57cec5SDimitry Andric //===----- BPFMISimplifyPatchable.cpp - MI Simplify Patchable Insts -------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This pass targets a subset of instructions like below 100b57cec5SDimitry Andric // ld_imm64 r1, @global 110b57cec5SDimitry Andric // ldd r2, r1, 0 120b57cec5SDimitry Andric // add r3, struct_base_reg, r2 130b57cec5SDimitry Andric // 148bcb0991SDimitry Andric // Here @global should represent an AMA (abstruct member access). 158bcb0991SDimitry Andric // Such an access is subject to bpf load time patching. After this pass, the 160b57cec5SDimitry Andric // code becomes 170b57cec5SDimitry Andric // ld_imm64 r1, @global 180b57cec5SDimitry Andric // add r3, struct_base_reg, r1 190b57cec5SDimitry Andric // 200b57cec5SDimitry Andric // Eventually, at BTF output stage, a relocation record will be generated 210b57cec5SDimitry Andric // for ld_imm64 which should be replaced later by bpf loader: 228bcb0991SDimitry Andric // r1 = <calculated field_info> 230b57cec5SDimitry Andric // add r3, struct_base_reg, r1 240b57cec5SDimitry Andric // 255ffd83dbSDimitry Andric // This pass also removes the intermediate load generated in IR pass for 265ffd83dbSDimitry Andric // __builtin_btf_type_id() intrinsic. 275ffd83dbSDimitry Andric // 280b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric #include "BPF.h" 310b57cec5SDimitry Andric #include "BPFCORE.h" 320b57cec5SDimitry Andric #include "BPFInstrInfo.h" 330b57cec5SDimitry Andric #include "BPFTargetMachine.h" 3481ad6265SDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h" 350b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstrBuilder.h" 360b57cec5SDimitry Andric #include "llvm/CodeGen/MachineRegisterInfo.h" 378bcb0991SDimitry Andric #include "llvm/Support/Debug.h" 3881ad6265SDimitry Andric #include <set> 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric using namespace llvm; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric #define DEBUG_TYPE "bpf-mi-simplify-patchable" 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric namespace { 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric struct BPFMISimplifyPatchable : public MachineFunctionPass { 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric static char ID; 490b57cec5SDimitry Andric const BPFInstrInfo *TII; 500b57cec5SDimitry Andric MachineFunction *MF; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric BPFMISimplifyPatchable() : MachineFunctionPass(ID) { 530b57cec5SDimitry Andric initializeBPFMISimplifyPatchablePass(*PassRegistry::getPassRegistry()); 540b57cec5SDimitry Andric } 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric private: 5781ad6265SDimitry Andric std::set<MachineInstr *> SkipInsts; 5881ad6265SDimitry Andric 590b57cec5SDimitry Andric // Initialize class variables. 600b57cec5SDimitry Andric void initialize(MachineFunction &MFParm); 610b57cec5SDimitry Andric 6281ad6265SDimitry Andric bool isLoadInst(unsigned Opcode); 6304eeddc0SDimitry Andric bool removeLD(); 64480093f4SDimitry Andric void processCandidate(MachineRegisterInfo *MRI, MachineBasicBlock &MBB, 65480093f4SDimitry Andric MachineInstr &MI, Register &SrcReg, Register &DstReg, 665ffd83dbSDimitry Andric const GlobalValue *GVal, bool IsAma); 67480093f4SDimitry Andric void processDstReg(MachineRegisterInfo *MRI, Register &DstReg, 68480093f4SDimitry Andric Register &SrcReg, const GlobalValue *GVal, 695ffd83dbSDimitry Andric bool doSrcRegProp, bool IsAma); 70480093f4SDimitry Andric void processInst(MachineRegisterInfo *MRI, MachineInstr *Inst, 71480093f4SDimitry Andric MachineOperand *RelocOp, const GlobalValue *GVal); 72480093f4SDimitry Andric void checkADDrr(MachineRegisterInfo *MRI, MachineOperand *RelocOp, 73480093f4SDimitry Andric const GlobalValue *GVal); 74480093f4SDimitry Andric void checkShift(MachineRegisterInfo *MRI, MachineBasicBlock &MBB, 75480093f4SDimitry Andric MachineOperand *RelocOp, const GlobalValue *GVal, 76480093f4SDimitry Andric unsigned Opcode); 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric public: 790b57cec5SDimitry Andric // Main entry point for this pass. 800b57cec5SDimitry Andric bool runOnMachineFunction(MachineFunction &MF) override { 8113138422SDimitry Andric if (skipFunction(MF.getFunction())) 8213138422SDimitry Andric return false; 8313138422SDimitry Andric 840b57cec5SDimitry Andric initialize(MF); 850b57cec5SDimitry Andric return removeLD(); 860b57cec5SDimitry Andric } 870b57cec5SDimitry Andric }; 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric // Initialize class variables. 900b57cec5SDimitry Andric void BPFMISimplifyPatchable::initialize(MachineFunction &MFParm) { 910b57cec5SDimitry Andric MF = &MFParm; 920b57cec5SDimitry Andric TII = MF->getSubtarget<BPFSubtarget>().getInstrInfo(); 930b57cec5SDimitry Andric LLVM_DEBUG(dbgs() << "*** BPF simplify patchable insts pass ***\n\n"); 940b57cec5SDimitry Andric } 950b57cec5SDimitry Andric 9681ad6265SDimitry Andric bool BPFMISimplifyPatchable::isLoadInst(unsigned Opcode) { 9781ad6265SDimitry Andric return Opcode == BPF::LDD || Opcode == BPF::LDW || Opcode == BPF::LDH || 9881ad6265SDimitry Andric Opcode == BPF::LDB || Opcode == BPF::LDW32 || Opcode == BPF::LDH32 || 9981ad6265SDimitry Andric Opcode == BPF::LDB32; 10081ad6265SDimitry Andric } 10181ad6265SDimitry Andric 102480093f4SDimitry Andric void BPFMISimplifyPatchable::checkADDrr(MachineRegisterInfo *MRI, 103480093f4SDimitry Andric MachineOperand *RelocOp, const GlobalValue *GVal) { 104480093f4SDimitry Andric const MachineInstr *Inst = RelocOp->getParent(); 105480093f4SDimitry Andric const MachineOperand *Op1 = &Inst->getOperand(1); 106480093f4SDimitry Andric const MachineOperand *Op2 = &Inst->getOperand(2); 107480093f4SDimitry Andric const MachineOperand *BaseOp = (RelocOp == Op1) ? Op2 : Op1; 108480093f4SDimitry Andric 109480093f4SDimitry Andric // Go through all uses of %1 as in %1 = ADD_rr %2, %3 110480093f4SDimitry Andric const MachineOperand Op0 = Inst->getOperand(0); 111349cc55cSDimitry Andric for (MachineOperand &MO : 112349cc55cSDimitry Andric llvm::make_early_inc_range(MRI->use_operands(Op0.getReg()))) { 113480093f4SDimitry Andric // The candidate needs to have a unique definition. 114349cc55cSDimitry Andric if (!MRI->getUniqueVRegDef(MO.getReg())) 115480093f4SDimitry Andric continue; 116480093f4SDimitry Andric 117349cc55cSDimitry Andric MachineInstr *DefInst = MO.getParent(); 118480093f4SDimitry Andric unsigned Opcode = DefInst->getOpcode(); 119480093f4SDimitry Andric unsigned COREOp; 120480093f4SDimitry Andric if (Opcode == BPF::LDB || Opcode == BPF::LDH || Opcode == BPF::LDW || 121480093f4SDimitry Andric Opcode == BPF::LDD || Opcode == BPF::STB || Opcode == BPF::STH || 122480093f4SDimitry Andric Opcode == BPF::STW || Opcode == BPF::STD) 123480093f4SDimitry Andric COREOp = BPF::CORE_MEM; 124480093f4SDimitry Andric else if (Opcode == BPF::LDB32 || Opcode == BPF::LDH32 || 125480093f4SDimitry Andric Opcode == BPF::LDW32 || Opcode == BPF::STB32 || 126480093f4SDimitry Andric Opcode == BPF::STH32 || Opcode == BPF::STW32) 127480093f4SDimitry Andric COREOp = BPF::CORE_ALU32_MEM; 128480093f4SDimitry Andric else 129480093f4SDimitry Andric continue; 130480093f4SDimitry Andric 131d65cd7a5SDimitry Andric // It must be a form of %2 = *(type *)(%1 + 0) or *(type *)(%1 + 0) = %2. 132480093f4SDimitry Andric const MachineOperand &ImmOp = DefInst->getOperand(2); 133480093f4SDimitry Andric if (!ImmOp.isImm() || ImmOp.getImm() != 0) 134480093f4SDimitry Andric continue; 135480093f4SDimitry Andric 136d65cd7a5SDimitry Andric // Reject the form: 137d65cd7a5SDimitry Andric // %1 = ADD_rr %2, %3 138d65cd7a5SDimitry Andric // *(type *)(%2 + 0) = %1 139d65cd7a5SDimitry Andric if (Opcode == BPF::STB || Opcode == BPF::STH || Opcode == BPF::STW || 140d65cd7a5SDimitry Andric Opcode == BPF::STD || Opcode == BPF::STB32 || Opcode == BPF::STH32 || 141d65cd7a5SDimitry Andric Opcode == BPF::STW32) { 142d65cd7a5SDimitry Andric const MachineOperand &Opnd = DefInst->getOperand(0); 143349cc55cSDimitry Andric if (Opnd.isReg() && Opnd.getReg() == MO.getReg()) 144d65cd7a5SDimitry Andric continue; 145d65cd7a5SDimitry Andric } 146d65cd7a5SDimitry Andric 147480093f4SDimitry Andric BuildMI(*DefInst->getParent(), *DefInst, DefInst->getDebugLoc(), TII->get(COREOp)) 148480093f4SDimitry Andric .add(DefInst->getOperand(0)).addImm(Opcode).add(*BaseOp) 149480093f4SDimitry Andric .addGlobalAddress(GVal); 150480093f4SDimitry Andric DefInst->eraseFromParent(); 151480093f4SDimitry Andric } 152480093f4SDimitry Andric } 153480093f4SDimitry Andric 154480093f4SDimitry Andric void BPFMISimplifyPatchable::checkShift(MachineRegisterInfo *MRI, 155480093f4SDimitry Andric MachineBasicBlock &MBB, MachineOperand *RelocOp, const GlobalValue *GVal, 156480093f4SDimitry Andric unsigned Opcode) { 157480093f4SDimitry Andric // Relocation operand should be the operand #2. 158480093f4SDimitry Andric MachineInstr *Inst = RelocOp->getParent(); 159480093f4SDimitry Andric if (RelocOp != &Inst->getOperand(2)) 160480093f4SDimitry Andric return; 161480093f4SDimitry Andric 162480093f4SDimitry Andric BuildMI(MBB, *Inst, Inst->getDebugLoc(), TII->get(BPF::CORE_SHIFT)) 163480093f4SDimitry Andric .add(Inst->getOperand(0)).addImm(Opcode) 164480093f4SDimitry Andric .add(Inst->getOperand(1)).addGlobalAddress(GVal); 165480093f4SDimitry Andric Inst->eraseFromParent(); 166480093f4SDimitry Andric } 167480093f4SDimitry Andric 168480093f4SDimitry Andric void BPFMISimplifyPatchable::processCandidate(MachineRegisterInfo *MRI, 169480093f4SDimitry Andric MachineBasicBlock &MBB, MachineInstr &MI, Register &SrcReg, 1705ffd83dbSDimitry Andric Register &DstReg, const GlobalValue *GVal, bool IsAma) { 171480093f4SDimitry Andric if (MRI->getRegClass(DstReg) == &BPF::GPR32RegClass) { 1725ffd83dbSDimitry Andric if (IsAma) { 173480093f4SDimitry Andric // We can optimize such a pattern: 174480093f4SDimitry Andric // %1:gpr = LD_imm64 @"llvm.s:0:4$0:2" 175480093f4SDimitry Andric // %2:gpr32 = LDW32 %1:gpr, 0 176480093f4SDimitry Andric // %3:gpr = SUBREG_TO_REG 0, %2:gpr32, %subreg.sub_32 177480093f4SDimitry Andric // %4:gpr = ADD_rr %0:gpr, %3:gpr 178480093f4SDimitry Andric // or similar patterns below for non-alu32 case. 179480093f4SDimitry Andric auto Begin = MRI->use_begin(DstReg), End = MRI->use_end(); 180480093f4SDimitry Andric decltype(End) NextI; 181480093f4SDimitry Andric for (auto I = Begin; I != End; I = NextI) { 182480093f4SDimitry Andric NextI = std::next(I); 183480093f4SDimitry Andric if (!MRI->getUniqueVRegDef(I->getReg())) 184480093f4SDimitry Andric continue; 185480093f4SDimitry Andric 186480093f4SDimitry Andric unsigned Opcode = I->getParent()->getOpcode(); 187480093f4SDimitry Andric if (Opcode == BPF::SUBREG_TO_REG) { 188480093f4SDimitry Andric Register TmpReg = I->getParent()->getOperand(0).getReg(); 1895ffd83dbSDimitry Andric processDstReg(MRI, TmpReg, DstReg, GVal, false, IsAma); 1905ffd83dbSDimitry Andric } 191480093f4SDimitry Andric } 192480093f4SDimitry Andric } 193480093f4SDimitry Andric 194480093f4SDimitry Andric BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(BPF::COPY), DstReg) 195480093f4SDimitry Andric .addReg(SrcReg, 0, BPF::sub_32); 196480093f4SDimitry Andric return; 197480093f4SDimitry Andric } 198480093f4SDimitry Andric 199480093f4SDimitry Andric // All uses of DstReg replaced by SrcReg 2005ffd83dbSDimitry Andric processDstReg(MRI, DstReg, SrcReg, GVal, true, IsAma); 201480093f4SDimitry Andric } 202480093f4SDimitry Andric 203480093f4SDimitry Andric void BPFMISimplifyPatchable::processDstReg(MachineRegisterInfo *MRI, 204480093f4SDimitry Andric Register &DstReg, Register &SrcReg, const GlobalValue *GVal, 2055ffd83dbSDimitry Andric bool doSrcRegProp, bool IsAma) { 206480093f4SDimitry Andric auto Begin = MRI->use_begin(DstReg), End = MRI->use_end(); 207480093f4SDimitry Andric decltype(End) NextI; 208480093f4SDimitry Andric for (auto I = Begin; I != End; I = NextI) { 209480093f4SDimitry Andric NextI = std::next(I); 210*8a4dda33SDimitry Andric if (doSrcRegProp) { 211*8a4dda33SDimitry Andric // In situations like below it is not known if usage is a kill 212*8a4dda33SDimitry Andric // after setReg(): 213*8a4dda33SDimitry Andric // 214*8a4dda33SDimitry Andric // .-> %2:gpr = LD_imm64 @"llvm.t:0:0$0:0" 215*8a4dda33SDimitry Andric // | 216*8a4dda33SDimitry Andric // |`----------------. 217*8a4dda33SDimitry Andric // | %3:gpr = LDD %2:gpr, 0 218*8a4dda33SDimitry Andric // | %4:gpr = ADD_rr %0:gpr(tied-def 0), killed %3:gpr <--- (1) 219*8a4dda33SDimitry Andric // | %5:gpr = LDD killed %4:gpr, 0 ^^^^^^^^^^^^^ 220*8a4dda33SDimitry Andric // | STD killed %5:gpr, %1:gpr, 0 this is I 221*8a4dda33SDimitry Andric // `----------------. 222*8a4dda33SDimitry Andric // %6:gpr = LDD %2:gpr, 0 223*8a4dda33SDimitry Andric // %7:gpr = ADD_rr %0:gpr(tied-def 0), killed %6:gpr <--- (2) 224*8a4dda33SDimitry Andric // %8:gpr = LDD killed %7:gpr, 0 ^^^^^^^^^^^^^ 225*8a4dda33SDimitry Andric // STD killed %8:gpr, %1:gpr, 0 this is I 226*8a4dda33SDimitry Andric // 227*8a4dda33SDimitry Andric // Instructions (1) and (2) would be updated by setReg() to: 228*8a4dda33SDimitry Andric // 229*8a4dda33SDimitry Andric // ADD_rr %0:gpr(tied-def 0), %2:gpr 230*8a4dda33SDimitry Andric // 231*8a4dda33SDimitry Andric // %2:gpr is not killed at (1), so it is necessary to remove kill flag 232*8a4dda33SDimitry Andric // from I. 233480093f4SDimitry Andric I->setReg(SrcReg); 234*8a4dda33SDimitry Andric I->setIsKill(false); 235*8a4dda33SDimitry Andric } 236480093f4SDimitry Andric 237480093f4SDimitry Andric // The candidate needs to have a unique definition. 2385ffd83dbSDimitry Andric if (IsAma && MRI->getUniqueVRegDef(I->getReg())) 239480093f4SDimitry Andric processInst(MRI, I->getParent(), &*I, GVal); 240480093f4SDimitry Andric } 241480093f4SDimitry Andric } 242480093f4SDimitry Andric 243480093f4SDimitry Andric // Check to see whether we could do some optimization 244480093f4SDimitry Andric // to attach relocation to downstream dependent instructions. 245480093f4SDimitry Andric // Two kinds of patterns are recognized below: 246480093f4SDimitry Andric // Pattern 1: 247480093f4SDimitry Andric // %1 = LD_imm64 @"llvm.b:0:4$0:1" <== patch_imm = 4 248480093f4SDimitry Andric // %2 = LDD %1, 0 <== this insn will be removed 249480093f4SDimitry Andric // %3 = ADD_rr %0, %2 250480093f4SDimitry Andric // %4 = LDW[32] %3, 0 OR STW[32] %4, %3, 0 251480093f4SDimitry Andric // The `%4 = ...` will be transformed to 252480093f4SDimitry Andric // CORE_[ALU32_]MEM(%4, mem_opcode, %0, @"llvm.b:0:4$0:1") 253480093f4SDimitry Andric // and later on, BTF emit phase will translate to 254480093f4SDimitry Andric // %4 = LDW[32] %0, 4 STW[32] %4, %0, 4 255480093f4SDimitry Andric // and attach a relocation to it. 256480093f4SDimitry Andric // Pattern 2: 257480093f4SDimitry Andric // %15 = LD_imm64 @"llvm.t:5:63$0:2" <== relocation type 5 258480093f4SDimitry Andric // %16 = LDD %15, 0 <== this insn will be removed 259480093f4SDimitry Andric // %17 = SRA_rr %14, %16 260480093f4SDimitry Andric // The `%17 = ...` will be transformed to 261480093f4SDimitry Andric // %17 = CORE_SHIFT(SRA_ri, %14, @"llvm.t:5:63$0:2") 262480093f4SDimitry Andric // and later on, BTF emit phase will translate to 263480093f4SDimitry Andric // %r4 = SRA_ri %r4, 63 264480093f4SDimitry Andric void BPFMISimplifyPatchable::processInst(MachineRegisterInfo *MRI, 265480093f4SDimitry Andric MachineInstr *Inst, MachineOperand *RelocOp, const GlobalValue *GVal) { 266480093f4SDimitry Andric unsigned Opcode = Inst->getOpcode(); 26781ad6265SDimitry Andric if (isLoadInst(Opcode)) { 26881ad6265SDimitry Andric SkipInsts.insert(Inst); 26981ad6265SDimitry Andric return; 27081ad6265SDimitry Andric } 27181ad6265SDimitry Andric 272480093f4SDimitry Andric if (Opcode == BPF::ADD_rr) 273480093f4SDimitry Andric checkADDrr(MRI, RelocOp, GVal); 274480093f4SDimitry Andric else if (Opcode == BPF::SLL_rr) 275480093f4SDimitry Andric checkShift(MRI, *Inst->getParent(), RelocOp, GVal, BPF::SLL_ri); 276480093f4SDimitry Andric else if (Opcode == BPF::SRA_rr) 277480093f4SDimitry Andric checkShift(MRI, *Inst->getParent(), RelocOp, GVal, BPF::SRA_ri); 278480093f4SDimitry Andric else if (Opcode == BPF::SRL_rr) 279480093f4SDimitry Andric checkShift(MRI, *Inst->getParent(), RelocOp, GVal, BPF::SRL_ri); 280480093f4SDimitry Andric } 281480093f4SDimitry Andric 2820b57cec5SDimitry Andric /// Remove unneeded Load instructions. 2830b57cec5SDimitry Andric bool BPFMISimplifyPatchable::removeLD() { 2840b57cec5SDimitry Andric MachineRegisterInfo *MRI = &MF->getRegInfo(); 2850b57cec5SDimitry Andric MachineInstr *ToErase = nullptr; 2860b57cec5SDimitry Andric bool Changed = false; 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andric for (MachineBasicBlock &MBB : *MF) { 2890b57cec5SDimitry Andric for (MachineInstr &MI : MBB) { 2900b57cec5SDimitry Andric if (ToErase) { 2910b57cec5SDimitry Andric ToErase->eraseFromParent(); 2920b57cec5SDimitry Andric ToErase = nullptr; 2930b57cec5SDimitry Andric } 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric // Ensure the register format is LOAD <reg>, <reg>, 0 29681ad6265SDimitry Andric if (!isLoadInst(MI.getOpcode())) 29781ad6265SDimitry Andric continue; 29881ad6265SDimitry Andric 29981ad6265SDimitry Andric if (SkipInsts.find(&MI) != SkipInsts.end()) 3000b57cec5SDimitry Andric continue; 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andric if (!MI.getOperand(0).isReg() || !MI.getOperand(1).isReg()) 3030b57cec5SDimitry Andric continue; 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andric if (!MI.getOperand(2).isImm() || MI.getOperand(2).getImm()) 3060b57cec5SDimitry Andric continue; 3070b57cec5SDimitry Andric 3088bcb0991SDimitry Andric Register DstReg = MI.getOperand(0).getReg(); 3098bcb0991SDimitry Andric Register SrcReg = MI.getOperand(1).getReg(); 3100b57cec5SDimitry Andric 3110b57cec5SDimitry Andric MachineInstr *DefInst = MRI->getUniqueVRegDef(SrcReg); 3120b57cec5SDimitry Andric if (!DefInst) 3130b57cec5SDimitry Andric continue; 3140b57cec5SDimitry Andric 3155ffd83dbSDimitry Andric if (DefInst->getOpcode() != BPF::LD_imm64) 3160b57cec5SDimitry Andric continue; 3170b57cec5SDimitry Andric 3185ffd83dbSDimitry Andric const MachineOperand &MO = DefInst->getOperand(1); 3195ffd83dbSDimitry Andric if (!MO.isGlobal()) 3205ffd83dbSDimitry Andric continue; 3215ffd83dbSDimitry Andric 3225ffd83dbSDimitry Andric const GlobalValue *GVal = MO.getGlobal(); 3235ffd83dbSDimitry Andric auto *GVar = dyn_cast<GlobalVariable>(GVal); 3245ffd83dbSDimitry Andric if (!GVar) 3255ffd83dbSDimitry Andric continue; 3265ffd83dbSDimitry Andric 3275ffd83dbSDimitry Andric // Global variables representing structure offset or type id. 3285ffd83dbSDimitry Andric bool IsAma = false; 3295ffd83dbSDimitry Andric if (GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr)) 3305ffd83dbSDimitry Andric IsAma = true; 3315ffd83dbSDimitry Andric else if (!GVar->hasAttribute(BPFCoreSharedInfo::TypeIdAttr)) 3325ffd83dbSDimitry Andric continue; 3335ffd83dbSDimitry Andric 3345ffd83dbSDimitry Andric processCandidate(MRI, MBB, MI, SrcReg, DstReg, GVal, IsAma); 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric ToErase = &MI; 3370b57cec5SDimitry Andric Changed = true; 3380b57cec5SDimitry Andric } 3390b57cec5SDimitry Andric } 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric return Changed; 3420b57cec5SDimitry Andric } 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric } // namespace 3450b57cec5SDimitry Andric 3460b57cec5SDimitry Andric INITIALIZE_PASS(BPFMISimplifyPatchable, DEBUG_TYPE, 3470b57cec5SDimitry Andric "BPF PreEmit SimplifyPatchable", false, false) 3480b57cec5SDimitry Andric 3490b57cec5SDimitry Andric char BPFMISimplifyPatchable::ID = 0; 3500b57cec5SDimitry Andric FunctionPass *llvm::createBPFMISimplifyPatchablePass() { 3510b57cec5SDimitry Andric return new BPFMISimplifyPatchable(); 3520b57cec5SDimitry Andric } 353