Path: blob/main/contrib/llvm-project/llvm/lib/Target/BPF/GISel/BPFInstructionSelector.cpp
35294 views
//===- BPFInstructionSelector.cpp --------------------------------*- C++ -*-==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8/// This file implements the targeting of the InstructionSelector class for BPF.9//===----------------------------------------------------------------------===//1011#include "BPFInstrInfo.h"12#include "BPFRegisterBankInfo.h"13#include "BPFSubtarget.h"14#include "BPFTargetMachine.h"15#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"16#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"17#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"18#include "llvm/CodeGen/MachineFunction.h"19#include "llvm/IR/IntrinsicsBPF.h"20#include "llvm/Support/Debug.h"2122#define DEBUG_TYPE "bpf-gisel"2324using namespace llvm;2526namespace {2728#define GET_GLOBALISEL_PREDICATE_BITSET29#include "BPFGenGlobalISel.inc"30#undef GET_GLOBALISEL_PREDICATE_BITSET3132class BPFInstructionSelector : public InstructionSelector {33public:34BPFInstructionSelector(const BPFTargetMachine &TM, const BPFSubtarget &STI,35const BPFRegisterBankInfo &RBI);3637bool select(MachineInstr &I) override;38static const char *getName() { return DEBUG_TYPE; }3940private:41/// tblgen generated 'select' implementation that is used as the initial42/// selector for the patterns that do not require complex C++.43bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;4445const BPFInstrInfo &TII;46const BPFRegisterInfo &TRI;47const BPFRegisterBankInfo &RBI;4849#define GET_GLOBALISEL_PREDICATES_DECL50#include "BPFGenGlobalISel.inc"51#undef GET_GLOBALISEL_PREDICATES_DECL5253#define GET_GLOBALISEL_TEMPORARIES_DECL54#include "BPFGenGlobalISel.inc"55#undef GET_GLOBALISEL_TEMPORARIES_DECL56};5758} // namespace5960#define GET_GLOBALISEL_IMPL61#include "BPFGenGlobalISel.inc"62#undef GET_GLOBALISEL_IMPL6364BPFInstructionSelector::BPFInstructionSelector(const BPFTargetMachine &TM,65const BPFSubtarget &STI,66const BPFRegisterBankInfo &RBI)67: TII(*STI.getInstrInfo()), TRI(*STI.getRegisterInfo()), RBI(RBI),68#define GET_GLOBALISEL_PREDICATES_INIT69#include "BPFGenGlobalISel.inc"70#undef GET_GLOBALISEL_PREDICATES_INIT71#define GET_GLOBALISEL_TEMPORARIES_INIT72#include "BPFGenGlobalISel.inc"73#undef GET_GLOBALISEL_TEMPORARIES_INIT74{75}7677bool BPFInstructionSelector::select(MachineInstr &I) {78if (!isPreISelGenericOpcode(I.getOpcode()))79return true;80if (selectImpl(I, *CoverageInfo))81return true;82return false;83}8485namespace llvm {86InstructionSelector *87createBPFInstructionSelector(const BPFTargetMachine &TM,88const BPFSubtarget &Subtarget,89const BPFRegisterBankInfo &RBI) {90return new BPFInstructionSelector(TM, Subtarget, RBI);91}92} // namespace llvm939495