Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- llvm/CodeGen/RegAllocRegistry.h --------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the implementation for register allocator function |
| 10 | // pass registry (RegisterRegAlloc). |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_REGALLOCREGISTRY_H |
| 15 | #define LLVM_CODEGEN_REGALLOCREGISTRY_H |
| 16 | |
| 17 | #include "llvm/CodeGen/MachinePassRegistry.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | class FunctionPass; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | /// |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 25 | /// RegisterRegAllocBase class - Track the registration of register allocators. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 26 | /// |
| 27 | //===----------------------------------------------------------------------===// |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 28 | template <class SubClass> |
| 29 | class RegisterRegAllocBase : public MachinePassRegistryNode<FunctionPass *(*)()> { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 30 | public: |
| 31 | using FunctionPassCtor = FunctionPass *(*)(); |
| 32 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 33 | static MachinePassRegistry<FunctionPassCtor> Registry; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 34 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 35 | RegisterRegAllocBase(const char *N, const char *D, FunctionPassCtor C) |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 36 | : MachinePassRegistryNode(N, D, C) { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 37 | Registry.Add(this); |
| 38 | } |
| 39 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 40 | ~RegisterRegAllocBase() { Registry.Remove(this); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 41 | |
| 42 | // Accessors. |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 43 | SubClass *getNext() const { |
| 44 | return static_cast<SubClass *>(MachinePassRegistryNode::getNext()); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 47 | static SubClass *getList() { |
| 48 | return static_cast<SubClass *>(Registry.getList()); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 51 | static FunctionPassCtor getDefault() { return Registry.getDefault(); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 52 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 53 | static void setDefault(FunctionPassCtor C) { Registry.setDefault(C); } |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 54 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 55 | static void setListener(MachinePassRegistryListener<FunctionPassCtor> *L) { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 56 | Registry.setListener(L); |
| 57 | } |
| 58 | }; |
| 59 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 60 | class RegisterRegAlloc : public RegisterRegAllocBase<RegisterRegAlloc> { |
| 61 | public: |
| 62 | RegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C) |
| 63 | : RegisterRegAllocBase(N, D, C) {} |
| 64 | }; |
| 65 | |
| 66 | /// RegisterRegAlloc's global Registry tracks allocator registration. |
| 67 | template <class T> |
| 68 | MachinePassRegistry<RegisterRegAlloc::FunctionPassCtor> |
| 69 | RegisterRegAllocBase<T>::Registry; |
| 70 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 71 | } // end namespace llvm |
| 72 | |
| 73 | #endif // LLVM_CODEGEN_REGALLOCREGISTRY_H |