|
| 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 | + |
| 16 | +namespace llvm { |
| 17 | +// TargetPassConfig callbacks |
| 18 | +static SmallVector<RegisterTargetPassConfigCallback *, 1> |
| 19 | + TargetPassConfigCallbacks{}; |
| 20 | + |
| 21 | +void invokeGlobalTargetPassConfigCallbacks(TargetMachine &TM, |
| 22 | + PassManagerBase &PM, |
| 23 | + TargetPassConfig *PassConfig) { |
| 24 | + for (const RegisterTargetPassConfigCallback *Reg : TargetPassConfigCallbacks) |
| 25 | + Reg->Callback(TM, PM, PassConfig); |
| 26 | +} |
| 27 | + |
| 28 | +RegisterTargetPassConfigCallback::RegisterTargetPassConfigCallback( |
| 29 | + PassConfigCallback &&C) |
| 30 | + : Callback(std::move(C)) { |
| 31 | + TargetPassConfigCallbacks.push_back(this); |
| 32 | +} |
| 33 | + |
| 34 | +RegisterTargetPassConfigCallback::~RegisterTargetPassConfigCallback() { |
| 35 | + const auto &It = find(TargetPassConfigCallbacks, this); |
| 36 | + if (It != TargetPassConfigCallbacks.end()) |
| 37 | + TargetPassConfigCallbacks.erase(It); |
| 38 | +} |
| 39 | +} // namespace llvm |
0 commit comments