LLVM 22.0.0git
BPFSubtarget.cpp
Go to the documentation of this file.
1//===-- BPFSubtarget.cpp - BPF Subtarget Information ----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the BPF specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "BPFSubtarget.h"
14#include "BPF.h"
15#include "BPFTargetMachine.h"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "bpf-subtarget"
25
26#define GET_SUBTARGETINFO_TARGET_DESC
27#define GET_SUBTARGETINFO_CTOR
28#include "BPFGenSubtargetInfo.inc"
29
30static cl::opt<bool> Disable_ldsx("disable-ldsx", cl::Hidden, cl::init(false),
31 cl::desc("Disable ldsx insns"));
32static cl::opt<bool> Disable_movsx("disable-movsx", cl::Hidden, cl::init(false),
33 cl::desc("Disable movsx insns"));
34static cl::opt<bool> Disable_bswap("disable-bswap", cl::Hidden, cl::init(false),
35 cl::desc("Disable bswap insns"));
36static cl::opt<bool> Disable_sdiv_smod("disable-sdiv-smod", cl::Hidden,
37 cl::init(false), cl::desc("Disable sdiv/smod insns"));
38static cl::opt<bool> Disable_gotol("disable-gotol", cl::Hidden, cl::init(false),
39 cl::desc("Disable gotol insn"));
40static cl::opt<bool>
41 Disable_StoreImm("disable-storeimm", cl::Hidden, cl::init(false),
42 cl::desc("Disable BPF_ST (immediate store) insn"));
44 "disable-load-acq-store-rel", cl::Hidden, cl::init(false),
45 cl::desc("Disable load-acquire and store-release insns"));
46
47void BPFSubtarget::anchor() {}
48
50 StringRef FS) {
51 initializeEnvironment();
52 initSubtargetFeatures(CPU, FS);
53 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
54 return *this;
55}
56
57void BPFSubtarget::initializeEnvironment() {
58 HasJmpExt = false;
59 HasJmp32 = false;
60 HasAlu32 = false;
61 UseDwarfRIS = false;
62 HasLdsx = false;
63 HasMovsx = false;
64 HasBswap = false;
65 HasSdivSmod = false;
66 HasGotol = false;
67 HasStoreImm = false;
68 HasLoadAcqStoreRel = false;
69}
70
71void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
72 if (CPU.empty())
73 CPU = "v3";
74 if (CPU == "probe")
76 if (CPU == "generic" || CPU == "v1")
77 return;
78 if (CPU == "v2") {
79 HasJmpExt = true;
80 return;
81 }
82 if (CPU == "v3") {
83 HasJmpExt = true;
84 HasJmp32 = true;
85 HasAlu32 = true;
86 return;
87 }
88 if (CPU == "v4") {
89 HasJmpExt = true;
90 HasJmp32 = true;
91 HasAlu32 = true;
99 return;
100 }
101}
102
103BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
104 const std::string &FS, const TargetMachine &TM)
105 : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
106 InstrInfo(initializeSubtargetDependencies(CPU, FS)), FrameLowering(*this),
107 TLInfo(TM, *this) {
108 IsLittleEndian = TT.isLittleEndian();
109
111 Legalizer.reset(new BPFLegalizerInfo(*this));
112 auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo());
113 RegBankInfo.reset(RBI);
114
116 *static_cast<const BPFTargetMachine *>(&TM), *this, *RBI));
117}
118
120 return CallLoweringInfo.get();
121}
122
126
128 return Legalizer.get();
129}
130
132 return RegBankInfo.get();
133}
This file describes how to lower LLVM calls to machine code calls.
This file declares the targeting of the Machinelegalizer class for BPF.
This file declares the targeting of the RegisterBankInfo class for BPF.
static cl::opt< bool > Disable_sdiv_smod("disable-sdiv-smod", cl::Hidden, cl::init(false), cl::desc("Disable sdiv/smod insns"))
static cl::opt< bool > Disable_ldsx("disable-ldsx", cl::Hidden, cl::init(false), cl::desc("Disable ldsx insns"))
static cl::opt< bool > Disable_gotol("disable-gotol", cl::Hidden, cl::init(false), cl::desc("Disable gotol insn"))
static cl::opt< bool > Disable_load_acq_store_rel("disable-load-acq-store-rel", cl::Hidden, cl::init(false), cl::desc("Disable load-acquire and store-release insns"))
static cl::opt< bool > Disable_movsx("disable-movsx", cl::Hidden, cl::init(false), cl::desc("Disable movsx insns"))
static cl::opt< bool > Disable_StoreImm("disable-storeimm", cl::Hidden, cl::init(false), cl::desc("Disable BPF_ST (immediate store) insn"))
static cl::opt< bool > Disable_bswap("disable-bswap", cl::Hidden, cl::init(false), cl::desc("Disable bswap insns"))
This class provides the information for the BPF target legalizer for GlobalISel.
BPFSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM)
InstructionSelector * getInstructionSelector() const override
BPFSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
std::unique_ptr< InstructionSelector > InstSelector
std::unique_ptr< LegalizerInfo > Legalizer
std::unique_ptr< CallLowering > CallLoweringInfo
const CallLowering * getCallLowering() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
const BPFRegisterInfo * getRegisterInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
const BPFTargetLowering * getTargetLowering() const override
const LegalizerInfo * getLegalizerInfo() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
Holds all the information related to register banks.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
initializer< Ty > init(const Ty &Val)
LLVM_ABI StringRef getHostCPUNameForBPF()
Definition Host.cpp:570
This is an optimization pass for GlobalISel generic memory operations.
InstructionSelector * createBPFInstructionSelector(const BPFTargetMachine &, const BPFSubtarget &, const BPFRegisterBankInfo &)