xref: /freebsd-src/contrib/llvm-project/llvm/lib/IR/PassInstrumentation.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- PassInstrumentation.cpp - Pass Instrumentation interface -*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file provides the implementation of PassInstrumentation class.
110b57cec5SDimitry Andric ///
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "llvm/IR/PassInstrumentation.h"
15e8d8bef9SDimitry Andric #include "llvm/ADT/STLExtras.h"
160b57cec5SDimitry Andric #include "llvm/IR/PassManager.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric namespace llvm {
190b57cec5SDimitry Andric 
20e8d8bef9SDimitry Andric void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName,
21e8d8bef9SDimitry Andric                                                       StringRef PassName) {
22*0fca6ea1SDimitry Andric   ClassToPassName.try_emplace(ClassName, PassName.str());
23e8d8bef9SDimitry Andric }
24e8d8bef9SDimitry Andric 
25e8d8bef9SDimitry Andric StringRef
26e8d8bef9SDimitry Andric PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) {
27*0fca6ea1SDimitry Andric   if (!ClassToPassNameCallbacks.empty()) {
28*0fca6ea1SDimitry Andric     for (auto &Fn : ClassToPassNameCallbacks)
29*0fca6ea1SDimitry Andric       Fn();
30*0fca6ea1SDimitry Andric     ClassToPassNameCallbacks.clear();
31*0fca6ea1SDimitry Andric   }
32e8d8bef9SDimitry Andric   return ClassToPassName[ClassName];
33e8d8bef9SDimitry Andric }
34e8d8bef9SDimitry Andric 
350b57cec5SDimitry Andric AnalysisKey PassInstrumentationAnalysis::Key;
360b57cec5SDimitry Andric 
37e8d8bef9SDimitry Andric bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) {
38e8d8bef9SDimitry Andric   size_t Pos = PassID.find('<');
39e8d8bef9SDimitry Andric   StringRef Prefix = PassID;
40e8d8bef9SDimitry Andric   if (Pos != StringRef::npos)
41e8d8bef9SDimitry Andric     Prefix = PassID.substr(0, Pos);
425f757f3fSDimitry Andric   return any_of(Specials,
435f757f3fSDimitry Andric                 [Prefix](StringRef S) { return Prefix.ends_with(S); });
44e8d8bef9SDimitry Andric }
45e8d8bef9SDimitry Andric 
460b57cec5SDimitry Andric } // namespace llvm
47