LLVM 20.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"));
43
44void BPFSubtarget::anchor() {}
45
47 StringRef FS) {
48 initializeEnvironment();
49 initSubtargetFeatures(CPU, FS);
50 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
51 return *this;
52}
53
54void BPFSubtarget::initializeEnvironment() {
55 HasJmpExt = false;
56 HasJmp32 = false;
57 HasAlu32 = false;
58 UseDwarfRIS = false;
59 HasLdsx = false;
60 HasMovsx = false;
61 HasBswap = false;
62 HasSdivSmod = false;
63 HasGotol = false;
64 HasStoreImm = false;
65}
66
67void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
68 if (CPU.empty())
69 CPU = "v3";
70 if (CPU == "probe")
72 if (CPU == "generic" || CPU == "v1")
73 return;
74 if (CPU == "v2") {
75 HasJmpExt = true;
76 return;
77 }
78 if (CPU == "v3") {
79 HasJmpExt = true;
80 HasJmp32 = true;
81 HasAlu32 = true;
82 return;
83 }
84 if (CPU == "v4") {
85 HasJmpExt = true;
86 HasJmp32 = true;
87 HasAlu32 = true;
94 return;
95 }
96}
97
98BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
99 const std::string &FS, const TargetMachine &TM)
100 : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
101 FrameLowering(initializeSubtargetDependencies(CPU, FS)),
102 TLInfo(TM, *this) {
103 IsLittleEndian = TT.isLittleEndian();
104
106 Legalizer.reset(new BPFLegalizerInfo(*this));
107 auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo());
108 RegBankInfo.reset(RBI);
109
111 *static_cast<const BPFTargetMachine *>(&TM), *this, *RBI));
112}
113
115 return CallLoweringInfo.get();
116}
117
119 return InstSelector.get();
120}
121
123 return Legalizer.get();
124}
125
127 return RegBankInfo.get();
128}
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_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
Definition: BPFSubtarget.h:70
std::unique_ptr< CallLowering > CallLoweringInfo
Definition: BPFSubtarget.h:69
const CallLowering * getCallLowering() const override
std::unique_ptr< RegisterBankInfo > RegBankInfo
Definition: BPFSubtarget.h:72
const BPFRegisterInfo * getRegisterInfo() const override
Definition: BPFSubtarget.h:108
const RegisterBankInfo * getRegBankInfo() const override
const BPFTargetLowering * getTargetLowering() const override
Definition: BPFSubtarget.h:102
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:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
StringRef getHostCPUNameForBPF()
Definition: Host.cpp:498
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
InstructionSelector * createBPFInstructionSelector(const BPFTargetMachine &, const BPFSubtarget &, const BPFRegisterBankInfo &)