clang  14.0.0git
BPF.h
Go to the documentation of this file.
1 //===--- BPF.h - Declare BPF target feature support -------------*- C++ -*-===//
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 declares BPF TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
15 
16 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 
21 namespace clang {
22 namespace targets {
23 
24 class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
25  static const Builtin::Info BuiltinInfo[];
26  bool HasAlu32 = false;
27 
28 public:
29  BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
30  : TargetInfo(Triple) {
31  LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
32  SizeType = UnsignedLong;
33  PtrDiffType = SignedLong;
34  IntPtrType = SignedLong;
35  IntMaxType = SignedLong;
36  Int64Type = SignedLong;
37  RegParmMax = 5;
38  if (Triple.getArch() == llvm::Triple::bpfeb) {
39  resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
40  } else {
41  resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
42  }
43  MaxAtomicPromoteWidth = 64;
44  MaxAtomicInlineWidth = 64;
45  TLSSupported = false;
46  }
47 
48  void getTargetDefines(const LangOptions &Opts,
49  MacroBuilder &Builder) const override;
50 
51  bool hasFeature(StringRef Feature) const override {
52  return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";
53  }
54 
55  void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
56  bool Enabled) const override {
57  Features[Name] = Enabled;
58  }
59  bool handleTargetFeatures(std::vector<std::string> &Features,
60  DiagnosticsEngine &Diags) override;
61 
62  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
63 
64  const char *getClobbers() const override { return ""; }
65 
68  }
69 
70  bool isValidGCCRegisterName(StringRef Name) const override { return true; }
71  ArrayRef<const char *> getGCCRegNames() const override { return None; }
72 
73  bool validateAsmConstraint(const char *&Name,
74  TargetInfo::ConstraintInfo &Info) const override {
75  switch (*Name) {
76  default:
77  break;
78  case 'w':
79  if (HasAlu32) {
80  Info.setAllowsRegister();
81  }
82  break;
83  }
84  return true;
85  }
86 
88  return None;
89  }
90 
91  bool allowDebugInfoForExternalRef() const override { return true; }
92 
94  switch (CC) {
95  default:
96  return CCCR_Warning;
97  case CC_C:
98  case CC_OpenCLKernel:
99  return CCCR_OK;
100  }
101  }
102 
103  bool isValidCPUName(StringRef Name) const override;
104 
105  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
106 
107  bool setCPU(const std::string &Name) override {
108  if (Name == "v3") {
109  HasAlu32 = true;
110  }
111 
112  StringRef CPUName(Name);
113  return isValidCPUName(CPUName);
114  }
115 };
116 } // namespace targets
117 } // namespace clang
118 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
clang::targets::BPFTargetInfo::allowDebugInfoForExternalRef
bool allowDebugInfoForExternalRef() const override
Whether target allows debuginfo types for decl only variables/functions.
Definition: BPF.h:91
clang::targets::BPFTargetInfo::BPFTargetInfo
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: BPF.h:29
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
TargetInfo.h
clang::targets::BPFTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: BPF.h:64
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::TargetInfo::VoidPtrBuiltinVaList
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition: TargetInfo.h:270
clang::targets::BPFTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: BPF.h:87
clang::targets::BPFTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: BPF.h:73
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:265
clang::TargetInfo::ConstraintInfo::setAllowsRegister
void setAllowsRegister()
Definition: TargetInfo.h:1025
clang::targets::BPFTargetInfo::isValidGCCRegisterName
bool isValidGCCRegisterName(StringRef Name) const override
Returns whether the passed in string is a valid register name according to GCC.
Definition: BPF.h:70
clang::CC_OpenCLKernel
@ CC_OpenCLKernel
Definition: Specifiers.h:277
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
clang::targets::BPFTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: BPF.h:107
clang::targets::BPFTargetInfo::getGCCRegNames
ArrayRef< const char * > getGCCRegNames() const override
Definition: BPF.h:71
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
clang::targets::BPFTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: BPF.h:66
clang::CC_C
@ CC_C
Definition: Specifiers.h:264
clang::targets::BPFTargetInfo
Definition: BPF.h:24
clang::targets::BPFTargetInfo::setFeatureEnabled
void setFeatureEnabled(llvm::StringMap< bool > &Features, StringRef Name, bool Enabled) const override
Enable or disable a specific target feature; the feature name must be valid.
Definition: BPF.h:55
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:960
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::targets::BPFTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: BPF.h:93
clang::targets::BPFTargetInfo::hasFeature
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: BPF.h:51
clang
Definition: CalledOnceCheck.h:17
clang::Builtin::Info
Definition: Builtins.h:55
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1459
clang::MacroBuilder
Definition: MacroBuilder.h:23