Skip to content

Commit

Permalink
[LLVM][PM] Make RemoveNI NewPM compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jul 14, 2021
1 parent 3d5bc0e commit 56888c5
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/llvm-remove-ni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "llvm-version.h"

#include <llvm/IR/Module.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Support/Debug.h>

Expand All @@ -14,31 +15,48 @@ using namespace llvm;

namespace {

struct RemoveNIPass : public ModulePass {
static bool removeNI(Module &M)
{
auto dlstr = M.getDataLayoutStr();
auto nistart = dlstr.find("-ni:");
if (nistart == std::string::npos)
return false;
auto len = dlstr.size();
auto niend = nistart + 1;
for (; niend < len; niend++) {
if (dlstr[niend] == '-') {
break;
}
}
dlstr.erase(nistart, niend - nistart);
M.setDataLayout(dlstr);
return true;
}
}

struct RemoveNI : PassInfoMixin<RemoveNI> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
};

PreservedAnalyses RemoveNI::run(Module &M, ModuleAnalysisManager &AM)
{
removeNI(M);
return PreservedAnalyses::all();
}

namespace {
struct RemoveNILegacy : public ModulePass {
static char ID;
RemoveNIPass() : ModulePass(ID) {};
RemoveNILegacy() : ModulePass(ID) {};

bool runOnModule(Module &M)
{
auto dlstr = M.getDataLayoutStr();
auto nistart = dlstr.find("-ni:");
if (nistart == std::string::npos)
return false;
auto len = dlstr.size();
auto niend = nistart + 1;
for (; niend < len; niend++) {
if (dlstr[niend] == '-') {
break;
}
}
dlstr.erase(nistart, niend - nistart);
M.setDataLayout(dlstr);
return true;
return removeNI(M);
}
};

char RemoveNIPass::ID = 0;
static RegisterPass<RemoveNIPass>
char RemoveNILegacy::ID = 0;
static RegisterPass<RemoveNILegacy>
Y("RemoveNI",
"Remove non-integral address space.",
false,
Expand All @@ -47,7 +65,7 @@ static RegisterPass<RemoveNIPass>

Pass *createRemoveNIPass()
{
return new RemoveNIPass();
return new RemoveNILegacy();
}

extern "C" JL_DLLEXPORT void LLVMExtraAddRemoveNIPass(LLVMPassManagerRef PM)
Expand Down

0 comments on commit 56888c5

Please sign in to comment.