1e4c8c807SAlexei Starovoitov //===-- BPFSubtarget.cpp - BPF Subtarget Information ----------------------===// 2e4c8c807SAlexei Starovoitov // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e4c8c807SAlexei Starovoitov // 7e4c8c807SAlexei Starovoitov //===----------------------------------------------------------------------===// 8e4c8c807SAlexei Starovoitov // 9e4c8c807SAlexei Starovoitov // This file implements the BPF specific subclass of TargetSubtargetInfo. 10e4c8c807SAlexei Starovoitov // 11e4c8c807SAlexei Starovoitov //===----------------------------------------------------------------------===// 12e4c8c807SAlexei Starovoitov 13e4c8c807SAlexei Starovoitov #include "BPFSubtarget.h" 14e4c8c807SAlexei Starovoitov #include "BPF.h" 15*89b57061SReid Kleckner #include "llvm/MC/TargetRegistry.h" 16dc1dbf6eSYonghong Song #include "llvm/Support/Host.h" 17e4c8c807SAlexei Starovoitov 18e4c8c807SAlexei Starovoitov using namespace llvm; 19e4c8c807SAlexei Starovoitov 20e4c8c807SAlexei Starovoitov #define DEBUG_TYPE "bpf-subtarget" 21e4c8c807SAlexei Starovoitov 22e4c8c807SAlexei Starovoitov #define GET_SUBTARGETINFO_TARGET_DESC 23e4c8c807SAlexei Starovoitov #define GET_SUBTARGETINFO_CTOR 24e4c8c807SAlexei Starovoitov #include "BPFGenSubtargetInfo.inc" 25e4c8c807SAlexei Starovoitov 26e4c8c807SAlexei Starovoitov void BPFSubtarget::anchor() {} 27e4c8c807SAlexei Starovoitov 28dc1dbf6eSYonghong Song BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU, 29dc1dbf6eSYonghong Song StringRef FS) { 30dc1dbf6eSYonghong Song initializeEnvironment(); 31dc1dbf6eSYonghong Song initSubtargetFeatures(CPU, FS); 32c7a0b268SCraig Topper ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS); 33dc1dbf6eSYonghong Song return *this; 34dc1dbf6eSYonghong Song } 35dc1dbf6eSYonghong Song 36dc1dbf6eSYonghong Song void BPFSubtarget::initializeEnvironment() { 37dc1dbf6eSYonghong Song HasJmpExt = false; 3866b18e57SJiong Wang HasJmp32 = false; 3942389377SYonghong Song HasAlu32 = false; 4003e1c8b8SYonghong Song UseDwarfRIS = false; 41dc1dbf6eSYonghong Song } 42dc1dbf6eSYonghong Song 43dc1dbf6eSYonghong Song void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { 44dc1dbf6eSYonghong Song if (CPU == "probe") 45dc1dbf6eSYonghong Song CPU = sys::detail::getHostCPUNameForBPF(); 46dc1dbf6eSYonghong Song if (CPU == "generic" || CPU == "v1") 47dc1dbf6eSYonghong Song return; 48dc1dbf6eSYonghong Song if (CPU == "v2") { 49dc1dbf6eSYonghong Song HasJmpExt = true; 50dc1dbf6eSYonghong Song return; 51dc1dbf6eSYonghong Song } 5266b18e57SJiong Wang if (CPU == "v3") { 5366b18e57SJiong Wang HasJmpExt = true; 5466b18e57SJiong Wang HasJmp32 = true; 556b8baf30SYonghong Song HasAlu32 = true; 5666b18e57SJiong Wang return; 5766b18e57SJiong Wang } 58dc1dbf6eSYonghong Song } 59dc1dbf6eSYonghong Song 60a73f1fdbSDaniel Sanders BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU, 61e4c8c807SAlexei Starovoitov const std::string &FS, const TargetMachine &TM) 62c7a0b268SCraig Topper : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(), 63dc1dbf6eSYonghong Song FrameLowering(initializeSubtargetDependencies(CPU, FS)), 6450f17235SDaniel Sanders TLInfo(TM, *this) {} 65