1 //===--- BPF.h - Declare BPF target feature support -------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares BPF TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
16 
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/TargetOptions.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace clang {
23 namespace targets {
24 
25 class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
26 public:
27   BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
28       : TargetInfo(Triple) {
29     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
30     SizeType = UnsignedLong;
31     PtrDiffType = SignedLong;
32     IntPtrType = SignedLong;
33     IntMaxType = SignedLong;
34     Int64Type = SignedLong;
35     RegParmMax = 5;
36     if (Triple.getArch() == llvm::Triple::bpfeb) {
37       resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
38     } else {
39       resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
40     }
41     MaxAtomicPromoteWidth = 64;
42     MaxAtomicInlineWidth = 64;
43     TLSSupported = false;
44   }
45 
46   void getTargetDefines(const LangOptions &Opts,
47                         MacroBuilder &Builder) const override;
48 
49   bool hasFeature(StringRef Feature) const override {
50     return Feature == "bpf" || Feature == "alu32";
51   }
52 
53   void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
54                          bool Enabled) const override {
55     Features[Name] = Enabled;
56   }
57 
58   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
59 
60   const char *getClobbers() const override { return ""; }
61 
62   BuiltinVaListKind getBuiltinVaListKind() const override {
63     return TargetInfo::VoidPtrBuiltinVaList;
64   }
65 
66   ArrayRef<const char *> getGCCRegNames() const override { return None; }
67 
68   bool validateAsmConstraint(const char *&Name,
69                              TargetInfo::ConstraintInfo &info) const override {
70     return true;
71   }
72 
73   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
74     return None;
75   }
76 
77   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
78     switch (CC) {
79     default:
80       return CCCR_Warning;
81     case CC_C:
82     case CC_OpenCLKernel:
83       return CCCR_OK;
84     }
85   }
86 
87   bool isValidCPUName(StringRef Name) const override;
88 
89   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
90 
91   bool setCPU(const std::string &Name) override {
92     StringRef CPUName(Name);
93     return isValidCPUName(CPUName);
94   }
95 };
96 } // namespace targets
97 } // namespace clang
98 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
99