LLVM 24.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"));
46static cl::opt<bool> Disable_gotox("disable-gotox", cl::Hidden, cl::init(false),
47 cl::desc("Disable gotox insn"));
48static cl::opt<bool>
49 Disable_hmul("disable-hmul", cl::Hidden, cl::init(false),
50 cl::desc("Disable high-half multiply (UHMUL/SHMUL) insns"));
51
52void BPFSubtarget::anchor() {}
53
55 StringRef FS) {
56 initializeEnvironment();
57 initSubtargetFeatures(CPU, FS);
58 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
59 return *this;
60}
61
62void BPFSubtarget::initializeEnvironment() {
63 HasJmpExt = false;
64 HasJmp32 = false;
65 HasAlu32 = false;
66 UseDwarfRIS = false;
67 HasLdsx = false;
68 HasMovsx = false;
69 HasBswap = false;
70 HasSdivSmod = false;
71 HasGotol = false;
72 HasStoreImm = false;
73 HasLoadAcqStoreRel = false;
74 HasGotox = false;
75 HasHmul = false;
77 HasFuncTable = false;
78}
79
80void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
81 if (CPU.empty())
82 CPU = "v3";
83 if (CPU == "probe")
85 if (CPU == "generic" || CPU == "v1")
86 return;
87 if (CPU == "v2") {
88 HasJmpExt = true;
89 return;
90 }
91 if (CPU == "v3") {
92 HasJmpExt = true;
93 HasJmp32 = true;
94 HasAlu32 = true;
95 return;
96 }
97 if (CPU == "v4" || CPU == "v5") {
98 HasJmpExt = true;
99 HasJmp32 = true;
100 HasAlu32 = true;
109 HasHmul = CPU == "v5" && !Disable_hmul;
110 return;
111 }
112}
113
114BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
115 const std::string &FS, const TargetMachine &TM)
116 : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
117 InstrInfo(initializeSubtargetDependencies(CPU, FS)), FrameLowering(*this),
118 TLInfo(TM, *this) {
119 IsLittleEndian = TT.isLittleEndian();
120
122 Legalizer.reset(new BPFLegalizerInfo(*this));
123 auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo());
124 RegBankInfo.reset(RBI);
125
127 *static_cast<const BPFTargetMachine *>(&TM), *this, *RBI));
128}
129
131 return CallLoweringInfo.get();
132}
133
137
139 return Legalizer.get();
140}
141
143 return RegBankInfo.get();
144}
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_gotox("disable-gotox", cl::Hidden, cl::init(false), cl::desc("Disable gotox insn"))
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_hmul("disable-hmul", cl::Hidden, cl::init(false), cl::desc("Disable high-half multiply (UHMUL/SHMUL) 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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
initializer< Ty > init(const Ty &Val)
LLVM_ABI StringRef getHostCPUNameForBPF()
Definition Host.cpp:579
This is an optimization pass for GlobalISel generic memory operations.
InstructionSelector * createBPFInstructionSelector(const BPFTargetMachine &, const BPFSubtarget &, const BPFRegisterBankInfo &)