Skip to content

Commit 235784a

Browse files
authored
Remove non-integral pointer from data layout before codegen (#36705)
This allows LLVM codegen passes to insert `inttoptr` and `ptrtoint` as it wish, and avoids hitting any illegal ones in those passes. Fix #36062
1 parent b7af3a1 commit 235784a

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ SRCS += codegen llvm-ptls
5555
RUNTIME_SRCS += jitlayers aotcompile debuginfo disasm llvm-simdloop llvm-muladd \
5656
llvm-final-gc-lowering llvm-pass-helpers llvm-late-gc-lowering \
5757
llvm-lower-handlers llvm-gc-invariant-verifier llvm-propagate-addrspaces \
58-
llvm-multiversioning llvm-alloc-opt cgmemmgr llvm-api llvm-remove-addrspaces
58+
llvm-multiversioning llvm-alloc-opt cgmemmgr llvm-api llvm-remove-addrspaces \
59+
llvm-remove-ni
5960
FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --includedir)
6061
LLVM_LIBS := all
6162
ifeq ($(USE_POLLY),1)

src/aotcompile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
632632
PM->add(createFinalLowerGCPass());
633633
PM->add(createLowerPTLSPass(dump_native));
634634
}
635+
PM->add(createRemoveNIPass());
635636
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
636637
if (dump_native)
637638
PM->add(createMultiVersioningPass());
@@ -754,6 +755,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
754755
// Clean up write barrier and ptls lowering
755756
PM->add(createCFGSimplificationPass());
756757
}
758+
PM->add(createRemoveNIPass());
757759
PM->add(createCombineMulAddPass());
758760
PM->add(createDivRemPairsPass());
759761
#if defined(JL_ASAN_ENABLED)

src/jitlayers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Pass *createLowerExcHandlersPass();
237237
Pass *createGCInvariantVerifierPass(bool Strong);
238238
Pass *createPropagateJuliaAddrspaces();
239239
Pass *createRemoveJuliaAddrspacesPass();
240+
Pass *createRemoveNIPass();
240241
Pass *createMultiVersioningPass();
241242
Pass *createAllocOptPass();
242243
// Whether the Function is an llvm or julia intrinsic.

src/llvm-remove-ni.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
#include "llvm-version.h"
4+
5+
#include <llvm/IR/Module.h>
6+
#include <llvm/IR/LegacyPassManager.h>
7+
#include <llvm/Support/Debug.h>
8+
9+
#define DEBUG_TYPE "remove_ni"
10+
11+
using namespace llvm;
12+
13+
namespace {
14+
15+
struct RemoveNIPass : public ModulePass {
16+
static char ID;
17+
RemoveNIPass() : ModulePass(ID) {};
18+
19+
bool runOnModule(Module &M)
20+
{
21+
auto dlstr = M.getDataLayoutStr();
22+
auto nistart = dlstr.find("-ni:");
23+
if (nistart == std::string::npos)
24+
return false;
25+
auto len = dlstr.size();
26+
auto niend = nistart + 1;
27+
for (; niend < len; niend++) {
28+
if (dlstr[niend] == '-') {
29+
break;
30+
}
31+
}
32+
dlstr.erase(nistart, niend - nistart);
33+
M.setDataLayout(dlstr);
34+
return true;
35+
}
36+
};
37+
38+
char RemoveNIPass::ID = 0;
39+
static RegisterPass<RemoveNIPass>
40+
Y("RemoveNI",
41+
"Remove non-integral address space.",
42+
false,
43+
false);
44+
}
45+
46+
Pass *createRemoveNIPass()
47+
{
48+
return new RemoveNIPass();
49+
}

0 commit comments

Comments
 (0)