@@ -2190,23 +2190,22 @@ void jl_dump_native_impl(void *native_code,
2190
2190
}
2191
2191
}
2192
2192
2193
-
2194
2193
// sometimes in GDB you want to find out what code would be created from a mi
2195
- extern " C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode (jl_method_instance_t *mi)
2194
+ extern " C" JL_DLLEXPORT_CODEGEN jl_code_instance_t *jl_gdbdumpcode (jl_method_instance_t *mi)
2196
2195
{
2197
2196
jl_llvmf_dump_t llvmf_dump;
2198
2197
size_t world = jl_current_task->world_age ;
2199
2198
JL_STREAM *stream = (JL_STREAM*)STDERR_FILENO;
2200
2199
2201
- jl_code_info_t *src = jl_gdbcodetyped1 (mi, world);
2202
- JL_GC_PUSH1 (&src );
2200
+ jl_code_instance_t *ci = jl_type_infer (mi, world, SOURCE_MODE_FORCE_SOURCE );
2201
+ JL_GC_PUSH1 (&ci );
2203
2202
2204
2203
jl_printf (stream, " ---- dumping IR for ----\n " );
2205
2204
jl_static_show (stream, (jl_value_t *)mi);
2206
2205
jl_printf (stream, " \n ----\n " );
2207
2206
2208
2207
jl_printf (stream, " \n ---- unoptimized IR ----\n " );
2209
- jl_get_llvmf_defn (&llvmf_dump, mi, src , 0 , false , jl_default_cgparams);
2208
+ jl_get_llvmf_defn (&llvmf_dump, ci, NULL , 0 , false , jl_default_cgparams);
2210
2209
if (llvmf_dump.F ) {
2211
2210
jl_value_t *ir = jl_dump_function_ir (&llvmf_dump, 0 , 1 , " source" );
2212
2211
if (ir != NULL && jl_is_string (ir))
@@ -2215,7 +2214,7 @@ extern "C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode(jl_method_instanc
2215
2214
jl_printf (stream, " \n ----\n " );
2216
2215
2217
2216
jl_printf (stream, " \n ---- optimized IR ----\n " );
2218
- jl_get_llvmf_defn (&llvmf_dump, mi, src , 0 , true , jl_default_cgparams);
2217
+ jl_get_llvmf_defn (&llvmf_dump, ci, NULL , 0 , true , jl_default_cgparams);
2219
2218
if (llvmf_dump.F ) {
2220
2219
jl_value_t *ir = jl_dump_function_ir (&llvmf_dump, 0 , 1 , " source" );
2221
2220
if (ir != NULL && jl_is_string (ir))
@@ -2224,7 +2223,7 @@ extern "C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode(jl_method_instanc
2224
2223
jl_printf (stream, " \n ----\n " );
2225
2224
2226
2225
jl_printf (stream, " \n ---- assembly ----\n " );
2227
- jl_get_llvmf_defn (&llvmf_dump, mi, src , 0 , true , jl_default_cgparams);
2226
+ jl_get_llvmf_defn (&llvmf_dump, ci, NULL , 0 , true , jl_default_cgparams);
2228
2227
if (llvmf_dump.F ) {
2229
2228
jl_value_t *ir = jl_dump_function_asm (&llvmf_dump, 0 , " " , " source" , 0 , true );
2230
2229
if (ir != NULL && jl_is_string (ir))
@@ -2233,92 +2232,90 @@ extern "C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode(jl_method_instanc
2233
2232
jl_printf (stream, " \n ----\n " );
2234
2233
JL_GC_POP ();
2235
2234
2236
- return src ;
2235
+ return ci ;
2237
2236
}
2238
2237
2239
2238
// --- native code info, and dump function to IR and ASM ---
2240
2239
// Get pointer to llvm::Function instance, compiling if necessary
2241
2240
// for use in reflection from Julia.
2242
2241
// This is paired with jl_dump_function_ir and jl_dump_function_asm, either of which will free all memory allocated here
2243
2242
extern " C" JL_DLLEXPORT_CODEGEN
2244
- void jl_get_llvmf_defn_impl (jl_llvmf_dump_t * dump, jl_method_instance_t *mi , jl_code_info_t *src, char getwrapper, char optimize, const jl_cgparams_t params)
2243
+ void jl_get_llvmf_defn_impl (jl_llvmf_dump_t * dump, jl_code_instance_t *ci , jl_code_info_t *src, char getwrapper, char optimize, const jl_cgparams_t params)
2245
2244
{
2246
2245
// emit this function into a new llvm module
2247
2246
dump->F = nullptr ;
2248
2247
dump->TSM = nullptr ;
2249
- if (src && jl_is_code_info (src)) {
2250
- auto ctx = jl_ExecutionEngine->makeContext ();
2251
- orc::ThreadSafeModule m = jl_create_ts_module (name_from_method_instance (mi), ctx);
2252
- uint64_t compiler_start_time = 0 ;
2253
- uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
2254
- if (measure_compile_time_enabled)
2255
- compiler_start_time = jl_hrtime ();
2256
- auto target_info = m.withModuleDo ([&](Module &M) {
2257
- return std::make_pair (M.getDataLayout (), Triple (M.getTargetTriple ()));
2258
- });
2259
- jl_codegen_params_t output (ctx, std::move (target_info.first ), std::move (target_info.second ));
2260
- output.params = ¶ms;
2261
- output.imaging_mode = imaging_default ();
2262
- // This would be nice, but currently it causes some assembly regressions that make printed output
2263
- // differ very significantly from the actual non-imaging mode code.
2264
- // // Force imaging mode for names of pointers
2265
- // output.imaging = true;
2266
- // This would also be nice, but it seems to cause OOMs on the windows32 builder
2267
- // To get correct names in the IR this needs to be at least 2
2268
- output.temporary_roots = jl_alloc_array_1d (jl_array_any_type, 0 );
2269
- JL_GC_PUSH1 (&output.temporary_roots );
2270
- auto decls = jl_emit_code (m, mi, src, NULL , output);
2271
- output.temporary_roots = nullptr ;
2272
- JL_GC_POP (); // GC the global_targets array contents now since reflection doesn't need it
2273
-
2274
- Function *F = NULL ;
2275
- if (m) {
2276
- // if compilation succeeded, prepare to return the result
2277
- // Similar to jl_link_global from jitlayers.cpp,
2278
- // so that code_llvm shows similar codegen to the jit
2279
- for (auto &global : output.global_targets ) {
2280
- if (jl_options.image_codegen ) {
2281
- global.second ->setLinkage (GlobalValue::ExternalLinkage);
2282
- }
2283
- else {
2284
- auto p = literal_static_pointer_val (global.first , global.second ->getValueType ());
2285
- Type *elty = PointerType::get (output.getContext (), 0 );
2286
- // For pretty printing, when LLVM inlines the global initializer into its loads
2287
- auto alias = GlobalAlias::create (elty, 0 , GlobalValue::PrivateLinkage, global.second ->getName () + " .jit" , p, global.second ->getParent ());
2288
- global.second ->setInitializer (ConstantExpr::getBitCast (alias, global.second ->getValueType ()));
2289
- global.second ->setConstant (true );
2290
- global.second ->setLinkage (GlobalValue::PrivateLinkage);
2291
- global.second ->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
2292
- global.second ->setVisibility (GlobalValue::DefaultVisibility);
2293
- }
2294
- }
2295
- if (!jl_options.image_codegen ) {
2296
- optimizeDLSyms (*m.getModuleUnlocked ());
2248
+ auto ctx = jl_ExecutionEngine->makeContext ();
2249
+ orc::ThreadSafeModule m = jl_create_ts_module (name_from_method_instance (jl_get_ci_mi (ci)), ctx);
2250
+ uint64_t compiler_start_time = 0 ;
2251
+ uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed (&jl_measure_compile_time_enabled);
2252
+ if (measure_compile_time_enabled)
2253
+ compiler_start_time = jl_hrtime ();
2254
+ auto target_info = m.withModuleDo ([&](Module &M) {
2255
+ return std::make_pair (M.getDataLayout (), Triple (M.getTargetTriple ()));
2256
+ });
2257
+ jl_codegen_params_t output (ctx, std::move (target_info.first ), std::move (target_info.second ));
2258
+ output.params = ¶ms;
2259
+ output.imaging_mode = imaging_default ();
2260
+ // This would be nice, but currently it causes some assembly regressions that make printed output
2261
+ // differ very significantly from the actual non-imaging mode code.
2262
+ // // Force imaging mode for names of pointers
2263
+ // output.imaging = true;
2264
+ // This would also be nice, but it seems to cause OOMs on the windows32 builder
2265
+ // To get correct names in the IR this needs to be at least 2
2266
+ output.temporary_roots = jl_alloc_array_1d (jl_array_any_type, 0 );
2267
+ JL_GC_PUSH1 (&output.temporary_roots );
2268
+ auto decls = jl_emit_codeinst (m, ci, src, output);
2269
+ output.temporary_roots = nullptr ;
2270
+ JL_GC_POP (); // GC the global_targets array contents now since reflection doesn't need it
2271
+
2272
+ Function *F = NULL ;
2273
+ if (m) {
2274
+ // if compilation succeeded, prepare to return the result
2275
+ // Similar to jl_link_global from jitlayers.cpp,
2276
+ // so that code_llvm shows similar codegen to the jit
2277
+ for (auto &global : output.global_targets ) {
2278
+ if (jl_options.image_codegen ) {
2279
+ global.second ->setLinkage (GlobalValue::ExternalLinkage);
2297
2280
}
2298
- assert (!verifyLLVMIR (*m.getModuleUnlocked ()));
2299
- if (optimize) {
2300
- NewPM PM{jl_ExecutionEngine->cloneTargetMachine (), getOptLevel (jl_options.opt_level )};
2301
- // Safe b/c context lock is held by output
2302
- PM.run (*m.getModuleUnlocked ());
2303
- assert (!verifyLLVMIR (*m.getModuleUnlocked ()));
2281
+ else {
2282
+ auto p = literal_static_pointer_val (global.first , global.second ->getValueType ());
2283
+ Type *elty = PointerType::get (output.getContext (), 0 );
2284
+ // For pretty printing, when LLVM inlines the global initializer into its loads
2285
+ auto alias = GlobalAlias::create (elty, 0 , GlobalValue::PrivateLinkage, global.second ->getName () + " .jit" , p, global.second ->getParent ());
2286
+ global.second ->setInitializer (ConstantExpr::getBitCast (alias, global.second ->getValueType ()));
2287
+ global.second ->setConstant (true );
2288
+ global.second ->setLinkage (GlobalValue::PrivateLinkage);
2289
+ global.second ->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
2290
+ global.second ->setVisibility (GlobalValue::DefaultVisibility);
2304
2291
}
2305
- const std::string *fname;
2306
- if (decls.functionObject == " jl_fptr_args" || decls.functionObject == " jl_fptr_sparam" )
2307
- getwrapper = false ;
2308
- if (!getwrapper)
2309
- fname = &decls.specFunctionObject ;
2310
- else
2311
- fname = &decls.functionObject ;
2312
- F = cast<Function>(m.getModuleUnlocked ()->getNamedValue (*fname));
2313
2292
}
2314
- if (measure_compile_time_enabled) {
2315
- auto end = jl_hrtime ();
2316
- jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, end - compiler_start_time);
2293
+ if (!jl_options.image_codegen ) {
2294
+ optimizeDLSyms (*m.getModuleUnlocked ());
2317
2295
}
2318
- if (F) {
2319
- dump->TSM = wrap (new orc::ThreadSafeModule (std::move (m)));
2320
- dump->F = wrap (F);
2321
- return ;
2296
+ assert (!verifyLLVMIR (*m.getModuleUnlocked ()));
2297
+ if (optimize) {
2298
+ NewPM PM{jl_ExecutionEngine->cloneTargetMachine (), getOptLevel (jl_options.opt_level )};
2299
+ // Safe b/c context lock is held by output
2300
+ PM.run (*m.getModuleUnlocked ());
2301
+ assert (!verifyLLVMIR (*m.getModuleUnlocked ()));
2322
2302
}
2303
+ const std::string *fname;
2304
+ if (decls.functionObject == " jl_fptr_args" || decls.functionObject == " jl_fptr_sparam" )
2305
+ getwrapper = false ;
2306
+ if (!getwrapper)
2307
+ fname = &decls.specFunctionObject ;
2308
+ else
2309
+ fname = &decls.functionObject ;
2310
+ F = cast<Function>(m.getModuleUnlocked ()->getNamedValue (*fname));
2311
+ }
2312
+ if (measure_compile_time_enabled) {
2313
+ auto end = jl_hrtime ();
2314
+ jl_atomic_fetch_add_relaxed (&jl_cumulative_compile_time, end - compiler_start_time);
2315
+ }
2316
+ if (F) {
2317
+ dump->TSM = wrap (new orc::ThreadSafeModule (std::move (m)));
2318
+ dump->F = wrap (F);
2319
+ return ;
2323
2320
}
2324
2321
}
0 commit comments