Skip to content

Commit b0a3130

Browse files
committed
[LLVM][PM] Make LowerPTLS NewPM compatible
1 parent 7ad142b commit b0a3130

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

src/aotcompile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,10 @@ static void registerCallbacks(PassBuilder &PB) {
938938
PM.addPass(MultiVersioning());
939939
return true;
940940
}
941+
if (Name == "LowerPTLS") {
942+
PM.addPass(LowerPTLSPass());
943+
return true;
944+
}
941945
return false;
942946
});
943947

src/llvm-ptls.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "llvm-version.h"
99
#include "support/dtypes.h"
10+
#include "passes.h"
1011

1112
#include <llvm-c/Core.h>
1213
#include <llvm-c/Types.h>
@@ -34,13 +35,12 @@ typedef Instruction TerminatorInst;
3435

3536
namespace {
3637

37-
struct LowerPTLS: public ModulePass {
38-
static char ID;
38+
struct LowerPTLS {
3939
LowerPTLS(bool imaging_mode=false)
40-
: ModulePass(ID),
41-
imaging_mode(imaging_mode)
40+
: imaging_mode(imaging_mode)
4241
{}
4342

43+
bool runOnModule(Module &M);
4444
private:
4545
const bool imaging_mode;
4646
Module *M;
@@ -62,7 +62,6 @@ struct LowerPTLS: public ModulePass {
6262
template<typename T> T *add_comdat(T *G) const;
6363
GlobalVariable *create_aliased_global(Type *T, StringRef name) const;
6464
void fix_pgcstack_use(CallInst *pgcstack);
65-
bool runOnModule(Module &M) override;
6665
};
6766

6867
void LowerPTLS::set_pgcstack_attrs(CallInst *pgcstack) const
@@ -291,17 +290,37 @@ bool LowerPTLS::runOnModule(Module &_M)
291290
return true;
292291
}
293292

294-
char LowerPTLS::ID = 0;
293+
struct LowerPTLSLegacy: public ModulePass {
294+
static char ID;
295+
LowerPTLSLegacy(bool imaging_mode=false)
296+
: ModulePass(ID),
297+
imaging_mode(imaging_mode)
298+
{}
295299

296-
static RegisterPass<LowerPTLS> X("LowerPTLS", "LowerPTLS Pass",
300+
bool imaging_mode;
301+
bool runOnModule(Module &M) override {
302+
LowerPTLS lower(imaging_mode);
303+
return lower.runOnModule(M);
304+
}
305+
};
306+
307+
char LowerPTLSLegacy::ID = 0;
308+
309+
static RegisterPass<LowerPTLSLegacy> X("LowerPTLS", "LowerPTLS Pass",
297310
false /* Only looks at CFG */,
298311
false /* Analysis Pass */);
299312

300313
} // anonymous namespace
301314

315+
PreservedAnalyses LowerPTLSPass::run(Module &M, ModuleAnalysisManager &AM) {
316+
LowerPTLS lower(imaging_mode);
317+
lower.runOnModule(M);
318+
return PreservedAnalyses::all();
319+
}
320+
302321
Pass *createLowerPTLSPass(bool imaging_mode)
303322
{
304-
return new LowerPTLS(imaging_mode);
323+
return new LowerPTLSLegacy(imaging_mode);
305324
}
306325

307326
extern "C" JL_DLLEXPORT void LLVMExtraAddLowerPTLSPass_impl(LLVMPassManagerRef PM, LLVMBool imaging_mode)

src/passes.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct RemoveJuliaAddrspacesPass : PassInfoMixin<RemoveJuliaAddrspacesPass> {
7575
};
7676

7777
struct RemoveAddrspacesPass : PassInfoMixin<RemoveAddrspacesPass> {
78-
7978
std::function<unsigned(unsigned)> ASRemapper;
8079
RemoveAddrspacesPass();
8180
RemoveAddrspacesPass(std::function<unsigned(unsigned)> ASRemapper) : ASRemapper(std::move(ASRemapper)) {}
@@ -84,6 +83,14 @@ struct RemoveAddrspacesPass : PassInfoMixin<RemoveAddrspacesPass> {
8483
static bool isRequired() { return true; }
8584
};
8685

86+
struct LowerPTLSPass : PassInfoMixin<LowerPTLSPass> {
87+
bool imaging_mode;
88+
LowerPTLSPass(bool imaging_mode=false) : imaging_mode(imaging_mode) {}
89+
90+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
91+
static bool isRequired() { return true; }
92+
};
93+
8794
// Loop Passes
8895
struct JuliaLICMPass : PassInfoMixin<JuliaLICMPass> {
8996
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,

0 commit comments

Comments
 (0)