Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / Target / BPF / BPFSubtarget.cpp
blobce02c831828e4db254c00c49216421eb629eb0b8
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.
11 //===----------------------------------------------------------------------===//
13 #include "BPFSubtarget.h"
14 #include "BPF.h"
15 #include "llvm/MC/TargetRegistry.h"
16 #include "llvm/TargetParser/Host.h"
18 using namespace llvm;
20 #define DEBUG_TYPE "bpf-subtarget"
22 #define GET_SUBTARGETINFO_TARGET_DESC
23 #define GET_SUBTARGETINFO_CTOR
24 #include "BPFGenSubtargetInfo.inc"
26 static cl::opt<bool> Disable_ldsx("disable-ldsx", cl::Hidden, cl::init(false),
27 cl::desc("Disable ldsx insns"));
28 static cl::opt<bool> Disable_movsx("disable-movsx", cl::Hidden, cl::init(false),
29 cl::desc("Disable movsx insns"));
30 static cl::opt<bool> Disable_bswap("disable-bswap", cl::Hidden, cl::init(false),
31 cl::desc("Disable bswap insns"));
32 static cl::opt<bool> Disable_sdiv_smod("disable-sdiv-smod", cl::Hidden,
33 cl::init(false), cl::desc("Disable sdiv/smod insns"));
34 static cl::opt<bool> Disable_gotol("disable-gotol", cl::Hidden, cl::init(false),
35 cl::desc("Disable gotol insn"));
36 static cl::opt<bool>
37 Disable_StoreImm("disable-storeimm", cl::Hidden, cl::init(false),
38 cl::desc("Disable BPF_ST (immediate store) insn"));
40 void BPFSubtarget::anchor() {}
42 BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU,
43 StringRef FS) {
44 initializeEnvironment();
45 initSubtargetFeatures(CPU, FS);
46 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
47 return *this;
50 void BPFSubtarget::initializeEnvironment() {
51 HasJmpExt = false;
52 HasJmp32 = false;
53 HasAlu32 = false;
54 UseDwarfRIS = false;
55 HasLdsx = false;
56 HasMovsx = false;
57 HasBswap = false;
58 HasSdivSmod = false;
59 HasGotol = false;
60 HasStoreImm = false;
63 void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
64 if (CPU == "probe")
65 CPU = sys::detail::getHostCPUNameForBPF();
66 if (CPU == "generic" || CPU == "v1")
67 return;
68 if (CPU == "v2") {
69 HasJmpExt = true;
70 return;
72 if (CPU == "v3") {
73 HasJmpExt = true;
74 HasJmp32 = true;
75 HasAlu32 = true;
76 return;
78 if (CPU == "v4") {
79 HasJmpExt = true;
80 HasJmp32 = true;
81 HasAlu32 = true;
82 HasLdsx = !Disable_ldsx;
83 HasMovsx = !Disable_movsx;
84 HasBswap = !Disable_bswap;
85 HasSdivSmod = !Disable_sdiv_smod;
86 HasGotol = !Disable_gotol;
87 HasStoreImm = !Disable_StoreImm;
88 return;
92 BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
93 const std::string &FS, const TargetMachine &TM)
94 : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
95 FrameLowering(initializeSubtargetDependencies(CPU, FS)),
96 TLInfo(TM, *this) {}