blob: 9a63674689b30167e7bc70502628ff69b873a290 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- llvm/CodeGen/RegAllocRegistry.h --------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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 Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
19namespace llvm {
20
21class FunctionPass;
22
23//===----------------------------------------------------------------------===//
24///
Andrew Walbran3d2c1972020-04-07 12:24:26 +010025/// RegisterRegAllocBase class - Track the registration of register allocators.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010026///
27//===----------------------------------------------------------------------===//
Andrew Walbran3d2c1972020-04-07 12:24:26 +010028template <class SubClass>
29class RegisterRegAllocBase : public MachinePassRegistryNode<FunctionPass *(*)()> {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010030public:
31 using FunctionPassCtor = FunctionPass *(*)();
32
Andrew Walbran16937d02019-10-22 13:54:20 +010033 static MachinePassRegistry<FunctionPassCtor> Registry;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010034
Andrew Walbran3d2c1972020-04-07 12:24:26 +010035 RegisterRegAllocBase(const char *N, const char *D, FunctionPassCtor C)
Andrew Walbran16937d02019-10-22 13:54:20 +010036 : MachinePassRegistryNode(N, D, C) {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037 Registry.Add(this);
38 }
39
Andrew Walbran3d2c1972020-04-07 12:24:26 +010040 ~RegisterRegAllocBase() { Registry.Remove(this); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010041
42 // Accessors.
Andrew Walbran3d2c1972020-04-07 12:24:26 +010043 SubClass *getNext() const {
44 return static_cast<SubClass *>(MachinePassRegistryNode::getNext());
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010045 }
46
Andrew Walbran3d2c1972020-04-07 12:24:26 +010047 static SubClass *getList() {
48 return static_cast<SubClass *>(Registry.getList());
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010049 }
50
Andrew Walbran16937d02019-10-22 13:54:20 +010051 static FunctionPassCtor getDefault() { return Registry.getDefault(); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052
Andrew Walbran16937d02019-10-22 13:54:20 +010053 static void setDefault(FunctionPassCtor C) { Registry.setDefault(C); }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010054
Andrew Walbran16937d02019-10-22 13:54:20 +010055 static void setListener(MachinePassRegistryListener<FunctionPassCtor> *L) {
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010056 Registry.setListener(L);
57 }
58};
59
Andrew Walbran3d2c1972020-04-07 12:24:26 +010060class RegisterRegAlloc : public RegisterRegAllocBase<RegisterRegAlloc> {
61public:
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.
67template <class T>
68MachinePassRegistry<RegisterRegAlloc::FunctionPassCtor>
69RegisterRegAllocBase<T>::Registry;
70
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010071} // end namespace llvm
72
73#endif // LLVM_CODEGEN_REGALLOCREGISTRY_H