Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.2 KiB

  1. //===-- llvm/CodeGen/MachinePassRegistry.h ----------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains the mechanics for machine function pass registries. A
  11. // function pass registry (MachinePassRegistry) is auto filled by the static
  12. // constructors of MachinePassRegistryNode. Further there is a command line
  13. // parser (RegisterPassParser) which listens to each registry for additions
  14. // and deletions, so that the appropriate command option is updated.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_MACHINEPASSREGISTRY_H
  18. #define LLVM_CODEGEN_MACHINEPASSREGISTRY_H
  19. #include "llvm/CodeGen/Passes.h"
  20. #include "llvm/Support/CommandLine.h"
  21. namespace llvm {
  22. typedef void *(*MachinePassCtor)();
  23. //===----------------------------------------------------------------------===//
  24. ///
  25. /// MachinePassRegistryListener - Listener to adds and removals of nodes in
  26. /// registration list.
  27. ///
  28. //===----------------------------------------------------------------------===//
  29. class MachinePassRegistryListener {
  30. virtual void anchor();
  31. public:
  32. MachinePassRegistryListener() {}
  33. virtual ~MachinePassRegistryListener() {}
  34. virtual void NotifyAdd(const char *N, MachinePassCtor C, const char *D) = 0;
  35. virtual void NotifyRemove(const char *N) = 0;
  36. };
  37. //===----------------------------------------------------------------------===//
  38. ///
  39. /// MachinePassRegistryNode - Machine pass node stored in registration list.
  40. ///
  41. //===----------------------------------------------------------------------===//
  42. class MachinePassRegistryNode {
  43. private:
  44. MachinePassRegistryNode *Next; // Next function pass in list.
  45. const char *Name; // Name of function pass.
  46. const char *Description; // Description string.
  47. MachinePassCtor Ctor; // Function pass creator.
  48. public:
  49. MachinePassRegistryNode(const char *N, const char *D, MachinePassCtor C)
  50. : Next(NULL)
  51. , Name(N)
  52. , Description(D)
  53. , Ctor(C)
  54. {}
  55. // Accessors
  56. MachinePassRegistryNode *getNext() const { return Next; }
  57. MachinePassRegistryNode **getNextAddress() { return &Next; }
  58. const char *getName() const { return Name; }
  59. const char *getDescription() const { return Description; }
  60. MachinePassCtor getCtor() const { return Ctor; }
  61. void setNext(MachinePassRegistryNode *N) { Next = N; }
  62. };
  63. //===----------------------------------------------------------------------===//
  64. ///
  65. /// MachinePassRegistry - Track the registration of machine passes.
  66. ///
  67. //===----------------------------------------------------------------------===//
  68. class MachinePassRegistry {
  69. private:
  70. MachinePassRegistryNode *List; // List of registry nodes.
  71. MachinePassCtor Default; // Default function pass creator.
  72. MachinePassRegistryListener* Listener;// Listener for list adds are removes.
  73. public:
  74. // NO CONSTRUCTOR - we don't want static constructor ordering to mess
  75. // with the registry.
  76. // Accessors.
  77. //
  78. MachinePassRegistryNode *getList() { return List; }
  79. MachinePassCtor getDefault() { return Default; }
  80. void setDefault(MachinePassCtor C) { Default = C; }
  81. void setDefault(StringRef Name);
  82. void setListener(MachinePassRegistryListener *L) { Listener = L; }
  83. /// Add - Adds a function pass to the registration list.
  84. ///
  85. void Add(MachinePassRegistryNode *Node);
  86. /// Remove - Removes a function pass from the registration list.
  87. ///
  88. void Remove(MachinePassRegistryNode *Node);
  89. };
  90. //===----------------------------------------------------------------------===//
  91. ///
  92. /// RegisterPassParser class - Handle the addition of new machine passes.
  93. ///
  94. //===----------------------------------------------------------------------===//
  95. template<class RegistryClass>
  96. class RegisterPassParser : public MachinePassRegistryListener,
  97. public cl::parser<typename RegistryClass::FunctionPassCtor> {
  98. public:
  99. RegisterPassParser() {}
  100. ~RegisterPassParser() { RegistryClass::setListener(NULL); }
  101. void initialize(cl::Option &O) {
  102. cl::parser<typename RegistryClass::FunctionPassCtor>::initialize(O);
  103. // Add existing passes to option.
  104. for (RegistryClass *Node = RegistryClass::getList();
  105. Node; Node = Node->getNext()) {
  106. this->addLiteralOption(Node->getName(),
  107. (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
  108. Node->getDescription());
  109. }
  110. // Make sure we listen for list changes.
  111. RegistryClass::setListener(this);
  112. }
  113. // Implement the MachinePassRegistryListener callbacks.
  114. //
  115. virtual void NotifyAdd(const char *N,
  116. MachinePassCtor C,
  117. const char *D) {
  118. this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
  119. }
  120. virtual void NotifyRemove(const char *N) {
  121. this->removeLiteralOption(N);
  122. }
  123. };
  124. } // end namespace llvm
  125. #endif