| 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" |
| 17 | #include "clang/Basic/TargetOptions.h" |
| 18 | #include "llvm/Support/Compiler.h" |
| 19 | #include "llvm/TargetParser/Triple.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | namespace targets { |
| 23 | |
| 24 | class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo { |
| 25 | bool HasAlu32 = false; |
| 26 | |
| 27 | public: |
| 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; |
| 36 | RegParmMax = 5; |
| 37 | resetDataLayout(); |
| 38 | MaxAtomicPromoteWidth = 64; |
| 39 | MaxAtomicInlineWidth = 64; |
| 40 | TLSSupported = false; |
| 41 | } |
| 42 | |
| 43 | void getTargetDefines(const LangOptions &Opts, |
| 44 | MacroBuilder &Builder) const override; |
| 45 | |
| 46 | bool hasFeature(StringRef Feature) const override { |
| 47 | return Feature == "bpf"|| Feature == "alu32"|| Feature == "dwarfris"; |
| 48 | } |
| 49 | |
| 50 | void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name, |
| 51 | bool Enabled) const override { |
| 52 | Features[Name] = Enabled; |
| 53 | } |
| 54 | bool handleTargetFeatures(std::vector<std::string> &Features, |
| 55 | DiagnosticsEngine &Diags) override; |
| 56 | |
| 57 | llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override; |
| 58 | |
| 59 | std::string_view getClobbers() const override { return ""; } |
| 60 | |
| 61 | BuiltinVaListKind getBuiltinVaListKind() const override { |
| 62 | return TargetInfo::VoidPtrBuiltinVaList; |
| 63 | } |
| 64 | |
| 65 | bool isValidGCCRegisterName(StringRef Name) const override { return true; } |
| 66 | ArrayRef<const char *> getGCCRegNames() const override { return {}; } |
| 67 | |
| 68 | bool validateAsmConstraint(const char *&Name, |
| 69 | TargetInfo::ConstraintInfo &Info) const override { |
| 70 | switch (*Name) { |
| 71 | default: |
| 72 | break; |
| 73 | case 'w': |
| 74 | if (HasAlu32) { |
| 75 | Info.setAllowsRegister(); |
| 76 | } |
| 77 | break; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { |
| 83 | return {}; |
| 84 | } |
| 85 | |
| 86 | bool allowDebugInfoForExternalRef() const override { return true; } |
| 87 | |
| 88 | CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { |
| 89 | switch (CC) { |
| 90 | default: |
| 91 | return CCCR_Warning; |
| 92 | case CC_C: |
| 93 | case CC_DeviceKernel: |
| 94 | return CCCR_OK; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | bool isValidCPUName(StringRef Name) const override; |
| 99 | |
| 100 | void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; |
| 101 | |
| 102 | bool setCPU(const std::string &Name) override { |
| 103 | if (Name == "v3"|| Name == "v4") { |
| 104 | HasAlu32 = true; |
| 105 | } |
| 106 | |
| 107 | StringRef CPUName(Name); |
| 108 | return isValidCPUName(Name: CPUName); |
| 109 | } |
| 110 | |
| 111 | std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override { |
| 112 | return std::make_pair(x: 32, y: 32); |
| 113 | } |
| 114 | }; |
| 115 | } // namespace targets |
| 116 | } // namespace clang |
| 117 | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H |
| 118 |