10b57cec5SDimitry Andric //===--- BPF.cpp - Implement BPF target feature support -------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file implements BPF TargetInfo objects. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #include "BPF.h" 140b57cec5SDimitry Andric #include "Targets.h" 150b57cec5SDimitry Andric #include "clang/Basic/MacroBuilder.h" 16a7dea167SDimitry Andric #include "clang/Basic/TargetBuiltins.h" 170b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h" 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric using namespace clang; 200b57cec5SDimitry Andric using namespace clang::targets; 210b57cec5SDimitry Andric 22a7dea167SDimitry Andric const Builtin::Info BPFTargetInfo::BuiltinInfo[] = { 23a7dea167SDimitry Andric #define BUILTIN(ID, TYPE, ATTRS) \ 24a7dea167SDimitry Andric {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr}, 25a7dea167SDimitry Andric #include "clang/Basic/BuiltinsBPF.def" 26a7dea167SDimitry Andric }; 27a7dea167SDimitry Andric 280b57cec5SDimitry Andric void BPFTargetInfo::getTargetDefines(const LangOptions &Opts, 290b57cec5SDimitry Andric MacroBuilder &Builder) const { 300b57cec5SDimitry Andric Builder.defineMacro("__bpf__"); 310b57cec5SDimitry Andric Builder.defineMacro("__BPF__"); 320b57cec5SDimitry Andric } 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric static constexpr llvm::StringLiteral ValidCPUNames[] = {"generic", "v1", "v2", 350b57cec5SDimitry Andric "v3", "probe"}; 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric bool BPFTargetInfo::isValidCPUName(StringRef Name) const { 380b57cec5SDimitry Andric return llvm::find(ValidCPUNames, Name) != std::end(ValidCPUNames); 390b57cec5SDimitry Andric } 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric void BPFTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const { 420b57cec5SDimitry Andric Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames)); 430b57cec5SDimitry Andric } 44a7dea167SDimitry Andric 45a7dea167SDimitry Andric ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const { 46a7dea167SDimitry Andric return llvm::makeArrayRef(BuiltinInfo, clang::BPF::LastTSBuiltin - 47a7dea167SDimitry Andric Builtin::FirstTSBuiltin); 48a7dea167SDimitry Andric } 49*fe6060f1SDimitry Andric 50*fe6060f1SDimitry Andric bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features, 51*fe6060f1SDimitry Andric DiagnosticsEngine &Diags) { 52*fe6060f1SDimitry Andric for (const auto &Feature : Features) { 53*fe6060f1SDimitry Andric if (Feature == "+alu32") { 54*fe6060f1SDimitry Andric HasAlu32 = true; 55*fe6060f1SDimitry Andric } 56*fe6060f1SDimitry Andric } 57*fe6060f1SDimitry Andric 58*fe6060f1SDimitry Andric return true; 59*fe6060f1SDimitry Andric } 60