1 //===- llvm/CodeGen/RegAllocRegistry.h --------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains the implementation for register allocator function
10 // pass registry (RegisterRegAlloc).
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_REGALLOCREGISTRY_H
15 #define LLVM_CODEGEN_REGALLOCREGISTRY_H
17 #include "llvm/CodeGen/MachinePassRegistry.h"
23 //===----------------------------------------------------------------------===//
25 /// RegisterRegAllocBase class - Track the registration of register allocators.
27 //===----------------------------------------------------------------------===//
28 template <class SubClass
>
29 class RegisterRegAllocBase
: public MachinePassRegistryNode
<FunctionPass
*(*)()> {
31 using FunctionPassCtor
= FunctionPass
*(*)();
33 static MachinePassRegistry
<FunctionPassCtor
> Registry
;
35 RegisterRegAllocBase(const char *N
, const char *D
, FunctionPassCtor C
)
36 : MachinePassRegistryNode(N
, D
, C
) {
40 ~RegisterRegAllocBase() { Registry
.Remove(this); }
43 SubClass
*getNext() const {
44 return static_cast<SubClass
*>(MachinePassRegistryNode::getNext());
47 static SubClass
*getList() {
48 return static_cast<SubClass
*>(Registry
.getList());
51 static FunctionPassCtor
getDefault() { return Registry
.getDefault(); }
53 static void setDefault(FunctionPassCtor C
) { Registry
.setDefault(C
); }
55 static void setListener(MachinePassRegistryListener
<FunctionPassCtor
> *L
) {
56 Registry
.setListener(L
);
60 class RegisterRegAlloc
: public RegisterRegAllocBase
<RegisterRegAlloc
> {
62 RegisterRegAlloc(const char *N
, const char *D
, FunctionPassCtor C
)
63 : RegisterRegAllocBase(N
, D
, C
) {}
66 /// RegisterRegAlloc's global Registry tracks allocator registration.
68 MachinePassRegistry
<RegisterRegAlloc::FunctionPassCtor
>
69 RegisterRegAllocBase
<T
>::Registry
;
71 } // end namespace llvm
73 #endif // LLVM_CODEGEN_REGALLOCREGISTRY_H