mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 22:06:06 +00:00

On MSVC the `this` uses inside `decltype` require a lambda capture. On clang they result in an unused capture warning instead. Add the capture and suppress the warning with `(void)this`. ----- Initializing this map is somewhat expensive (especially for O0), so we currently only do it if certain flags are used. I would like to make use of it for crash dumps (#96078), where we don't know in advance whether it will be needed or not. This patch changes the initialization to a lazy approach, where a callback is registered that does the actual initialization. The callbacks will be run the first time the pass name is requested. This way there is no compile-time impact if the mapping is not used.
47 lines
1.5 KiB
C++
47 lines
1.5 KiB
C++
//===- PassInstrumentation.cpp - Pass Instrumentation interface -*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
/// \file
|
|
///
|
|
/// This file provides the implementation of PassInstrumentation class.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/IR/PassInstrumentation.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
#include "llvm/IR/PassManager.h"
|
|
|
|
namespace llvm {
|
|
|
|
void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName,
|
|
StringRef PassName) {
|
|
ClassToPassName.try_emplace(ClassName, PassName.str());
|
|
}
|
|
|
|
StringRef
|
|
PassInstrumentationCallbacks::getPassNameForClassName(StringRef ClassName) {
|
|
if (!ClassToPassNameCallbacks.empty()) {
|
|
for (auto &Fn : ClassToPassNameCallbacks)
|
|
Fn();
|
|
ClassToPassNameCallbacks.clear();
|
|
}
|
|
return ClassToPassName[ClassName];
|
|
}
|
|
|
|
AnalysisKey PassInstrumentationAnalysis::Key;
|
|
|
|
bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials) {
|
|
size_t Pos = PassID.find('<');
|
|
StringRef Prefix = PassID;
|
|
if (Pos != StringRef::npos)
|
|
Prefix = PassID.substr(0, Pos);
|
|
return any_of(Specials,
|
|
[Prefix](StringRef S) { return Prefix.ends_with(S); });
|
|
}
|
|
|
|
} // namespace llvm
|