LLVM 19.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 == "probe")
70 if (CPU == "generic" || CPU == "v1")
71 return;
72 if (CPU == "v2") {
73 HasJmpExt = true;
74 return;
75 }
76 if (CPU == "v3") {
77 HasJmpExt = true;
78 HasJmp32 = true;
79 HasAlu32 = true;
80 return;
81 }
82 if (CPU == "v4") {
83 HasJmpExt = true;
84 HasJmp32 = true;
85 HasAlu32 = true;
92 return;
93 }
94}
95
96BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
97 const std::string &FS, const TargetMachine &TM)
98 : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
99 FrameLowering(initializeSubtargetDependencies(CPU, FS)),
100 TLInfo(TM, *this) {
101 IsLittleEndian = TT.isLittleEndian();
102
104 Legalizer.reset(new BPFLegalizerInfo(*this));
105 auto *RBI = new BPFRegisterBankInfo(*getRegisterInfo());
106 RegBankInfo.reset(RBI);
107
109 *static_cast<const BPFTargetMachine *>(&TM), *this, *RBI));
110}
111
113 return CallLoweringInfo.get();
114}
115
117 return InstSelector.get();
118}
119
121 return Legalizer.get();
122}
123
125 return RegBankInfo.get();
126}
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"))
const char LLVMTargetMachineRef TM
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:50
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
StringRef getHostCPUNameForBPF()
Definition: Host.cpp:450
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
InstructionSelector * createBPFInstructionSelector(const BPFTargetMachine &, const BPFSubtarget &, const BPFRegisterBankInfo &)