Skip to content

Commit 00c41cc

Browse files
authored
Remove address spaces during IR printing. (#36358)
Respect the strip_ir_metadata/raw flags.
1 parent 4db59da commit 00c41cc

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/aotcompile.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,6 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper,
825825
PM = new legacy::PassManager();
826826
addTargetPasses(PM, jl_TargetMachine);
827827
addOptimizationPasses(PM, jl_options.opt_level);
828-
PM->add(createRemoveJuliaAddrspacesPass());
829-
}
830-
831-
static legacy::PassManager *PM_minimal;
832-
if (!PM_minimal) {
833-
PM_minimal = new legacy::PassManager();
834-
addTargetPasses(PM_minimal, jl_TargetMachine);
835-
PM_minimal->add(createRemoveJuliaAddrspacesPass());
836828
}
837829

838830
// get the source code for this function
@@ -874,8 +866,6 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper,
874866
// if compilation succeeded, prepare to return the result
875867
if (optimize)
876868
PM->run(*m.get());
877-
else
878-
PM_minimal->run(*m.get());
879869
const std::string *fname;
880870
if (decls.functionObject == "jl_fptr_args" || decls.functionObject == "jl_fptr_sparam")
881871
getwrapper = false;

src/disasm.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@
6363
#include <llvm/IR/Module.h>
6464
#include <llvm/IR/IntrinsicInst.h>
6565
#include "llvm/IR/AssemblyAnnotationWriter.h"
66+
#include "llvm/IR/LegacyPassManager.h"
6667

6768
#include "julia.h"
6869
#include "julia_internal.h"
70+
#include "jitlayers.h"
6971
#include "processor.h"
7072

7173
using namespace llvm;
@@ -431,6 +433,13 @@ void jl_strip_llvm_debug(Module *m)
431433
jl_strip_llvm_debug(m, false, NULL);
432434
}
433435

436+
void jl_strip_llvm_addrspaces(Module *m)
437+
{
438+
legacy::PassManager PM;
439+
PM.add(createRemoveJuliaAddrspacesPass());
440+
PM.run(*m);
441+
}
442+
434443
// print an llvm IR acquired from jl_get_llvmf
435444
// warning: this takes ownership of, and destroys, f->getParent()
436445
extern "C" JL_DLLEXPORT
@@ -452,8 +461,13 @@ jl_value_t *jl_dump_function_ir(void *f, char strip_ir_metadata, char dump_modul
452461
}
453462
else {
454463
Module *m = llvmf->getParent();
455-
if (strip_ir_metadata)
464+
if (strip_ir_metadata) {
465+
std::string llvmfn = llvmf->getName();
456466
jl_strip_llvm_debug(m, true, &AAW);
467+
jl_strip_llvm_addrspaces(m);
468+
// rewriting the function type creates a new function, so look it up again
469+
llvmf = m->getFunction(llvmfn);
470+
}
457471
if (dump_module) {
458472
m->print(stream, &AAW);
459473
}

src/jitlayers.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <llvm/Target/TargetMachine.h>
1818
#include "julia_assert.h"
1919

20+
using namespace llvm;
21+
2022
extern "C" {
2123
extern int globalUnique;
2224
}

0 commit comments

Comments
 (0)