@@ -237,6 +237,16 @@ function split_critical_edges!(ir)
237
237
return ir′
238
238
end
239
239
240
+ function make_opaque_closure (typ, name, meth_nargs, isva, lno, cis, revs... )
241
+ if VERSION >= v " 1.8.0-DEV.1563"
242
+ Expr (:new_opaque_closure , typ, Union{}, Any,
243
+ Expr (:opaque_closure_method , name, meth_nargs, isva, lno, cis), revs... )
244
+ else
245
+ Expr (:new_opaque_closure , typ, isva, Union{}, Any,
246
+ Expr (:opaque_closure_method , name, meth_nargs, lno, cis), revs... )
247
+ end
248
+ end
249
+
240
250
Base. iterate (c:: IncrementalCompact , args... ) = Core. Compiler. iterate (c, args... )
241
251
Base. iterate (p:: Core.Compiler.Pair , args... ) = Core. Compiler. iterate (p, args... )
242
252
Base. iterate (urs:: Core.Compiler.UseRefIterator , args... ) = Core. Compiler. iterate (urs, args... )
@@ -255,10 +265,11 @@ function transform!(ci, meth, nargs, sparams, N)
255
265
slotflags = UInt8[(0x00 for i = 1 : 2 ). .. , ci. slotflags... ]
256
266
slottypes = UInt8[(0x00 for i = 1 : 2 ). .. , ci. slotflags... ]
257
267
268
+ meta = VERSION < v " 1.9.0-DEV.472" ? Any[] : Expr[]
258
269
ir = IRCode (Core. Compiler. InstructionStream (code, Any[],
259
270
Any[nothing for i = 1 : length (code)],
260
271
ci. codelocs, UInt8[0 for i = 1 : length (code)]), cfg, Core. LineInfoNode[ci. linetable... ],
261
- Any[Any for i = 1 : 2 ], Any[] , Any[sparams... ])
272
+ Any[Any for i = 1 : 2 ], meta , Any[sparams... ])
262
273
263
274
# SSA conversion
264
275
domtree = construct_domtree (ir. cfg. blocks)
@@ -629,8 +640,13 @@ function transform!(ci, meth, nargs, sparams, N)
629
640
end
630
641
if nc != n_closures
631
642
lno = LineNumberNode (1 , :none )
632
- next_oc = insert_node_rev! (Expr (:new_opaque_closure , Tuple{(Any for i = 1 : nargs+ 1 ). .. }, meth. isva, Union{}, Any,
633
- Expr (:opaque_closure_method , cname (nc+ 1 , N, meth. name), Int (meth. nargs), lno, opaque_cis[nc+ 1 ]), revs[nc+ 1 ]. .. ))
643
+ next_oc = insert_node_rev! (make_opaque_closure (Tuple{(Any for i = 1 : nargs+ 1 ). .. },
644
+ cname (nc+ 1 , N, meth. name),
645
+ meth. nargs,
646
+ meth. isva,
647
+ lno,
648
+ opaque_cis[nc+ 1 ],
649
+ revs[nc+ 1 ]. .. ))
634
650
ret_tuple = insert_node_rev! (Expr (:call , tuple, arg_tuple, next_oc))
635
651
end
636
652
insert_node_rev! (Core. ReturnNode (ret_tuple))
@@ -684,8 +700,13 @@ function transform!(ci, meth, nargs, sparams, N)
684
700
revs[nc+ 1 ][i] = dual
685
701
elseif isa (stmt, ReturnNode)
686
702
lno = LineNumberNode (1 , :none )
687
- next_oc = insert_node_here! (Expr (:new_opaque_closure , Tuple{Any}, false , Union{}, Any,
688
- Expr (:opaque_closure_method , cname (nc+ 1 , N, meth. name), 1 , lno, opaque_cis[nc + 1 ]), revs[nc+ 1 ]. .. ))
703
+ next_oc = insert_node_here! (make_opaque_closure (Tuple{Any},
704
+ cname (nc+ 1 , N, meth. name),
705
+ 1 ,
706
+ false ,
707
+ lno,
708
+ opaque_cis[nc + 1 ],
709
+ revs[nc+ 1 ]. .. ))
689
710
ret_tup = insert_node_here! (Expr (:call , tuple, stmt. val, next_oc))
690
711
insert_node_here! (ReturnNode (ret_tup))
691
712
elseif isexpr (stmt, :new )
@@ -704,6 +725,8 @@ function transform!(ci, meth, nargs, sparams, N)
704
725
error ()
705
726
elseif isa (stmt, GlobalRef)
706
727
fwds[i] = ZeroTangent ()
728
+ elseif isexpr (stmt, :static_parameter )
729
+ fwds[i] = ZeroTangent ()
707
730
elseif isa (stmt, Union{GotoNode, GotoIfNot})
708
731
return :(error (" Control flow support not fully implemented yet for higher-order reverse mode (TODO)" ))
709
732
elseif ! isa (stmt, Expr)
@@ -721,7 +744,6 @@ function transform!(ci, meth, nargs, sparams, N)
721
744
722
745
# TODO : This is absolutely aweful, but the best we can do given the data structures we have
723
746
has_terminator = [isa (ir. stmts[last (range)]. inst, Union{GotoNode, GotoIfNot}) for range in orig_bb_ranges]
724
-
725
747
compact = IncrementalCompact (ir)
726
748
727
749
arg_mapping = Any[]
@@ -749,7 +771,7 @@ function transform!(ci, meth, nargs, sparams, N)
749
771
for ((old_idx, idx), stmt) in compact
750
772
# remap arguments
751
773
urs = userefs (stmt)
752
- compact[idx] = nothing
774
+ compact[SSAValue ( idx) ] = nothing
753
775
for op in urs
754
776
val = op[]
755
777
if isa (val, Argument)
@@ -759,14 +781,14 @@ function transform!(ci, meth, nargs, sparams, N)
759
781
op[] = quoted (sparams[val. args[1 ]])
760
782
end
761
783
end
762
- compact[idx] = stmt = urs[]
784
+ compact[SSAValue ( idx) ] = stmt = urs[]
763
785
# f(args...) -> ∂⃖{N}(args...)
764
786
orig_stmt = stmt
765
787
if isexpr (stmt, :(= ))
766
788
stmt = stmt. args[2 ]
767
789
end
768
790
if isexpr (stmt, :call )
769
- compact[idx] = Expr (:call , ∂⃖ {N} (), stmt. args... )
791
+ compact[SSAValue ( idx) ] = Expr (:call , ∂⃖ {N} (), stmt. args... )
770
792
if isexpr (orig_stmt, :(= ))
771
793
orig_stmt. args[2 ] = stmt
772
794
stmt = orig_stmt
@@ -783,18 +805,23 @@ function transform!(ci, meth, nargs, sparams, N)
783
805
orig_stmt. args[2 ] = stmt
784
806
stmt = orig_stmt
785
807
end
786
- compact[idx] = stmt
808
+ compact[SSAValue ( idx) ] = stmt
787
809
elseif isexpr (stmt, :new ) || isexpr (stmt, :splatnew )
788
810
rev[old_idx] = stmt. args[1 ]
789
811
elseif isexpr (stmt, :phi_placeholder )
790
- compact[idx] = phi_nodes[active_bb]
812
+ compact[SSAValue ( idx) ] = phi_nodes[active_bb]
791
813
# TODO : This is a base julia bug
792
814
push! (compact. late_fixup, idx)
793
815
rev[old_idx] = SSAValue (idx)
794
816
elseif isa (stmt, Core. ReturnNode)
795
817
lno = LineNumberNode (1 , :none )
796
- compact[idx] = Expr (:new_opaque_closure , Tuple{Any}, false , Union{}, Any,
797
- Expr (:opaque_closure_method , cname (1 , N, meth. name), 1 , lno, opaque_cis[1 ]), rev[orig_bb_ranges[end ]]. .. )
818
+ compact[SSAValue (idx)] = make_opaque_closure (Tuple{Any},
819
+ cname (1 , N, meth. name),
820
+ 1 ,
821
+ false ,
822
+ lno,
823
+ opaque_cis[1 ],
824
+ rev[orig_bb_ranges[end ]]. .. )
798
825
argty = insert_node_here! (compact,
799
826
NewInstruction (Expr (:call , typeof, stmt. val), Any, compact. result[idx][:line ]), true )
800
827
applyty = insert_node_here! (compact,
@@ -814,13 +841,14 @@ function transform!(ci, meth, nargs, sparams, N)
814
841
if length (succs) != 0
815
842
override = false
816
843
if has_terminator[active_bb]
817
- terminator = compact[idx]
818
- compact[idx] = nothing
844
+ terminator = compact[SSAValue (idx)]
845
+ terminator = VERSION < v " 1.9.0-DEV.739" ? terminator : terminator. inst
846
+ compact[SSAValue (idx)] = nothing
819
847
override = true
820
848
end
821
849
function terminator_insert_node! (node)
822
850
if override
823
- compact[idx] = node. stmt
851
+ compact[SSAValue ( idx) ] = node. stmt
824
852
override = false
825
853
return SSAValue (idx)
826
854
else
@@ -851,8 +879,15 @@ function transform!(ci, meth, nargs, sparams, N)
851
879
852
880
non_dce_finish! (compact)
853
881
ir = complete (compact)
882
+ # @show ir
854
883
ir = compact! (ir)
855
- Core. Compiler. verify_ir (ir)
884
+ if VERSION < v " 1.8"
885
+ Core. Compiler. verify_ir (ir, true )
886
+ elseif VERSION >= v " 1.9.0-DEV.854"
887
+ Core. Compiler. verify_ir (ir, true , true )
888
+ else
889
+ @warn " ir verification broken. Either use 1.9 or 1.7"
890
+ end
856
891
857
892
Core. Compiler. replace_code_newstyle! (ci, ir, nargs+ 1 )
858
893
ci. ssavaluetypes = length (ci. code)
0 commit comments