clang 22.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
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
25 bool HasAlu32 = false;
26
27public:
28 BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
29 : TargetInfo(Triple) {
36 RegParmMax = 5;
37 if (Triple.getArch() == llvm::Triple::bpfeb) {
38 resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
39 } else {
40 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
41 }
44 TLSSupported = false;
45 }
46
47 void getTargetDefines(const LangOptions &Opts,
48 MacroBuilder &Builder) const override;
49
50 bool hasFeature(StringRef Feature) const override {
51 return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";
52 }
53
54 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
55 bool Enabled) const override {
56 Features[Name] = Enabled;
57 }
58 bool handleTargetFeatures(std::vector<std::string> &Features,
59 DiagnosticsEngine &Diags) override;
60
61 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
62
63 std::string_view getClobbers() const override { return ""; }
64
68
69 bool isValidGCCRegisterName(StringRef Name) const override { return true; }
70 ArrayRef<const char *> getGCCRegNames() const override { return {}; }
71
72 bool validateAsmConstraint(const char *&Name,
73 TargetInfo::ConstraintInfo &Info) const override {
74 switch (*Name) {
75 default:
76 break;
77 case 'w':
78 if (HasAlu32) {
79 Info.setAllowsRegister();
80 }
81 break;
82 }
83 return true;
84 }
85
87 return {};
88 }
89
90 bool allowDebugInfoForExternalRef() const override { return true; }
91
93 switch (CC) {
94 default:
95 return CCCR_Warning;
96 case CC_C:
97 case CC_DeviceKernel:
98 return CCCR_OK;
99 }
100 }
101
102 bool isValidCPUName(StringRef Name) const override;
103
104 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
105
106 bool setCPU(const std::string &Name) override {
107 if (Name == "v3" || Name == "v4") {
108 HasAlu32 = true;
109 }
110
111 StringRef CPUName(Name);
112 return isValidCPUName(CPUName);
113 }
114
115 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
116 return std::make_pair(32, 32);
117 }
118};
119} // namespace targets
120} // namespace clang
121#endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:231
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:330
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:335
unsigned char RegParmMax
Definition TargetInfo.h:255
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:251
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:251
Options for controlling the target.
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition BPF.h:86
BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition BPF.h:28
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition BPF.h:63
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:54
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition BPF.h:106
bool allowDebugInfoForExternalRef() const override
Whether target allows debuginfo types for decl only variables/functions.
Definition BPF.h:90
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition BPF.h:50
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
Definition BPF.h:115
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition BPF.h:72
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition BPF.cpp:84
ArrayRef< const char * > getGCCRegNames() const override
Definition BPF.h:70
bool isValidGCCRegisterName(StringRef Name) const override
Returns whether the passed in string is a valid register name according to GCC.
Definition BPF.h:69
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition BPF.h:92
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition BPF.h:65
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:278
@ CC_DeviceKernel
Definition Specifiers.h:292