1e4c8c807SAlexei Starovoitov //===-- BPFSubtarget.cpp - BPF Subtarget Information ----------------------===// 2e4c8c807SAlexei Starovoitov // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler 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" 15dc1dbf6eSYonghong Song #include "llvm/Support/Host.h" 16e4c8c807SAlexei Starovoitov #include "llvm/Support/TargetRegistry.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); 3242389377SYonghong Song ParseSubtargetFeatures(CPU, FS); 33dc1dbf6eSYonghong Song return *this; 34dc1dbf6eSYonghong Song } 35dc1dbf6eSYonghong Song 36dc1dbf6eSYonghong Song void BPFSubtarget::initializeEnvironment() { 37dc1dbf6eSYonghong Song HasJmpExt = false; 3842389377SYonghong Song HasAlu32 = false; 3903e1c8b8SYonghong Song UseDwarfRIS = false; 40dc1dbf6eSYonghong Song } 41dc1dbf6eSYonghong Song 42dc1dbf6eSYonghong Song void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { 43dc1dbf6eSYonghong Song if (CPU == "probe") 44dc1dbf6eSYonghong Song CPU = sys::detail::getHostCPUNameForBPF(); 45dc1dbf6eSYonghong Song if (CPU == "generic" || CPU == "v1") 46dc1dbf6eSYonghong Song return; 47dc1dbf6eSYonghong Song if (CPU == "v2") { 48dc1dbf6eSYonghong Song HasJmpExt = true; 49dc1dbf6eSYonghong Song return; 50dc1dbf6eSYonghong Song } 51dc1dbf6eSYonghong Song } 52dc1dbf6eSYonghong Song 53a73f1fdbSDaniel Sanders BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU, 54e4c8c807SAlexei Starovoitov const std::string &FS, const TargetMachine &TM) 55dc1dbf6eSYonghong Song : BPFGenSubtargetInfo(TT, CPU, FS), InstrInfo(), 56dc1dbf6eSYonghong Song FrameLowering(initializeSubtargetDependencies(CPU, FS)), 5750f17235SDaniel Sanders TLInfo(TM, *this) {} 58