1 //===--- BPF.h - Declare BPF target feature support -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares BPF TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
24 class LLVM_LIBRARY_VISIBILITY BPFTargetInfo
: public TargetInfo
{
25 bool HasAlu32
= false;
28 BPFTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
29 : TargetInfo(Triple
) {
30 LongWidth
= LongAlign
= PointerWidth
= PointerAlign
= 64;
31 SizeType
= UnsignedLong
;
32 PtrDiffType
= SignedLong
;
33 IntPtrType
= SignedLong
;
34 IntMaxType
= SignedLong
;
35 Int64Type
= SignedLong
;
37 if (Triple
.getArch() == llvm::Triple::bpfeb
) {
38 resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
40 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
42 MaxAtomicPromoteWidth
= 64;
43 MaxAtomicInlineWidth
= 64;
47 void getTargetDefines(const LangOptions
&Opts
,
48 MacroBuilder
&Builder
) const override
;
50 bool hasFeature(StringRef Feature
) const override
{
51 return Feature
== "bpf" || Feature
== "alu32" || Feature
== "dwarfris";
54 void setFeatureEnabled(llvm::StringMap
<bool> &Features
, StringRef Name
,
55 bool Enabled
) const override
{
56 Features
[Name
] = Enabled
;
58 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
59 DiagnosticsEngine
&Diags
) override
;
61 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
63 std::string_view
getClobbers() const override
{ return ""; }
65 BuiltinVaListKind
getBuiltinVaListKind() const override
{
66 return TargetInfo::VoidPtrBuiltinVaList
;
69 bool isValidGCCRegisterName(StringRef Name
) const override
{ return true; }
70 ArrayRef
<const char *> getGCCRegNames() const override
{
74 bool validateAsmConstraint(const char *&Name
,
75 TargetInfo::ConstraintInfo
&Info
) const override
{
81 Info
.setAllowsRegister();
88 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
92 bool allowDebugInfoForExternalRef() const override
{ return true; }
94 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
104 bool isValidCPUName(StringRef Name
) const override
;
106 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
108 bool setCPU(const std::string
&Name
) override
{
109 if (Name
== "v3" || Name
== "v4") {
113 StringRef
CPUName(Name
);
114 return isValidCPUName(CPUName
);
117 } // namespace targets
119 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H