Coverage Report

Created: 2023-05-31 04:38

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Basic/Targets/BPF.h
Line
Count
Source (jump to first uncovered line)
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
21
      : TargetInfo(Triple) {
30
21
    LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
31
21
    SizeType = UnsignedLong;
32
21
    PtrDiffType = SignedLong;
33
21
    IntPtrType = SignedLong;
34
21
    IntMaxType = SignedLong;
35
21
    Int64Type = SignedLong;
36
21
    RegParmMax = 5;
37
21
    if (Triple.getArch() == llvm::Triple::bpfeb) {
38
5
      resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
39
16
    } else {
40
16
      resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
41
16
    }
42
21
    MaxAtomicPromoteWidth = 64;
43
21
    MaxAtomicInlineWidth = 64;
44
21
    TLSSupported = false;
45
21
  }
46
47
  void getTargetDefines(const LangOptions &Opts,
48
                        MacroBuilder &Builder) const override;
49
50
11
  bool hasFeature(StringRef Feature) const override {
51
11
    return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";
52
11
  }
53
54
  void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
55
0
                         bool Enabled) const override {
56
0
    Features[Name] = Enabled;
57
0
  }
58
  bool handleTargetFeatures(std::vector<std::string> &Features,
59
                            DiagnosticsEngine &Diags) override;
60
61
  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
62
63
0
  std::string_view getClobbers() const override { return ""; }
64
65
16
  BuiltinVaListKind getBuiltinVaListKind() const override {
66
16
    return TargetInfo::VoidPtrBuiltinVaList;
67
16
  }
68
69
0
  bool isValidGCCRegisterName(StringRef Name) const override { return true; }
70
0
  ArrayRef<const char *> getGCCRegNames() const override {
71
0
    return std::nullopt;
72
0
  }
73
74
  bool validateAsmConstraint(const char *&Name,
75
0
                             TargetInfo::ConstraintInfo &Info) const override {
76
0
    switch (*Name) {
77
0
    default:
78
0
      break;
79
0
    case 'w':
80
0
      if (HasAlu32) {
81
0
        Info.setAllowsRegister();
82
0
      }
83
0
      break;
84
0
    }
85
0
    return true;
86
0
  }
87
88
0
  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
89
0
    return std::nullopt;
90
0
  }
91
92
15
  bool allowDebugInfoForExternalRef() const override { return true; }
93
94
0
  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
95
0
    switch (CC) {
96
0
    default:
97
0
      return CCCR_Warning;
98
0
    case CC_C:
99
0
    case CC_OpenCLKernel:
100
0
      return CCCR_OK;
101
0
    }
102
0
  }
103
104
  bool isValidCPUName(StringRef Name) const override;
105
106
  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
107
108
1
  bool setCPU(const std::string &Name) override {
109
1
    if (Name == "v3") {
110
0
      HasAlu32 = true;
111
0
    }
112
113
1
    StringRef CPUName(Name);
114
1
    return isValidCPUName(CPUName);
115
1
  }
116
};
117
} // namespace targets
118
} // namespace clang
119
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H