clang  14.0.0git
BPF.cpp
Go to the documentation of this file.
1 //===--- BPF.cpp - Implement BPF target feature support -------------------===//
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 BPF TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "BPF.h"
14 #include "Targets.h"
17 #include "llvm/ADT/StringRef.h"
18 
19 using namespace clang;
20 using namespace clang::targets;
21 
22 const Builtin::Info BPFTargetInfo::BuiltinInfo[] = {
23 #define BUILTIN(ID, TYPE, ATTRS) \
24  {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
25 #include "clang/Basic/BuiltinsBPF.def"
26 };
27 
29  MacroBuilder &Builder) const {
30  Builder.defineMacro("__bpf__");
31  Builder.defineMacro("__BPF__");
32 }
33 
34 static constexpr llvm::StringLiteral ValidCPUNames[] = {"generic", "v1", "v2",
35  "v3", "probe"};
36 
37 bool BPFTargetInfo::isValidCPUName(StringRef Name) const {
38  return llvm::is_contained(ValidCPUNames, Name);
39 }
40 
42  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
43 }
44 
46  return llvm::makeArrayRef(BuiltinInfo, clang::BPF::LastTSBuiltin -
48 }
49 
50 bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
51  DiagnosticsEngine &Diags) {
52  for (const auto &Feature : Features) {
53  if (Feature == "+alu32") {
54  HasAlu32 = true;
55  }
56  }
57 
58  return true;
59 }
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::targets::BPFTargetInfo::fillValidCPUList
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition: BPF.cpp:41
BPF.h
clang::targets::BPFTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: BPF.cpp:37
Targets.h
MacroBuilder.h
clang::targets::BPFTargetInfo::getTargetBuiltins
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: BPF.cpp:45
llvm::ArrayRef
Definition: LLVM.h:34
TargetBuiltins.h
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang
Definition: CalledOnceCheck.h:17
clang::targets
Definition: AArch64.h:21
clang::BPF::LastTSBuiltin
@ LastTSBuiltin
Definition: TargetBuiltins.h:74
clang::Builtin::Info
Definition: Builtins.h:55
ValidCPUNames
static constexpr llvm::StringLiteral ValidCPUNames[]
Definition: BPF.cpp:34
clang::Builtin::FirstTSBuiltin
@ FirstTSBuiltin
Definition: Builtins.h:52
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::targets::BPFTargetInfo::getTargetDefines
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: BPF.cpp:28
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::BPFTargetInfo::handleTargetFeatures
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition: BPF.cpp:50