1 //===- bolt/Rewrite/MetadataManager.cpp -----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "bolt/Rewrite/MetadataManager.h"
10 #include "llvm/Support/Debug.h"
13 #define DEBUG_TYPE "bolt-metadata"
18 void MetadataManager::registerRewriter(
19 std::unique_ptr
<MetadataRewriter
> Rewriter
) {
20 Rewriters
.emplace_back(std::move(Rewriter
));
23 void MetadataManager::runInitializersPreCFG() {
24 for (auto &Rewriter
: Rewriters
) {
25 LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter
->getName()
26 << " before CFG construction\n");
27 if (Error E
= Rewriter
->preCFGInitializer()) {
28 errs() << "BOLT-ERROR: while running " << Rewriter
->getName()
29 << " in pre-CFG state: " << toString(std::move(E
)) << '\n';
35 void MetadataManager::runInitializersPostCFG() {
36 for (auto &Rewriter
: Rewriters
) {
37 LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter
->getName()
38 << " after CFG construction\n");
39 if (Error E
= Rewriter
->postCFGInitializer()) {
40 errs() << "BOLT-ERROR: while running " << Rewriter
->getName()
41 << " in CFG state: " << toString(std::move(E
)) << '\n';
47 void MetadataManager::runFinalizersAfterEmit() {
48 for (auto &Rewriter
: Rewriters
) {
49 LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter
->getName()
51 if (Error E
= Rewriter
->postEmitFinalizer()) {
52 errs() << "BOLT-ERROR: while running " << Rewriter
->getName()
53 << " after emit: " << toString(std::move(E
)) << '\n';