BPF.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H
  14. #include "clang/Basic/TargetInfo.h"
  15. #include "clang/Basic/TargetOptions.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/Support/Compiler.h"
  18. namespace clang {
  19. namespace targets {
  20. class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
  21. static const Builtin::Info BuiltinInfo[];
  22. public:
  23. BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  24. : TargetInfo(Triple) {
  25. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  26. SizeType = UnsignedLong;
  27. PtrDiffType = SignedLong;
  28. IntPtrType = SignedLong;
  29. IntMaxType = SignedLong;
  30. Int64Type = SignedLong;
  31. RegParmMax = 5;
  32. if (Triple.getArch() == llvm::Triple::bpfeb) {
  33. resetDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
  34. } else {
  35. resetDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
  36. }
  37. MaxAtomicPromoteWidth = 64;
  38. MaxAtomicInlineWidth = 64;
  39. TLSSupported = false;
  40. }
  41. void getTargetDefines(const LangOptions &Opts,
  42. MacroBuilder &Builder) const override;
  43. bool hasFeature(StringRef Feature) const override {
  44. return Feature == "bpf" || Feature == "alu32" || Feature == "dwarfris";
  45. }
  46. void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
  47. bool Enabled) const override {
  48. Features[Name] = Enabled;
  49. }
  50. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  51. const char *getClobbers() const override { return ""; }
  52. BuiltinVaListKind getBuiltinVaListKind() const override {
  53. return TargetInfo::VoidPtrBuiltinVaList;
  54. }
  55. bool isValidGCCRegisterName(StringRef Name) const override { return true; }
  56. ArrayRef<const char *> getGCCRegNames() const override { return None; }
  57. bool validateAsmConstraint(const char *&Name,
  58. TargetInfo::ConstraintInfo &info) const override {
  59. return true;
  60. }
  61. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
  62. return None;
  63. }
  64. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  65. switch (CC) {
  66. default:
  67. return CCCR_Warning;
  68. case CC_C:
  69. case CC_OpenCLKernel:
  70. return CCCR_OK;
  71. }
  72. }
  73. bool isValidCPUName(StringRef Name) const override;
  74. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  75. bool setCPU(const std::string &Name) override {
  76. StringRef CPUName(Name);
  77. return isValidCPUName(CPUName);
  78. }
  79. };
  80. } // namespace targets
  81. } // namespace clang
  82. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_BPF_H