Skip to content

Commit

Permalink
[LLVM][PM] Make LowerPTLS NewPM compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Feb 20, 2022
1 parent 7ad142b commit b0a3130
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,10 @@ static void registerCallbacks(PassBuilder &PB) {
PM.addPass(MultiVersioning());
return true;
}
if (Name == "LowerPTLS") {
PM.addPass(LowerPTLSPass());
return true;
}
return false;
});

Expand Down
35 changes: 27 additions & 8 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "llvm-version.h"
#include "support/dtypes.h"
#include "passes.h"

#include <llvm-c/Core.h>
#include <llvm-c/Types.h>
Expand Down Expand Up @@ -34,13 +35,12 @@ typedef Instruction TerminatorInst;

namespace {

struct LowerPTLS: public ModulePass {
static char ID;
struct LowerPTLS {
LowerPTLS(bool imaging_mode=false)
: ModulePass(ID),
imaging_mode(imaging_mode)
: imaging_mode(imaging_mode)
{}

bool runOnModule(Module &M);
private:
const bool imaging_mode;
Module *M;
Expand All @@ -62,7 +62,6 @@ struct LowerPTLS: public ModulePass {
template<typename T> T *add_comdat(T *G) const;
GlobalVariable *create_aliased_global(Type *T, StringRef name) const;
void fix_pgcstack_use(CallInst *pgcstack);
bool runOnModule(Module &M) override;
};

void LowerPTLS::set_pgcstack_attrs(CallInst *pgcstack) const
Expand Down Expand Up @@ -291,17 +290,37 @@ bool LowerPTLS::runOnModule(Module &_M)
return true;
}

char LowerPTLS::ID = 0;
struct LowerPTLSLegacy: public ModulePass {
static char ID;
LowerPTLSLegacy(bool imaging_mode=false)
: ModulePass(ID),
imaging_mode(imaging_mode)
{}

static RegisterPass<LowerPTLS> X("LowerPTLS", "LowerPTLS Pass",
bool imaging_mode;
bool runOnModule(Module &M) override {
LowerPTLS lower(imaging_mode);
return lower.runOnModule(M);
}
};

char LowerPTLSLegacy::ID = 0;

static RegisterPass<LowerPTLSLegacy> X("LowerPTLS", "LowerPTLS Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);

} // anonymous namespace

PreservedAnalyses LowerPTLSPass::run(Module &M, ModuleAnalysisManager &AM) {
LowerPTLS lower(imaging_mode);
lower.runOnModule(M);
return PreservedAnalyses::all();
}

Pass *createLowerPTLSPass(bool imaging_mode)
{
return new LowerPTLS(imaging_mode);
return new LowerPTLSLegacy(imaging_mode);
}

extern "C" JL_DLLEXPORT void LLVMExtraAddLowerPTLSPass_impl(LLVMPassManagerRef PM, LLVMBool imaging_mode)
Expand Down
9 changes: 8 additions & 1 deletion src/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct RemoveJuliaAddrspacesPass : PassInfoMixin<RemoveJuliaAddrspacesPass> {
};

struct RemoveAddrspacesPass : PassInfoMixin<RemoveAddrspacesPass> {

std::function<unsigned(unsigned)> ASRemapper;
RemoveAddrspacesPass();
RemoveAddrspacesPass(std::function<unsigned(unsigned)> ASRemapper) : ASRemapper(std::move(ASRemapper)) {}
Expand All @@ -84,6 +83,14 @@ struct RemoveAddrspacesPass : PassInfoMixin<RemoveAddrspacesPass> {
static bool isRequired() { return true; }
};

struct LowerPTLSPass : PassInfoMixin<LowerPTLSPass> {
bool imaging_mode;
LowerPTLSPass(bool imaging_mode=false) : imaging_mode(imaging_mode) {}

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
static bool isRequired() { return true; }
};

// Loop Passes
struct JuliaLICMPass : PassInfoMixin<JuliaLICMPass> {
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
Expand Down

0 comments on commit b0a3130

Please sign in to comment.