BPF.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===--- BPF.cpp - Implement BPF target feature support -------------------===//
  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 implements BPF TargetInfo objects.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "BPF.h"
  13. #include "Targets.h"
  14. #include "clang/Basic/MacroBuilder.h"
  15. #include "clang/Basic/TargetBuiltins.h"
  16. #include "llvm/ADT/StringRef.h"
  17. using namespace clang;
  18. using namespace clang::targets;
  19. const Builtin::Info BPFTargetInfo::BuiltinInfo[] = {
  20. #define BUILTIN(ID, TYPE, ATTRS) \
  21. {#ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr},
  22. #include "clang/Basic/BuiltinsBPF.def"
  23. };
  24. void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
  25. MacroBuilder &Builder) const {
  26. Builder.defineMacro("__bpf__");
  27. Builder.defineMacro("__BPF__");
  28. }
  29. static constexpr llvm::StringLiteral ValidCPUNames[] = {"generic", "v1", "v2",
  30. "v3", "probe"};
  31. bool BPFTargetInfo::isValidCPUName(StringRef Name) const {
  32. return llvm::is_contained(ValidCPUNames, Name);
  33. }
  34. void BPFTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
  35. Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
  36. }
  37. ArrayRef<Builtin::Info> BPFTargetInfo::getTargetBuiltins() const {
  38. return llvm::makeArrayRef(BuiltinInfo, clang::BPF::LastTSBuiltin -
  39. Builtin::FirstTSBuiltin);
  40. }
  41. bool BPFTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
  42. DiagnosticsEngine &Diags) {
  43. for (const auto &Feature : Features) {
  44. if (Feature == "+alu32") {
  45. HasAlu32 = true;
  46. }
  47. }
  48. return true;
  49. }