llvm-project
81 строка · 2.8 Кб
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_TYPE13#define DEBUG_TYPE "bolt-metadata"14
15using namespace llvm;16using namespace bolt;17
18void MetadataManager::registerRewriter(19std::unique_ptr<MetadataRewriter> Rewriter) {20Rewriters.emplace_back(std::move(Rewriter));21}
22
23void MetadataManager::runSectionInitializers() {24for (auto &Rewriter : Rewriters) {25LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()26<< " after reading sections\n");27if (Error E = Rewriter->sectionInitializer()) {28errs() << "BOLT-ERROR: while running " << Rewriter->getName()29<< " after reading sections: " << toString(std::move(E)) << '\n';30exit(1);31}32}33}
34
35void MetadataManager::runInitializersPreCFG() {36for (auto &Rewriter : Rewriters) {37LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()38<< " before CFG construction\n");39if (Error E = Rewriter->preCFGInitializer()) {40errs() << "BOLT-ERROR: while running " << Rewriter->getName()41<< " in pre-CFG state: " << toString(std::move(E)) << '\n';42exit(1);43}44}45}
46
47void MetadataManager::runInitializersPostCFG() {48for (auto &Rewriter : Rewriters) {49LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()50<< " after CFG construction\n");51if (Error E = Rewriter->postCFGInitializer()) {52errs() << "BOLT-ERROR: while running " << Rewriter->getName()53<< " in CFG state: " << toString(std::move(E)) << '\n';54exit(1);55}56}57}
58
59void MetadataManager::runFinalizersPreEmit() {60for (auto &Rewriter : Rewriters) {61LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()62<< " before emitting binary context\n");63if (Error E = Rewriter->preEmitFinalizer()) {64errs() << "BOLT-ERROR: while running " << Rewriter->getName()65<< " before emit: " << toString(std::move(E)) << '\n';66exit(1);67}68}69}
70
71void MetadataManager::runFinalizersAfterEmit() {72for (auto &Rewriter : Rewriters) {73LLVM_DEBUG(dbgs() << "BOLT-DEBUG: invoking " << Rewriter->getName()74<< " after emit\n");75if (Error E = Rewriter->postEmitFinalizer()) {76errs() << "BOLT-ERROR: while running " << Rewriter->getName()77<< " after emit: " << toString(std::move(E)) << '\n';78exit(1);79}80}81}
82