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/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
24 class LLVM_LIBRARY_VISIBILITY BPFTargetInfo
: public TargetInfo
{
25 static const Builtin::Info BuiltinInfo
[];
26 bool HasAlu32
= false;
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
;
38 if (Triple
.getArch() == llvm::Triple::bpfeb
) {
39 resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
41 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
43 MaxAtomicPromoteWidth
= 64;
44 MaxAtomicInlineWidth
= 64;
48 void getTargetDefines(const LangOptions
&Opts
,
49 MacroBuilder
&Builder
) const override
;
51 bool hasFeature(StringRef Feature
) const override
{
52 return Feature
== "bpf" || Feature
== "alu32" || Feature
== "dwarfris";
55 void setFeatureEnabled(llvm::StringMap
<bool> &Features
, StringRef Name
,
56 bool Enabled
) const override
{
57 Features
[Name
] = Enabled
;
59 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
60 DiagnosticsEngine
&Diags
) override
;
62 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
64 const char *getClobbers() const override
{ return ""; }
66 BuiltinVaListKind
getBuiltinVaListKind() const override
{
67 return TargetInfo::VoidPtrBuiltinVaList
;
70 bool isValidGCCRegisterName(StringRef Name
) const override
{ return true; }
71 ArrayRef
<const char *> getGCCRegNames() const override
{ return None
; }
73 bool validateAsmConstraint(const char *&Name
,
74 TargetInfo::ConstraintInfo
&Info
) const override
{
80 Info
.setAllowsRegister();
87 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
91 bool allowDebugInfoForExternalRef() const override
{ return true; }
93 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
103 bool isValidCPUName(StringRef Name
) const override
;
105 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
107 bool setCPU(const std::string
&Name
) override
{
112 StringRef
CPUName(Name
);
113 return isValidCPUName(CPUName
);
116 } // namespace targets
118 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H