Skip to content

Commit e39aee5

Browse files
committed
[llvm] Support llvm::Any across shared libraries on windows in a limited form
Explicitly import and export Any::TypeId template instantiations for uses of llvm::Any in the LLVM codebase to support LLVM Windows shared library builds. This change is required to allow external code to use PassManager callbacks including LLVM's own tests for it. Remove the only use of llvm::Any for LoopNest that only existed in debug code and there was no code creating Any<LoopNest>
1 parent 39ac8b2 commit e39aee5

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

llvm/include/llvm/Analysis/LazyCallGraph.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#ifndef LLVM_ANALYSIS_LAZYCALLGRAPH_H
3535
#define LLVM_ANALYSIS_LAZYCALLGRAPH_H
3636

37+
#include "llvm/ADT/Any.h"
3738
#include "llvm/ADT/ArrayRef.h"
3839
#include "llvm/ADT/DenseMap.h"
3940
#include "llvm/ADT/PointerIntPair.h"
@@ -1308,6 +1309,10 @@ class LazyCallGraphDOTPrinterPass
13081309
static bool isRequired() { return true; }
13091310
};
13101311

1312+
#ifdef _WIN32
1313+
extern template struct LLVM_TEMPLATE_ABI
1314+
Any::TypeId<const LazyCallGraph::SCC *>;
1315+
#endif
13111316
} // end namespace llvm
13121317

13131318
#endif // LLVM_ANALYSIS_LAZYCALLGRAPH_H

llvm/include/llvm/IR/PassInstrumentation.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,27 @@
5050
#define LLVM_IR_PASSINSTRUMENTATION_H
5151

5252
#include "llvm/ADT/Any.h"
53+
#include "llvm/ADT/DenseMap.h"
5354
#include "llvm/ADT/FunctionExtras.h"
5455
#include "llvm/ADT/SmallVector.h"
55-
#include "llvm/ADT/DenseMap.h"
5656
#include "llvm/IR/PassManager.h"
57+
#include "llvm/Support/Compiler.h"
5758
#include <type_traits>
5859
#include <vector>
5960

6061
namespace llvm {
6162

6263
class PreservedAnalyses;
6364
class StringRef;
65+
class Module;
66+
class Loop;
67+
class Function;
68+
69+
#ifdef _WIN32
70+
extern template struct LLVM_TEMPLATE_ABI Any::TypeId<const Module *>;
71+
extern template struct LLVM_TEMPLATE_ABI Any::TypeId<const Function *>;
72+
extern template struct LLVM_TEMPLATE_ABI Any::TypeId<const Loop *>;
73+
#endif
6474

6575
/// This class manages callbacks registration, as well as provides a way for
6676
/// PassInstrumentation to pass control to the registered callbacks.

llvm/lib/Analysis/LazyCallGraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ using namespace llvm;
3737

3838
#define DEBUG_TYPE "lcg"
3939

40+
#ifdef _WIN32
41+
template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const LazyCallGraph::SCC *>;
42+
#endif
43+
4044
void LazyCallGraph::EdgeSequence::insertEdgeInternal(Node &TargetN,
4145
Edge::Kind EK) {
4246
EdgeIndexMap.try_emplace(&TargetN, Edges.size());

llvm/lib/IR/PassInstrumentation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
namespace llvm {
1919

20+
#ifdef _WIN32
21+
template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Module *>;
22+
template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Function *>;
23+
template struct LLVM_EXPORT_TEMPLATE Any::TypeId<const Loop *>;
24+
#endif
25+
2026
void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName,
2127
StringRef PassName) {
2228
ClassToPassName.try_emplace(ClassName, PassName.str());

llvm/lib/Transforms/Scalar/LoopPassManager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ PreservedAnalyses FunctionToLoopPassAdaptor::run(Function &F,
273273
llvm::any_cast<const LoopNest *>(&IR));
274274
const Loop **LPtr = llvm::any_cast<const Loop *>(&IR);
275275
const Loop *L = LPtr ? *LPtr : nullptr;
276-
if (!L)
277-
L = &llvm::any_cast<const LoopNest *>(IR)->getOutermostLoop();
278276
assert(L && "Loop should be valid for printing");
279277

280278
// Verify the loop structure and LCSSA form before visiting the loop.

llvm/unittests/IR/PassBuilderCallbacksTest.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ template <> std::string getName(const Any &WrappedIR) {
298298
return (*F)->getName().str();
299299
if (const auto *const *L = llvm::any_cast<const Loop *>(&WrappedIR))
300300
return (*L)->getName().str();
301-
if (const auto *const *L = llvm::any_cast<const LoopNest *>(&WrappedIR))
302-
return (*L)->getName().str();
303301
if (const auto *const *C =
304302
llvm::any_cast<const LazyCallGraph::SCC *>(&WrappedIR))
305303
return (*C)->getName();

0 commit comments

Comments
 (0)