BPFSubtarget.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===-- BPFSubtarget.cpp - BPF Subtarget Information ----------------------===//
  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 the BPF specific subclass of TargetSubtargetInfo.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "BPFSubtarget.h"
  13. #include "BPF.h"
  14. #include "llvm/MC/TargetRegistry.h"
  15. #include "llvm/Support/Host.h"
  16. using namespace llvm;
  17. #define DEBUG_TYPE "bpf-subtarget"
  18. #define GET_SUBTARGETINFO_TARGET_DESC
  19. #define GET_SUBTARGETINFO_CTOR
  20. #include "BPFGenSubtargetInfo.inc"
  21. void BPFSubtarget::anchor() {}
  22. BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU,
  23. StringRef FS) {
  24. initializeEnvironment();
  25. initSubtargetFeatures(CPU, FS);
  26. ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
  27. return *this;
  28. }
  29. void BPFSubtarget::initializeEnvironment() {
  30. HasJmpExt = false;
  31. HasJmp32 = false;
  32. HasAlu32 = false;
  33. UseDwarfRIS = false;
  34. }
  35. void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
  36. if (CPU == "probe")
  37. CPU = sys::detail::getHostCPUNameForBPF();
  38. if (CPU == "generic" || CPU == "v1")
  39. return;
  40. if (CPU == "v2") {
  41. HasJmpExt = true;
  42. return;
  43. }
  44. if (CPU == "v3") {
  45. HasJmpExt = true;
  46. HasJmp32 = true;
  47. HasAlu32 = true;
  48. return;
  49. }
  50. }
  51. BPFSubtarget::BPFSubtarget(const Triple &TT, const std::string &CPU,
  52. const std::string &FS, const TargetMachine &TM)
  53. : BPFGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
  54. FrameLowering(initializeSubtargetDependencies(CPU, FS)),
  55. TLInfo(TM, *this) {}