[llvm] aeac2e4 - [llvm] Replace llvm::Any with std::any
Sebastian Neubauer via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 8 02:48:09 PST 2022
Author: Sebastian Neubauer
Date: 2022-12-08T11:48:00+01:00
New Revision: aeac2e4884a3ce62c920cd51806a9396da64d9f7
URL: https://github.com/llvm/llvm-project/commit/aeac2e4884a3ce62c920cd51806a9396da64d9f7
DIFF: https://github.com/llvm/llvm-project/commit/aeac2e4884a3ce62c920cd51806a9396da64d9f7.diff
LOG: [llvm] Replace llvm::Any with std::any
llvm::Any had several bugs in the past, due to being sensitive to symbol
visibility. (See D101972 and D108943)
Even with these fixes applied, I still encounter the same issue on
Windows.
Similar to llvm::Optional going away in favor of std::optional, we can
use std::any from C++17.
Using std::any fixes the problem and puts the burden to do it correctly
on the standard library.
Differential Revision: https://reviews.llvm.org/D139532
Added:
Modified:
llvm/include/llvm/IR/PassInstrumentation.h
llvm/include/llvm/Passes/StandardInstrumentations.h
llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
llvm/lib/CodeGen/MachinePassManager.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/IR/LLVMContextImpl.h
llvm/lib/IR/PassTimingInfo.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/lib/Transforms/Scalar/LoopPassManager.cpp
llvm/lib/Transforms/Utils/Debugify.cpp
llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp
llvm/unittests/IR/PassBuilderCallbacksTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PassInstrumentation.h b/llvm/include/llvm/IR/PassInstrumentation.h
index 519a5e46b437..0581efac0716 100644
--- a/llvm/include/llvm/IR/PassInstrumentation.h
+++ b/llvm/include/llvm/IR/PassInstrumentation.h
@@ -35,7 +35,7 @@
/// executed and IRUnit it works on. There can be
diff erent schemes of
/// providing names in future, currently it is just a name() of the pass.
///
-/// - PassInstrumentation wraps address of IRUnit into llvm::Any and passes
+/// - PassInstrumentation wraps address of IRUnit into std::any and passes
/// control to all the registered callbacks. Note that we specifically wrap
/// 'const IRUnitT*' so as to avoid any accidental changes to IR in
/// instrumenting callbacks.
@@ -49,10 +49,10 @@
#ifndef LLVM_IR_PASSINSTRUMENTATION_H
#define LLVM_IR_PASSINSTRUMENTATION_H
-#include "llvm/ADT/Any.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
+#include <any>
#include <type_traits>
#include <vector>
@@ -66,7 +66,7 @@ class StringRef;
class PassInstrumentationCallbacks {
public:
// Before/After callbacks accept IRUnits whenever appropriate, so they need
- // to take them as constant pointers, wrapped with llvm::Any.
+ // to take them as constant pointers, wrapped with std::any.
// For the case when IRUnit has been invalidated there is a
diff erent
// callback to use - AfterPassInvalidated.
// We call all BeforePassFuncs to determine if a pass should run or not.
@@ -75,14 +75,14 @@ class PassInstrumentationCallbacks {
// already invalidated IRUnit is unsafe. There are ways to handle invalidated
// IRUnits in a safe way, and we might pursue that as soon as there is a
// useful instrumentation that needs it.
- using BeforePassFunc = bool(StringRef, Any);
- using BeforeSkippedPassFunc = void(StringRef, Any);
- using BeforeNonSkippedPassFunc = void(StringRef, Any);
- using AfterPassFunc = void(StringRef, Any, const PreservedAnalyses &);
+ using BeforePassFunc = bool(StringRef, std::any);
+ using BeforeSkippedPassFunc = void(StringRef, std::any);
+ using BeforeNonSkippedPassFunc = void(StringRef, std::any);
+ using AfterPassFunc = void(StringRef, std::any, const PreservedAnalyses &);
using AfterPassInvalidatedFunc = void(StringRef, const PreservedAnalyses &);
- using BeforeAnalysisFunc = void(StringRef, Any);
- using AfterAnalysisFunc = void(StringRef, Any);
- using AnalysisInvalidatedFunc = void(StringRef, Any);
+ using BeforeAnalysisFunc = void(StringRef, std::any);
+ using AfterAnalysisFunc = void(StringRef, std::any);
+ using AnalysisInvalidatedFunc = void(StringRef, std::any);
using AnalysesClearedFunc = void(StringRef);
public:
@@ -233,15 +233,15 @@ class PassInstrumentation {
bool ShouldRun = true;
if (!isRequired(Pass)) {
for (auto &C : Callbacks->ShouldRunOptionalPassCallbacks)
- ShouldRun &= C(Pass.name(), llvm::Any(&IR));
+ ShouldRun &= C(Pass.name(), std::any(&IR));
}
if (ShouldRun) {
for (auto &C : Callbacks->BeforeNonSkippedPassCallbacks)
- C(Pass.name(), llvm::Any(&IR));
+ C(Pass.name(), std::any(&IR));
} else {
for (auto &C : Callbacks->BeforeSkippedPassCallbacks)
- C(Pass.name(), llvm::Any(&IR));
+ C(Pass.name(), std::any(&IR));
}
return ShouldRun;
@@ -255,7 +255,7 @@ class PassInstrumentation {
const PreservedAnalyses &PA) const {
if (Callbacks)
for (auto &C : Callbacks->AfterPassCallbacks)
- C(Pass.name(), llvm::Any(&IR), PA);
+ C(Pass.name(), std::any(&IR), PA);
}
/// AfterPassInvalidated instrumentation point - takes \p Pass instance
@@ -275,7 +275,7 @@ class PassInstrumentation {
void runBeforeAnalysis(const PassT &Analysis, const IRUnitT &IR) const {
if (Callbacks)
for (auto &C : Callbacks->BeforeAnalysisCallbacks)
- C(Analysis.name(), llvm::Any(&IR));
+ C(Analysis.name(), std::any(&IR));
}
/// AfterAnalysis instrumentation point - takes \p Analysis instance
@@ -284,7 +284,7 @@ class PassInstrumentation {
void runAfterAnalysis(const PassT &Analysis, const IRUnitT &IR) const {
if (Callbacks)
for (auto &C : Callbacks->AfterAnalysisCallbacks)
- C(Analysis.name(), llvm::Any(&IR));
+ C(Analysis.name(), std::any(&IR));
}
/// AnalysisInvalidated instrumentation point - takes \p Analysis instance
@@ -294,7 +294,7 @@ class PassInstrumentation {
void runAnalysisInvalidated(const PassT &Analysis, const IRUnitT &IR) const {
if (Callbacks)
for (auto &C : Callbacks->AnalysisInvalidatedCallbacks)
- C(Analysis.name(), llvm::Any(&IR));
+ C(Analysis.name(), std::any(&IR));
}
/// AnalysesCleared instrumentation point - takes name of IR that analyses
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index c8614ec49688..e95c3d98caf0 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -46,8 +46,8 @@ class PrintIRInstrumentation {
void registerCallbacks(PassInstrumentationCallbacks &PIC);
private:
- void printBeforePass(StringRef PassID, Any IR);
- void printAfterPass(StringRef PassID, Any IR);
+ void printBeforePass(StringRef PassID, std::any IR);
+ void printAfterPass(StringRef PassID, std::any IR);
void printAfterPassInvalidated(StringRef PassID);
bool shouldPrintBeforePass(StringRef PassID);
@@ -55,7 +55,7 @@ class PrintIRInstrumentation {
using PrintModuleDesc = std::tuple<const Module *, std::string, StringRef>;
- void pushModuleDesc(StringRef PassID, Any IR);
+ void pushModuleDesc(StringRef PassID, std::any IR);
PrintModuleDesc popModuleDesc(StringRef PassID);
PassInstrumentationCallbacks *PIC;
@@ -71,7 +71,7 @@ class OptNoneInstrumentation {
private:
bool DebugLogging;
- bool shouldRun(StringRef PassID, Any IR);
+ bool shouldRun(StringRef PassID, std::any IR);
};
class OptPassGateInstrumentation {
@@ -79,7 +79,7 @@ class OptPassGateInstrumentation {
bool HasWrittenIR = false;
public:
OptPassGateInstrumentation(LLVMContext &Context) : Context(Context) {}
- bool shouldRun(StringRef PassName, Any IR);
+ bool shouldRun(StringRef PassName, std::any IR);
void registerCallbacks(PassInstrumentationCallbacks &PIC);
};
@@ -181,9 +181,9 @@ template <typename IRUnitT> class ChangeReporter {
// Determine if this pass/IR is interesting and if so, save the IR
// otherwise it is left on the stack without data.
- void saveIRBeforePass(Any IR, StringRef PassID, StringRef PassName);
+ void saveIRBeforePass(std::any IR, StringRef PassID, StringRef PassName);
// Compare the IR from before the pass after the pass.
- void handleIRAfterPass(Any IR, StringRef PassID, StringRef PassName);
+ void handleIRAfterPass(std::any IR, StringRef PassID, StringRef PassName);
// Handle the situation where a pass is invalidated.
void handleInvalidatedPass(StringRef PassID);
@@ -192,16 +192,16 @@ template <typename IRUnitT> class ChangeReporter {
void registerRequiredCallbacks(PassInstrumentationCallbacks &PIC);
// Called on the first IR processed.
- virtual void handleInitialIR(Any IR) = 0;
+ virtual void handleInitialIR(std::any IR) = 0;
// Called before and after a pass to get the representation of the IR.
- virtual void generateIRRepresentation(Any IR, StringRef PassID,
+ virtual void generateIRRepresentation(std::any IR, StringRef PassID,
IRUnitT &Output) = 0;
// Called when the pass is not iteresting.
virtual void omitAfter(StringRef PassID, std::string &Name) = 0;
// Called when an interesting IR has changed.
virtual void handleAfter(StringRef PassID, std::string &Name,
const IRUnitT &Before, const IRUnitT &After,
- Any) = 0;
+ std::any) = 0;
// Called when an interesting pass is invalidated.
virtual void handleInvalidated(StringRef PassID) = 0;
// Called when the IR or pass is not interesting.
@@ -226,7 +226,7 @@ class TextChangeReporter : public ChangeReporter<IRUnitT> {
TextChangeReporter(bool Verbose);
// Print a module dump of the first IR that is changed.
- void handleInitialIR(Any IR) override;
+ void handleInitialIR(std::any IR) override;
// Report that the IR was omitted because it did not change.
void omitAfter(StringRef PassID, std::string &Name) override;
// Report that the pass was invalidated.
@@ -254,12 +254,12 @@ class IRChangedPrinter : public TextChangeReporter<std::string> {
protected:
// Called before and after a pass to get the representation of the IR.
- void generateIRRepresentation(Any IR, StringRef PassID,
+ void generateIRRepresentation(std::any IR, StringRef PassID,
std::string &Output) override;
// Called when an interesting IR has changed.
void handleAfter(StringRef PassID, std::string &Name,
const std::string &Before, const std::string &After,
- Any) override;
+ std::any) override;
};
class IRChangedTester : public IRChangedPrinter {
@@ -272,7 +272,7 @@ class IRChangedTester : public IRChangedPrinter {
void handleIR(const std::string &IR, StringRef PassID);
// Check initial IR
- void handleInitialIR(Any IR) override;
+ void handleInitialIR(std::any IR) override;
// Do nothing.
void omitAfter(StringRef PassID, std::string &Name) override;
// Do nothing.
@@ -285,7 +285,7 @@ class IRChangedTester : public IRChangedPrinter {
// Call test as interesting IR has changed.
void handleAfter(StringRef PassID, std::string &Name,
const std::string &Before, const std::string &After,
- Any) override;
+ std::any) override;
};
// Information that needs to be saved for a basic block in order to compare
@@ -385,7 +385,7 @@ template <typename T> class IRComparer {
CompareFunc);
// Analyze \p IR and build the IR representation in \p Data.
- static void analyzeIR(Any IR, IRDataT<T> &Data);
+ static void analyzeIR(std::any IR, IRDataT<T> &Data);
protected:
// Generate the data for \p F into \p Data.
@@ -411,13 +411,13 @@ class InLineChangePrinter : public TextChangeReporter<IRDataT<EmptyData>> {
protected:
// Create a representation of the IR.
- void generateIRRepresentation(Any IR, StringRef PassID,
+ void generateIRRepresentation(std::any IR, StringRef PassID,
IRDataT<EmptyData> &Output) override;
// Called when an interesting IR has changed.
void handleAfter(StringRef PassID, std::string &Name,
const IRDataT<EmptyData> &Before,
- const IRDataT<EmptyData> &After, Any) override;
+ const IRDataT<EmptyData> &After, std::any) override;
void handleFunctionCompare(StringRef Name, StringRef Prefix, StringRef PassID,
StringRef Divider, bool InModule, unsigned Minor,
@@ -449,7 +449,7 @@ class TimeProfilingPassesHandler {
private:
// Implementation of pass instrumentation callbacks.
- void runBeforePass(StringRef PassID, Any IR);
+ void runBeforePass(StringRef PassID, std::any IR);
void runAfterPass();
};
@@ -497,16 +497,16 @@ class DotCfgChangeReporter : public ChangeReporter<IRDataT<DCData>> {
bool initializeHTML();
// Called on the first IR processed.
- void handleInitialIR(Any IR) override;
+ void handleInitialIR(std::any IR) override;
// Called before and after a pass to get the representation of the IR.
- void generateIRRepresentation(Any IR, StringRef PassID,
+ void generateIRRepresentation(std::any IR, StringRef PassID,
IRDataT<DCData> &Output) override;
// Called when the pass is not iteresting.
void omitAfter(StringRef PassID, std::string &Name) override;
// Called when an interesting IR has changed.
void handleAfter(StringRef PassID, std::string &Name,
const IRDataT<DCData> &Before, const IRDataT<DCData> &After,
- Any) override;
+ std::any) override;
// Called when an interesting pass is invalidated.
void handleInvalidated(StringRef PassID) override;
// Called when the IR or pass is not interesting.
diff --git a/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h b/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
index ebac3d6a24ef..89d6bfed37a8 100644
--- a/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
+++ b/llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
@@ -61,7 +61,7 @@ class PseudoProbeVerifier {
void registerCallbacks(PassInstrumentationCallbacks &PIC);
// Implementation of pass instrumentation callbacks for new pass manager.
- void runAfterPass(StringRef PassID, Any IR);
+ void runAfterPass(StringRef PassID, std::any IR);
private:
// Allow a little bias due the rounding to integral factors.
diff --git a/llvm/lib/CodeGen/MachinePassManager.cpp b/llvm/lib/CodeGen/MachinePassManager.cpp
index 476dc059d2b5..739f7d6cb401 100644
--- a/llvm/lib/CodeGen/MachinePassManager.cpp
+++ b/llvm/lib/CodeGen/MachinePassManager.cpp
@@ -15,6 +15,8 @@
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/PassManagerImpl.h"
+#include <any>
+
using namespace llvm;
namespace llvm {
@@ -40,12 +42,12 @@ Error MachineFunctionPassManager::run(Module &M,
// No need to pop this callback later since MIR pipeline is flat which means
// current pipeline is the top-level pipeline. Callbacks are not used after
// current pipeline.
- PI.pushBeforeNonSkippedPassCallback([&MFAM](StringRef PassID, Any IR) {
- assert(any_isa<const MachineFunction *>(IR));
- const MachineFunction *MF = any_cast<const MachineFunction *>(IR);
+ PI.pushBeforeNonSkippedPassCallback([&MFAM](StringRef PassID, std::any IR) {
+ assert(std::any_cast<const MachineFunction *>(&IR));
+ const MachineFunction **MF = std::any_cast<const MachineFunction *>(&IR);
assert(MF && "Machine function should be valid for printing");
std::string Banner = std::string("After ") + std::string(PassID);
- verifyMachineFunction(&MFAM, Banner, *MF);
+ verifyMachineFunction(&MFAM, Banner, **MF);
});
}
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 87f29b3173d5..eb49ab7f9b65 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -551,7 +551,7 @@ static void registerPartialPipelineCallback(PassInstrumentationCallbacks &PIC,
[=, EnableCurrent = StartBefore.empty() && StartAfter.empty(),
EnableNext = std::optional<bool>(), StartBeforeCount = 0u,
StartAfterCount = 0u, StopBeforeCount = 0u,
- StopAfterCount = 0u](StringRef P, Any) mutable {
+ StopAfterCount = 0u](StringRef P, std::any) mutable {
bool StartBeforePass = !StartBefore.empty() && P.contains(StartBefore);
bool StartAfterPass = !StartAfter.empty() && P.contains(StartAfter);
bool StopBeforePass = !StopBefore.empty() && P.contains(StopBefore);
@@ -586,7 +586,7 @@ void llvm::registerCodeGenCallback(PassInstrumentationCallbacks &PIC,
LLVMTargetMachine &LLVMTM) {
// Register a callback for disabling passes.
- PIC.registerShouldRunOptionalPassCallback([](StringRef P, Any) {
+ PIC.registerShouldRunOptionalPassCallback([](StringRef P, std::any) {
#define DISABLE_PASS(Option, Name) \
if (Option && P.contains(#Name)) \
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index eadb3b7fba77..5a87a025e3c3 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -17,7 +17,6 @@
#include "ConstantsContext.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
-#include "llvm/ADT/Any.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index cfd27bf78793..3cccd7d9064f 100644
--- a/llvm/lib/IR/PassTimingInfo.cpp
+++ b/llvm/lib/IR/PassTimingInfo.cpp
@@ -26,6 +26,7 @@
#include "llvm/Support/Mutex.h"
#include "llvm/Support/TypeName.h"
#include "llvm/Support/raw_ostream.h"
+#include <any>
#include <string>
using namespace llvm;
@@ -301,9 +302,9 @@ void TimePassesHandler::registerCallbacks(PassInstrumentationCallbacks &PIC) {
return;
PIC.registerBeforeNonSkippedPassCallback(
- [this](StringRef P, Any) { this->startPassTimer(P); });
+ [this](StringRef P, std::any) { this->startPassTimer(P); });
PIC.registerAfterPassCallback(
- [this](StringRef P, Any, const PreservedAnalyses &) {
+ [this](StringRef P, std::any, const PreservedAnalyses &) {
this->stopPassTimer(P);
});
PIC.registerAfterPassInvalidatedCallback(
@@ -311,9 +312,9 @@ void TimePassesHandler::registerCallbacks(PassInstrumentationCallbacks &PIC) {
this->stopPassTimer(P);
});
PIC.registerBeforeAnalysisCallback(
- [this](StringRef P, Any) { this->startAnalysisTimer(P); });
+ [this](StringRef P, std::any) { this->startAnalysisTimer(P); });
PIC.registerAfterAnalysisCallback(
- [this](StringRef P, Any) { this->stopAnalysisTimer(P); });
+ [this](StringRef P, std::any) { this->stopAnalysisTimer(P); });
}
} // namespace llvm
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index fa11bce600ad..622533dcf90d 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/Passes/StandardInstrumentations.h"
-#include "llvm/ADT/Any.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
@@ -37,6 +36,7 @@
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
+#include <any>
#include <unordered_map>
#include <unordered_set>
#include <utility>
@@ -122,21 +122,19 @@ static cl::opt<std::string>
/// Extract Module out of \p IR unit. May return nullptr if \p IR does not match
/// certain global filters. Will never return nullptr if \p Force is true.
-const Module *unwrapModule(Any IR, bool Force = false) {
- if (any_isa<const Module *>(IR))
- return any_cast<const Module *>(IR);
+const Module *unwrapModule(std::any IR, bool Force = false) {
+ if (const auto **M = std::any_cast<const Module *>(&IR))
+ return *M;
- if (any_isa<const Function *>(IR)) {
- const Function *F = any_cast<const Function *>(IR);
- if (!Force && !isFunctionInPrintList(F->getName()))
+ if (const auto **F = std::any_cast<const Function *>(&IR)) {
+ if (!Force && !isFunctionInPrintList((*F)->getName()))
return nullptr;
- return F->getParent();
+ return (*F)->getParent();
}
- if (any_isa<const LazyCallGraph::SCC *>(IR)) {
- const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
- for (const LazyCallGraph::Node &N : *C) {
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR)) {
+ for (const LazyCallGraph::Node &N : **C) {
const Function &F = N.getFunction();
if (Force || (!F.isDeclaration() && isFunctionInPrintList(F.getName()))) {
return F.getParent();
@@ -146,9 +144,8 @@ const Module *unwrapModule(Any IR, bool Force = false) {
return nullptr;
}
- if (any_isa<const Loop *>(IR)) {
- const Loop *L = any_cast<const Loop *>(IR);
- const Function *F = L->getHeader()->getParent();
+ if (const auto **L = std::any_cast<const Loop *>(&IR)) {
+ const Function *F = (*L)->getHeader()->getParent();
if (!Force && !isFunctionInPrintList(F->getName()))
return nullptr;
return F->getParent();
@@ -189,23 +186,20 @@ void printIR(raw_ostream &OS, const Loop *L) {
printLoop(const_cast<Loop &>(*L), OS);
}
-std::string getIRName(Any IR) {
- if (any_isa<const Module *>(IR))
+std::string getIRName(std::any IR) {
+ if (std::any_cast<const Module *>(&IR))
return "[module]";
- if (any_isa<const Function *>(IR)) {
- const Function *F = any_cast<const Function *>(IR);
- return F->getName().str();
+ if (const auto **F = std::any_cast<const Function *>(&IR)) {
+ return (*F)->getName().str();
}
- if (any_isa<const LazyCallGraph::SCC *>(IR)) {
- const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
- return C->getName();
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR)) {
+ return (*C)->getName();
}
- if (any_isa<const Loop *>(IR)) {
- const Loop *L = any_cast<const Loop *>(IR);
- return L->getName().str();
+ if (const auto **L = std::any_cast<const Loop *>(&IR)) {
+ return (*L)->getName().str();
}
llvm_unreachable("Unknown wrapped IR type");
@@ -227,32 +221,28 @@ bool sccContainsFilterPrintFunc(const LazyCallGraph::SCC &C) {
isFunctionInPrintList("*");
}
-bool shouldPrintIR(Any IR) {
- if (any_isa<const Module *>(IR)) {
- const Module *M = any_cast<const Module *>(IR);
- return moduleContainsFilterPrintFunc(*M);
+bool shouldPrintIR(std::any IR) {
+ if (const auto **M = std::any_cast<const Module *>(&IR)) {
+ return moduleContainsFilterPrintFunc(**M);
}
- if (any_isa<const Function *>(IR)) {
- const Function *F = any_cast<const Function *>(IR);
- return isFunctionInPrintList(F->getName());
+ if (const auto **F = std::any_cast<const Function *>(&IR)) {
+ return isFunctionInPrintList((*F)->getName());
}
- if (any_isa<const LazyCallGraph::SCC *>(IR)) {
- const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
- return sccContainsFilterPrintFunc(*C);
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR)) {
+ return sccContainsFilterPrintFunc(**C);
}
- if (any_isa<const Loop *>(IR)) {
- const Loop *L = any_cast<const Loop *>(IR);
- return isFunctionInPrintList(L->getHeader()->getParent()->getName());
+ if (const auto **L = std::any_cast<const Loop *>(&IR)) {
+ return isFunctionInPrintList((*L)->getHeader()->getParent()->getName());
}
llvm_unreachable("Unknown wrapped IR type");
}
/// Generic IR-printing helper that unpacks a pointer to IRUnit wrapped into
-/// llvm::Any and does actual print job.
-void unwrapAndPrint(raw_ostream &OS, Any IR) {
+/// std::any and does actual print job.
+void unwrapAndPrint(raw_ostream &OS, std::any IR) {
if (!shouldPrintIR(IR))
return;
@@ -263,27 +253,23 @@ void unwrapAndPrint(raw_ostream &OS, Any IR) {
return;
}
- if (any_isa<const Module *>(IR)) {
- const Module *M = any_cast<const Module *>(IR);
- printIR(OS, M);
+ if (const auto **M = std::any_cast<const Module *>(&IR)) {
+ printIR(OS, *M);
return;
}
- if (any_isa<const Function *>(IR)) {
- const Function *F = any_cast<const Function *>(IR);
- printIR(OS, F);
+ if (const auto **F = std::any_cast<const Function *>(&IR)) {
+ printIR(OS, *F);
return;
}
- if (any_isa<const LazyCallGraph::SCC *>(IR)) {
- const LazyCallGraph::SCC *C = any_cast<const LazyCallGraph::SCC *>(IR);
- printIR(OS, C);
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR)) {
+ printIR(OS, *C);
return;
}
- if (any_isa<const Loop *>(IR)) {
- const Loop *L = any_cast<const Loop *>(IR);
- printIR(OS, L);
+ if (const auto **L = std::any_cast<const Loop *>(&IR)) {
+ printIR(OS, *L);
return;
}
llvm_unreachable("Unknown wrapped IR type");
@@ -312,11 +298,11 @@ std::string makeHTMLReady(StringRef SR) {
}
// Return the module when that is the appropriate level of comparison for \p IR.
-const Module *getModuleForComparison(Any IR) {
- if (any_isa<const Module *>(IR))
- return any_cast<const Module *>(IR);
- if (any_isa<const LazyCallGraph::SCC *>(IR))
- return any_cast<const LazyCallGraph::SCC *>(IR)
+const Module *getModuleForComparison(std::any IR) {
+ if (const auto **M = std::any_cast<const Module *>(&IR))
+ return *M;
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR))
+ return (*C)
->begin()
->getFunction()
.getParent();
@@ -329,11 +315,11 @@ bool isInterestingFunction(const Function &F) {
// Return true when this is a pass on IR for which printing
// of changes is desired.
-bool isInteresting(Any IR, StringRef PassID, StringRef PassName) {
+bool isInteresting(std::any IR, StringRef PassID, StringRef PassName) {
if (isIgnored(PassID) || !isPassInPrintList(PassName))
return false;
- if (any_isa<const Function *>(IR))
- return isInterestingFunction(*any_cast<const Function *>(IR));
+ if (const auto **F = std::any_cast<const Function *>(&IR))
+ return isInterestingFunction(**F);
return true;
}
@@ -344,7 +330,7 @@ template <typename T> ChangeReporter<T>::~ChangeReporter() {
}
template <typename T>
-void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID,
+void ChangeReporter<T>::saveIRBeforePass(std::any IR, StringRef PassID,
StringRef PassName) {
// Always need to place something on the stack because invalidated passes
// are not given the IR so it cannot be determined whether the pass was for
@@ -366,7 +352,7 @@ void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID,
}
template <typename T>
-void ChangeReporter<T>::handleIRAfterPass(Any IR, StringRef PassID,
+void ChangeReporter<T>::handleIRAfterPass(std::any IR, StringRef PassID,
StringRef PassName) {
assert(!BeforeStack.empty() && "Unexpected empty stack encountered.");
@@ -411,12 +397,12 @@ void ChangeReporter<T>::handleInvalidatedPass(StringRef PassID) {
template <typename T>
void ChangeReporter<T>::registerRequiredCallbacks(
PassInstrumentationCallbacks &PIC) {
- PIC.registerBeforeNonSkippedPassCallback([&PIC, this](StringRef P, Any IR) {
+ PIC.registerBeforeNonSkippedPassCallback([&PIC, this](StringRef P, std::any IR) {
saveIRBeforePass(IR, P, PIC.getPassNameForClassName(P));
});
PIC.registerAfterPassCallback(
- [&PIC, this](StringRef P, Any IR, const PreservedAnalyses &) {
+ [&PIC, this](StringRef P, std::any IR, const PreservedAnalyses &) {
handleIRAfterPass(IR, P, PIC.getPassNameForClassName(P));
});
PIC.registerAfterPassInvalidatedCallback(
@@ -429,7 +415,7 @@ template <typename T>
TextChangeReporter<T>::TextChangeReporter(bool Verbose)
: ChangeReporter<T>(Verbose), Out(dbgs()) {}
-template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
+template <typename T> void TextChangeReporter<T>::handleInitialIR(std::any IR) {
// Always print the module.
// Unwrap and print directly to avoid filtering problems in general routines.
auto *M = unwrapModule(IR, /*Force=*/true);
@@ -470,7 +456,7 @@ void IRChangedPrinter::registerCallbacks(PassInstrumentationCallbacks &PIC) {
TextChangeReporter<std::string>::registerRequiredCallbacks(PIC);
}
-void IRChangedPrinter::generateIRRepresentation(Any IR, StringRef PassID,
+void IRChangedPrinter::generateIRRepresentation(std::any IR, StringRef PassID,
std::string &Output) {
raw_string_ostream OS(Output);
unwrapAndPrint(OS, IR);
@@ -479,7 +465,7 @@ void IRChangedPrinter::generateIRRepresentation(Any IR, StringRef PassID,
void IRChangedPrinter::handleAfter(StringRef PassID, std::string &Name,
const std::string &Before,
- const std::string &After, Any) {
+ const std::string &After, std::any) {
// Report the IR before the changes when requested.
if (PrintChangedBefore)
Out << "*** IR Dump Before " << PassID << " on " << Name << " ***\n"
@@ -528,7 +514,7 @@ void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
dbgs() << "Unable to remove temporary file.";
}
-void IRChangedTester::handleInitialIR(Any IR) {
+void IRChangedTester::handleInitialIR(std::any IR) {
// Always test the initial module.
// Unwrap and print directly to avoid filtering problems in general routines.
std::string S;
@@ -542,7 +528,7 @@ void IRChangedTester::handleFiltered(StringRef PassID, std::string &Name) {}
void IRChangedTester::handleIgnored(StringRef PassID, std::string &Name) {}
void IRChangedTester::handleAfter(StringRef PassID, std::string &Name,
const std::string &Before,
- const std::string &After, Any) {
+ const std::string &After, std::any) {
handleIR(After, PassID);
}
@@ -646,7 +632,8 @@ void IRComparer<T>::compare(
});
}
-template <typename T> void IRComparer<T>::analyzeIR(Any IR, IRDataT<T> &Data) {
+template <typename T>
+void IRComparer<T>::analyzeIR(std::any IR, IRDataT<T> &Data) {
if (const Module *M = getModuleForComparison(IR)) {
// Create data for each existing/interesting function in the module.
for (const Function &F : *M)
@@ -654,13 +641,12 @@ template <typename T> void IRComparer<T>::analyzeIR(Any IR, IRDataT<T> &Data) {
return;
}
- const Function *F = nullptr;
- if (any_isa<const Function *>(IR))
- F = any_cast<const Function *>(IR);
- else {
- assert(any_isa<const Loop *>(IR) && "Unknown IR unit.");
- const Loop *L = any_cast<const Loop *>(IR);
- F = L->getHeader()->getParent();
+ const Function **FPtr = std::any_cast<const Function *>(&IR);
+ const Function *F = FPtr ? *FPtr : nullptr;
+ if (!F) {
+ const Loop **L = std::any_cast<const Loop *>(&IR);
+ assert(L && "Unknown IR unit.");
+ F = (*L)->getHeader()->getParent();
}
assert(F && "Unknown IR unit.");
generateFunctionData(Data, *F);
@@ -691,7 +677,7 @@ PrintIRInstrumentation::~PrintIRInstrumentation() {
assert(ModuleDescStack.empty() && "ModuleDescStack is not empty at exit");
}
-void PrintIRInstrumentation::pushModuleDesc(StringRef PassID, Any IR) {
+void PrintIRInstrumentation::pushModuleDesc(StringRef PassID, std::any IR) {
const Module *M = unwrapModule(IR);
ModuleDescStack.emplace_back(M, getIRName(IR), PassID);
}
@@ -704,7 +690,7 @@ PrintIRInstrumentation::popModuleDesc(StringRef PassID) {
return ModuleDesc;
}
-void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
+void PrintIRInstrumentation::printBeforePass(StringRef PassID, std::any IR) {
if (isIgnored(PassID))
return;
@@ -726,7 +712,7 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
unwrapAndPrint(dbgs(), IR);
}
-void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
+void PrintIRInstrumentation::printAfterPass(StringRef PassID, std::any IR) {
if (isIgnored(PassID))
return;
@@ -794,11 +780,11 @@ void PrintIRInstrumentation::registerCallbacks(
// for later use in AfterPassInvalidated.
if (shouldPrintBeforeSomePass() || shouldPrintAfterSomePass())
PIC.registerBeforeNonSkippedPassCallback(
- [this](StringRef P, Any IR) { this->printBeforePass(P, IR); });
+ [this](StringRef P, std::any IR) { this->printBeforePass(P, IR); });
if (shouldPrintAfterSomePass()) {
PIC.registerAfterPassCallback(
- [this](StringRef P, Any IR, const PreservedAnalyses &) {
+ [this](StringRef P, std::any IR, const PreservedAnalyses &) {
this->printAfterPass(P, IR);
});
PIC.registerAfterPassInvalidatedCallback(
@@ -811,15 +797,15 @@ void PrintIRInstrumentation::registerCallbacks(
void OptNoneInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
PIC.registerShouldRunOptionalPassCallback(
- [this](StringRef P, Any IR) { return this->shouldRun(P, IR); });
+ [this](StringRef P, std::any IR) { return this->shouldRun(P, IR); });
}
-bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
- const Function *F = nullptr;
- if (any_isa<const Function *>(IR)) {
- F = any_cast<const Function *>(IR);
- } else if (any_isa<const Loop *>(IR)) {
- F = any_cast<const Loop *>(IR)->getHeader()->getParent();
+bool OptNoneInstrumentation::shouldRun(StringRef PassID, std::any IR) {
+ const Function **FPtr = std::any_cast<const Function *>(&IR);
+ const Function *F = FPtr ? *FPtr : nullptr;
+ if (!F) {
+ if (const auto **L = std::any_cast<const Loop *>(&IR))
+ F = (*L)->getHeader()->getParent();
}
bool ShouldRun = !(F && F->hasOptNone());
if (!ShouldRun && DebugLogging) {
@@ -829,7 +815,7 @@ bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
return ShouldRun;
}
-bool OptPassGateInstrumentation::shouldRun(StringRef PassName, Any IR) {
+bool OptPassGateInstrumentation::shouldRun(StringRef PassName, std::any IR) {
if (isIgnored(PassName))
return true;
@@ -856,7 +842,7 @@ void OptPassGateInstrumentation::registerCallbacks(
if (!PassGate.isEnabled())
return;
- PIC.registerShouldRunOptionalPassCallback([this](StringRef PassName, Any IR) {
+ PIC.registerShouldRunOptionalPassCallback([this](StringRef PassName, std::any IR) {
return this->shouldRun(PassName, IR);
});
}
@@ -881,27 +867,27 @@ void PrintPassInstrumentation::registerCallbacks(
}
PIC.registerBeforeSkippedPassCallback([this, SpecialPasses](StringRef PassID,
- Any IR) {
+ std::any IR) {
assert(!isSpecialPass(PassID, SpecialPasses) &&
"Unexpectedly skipping special pass");
print() << "Skipping pass: " << PassID << " on " << getIRName(IR) << "\n";
});
PIC.registerBeforeNonSkippedPassCallback([this, SpecialPasses](
- StringRef PassID, Any IR) {
+ StringRef PassID, std::any IR) {
if (isSpecialPass(PassID, SpecialPasses))
return;
auto &OS = print();
OS << "Running pass: " << PassID << " on " << getIRName(IR);
- if (any_isa<const Function *>(IR)) {
- unsigned Count = any_cast<const Function *>(IR)->getInstructionCount();
+ if (const auto **F = std::any_cast<const Function *>(&IR)) {
+ unsigned Count = (*F)->getInstructionCount();
OS << " (" << Count << " instruction";
if (Count != 1)
OS << 's';
OS << ')';
- } else if (any_isa<const LazyCallGraph::SCC *>(IR)) {
- int Count = any_cast<const LazyCallGraph::SCC *>(IR)->size();
+ } else if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR)) {
+ int Count = (*C)->size();
OS << " (" << Count << " node";
if (Count != 1)
OS << 's';
@@ -911,7 +897,7 @@ void PrintPassInstrumentation::registerCallbacks(
Indent += 2;
});
PIC.registerAfterPassCallback(
- [this, SpecialPasses](StringRef PassID, Any IR,
+ [this, SpecialPasses](StringRef PassID, std::any IR,
const PreservedAnalyses &) {
if (isSpecialPass(PassID, SpecialPasses))
return;
@@ -919,7 +905,7 @@ void PrintPassInstrumentation::registerCallbacks(
Indent -= 2;
});
PIC.registerAfterPassInvalidatedCallback(
- [this, SpecialPasses](StringRef PassID, Any IR) {
+ [this, SpecialPasses](StringRef PassID, std::any IR) {
if (isSpecialPass(PassID, SpecialPasses))
return;
@@ -927,14 +913,15 @@ void PrintPassInstrumentation::registerCallbacks(
});
if (!Opts.SkipAnalyses) {
- PIC.registerBeforeAnalysisCallback([this](StringRef PassID, Any IR) {
+ PIC.registerBeforeAnalysisCallback([this](StringRef PassID, std::any IR) {
print() << "Running analysis: " << PassID << " on " << getIRName(IR)
<< "\n";
Indent += 2;
});
PIC.registerAfterAnalysisCallback(
- [this](StringRef PassID, Any IR) { Indent -= 2; });
- PIC.registerAnalysisInvalidatedCallback([this](StringRef PassID, Any IR) {
+ [this](StringRef PassID, std::any IR) { Indent -= 2; });
+ PIC.registerAnalysisInvalidatedCallback([this](StringRef PassID,
+ std::any IR) {
print() << "Invalidating analysis: " << PassID << " on " << getIRName(IR)
<< "\n";
});
@@ -1099,18 +1086,19 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
report_fatal_error(Twine("CFG unexpectedly changed by ", Pass));
};
- PIC.registerBeforeNonSkippedPassCallback([this, &FAM](StringRef P, Any IR) {
+ PIC.registerBeforeNonSkippedPassCallback(
+ [this, &FAM](StringRef P, std::any IR) {
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
- assert(&PassStack.emplace_back(P));
+ assert(&PassStack.emplace_back(P));
#endif
- (void)this;
- if (!any_isa<const Function *>(IR))
- return;
+ (void)this;
+ const auto **F = std::any_cast<const Function *>(&IR);
+ if (!F)
+ return;
- const auto *F = any_cast<const Function *>(IR);
- // Make sure a fresh CFG snapshot is available before the pass.
- FAM.getResult<PreservedCFGCheckerAnalysis>(*const_cast<Function *>(F));
- });
+ // Make sure a fresh CFG snapshot is available before the pass.
+ FAM.getResult<PreservedCFGCheckerAnalysis>(*const_cast<Function *>(*F));
+ });
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef P, const PreservedAnalyses &PassPA) {
@@ -1122,7 +1110,7 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
});
PIC.registerAfterPassCallback([this, &FAM,
- checkCFG](StringRef P, Any IR,
+ checkCFG](StringRef P, std::any IR,
const PreservedAnalyses &PassPA) {
#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
assert(PassStack.pop_back_val() == P &&
@@ -1130,67 +1118,71 @@ void PreservedCFGCheckerInstrumentation::registerCallbacks(
#endif
(void)this;
- if (!any_isa<const Function *>(IR))
+ const auto **F = std::any_cast<const Function *>(&IR);
+ if (!F)
return;
if (!PassPA.allAnalysesInSetPreserved<CFGAnalyses>() &&
!PassPA.allAnalysesInSetPreserved<AllAnalysesOn<Function>>())
return;
- const auto *F = any_cast<const Function *>(IR);
if (auto *GraphBefore = FAM.getCachedResult<PreservedCFGCheckerAnalysis>(
- *const_cast<Function *>(F)))
- checkCFG(P, F->getName(), *GraphBefore,
- CFG(F, /* TrackBBLifetime */ false));
+ *const_cast<Function *>(*F)))
+ checkCFG(P, (*F)->getName(), *GraphBefore,
+ CFG(*F, /* TrackBBLifetime */ false));
});
}
void VerifyInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
PIC.registerAfterPassCallback(
- [this](StringRef P, Any IR, const PreservedAnalyses &PassPA) {
+ [this](StringRef P, std::any IR, const PreservedAnalyses &PassPA) {
if (isIgnored(P) || P == "VerifierPass")
return;
- if (any_isa<const Function *>(IR) || any_isa<const Loop *>(IR)) {
- const Function *F;
- if (any_isa<const Loop *>(IR))
- F = any_cast<const Loop *>(IR)->getHeader()->getParent();
- else
- F = any_cast<const Function *>(IR);
+ const Function **FPtr = std::any_cast<const Function *>(&IR);
+ const Function *F = FPtr ? *FPtr : nullptr;
+ if (!F) {
+ if (const auto **L = std::any_cast<const Loop *>(&IR))
+ F = (*L)->getHeader()->getParent();
+ }
+
+ if (F) {
if (DebugLogging)
dbgs() << "Verifying function " << F->getName() << "\n";
if (verifyFunction(*F, &errs()))
report_fatal_error("Broken function found, compilation aborted!");
- } else if (any_isa<const Module *>(IR) ||
- any_isa<const LazyCallGraph::SCC *>(IR)) {
- const Module *M;
- if (any_isa<const LazyCallGraph::SCC *>(IR))
- M = any_cast<const LazyCallGraph::SCC *>(IR)
- ->begin()
- ->getFunction()
- .getParent();
- else
- M = any_cast<const Module *>(IR);
- if (DebugLogging)
- dbgs() << "Verifying module " << M->getName() << "\n";
-
- if (verifyModule(*M, &errs()))
- report_fatal_error("Broken module found, compilation aborted!");
+ } else {
+ const Module **MPtr = std::any_cast<const Module *>(&IR);
+ const Module *M = MPtr ? *MPtr : nullptr;
+ if (!M) {
+ if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR))
+ M = (*C)->begin()->getFunction().getParent();
+ }
+
+ if (M) {
+ if (DebugLogging)
+ dbgs() << "Verifying module " << M->getName() << "\n";
+
+ if (verifyModule(*M, &errs()))
+ report_fatal_error("Broken module found, compilation aborted!");
+ }
}
});
}
InLineChangePrinter::~InLineChangePrinter() = default;
-void InLineChangePrinter::generateIRRepresentation(Any IR, StringRef PassID,
+void InLineChangePrinter::generateIRRepresentation(std::any IR,
+ StringRef PassID,
IRDataT<EmptyData> &D) {
IRComparer<EmptyData>::analyzeIR(IR, D);
}
void InLineChangePrinter::handleAfter(StringRef PassID, std::string &Name,
const IRDataT<EmptyData> &Before,
- const IRDataT<EmptyData> &After, Any IR) {
+ const IRDataT<EmptyData> &After,
+ std::any IR) {
SmallString<20> Banner =
formatv("*** IR Dump After {0} on {1} ***\n", PassID, Name);
Out << Banner;
@@ -1241,9 +1233,9 @@ void TimeProfilingPassesHandler::registerCallbacks(
if (!getTimeTraceProfilerInstance())
return;
PIC.registerBeforeNonSkippedPassCallback(
- [this](StringRef P, Any IR) { this->runBeforePass(P, IR); });
+ [this](StringRef P, std::any IR) { this->runBeforePass(P, IR); });
PIC.registerAfterPassCallback(
- [this](StringRef P, Any IR, const PreservedAnalyses &) {
+ [this](StringRef P, std::any IR, const PreservedAnalyses &) {
this->runAfterPass();
},
true);
@@ -1251,12 +1243,12 @@ void TimeProfilingPassesHandler::registerCallbacks(
[this](StringRef P, const PreservedAnalyses &) { this->runAfterPass(); },
true);
PIC.registerBeforeAnalysisCallback(
- [this](StringRef P, Any IR) { this->runBeforePass(P, IR); });
+ [this](StringRef P, std::any IR) { this->runBeforePass(P, IR); });
PIC.registerAfterAnalysisCallback(
- [this](StringRef P, Any IR) { this->runAfterPass(); }, true);
+ [this](StringRef P, std::any IR) { this->runAfterPass(); }, true);
}
-void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, Any IR) {
+void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, std::any IR) {
timeTraceProfilerBegin(PassID, getIRName(IR));
}
@@ -1949,7 +1941,7 @@ std::string DotCfgChangeReporter::genHTML(StringRef Text, StringRef DotFile,
return S.c_str();
}
-void DotCfgChangeReporter::handleInitialIR(Any IR) {
+void DotCfgChangeReporter::handleInitialIR(std::any IR) {
assert(HTML && "Expected outstream to be set");
*HTML << "<button type=\"button\" class=\"collapsible\">0. "
<< "Initial IR (by function)</button>\n"
@@ -1973,7 +1965,8 @@ void DotCfgChangeReporter::handleInitialIR(Any IR) {
++N;
}
-void DotCfgChangeReporter::generateIRRepresentation(Any IR, StringRef PassID,
+void DotCfgChangeReporter::generateIRRepresentation(std::any IR,
+ StringRef PassID,
IRDataT<DCData> &Data) {
IRComparer<DCData>::analyzeIR(IR, Data);
}
@@ -1989,7 +1982,8 @@ void DotCfgChangeReporter::omitAfter(StringRef PassID, std::string &Name) {
void DotCfgChangeReporter::handleAfter(StringRef PassID, std::string &Name,
const IRDataT<DCData> &Before,
- const IRDataT<DCData> &After, Any IR) {
+ const IRDataT<DCData> &After,
+ std::any IR) {
assert(HTML && "Expected outstream to be set");
IRComparer<DCData>(Before, After)
.compare(getModuleForComparison(IR),
@@ -2152,7 +2146,7 @@ void PrintCrashIRInstrumentation::registerCallbacks(
CrashReporter = this;
PIC.registerBeforeNonSkippedPassCallback([&PIC, this](StringRef PassID,
- Any IR) {
+ std::any IR) {
SavedIR.clear();
raw_string_ostream OS(SavedIR);
OS << formatv("*** Dump of {0}IR Before Last Pass {1}",
diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
index d1edea9cba77..419f763f0ce5 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -87,25 +87,25 @@ bool PseudoProbeVerifier::shouldVerifyFunction(const Function *F) {
void PseudoProbeVerifier::registerCallbacks(PassInstrumentationCallbacks &PIC) {
if (VerifyPseudoProbe) {
PIC.registerAfterPassCallback(
- [this](StringRef P, Any IR, const PreservedAnalyses &) {
+ [this](StringRef P, std::any IR, const PreservedAnalyses &) {
this->runAfterPass(P, IR);
});
}
}
// Callback to run after each transformation for the new pass manager.
-void PseudoProbeVerifier::runAfterPass(StringRef PassID, Any IR) {
+void PseudoProbeVerifier::runAfterPass(StringRef PassID, std::any IR) {
std::string Banner =
"\n*** Pseudo Probe Verification After " + PassID.str() + " ***\n";
dbgs() << Banner;
- if (any_isa<const Module *>(IR))
- runAfterPass(any_cast<const Module *>(IR));
- else if (any_isa<const Function *>(IR))
- runAfterPass(any_cast<const Function *>(IR));
- else if (any_isa<const LazyCallGraph::SCC *>(IR))
- runAfterPass(any_cast<const LazyCallGraph::SCC *>(IR));
- else if (any_isa<const Loop *>(IR))
- runAfterPass(any_cast<const Loop *>(IR));
+ if (const auto **M = std::any_cast<const Module *>(&IR))
+ runAfterPass(*M);
+ else if (const auto **F = std::any_cast<const Function *>(&IR))
+ runAfterPass(*F);
+ else if (const auto **C = std::any_cast<const LazyCallGraph::SCC *>(&IR))
+ runAfterPass(*C);
+ else if (const auto **L = std::any_cast<const Loop *>(&IR))
+ runAfterPass(*L);
else
llvm_unreachable("Unknown IR unit");
}
diff --git a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
index e701ce560a1a..f9c87c18f2f6 100644
--- a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp
@@ -265,13 +265,14 @@ PreservedAnalyses FunctionToLoopPassAdaptor::run(Function &F,
}
#ifndef NDEBUG
- PI.pushBeforeNonSkippedPassCallback([&LAR, &LI](StringRef PassID, Any IR) {
+ PI.pushBeforeNonSkippedPassCallback([&LAR, &LI](StringRef PassID, std::any IR) {
if (isSpecialPass(PassID, {"PassManager"}))
return;
- assert(any_isa<const Loop *>(IR) || any_isa<const LoopNest *>(IR));
- const Loop *L = any_isa<const Loop *>(IR)
- ? any_cast<const Loop *>(IR)
- : &any_cast<const LoopNest *>(IR)->getOutermostLoop();
+ assert(std::any_cast<const Loop *>(&IR) || std::any_cast<const LoopNest *>(&IR));
+ const Loop **LPtr = std::any_cast<const Loop *>(&IR);
+ const Loop *L = LPtr ? *LPtr : nullptr;
+ if (!L)
+ L = &std::any_cast<const LoopNest *>(IR)->getOutermostLoop();
assert(L && "Loop should be valid for printing");
// Verify the loop structure and LCSSA form before visiting the loop.
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index f4d9bce72dc3..0baae37a660f 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -29,6 +29,8 @@
#include "llvm/Support/JSON.h"
#include <optional>
+#include <any>
+
#define DEBUG_TYPE "debugify"
using namespace llvm;
@@ -1028,22 +1030,22 @@ static bool isIgnoredPass(StringRef PassID) {
void DebugifyEachInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
- PIC.registerBeforeNonSkippedPassCallback([this](StringRef P, Any IR) {
+ PIC.registerBeforeNonSkippedPassCallback([this](StringRef P, std::any IR) {
if (isIgnoredPass(P))
return;
- if (any_isa<const Function *>(IR))
- applyDebugify(*const_cast<Function *>(any_cast<const Function *>(IR)),
+ if (const auto **F = std::any_cast<const Function *>(&IR))
+ applyDebugify(*const_cast<Function *>(*F),
Mode, DebugInfoBeforePass, P);
- else if (any_isa<const Module *>(IR))
- applyDebugify(*const_cast<Module *>(any_cast<const Module *>(IR)),
+ else if (const auto **M = std::any_cast<const Module *>(&IR))
+ applyDebugify(*const_cast<Module *>(*M),
Mode, DebugInfoBeforePass, P);
});
- PIC.registerAfterPassCallback([this](StringRef P, Any IR,
+ PIC.registerAfterPassCallback([this](StringRef P, std::any IR,
const PreservedAnalyses &PassPA) {
if (isIgnoredPass(P))
return;
- if (any_isa<const Function *>(IR)) {
- auto &F = *const_cast<Function *>(any_cast<const Function *>(IR));
+ if (const auto **CF = std::any_cast<const Function *>(&IR)) {
+ auto &F = *const_cast<Function *>(*CF);
Module &M = *F.getParent();
auto It = F.getIterator();
if (Mode == DebugifyMode::SyntheticDebugInfo)
@@ -1054,8 +1056,8 @@ void DebugifyEachInstrumentation::registerCallbacks(
M, make_range(It, std::next(It)), *DebugInfoBeforePass,
"CheckModuleDebugify (original debuginfo)",
P, OrigDIVerifyBugsReportFilePath);
- } else if (any_isa<const Module *>(IR)) {
- auto &M = *const_cast<Module *>(any_cast<const Module *>(IR));
+ } else if (const auto **CM = std::any_cast<const Module *>(&IR)) {
+ auto &M = *const_cast<Module *>(*CM);
if (Mode == DebugifyMode::SyntheticDebugInfo)
checkDebugifyMetadata(M, M.functions(), P, "CheckModuleDebugify",
/*Strip=*/true, DIStatsMap);
diff --git a/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp b/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp
index 51862393f3fe..4a4ae5fce6c0 100644
--- a/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp
+++ b/llvm/tools/llvm-reduce/deltas/RunIRPasses.cpp
@@ -29,7 +29,7 @@ static void runPasses(Oracle &O, Module &Program) {
PassInstrumentationCallbacks PIC;
PIC.registerShouldRunOptionalPassCallback(
- [&](StringRef, Any) { return !O.shouldKeep(); });
+ [&](StringRef, std::any) { return !O.shouldKeep(); });
PassBuilder PB(nullptr, PipelineTuningOptions(), std::nullopt, &PIC);
PB.registerModuleAnalyses(MAM);
diff --git a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
index c5947cfc381b..441867d02f37 100644
--- a/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
+++ b/llvm/unittests/IR/PassBuilderCallbacksTest.cpp
@@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//
#include "llvm/Testing/Support/Error.h"
+#include <any>
#include <functional>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include <llvm/ADT/Any.h>
#include <llvm/Analysis/CGSCCPassManager.h>
#include <llvm/Analysis/LoopAnalysisManager.h>
#include <llvm/AsmParser/Parser.h>
@@ -281,7 +281,7 @@ static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
}
/// Helper for HasName matcher that returns getName both for IRUnit and
-/// for IRUnit pointer wrapper into llvm::Any (wrapped by PassInstrumentation).
+/// for IRUnit pointer wrapper into std::any (wrapped by PassInstrumentation).
template <typename IRUnitT> std::string getName(const IRUnitT &IR) {
return std::string(IR.getName());
}
@@ -290,17 +290,17 @@ template <> std::string getName(const StringRef &name) {
return std::string(name);
}
-template <> std::string getName(const llvm::Any &WrappedIR) {
- if (any_isa<const Module *>(WrappedIR))
- return any_cast<const Module *>(WrappedIR)->getName().str();
- if (any_isa<const Function *>(WrappedIR))
- return any_cast<const Function *>(WrappedIR)->getName().str();
- if (any_isa<const Loop *>(WrappedIR))
- return any_cast<const Loop *>(WrappedIR)->getName().str();
- if (any_isa<const LoopNest *>(WrappedIR))
- return any_cast<const LoopNest *>(WrappedIR)->getName().str();
- if (any_isa<const LazyCallGraph::SCC *>(WrappedIR))
- return any_cast<const LazyCallGraph::SCC *>(WrappedIR)->getName();
+template <> std::string getName(const std::any &WrappedIR) {
+ if (const auto *const *M = std::any_cast<const Module *>(&WrappedIR))
+ return (*M)->getName().str();
+ if (const auto *const *F = std::any_cast<const Function *>(&WrappedIR))
+ return (*F)->getName().str();
+ if (const auto *const *L = std::any_cast<const Loop *>(&WrappedIR))
+ return (*L)->getName().str();
+ if (const auto *const *L = std::any_cast<const LoopNest *>(&WrappedIR))
+ return (*L)->getName().str();
+ if (const auto *const *C = std::any_cast<const LazyCallGraph::SCC *>(&WrappedIR))
+ return (*C)->getName();
return "<UNKNOWN>";
}
/// Define a custom matcher for objects which support a 'getName' method.
@@ -334,42 +334,42 @@ struct MockPassInstrumentationCallbacks {
MockPassInstrumentationCallbacks() {
ON_CALL(*this, runBeforePass(_, _)).WillByDefault(Return(true));
}
- MOCK_METHOD2(runBeforePass, bool(StringRef PassID, llvm::Any));
- MOCK_METHOD2(runBeforeSkippedPass, void(StringRef PassID, llvm::Any));
- MOCK_METHOD2(runBeforeNonSkippedPass, void(StringRef PassID, llvm::Any));
+ MOCK_METHOD2(runBeforePass, bool(StringRef PassID, std::any));
+ MOCK_METHOD2(runBeforeSkippedPass, void(StringRef PassID, std::any));
+ MOCK_METHOD2(runBeforeNonSkippedPass, void(StringRef PassID, std::any));
MOCK_METHOD3(runAfterPass,
- void(StringRef PassID, llvm::Any, const PreservedAnalyses &PA));
+ void(StringRef PassID, std::any, const PreservedAnalyses &PA));
MOCK_METHOD2(runAfterPassInvalidated,
void(StringRef PassID, const PreservedAnalyses &PA));
- MOCK_METHOD2(runBeforeAnalysis, void(StringRef PassID, llvm::Any));
- MOCK_METHOD2(runAfterAnalysis, void(StringRef PassID, llvm::Any));
+ MOCK_METHOD2(runBeforeAnalysis, void(StringRef PassID, std::any));
+ MOCK_METHOD2(runAfterAnalysis, void(StringRef PassID, std::any));
void registerPassInstrumentation() {
Callbacks.registerShouldRunOptionalPassCallback(
- [this](StringRef P, llvm::Any IR) {
+ [this](StringRef P, std::any IR) {
return this->runBeforePass(P, IR);
});
Callbacks.registerBeforeSkippedPassCallback(
- [this](StringRef P, llvm::Any IR) {
+ [this](StringRef P, std::any IR) {
this->runBeforeSkippedPass(P, IR);
});
Callbacks.registerBeforeNonSkippedPassCallback(
- [this](StringRef P, llvm::Any IR) {
+ [this](StringRef P, std::any IR) {
this->runBeforeNonSkippedPass(P, IR);
});
Callbacks.registerAfterPassCallback(
- [this](StringRef P, llvm::Any IR, const PreservedAnalyses &PA) {
+ [this](StringRef P, std::any IR, const PreservedAnalyses &PA) {
this->runAfterPass(P, IR, PA);
});
Callbacks.registerAfterPassInvalidatedCallback(
[this](StringRef P, const PreservedAnalyses &PA) {
this->runAfterPassInvalidated(P, PA);
});
- Callbacks.registerBeforeAnalysisCallback([this](StringRef P, llvm::Any IR) {
+ Callbacks.registerBeforeAnalysisCallback([this](StringRef P, std::any IR) {
return this->runBeforeAnalysis(P, IR);
});
Callbacks.registerAfterAnalysisCallback(
- [this](StringRef P, llvm::Any IR) { this->runAfterAnalysis(P, IR); });
+ [this](StringRef P, std::any IR) { this->runAfterAnalysis(P, IR); });
}
void ignoreNonMockPassInstrumentation(StringRef IRName) {
More information about the llvm-commits
mailing list