| 1 | //===- PassInstrumentation.cpp - Pass Instrumentation interface -*- C++ -*-===// |
|---|---|
| 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 | /// \file |
| 9 | /// |
| 10 | /// This file provides the implementation of PassInstrumentation class. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/IR/PassInstrumentation.h" |
| 15 | #include "llvm/ADT/STLExtras.h" |
| 16 | #include "llvm/IR/PassManager.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | |
| 20 | template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Module *>; |
| 21 | template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Function *>; |
| 22 | template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Loop *>; |
| 23 | |
| 24 | void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName, |
| 25 | StringRef PassName) { |
| 26 | ClassToPassName.try_emplace(Key: ClassName, Args: PassName.str()); |
| 27 | } |
| 28 | |
| 29 | StringRef |
| 30 | PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) { |
| 31 | if (!ClassToPassNameCallbacks.empty()) { |
| 32 | for (auto &Fn : ClassToPassNameCallbacks) |
| 33 | Fn(); |
| 34 | ClassToPassNameCallbacks.clear(); |
| 35 | } |
| 36 | return ClassToPassName[ClassName]; |
| 37 | } |
| 38 | |
| 39 | AnalysisKey PassInstrumentationAnalysis::Key; |
| 40 | |
| 41 | bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) { |
| 42 | size_t Pos = PassID.find(C: '<'); |
| 43 | StringRef Prefix = PassID; |
| 44 | if (Pos != StringRef::npos) |
| 45 | Prefix = PassID.substr(Start: 0, N: Pos); |
| 46 | return any_of(Range: Specials, |
| 47 | P: [Prefix](StringRef S) { return Prefix.ends_with(Suffix: S); }); |
| 48 | } |
| 49 | |
| 50 | } // namespace llvm |
| 51 |