xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RegisterTargetPassConfigCallback.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric ///
9*700637cbSDimitry Andric /// This file contains the registry for PassConfigCallbacks that enable changes
10*700637cbSDimitry Andric /// to the TargetPassConfig during the initialization of TargetMachine.
11*700637cbSDimitry Andric ///
12*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
13*700637cbSDimitry Andric 
14*700637cbSDimitry Andric #include "llvm/Target/RegisterTargetPassConfigCallback.h"
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric namespace llvm {
17*700637cbSDimitry Andric // TargetPassConfig callbacks
18*700637cbSDimitry Andric static SmallVector<RegisterTargetPassConfigCallback *, 1>
19*700637cbSDimitry Andric     TargetPassConfigCallbacks{};
20*700637cbSDimitry Andric 
invokeGlobalTargetPassConfigCallbacks(TargetMachine & TM,PassManagerBase & PM,TargetPassConfig * PassConfig)21*700637cbSDimitry Andric void invokeGlobalTargetPassConfigCallbacks(TargetMachine &TM,
22*700637cbSDimitry Andric                                            PassManagerBase &PM,
23*700637cbSDimitry Andric                                            TargetPassConfig *PassConfig) {
24*700637cbSDimitry Andric   for (const RegisterTargetPassConfigCallback *Reg : TargetPassConfigCallbacks)
25*700637cbSDimitry Andric     Reg->Callback(TM, PM, PassConfig);
26*700637cbSDimitry Andric }
27*700637cbSDimitry Andric 
RegisterTargetPassConfigCallback(PassConfigCallback && C)28*700637cbSDimitry Andric RegisterTargetPassConfigCallback::RegisterTargetPassConfigCallback(
29*700637cbSDimitry Andric     PassConfigCallback &&C)
30*700637cbSDimitry Andric     : Callback(std::move(C)) {
31*700637cbSDimitry Andric   TargetPassConfigCallbacks.push_back(this);
32*700637cbSDimitry Andric }
33*700637cbSDimitry Andric 
~RegisterTargetPassConfigCallback()34*700637cbSDimitry Andric RegisterTargetPassConfigCallback::~RegisterTargetPassConfigCallback() {
35*700637cbSDimitry Andric   const auto &It = find(TargetPassConfigCallbacks, this);
36*700637cbSDimitry Andric   if (It != TargetPassConfigCallbacks.end())
37*700637cbSDimitry Andric     TargetPassConfigCallbacks.erase(It);
38*700637cbSDimitry Andric }
39*700637cbSDimitry Andric } // namespace llvm
40