RegAllocRegistry.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/RegAllocRegistry.h --------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains the implementation for register allocator function
  15. // pass registry (RegisterRegAlloc).
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CODEGEN_REGALLOCREGISTRY_H
  19. #define LLVM_CODEGEN_REGALLOCREGISTRY_H
  20. #include "llvm/CodeGen/RegAllocCommon.h"
  21. #include "llvm/CodeGen/MachinePassRegistry.h"
  22. namespace llvm {
  23. class FunctionPass;
  24. //===----------------------------------------------------------------------===//
  25. ///
  26. /// RegisterRegAllocBase class - Track the registration of register allocators.
  27. ///
  28. //===----------------------------------------------------------------------===//
  29. template <class SubClass>
  30. class RegisterRegAllocBase : public MachinePassRegistryNode<FunctionPass *(*)()> {
  31. public:
  32. using FunctionPassCtor = FunctionPass *(*)();
  33. static MachinePassRegistry<FunctionPassCtor> Registry;
  34. RegisterRegAllocBase(const char *N, const char *D, FunctionPassCtor C)
  35. : MachinePassRegistryNode(N, D, C) {
  36. Registry.Add(this);
  37. }
  38. ~RegisterRegAllocBase() { Registry.Remove(this); }
  39. // Accessors.
  40. SubClass *getNext() const {
  41. return static_cast<SubClass *>(MachinePassRegistryNode::getNext());
  42. }
  43. static SubClass *getList() {
  44. return static_cast<SubClass *>(Registry.getList());
  45. }
  46. static FunctionPassCtor getDefault() { return Registry.getDefault(); }
  47. static void setDefault(FunctionPassCtor C) { Registry.setDefault(C); }
  48. static void setListener(MachinePassRegistryListener<FunctionPassCtor> *L) {
  49. Registry.setListener(L);
  50. }
  51. };
  52. class RegisterRegAlloc : public RegisterRegAllocBase<RegisterRegAlloc> {
  53. public:
  54. RegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
  55. : RegisterRegAllocBase(N, D, C) {}
  56. };
  57. /// RegisterRegAlloc's global Registry tracks allocator registration.
  58. template <class T>
  59. MachinePassRegistry<RegisterRegAlloc::FunctionPassCtor>
  60. RegisterRegAllocBase<T>::Registry;
  61. } // end namespace llvm
  62. #endif // LLVM_CODEGEN_REGALLOCREGISTRY_H
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif