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
18namespace llvm {
19
20void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName,
21 StringRef PassName) {
22 ClassToPassName.try_emplace(Key: ClassName, Args: PassName.str());
23}
24
25StringRef
26PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) {
27 if (!ClassToPassNameCallbacks.empty()) {
28 for (auto &Fn : ClassToPassNameCallbacks)
29 Fn();
30 ClassToPassNameCallbacks.clear();
31 }
32 return ClassToPassName[ClassName];
33}
34
35AnalysisKey PassInstrumentationAnalysis::Key;
36
37bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) {
38 size_t Pos = PassID.find(C: '<');
39 StringRef Prefix = PassID;
40 if (Pos != StringRef::npos)
41 Prefix = PassID.substr(Start: 0, N: Pos);
42 return any_of(Range: Specials,
43 P: [Prefix](StringRef S) { return Prefix.ends_with(Suffix: S); });
44}
45
46} // namespace llvm
47