@@ -16,14 +16,14 @@ function find_matching_ci(predicate, mi::MethodInstance, world::UInt)
1616 return nothing
1717end
1818
19- function structural_analysis! (ci:: CodeInstance , world:: UInt )
19+ function structural_analysis! (ci:: CodeInstance , world:: UInt , settings :: Settings )
2020 # Check if we have aleady done this work - if so return the cached result
2121 result_ci = find_matching_ci (ci-> ci. owner == StructureCache (), ci. def, world)
2222 if result_ci != = nothing
2323 return result_ci. inferred
2424 end
2525
26- result = _structural_analysis! (ci, world)
26+ result = _structural_analysis! (ci, world, settings )
2727 # TODO : The world bounds might have been narrowed
2828 cache_dae_ci! (ci, result, nothing , nothing , StructureCache ())
2929
@@ -40,7 +40,7 @@ struct EqVarState
4040 eq_callee_mapping
4141end
4242
43- function _structural_analysis! (ci:: CodeInstance , world:: UInt )
43+ function _structural_analysis! (ci:: CodeInstance , world:: UInt , settings :: Settings )
4444 # Variables
4545 var_to_diff = DiffGraph (0 )
4646 varclassification = VarEqClassification[]
@@ -83,7 +83,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
8383 compact = IncrementalCompact (ir)
8484 old_argtypes = copy (ir. argtypes)
8585 empty! (ir. argtypes)
86- (arg_replacements, new_argtypes, nexternalargvars, nexternaleqs) = flatten_arguments! (compact, old_argtypes, 0 , 0 , ir. argtypes)
86+ (arg_replacements, new_argtypes, nexternalargvars, nexternaleqs) = flatten_arguments! (compact, settings, old_argtypes, 0 , 0 , ir. argtypes)
8787 if nexternalargvars == - 1
8888 return UncompilableIPOResult (warnings, UnsupportedIRException (" Unhandled argument types" , Compiler. finish (compact)))
8989 end
@@ -98,7 +98,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
9898 argtypes = Any[Incidence (new_argtypes[i], i) for i = 1 : nexternalargvars]
9999
100100 # Allocate variable and equation numbers of any incoming arguments
101- refiner = StructuralRefiner (world, var_to_diff, varkinds, varclassification, eqkinds, eqclassification)
101+ refiner = StructuralRefiner (world, settings, var_to_diff, varkinds, varclassification, eqkinds, eqclassification)
102102 nexternalargvars = length (var_to_diff)
103103
104104 # Go through the IR, annotating each intrinsic with an appropriate taint
@@ -337,7 +337,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
337337 if isa (info, MappingInfo)
338338 (; result, mapping) = info
339339 else
340- result = structural_analysis! (callee_codeinst, Compiler. get_inference_world (refiner))
340+ result = structural_analysis! (callee_codeinst, Compiler. get_inference_world (refiner), settings )
341341
342342 if isa (result, UncompilableIPOResult)
343343 # TODO : Stack trace?
@@ -360,9 +360,9 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
360360 # Rewrite to flattened ABI
361361 compact[SSAValue (i)] = nothing
362362 compact. result_idx -= 1
363- new_args = _flatten_parameter! (Compiler. optimizer_lattice (refiner), compact, callee_codeinst. inferred. ir. argtypes, arg-> stmt. args[arg+ 1 ], line)
363+ new_args = _flatten_parameter! (Compiler. optimizer_lattice (refiner), compact, callee_codeinst. inferred. ir. argtypes, arg-> stmt. args[arg+ 1 ], line, settings )
364364
365- new_call = insert_node_here ! (compact,
365+ new_call = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
366366 NewInstruction (Expr (:invoke , (StructuralSSARef (compact. result_idx), callee_codeinst), new_args... ), stmtype, info, line, stmtflags))
367367 compact. ssa_rename[compact. idx - 1 ] = new_call
368368
@@ -386,8 +386,8 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
386386 line = ret_stmt_inst[:line ]
387387 Compiler. delete_inst_here! (compact)
388388
389- (new_ret, ultimate_rt) = rewrite_ipo_return! (Compiler. typeinf_lattice (refiner), compact, line, ret_stmt. val, ultimate_rt, eqvars)
390- insert_node_here ! (compact, NewInstruction (ReturnNode (new_ret), ultimate_rt, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
389+ (new_ret, ultimate_rt) = rewrite_ipo_return! (Compiler. typeinf_lattice (refiner), compact, line, settings, ret_stmt. val, ultimate_rt, eqvars)
390+ insert_instruction_here ! (compact, settings, @__SOURCE__ , NewInstruction (ReturnNode (new_ret), ultimate_rt, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), reverse_affinity = true )
391391 elseif isa (ultimate_rt, Type)
392392 # If we don't have any internal variables (in which case we might have to to do a more aggressive rewrite), strengthen the incidence
393393 # by demoting to full incidence over the argument variables. Incidence is not allowed to propagate through global mutable state, so
@@ -415,7 +415,7 @@ function _structural_analysis!(ci::CodeInstance, world::UInt)
415415 warnings)
416416end
417417
418- function rewrite_ipo_return! (𝕃, compact:: IncrementalCompact , line, ssa, ultimate_rt:: Any , eqvars:: EqVarState )
418+ function rewrite_ipo_return! (𝕃, compact:: IncrementalCompact , line, settings, ssa, ultimate_rt:: Any , eqvars:: EqVarState )
419419 if isa (ultimate_rt, Eq)
420420 return Pair {Any, Any} (ssa, ultimate_rt)
421421 end
@@ -425,22 +425,23 @@ function rewrite_ipo_return!(𝕃, compact::IncrementalCompact, line, ssa, ultim
425425 new_types = Any[]
426426 for i = 1 : length (ultimate_rt. fields)
427427 ssa_type = Compiler. getfield_tfunc (𝕃, ultimate_rt, Const (i))
428- ssa_field = insert_node_here ! (compact,
429- NewInstruction (Expr (:call , getfield, variable), ssa_type, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
428+ ssa_field = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
429+ NewInstruction (Expr (:call , getfield, variable), ssa_type, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), reverse_affinity = true )
430430
431- (new_field, new_type) = rewrite_ipo_return! (𝕃, compact, line, ssa_field, ssa_type, eqvars)
431+ (new_field, new_type) = rewrite_ipo_return! (𝕃, compact, line, settings, ssa_field, ssa_type, eqvars)
432432 push! (new_fields, new_field)
433433 push! (new_types, new_type)
434434 end
435435 newT = Compiler. PartialStruct (ultimate_rt. typ, new_types)
436436 if widenconst (ultimate_rt) <: Tuple
437- retssa = insert_node_here ! (compact,
438- NewInstruction (Expr (:call , tuple, new_fields... ), newT, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
437+ retssa = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
438+ NewInstruction (Expr (:call , tuple, new_fields... ), newT, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), reverse_affinity = true )
439439 else
440- T = insert_node_here! (compact,
441- NewInstruction (Expr (:call , typeof, ssa), Type, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
442- retssa = insert_node_here! (compact,
443- NewInstruction (Expr (:new , T, new_fields... ), newT, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
440+ T = insert_instruction_here! (compact, settings, @__SOURCE__ ,
441+ NewInstruction (Expr (:call , typeof, ssa), Type, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), reverse_affinity = true )
442+
443+ retssa = insert_instruction_here! (compact, settings, @__SOURCE__ ,
444+ NewInstruction (Expr (:new , T, new_fields... ), newT, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), reverse_affinity = true )
444445 end
445446 return Pair {Any, Any} (retssa, newT)
446447 end
@@ -453,8 +454,8 @@ function rewrite_ipo_return!(𝕃, compact::IncrementalCompact, line, ssa, ultim
453454 push! (eqvars. varclassification, External)
454455 push! (eqvars. varkinds, Intrinsics. Continuous)
455456
456- new_var_ssa = insert_node_here ! (compact,
457- NewInstruction (Expr (:invoke , nothing , variable), Incidence (nonlinrepl), Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
457+ new_var_ssa = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
458+ NewInstruction (Expr (:invoke , nothing , variable), Incidence (nonlinrepl), Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED); reverse_affinity = true )
458459
459460 eq_incidence = ultimate_rt - Incidence (nonlinrepl)
460461 push! (eqvars. total_incidence, eq_incidence)
@@ -463,14 +464,14 @@ function rewrite_ipo_return!(𝕃, compact::IncrementalCompact, line, ssa, ultim
463464 push! (eqvars. eqkinds, Intrinsics. Always)
464465 new_eq = length (eqvars. total_incidence)
465466
466- new_eq_ssa = insert_node_here ! (compact,
467- NewInstruction (Expr (:invoke , nothing , equation), Eq (new_eq), Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
467+ new_eq_ssa = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
468+ NewInstruction (Expr (:invoke , nothing , equation), Eq (new_eq), Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED); reverse_affinity = true )
468469
469- eq_val_ssa = insert_node_here ! (compact,
470- NewInstruction (Expr (:call , InternalIntrinsics. assign_var, new_var_ssa, ssa), eq_incidence, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
470+ eq_val_ssa = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
471+ NewInstruction (Expr (:call , InternalIntrinsics. assign_var, new_var_ssa, ssa), eq_incidence, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED); reverse_affinity = true )
471472
472- eq_call_ssa = insert_node_here ! (compact,
473- NewInstruction (Expr (:invoke , nothing , new_eq_ssa, eq_val_ssa), Nothing, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED), true )
473+ eq_call_ssa = insert_instruction_here ! (compact, settings, @__SOURCE__ ,
474+ NewInstruction (Expr (:invoke , nothing , new_eq_ssa, eq_val_ssa), Nothing, Compiler. NoCallInfo (), line, Compiler. IR_FLAG_REFINED); reverse_affinity = true )
474475
475476 T = widenconst (ultimate_rt)
476477 # TODO : We don't have a way to express that the return value is directly this variable for arbitrary types
0 commit comments