forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathllvm-remove-ni.cpp
74 lines (61 loc) · 1.53 KB
/
llvm-remove-ni.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// This file is a part of Julia. License is MIT: https://julialang.org/license
#include "llvm-version.h"
#include "passes.h"
#include <llvm/Pass.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Support/Debug.h>
#include "julia.h"
#define DEBUG_TYPE "remove_ni"
using namespace llvm;
namespace {
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;
}
}
PreservedAnalyses RemoveNI::run(Module &M, ModuleAnalysisManager &AM)
{
if (removeNI(M)) {
return PreservedAnalyses::allInSet<CFGAnalyses>();
}
return PreservedAnalyses::all();
}
namespace {
struct RemoveNILegacy : public ModulePass {
static char ID;
RemoveNILegacy() : ModulePass(ID) {};
bool runOnModule(Module &M)
{
return removeNI(M);
}
};
char RemoveNILegacy::ID = 0;
static RegisterPass<RemoveNILegacy>
Y("RemoveNI",
"Remove non-integral address space.",
false,
false);
}
Pass *createRemoveNIPass()
{
return new RemoveNILegacy();
}
extern "C" JL_DLLEXPORT void LLVMExtraAddRemoveNIPass_impl(LLVMPassManagerRef PM)
{
unwrap(PM)->add(createRemoveNIPass());
}