17330f729Sjoerg //===--- BPF.cpp - Implement BPF target feature support -------------------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg //
97330f729Sjoerg // This file implements BPF TargetInfo objects.
107330f729Sjoerg //
117330f729Sjoerg //===----------------------------------------------------------------------===//
127330f729Sjoerg
137330f729Sjoerg #include "BPF.h"
147330f729Sjoerg #include "Targets.h"
157330f729Sjoerg #include "clang/Basic/MacroBuilder.h"
167330f729Sjoerg #include "clang/Basic/TargetBuiltins.h"
177330f729Sjoerg #include "llvm/ADT/StringRef.h"
187330f729Sjoerg
197330f729Sjoerg using namespace clang;
207330f729Sjoerg using namespace clang::targets;
217330f729Sjoerg
227330f729Sjoerg const Builtin::Info BPFTargetInfo::BuiltinInfo[] = {
237330f729Sjoerg #define BUILTIN(ID, TYPE, ATTRS) \
247330f729Sjoerg {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
257330f729Sjoerg #include "clang/Basic/BuiltinsBPF.def"
267330f729Sjoerg };
277330f729Sjoerg
getTargetDefines(const LangOptions & Opts,MacroBuilder & Builder) const287330f729Sjoerg void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
297330f729Sjoerg MacroBuilder &Builder) const {
307330f729Sjoerg Builder.defineMacro("__bpf__");
317330f729Sjoerg Builder.defineMacro("__BPF__");
327330f729Sjoerg }
337330f729Sjoerg
347330f729Sjoerg static constexpr llvm::StringLiteral ValidCPUNames[] = {"generic", "v1", "v2",
357330f729Sjoerg "v3", "probe"};
367330f729Sjoerg
isValidCPUName(StringRef Name) const377330f729Sjoerg bool BPFTargetInfo::isValidCPUName(StringRef Name) const {
387330f729Sjoerg return llvm::find(ValidCPUNames, Name) != std::end(ValidCPUNames);
397330f729Sjoerg }
407330f729Sjoerg
fillValidCPUList(SmallVectorImpl<StringRef> & Values) const417330f729Sjoerg void BPFTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
427330f729Sjoerg Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
437330f729Sjoerg }
447330f729Sjoerg
getTargetBuiltins() const457330f729Sjoerg ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const {
467330f729Sjoerg return llvm::makeArrayRef(BuiltinInfo, clang::BPF::LastTSBuiltin -
477330f729Sjoerg Builtin::FirstTSBuiltin);
487330f729Sjoerg }
49*e038c9c4Sjoerg
handleTargetFeatures(std::vector<std::string> & Features,DiagnosticsEngine & Diags)50*e038c9c4Sjoerg bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
51*e038c9c4Sjoerg DiagnosticsEngine &Diags) {
52*e038c9c4Sjoerg for (const auto &Feature : Features) {
53*e038c9c4Sjoerg if (Feature == "+alu32") {
54*e038c9c4Sjoerg HasAlu32 = true;
55*e038c9c4Sjoerg }
56*e038c9c4Sjoerg }
57*e038c9c4Sjoerg
58*e038c9c4Sjoerg return true;
59*e038c9c4Sjoerg }
60