forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm-remove-ni.cpp
56 lines (45 loc) · 1.22 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
// This file is a part of Julia. License is MIT: https://julialang.org/license
#include "llvm-version.h"
#include <llvm/IR/Module.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Support/Debug.h>
#include "julia.h"
#define DEBUG_TYPE "remove_ni"
using namespace llvm;
namespace {
struct RemoveNIPass : public ModulePass {
static char ID;
RemoveNIPass() : 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;
}
};
char RemoveNIPass::ID = 0;
static RegisterPass<RemoveNIPass>
Y("RemoveNI",
"Remove non-integral address space.",
false,
false);
}
Pass *createRemoveNIPass()
{
return new RemoveNIPass();
}
extern "C" JL_DLLEXPORT void LLVMExtraAddRemoveNIPass(LLVMPassManagerRef PM)
{
unwrap(PM)->add(createRemoveNIPass());
}