1//===----------------------------------------------------------------------===//
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 registry for PassConfigCallbacks that enable changes
10/// to the TargetPassConfig during the initialization of TargetMachine.
11///
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/RegisterTargetPassConfigCallback.h"
15
16namespace llvm {
17// TargetPassConfig callbacks
18static SmallVector<RegisterTargetPassConfigCallback *, 1>
19 TargetPassConfigCallbacks{};
20
21void invokeGlobalTargetPassConfigCallbacks(TargetMachine &TM,
22 PassManagerBase &PM,
23 TargetPassConfig *PassConfig) {
24 for (const RegisterTargetPassConfigCallback *Reg : TargetPassConfigCallbacks)
25 Reg->Callback(TM, PM, PassConfig);
26}
27
28RegisterTargetPassConfigCallback::RegisterTargetPassConfigCallback(
29 PassConfigCallback &&C)
30 : Callback(std::move(C)) {
31 TargetPassConfigCallbacks.push_back(Elt: this);
32}
33
34RegisterTargetPassConfigCallback::~RegisterTargetPassConfigCallback() {
35 const auto &It = find(Range&: TargetPassConfigCallbacks, Val: this);
36 if (It != TargetPassConfigCallbacks.end())
37 TargetPassConfigCallbacks.erase(CI: It);
38}
39} // namespace llvm
40