1//===- llvm/CodeGen/RegAllocRegistry.h --------------------------*- C++ -*-===//
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 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/RegAllocCommon.h"
18#include "llvm/CodeGen/MachinePassRegistry.h"
19
20namespace llvm {
21
22class FunctionPass;
23
24//===----------------------------------------------------------------------===//
25///
26/// RegisterRegAllocBase class - Track the registration of register allocators.
27///
28//===----------------------------------------------------------------------===//
29template <class SubClass>
30class RegisterRegAllocBase : public MachinePassRegistryNode<FunctionPass *(*)()> {
31public:
32 using FunctionPassCtor = FunctionPass *(*)();
33
34 static MachinePassRegistry<FunctionPassCtor> Registry;
35
36 RegisterRegAllocBase(const char *N, const char *D, FunctionPassCtor C)
37 : MachinePassRegistryNode(N, D, C) {
38 Registry.Add(Node: this);
39 }
40
41 ~RegisterRegAllocBase() { Registry.Remove(Node: this); }
42
43 // Accessors.
44 SubClass *getNext() const {
45 return static_cast<SubClass *>(MachinePassRegistryNode::getNext());
46 }
47
48 static SubClass *getList() {
49 return static_cast<SubClass *>(Registry.getList());
50 }
51
52 static FunctionPassCtor getDefault() { return Registry.getDefault(); }
53
54 static void setDefault(FunctionPassCtor C) { Registry.setDefault(C); }
55
56 static void setListener(MachinePassRegistryListener<FunctionPassCtor> *L) {
57 Registry.setListener(L);
58 }
59};
60
61class RegisterRegAlloc : public RegisterRegAllocBase<RegisterRegAlloc> {
62public:
63 RegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
64 : RegisterRegAllocBase(N, D, C) {}
65};
66
67/// RegisterRegAlloc's global Registry tracks allocator registration.
68template <class T>
69MachinePassRegistry<typename RegisterRegAllocBase<T>::FunctionPassCtor>
70RegisterRegAllocBase<T>::Registry;
71
72} // end namespace llvm
73
74#endif // LLVM_CODEGEN_REGALLOCREGISTRY_H
75

source code of llvm/include/llvm/CodeGen/RegAllocRegistry.h