1 | //===- bolt/Rewrite/MetadataManager.cpp -----------------------------------===// |
---|---|
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 | #include "bolt/Rewrite/MetadataManager.h" |
10 | #include "llvm/Support/Debug.h" |
11 | |
12 | #undef DEBUG_TYPE |
13 | #define DEBUG_TYPE "bolt-metadata" |
14 | |
15 | using namespace llvm; |
16 | using namespace bolt; |
17 | |
18 | void MetadataManager::registerRewriter( |
19 | std::unique_ptr<MetadataRewriter> Rewriter) { |
20 | Rewriters.emplace_back(Args: std::move(Rewriter)); |
21 | } |
22 | |
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(E: std::move(E)) << '\n'; |
30 | exit(status: 1); |
31 | } |
32 | } |
33 | } |
34 | |
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(E: std::move(E)) << '\n'; |
42 | exit(status: 1); |
43 | } |
44 | } |
45 | } |
46 | |
47 | void MetadataManager::runFinalizersPreEmit() { |
48 | for (auto &Rewriter : Rewriters) { |
49 | LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking "<< Rewriter->getName() |
50 | << " before emitting binary context\n"); |
51 | if (Error E = Rewriter->preEmitFinalizer()) { |
52 | errs() << "BOLT-ERROR: while running "<< Rewriter->getName() |
53 | << " before emit: "<< toString(E: std::move(E)) << '\n'; |
54 | exit(status: 1); |
55 | } |
56 | } |
57 | } |
58 | |
59 | void MetadataManager::runFinalizersAfterEmit() { |
60 | for (auto &Rewriter : Rewriters) { |
61 | LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking "<< Rewriter->getName() |
62 | << " after emit\n"); |
63 | if (Error E = Rewriter->postEmitFinalizer()) { |
64 | errs() << "BOLT-ERROR: while running "<< Rewriter->getName() |
65 | << " after emit: "<< toString(E: std::move(E)) << '\n'; |
66 | exit(status: 1); |
67 | } |
68 | } |
69 | } |
70 |