@@ -21,7 +21,7 @@ function IRCode(ir::IR)
21
21
for b in IRTools. blocks (ir)
22
22
if b. id == 1
23
23
for (i, arg) in enumerate (IRTools. arguments (b))
24
- defs[arg] = Core. Compiler . Argument (i)
24
+ defs[arg] = Core. SlotNumber (i)
25
25
end
26
26
else
27
27
@assert isempty (BasicBlock (b). args)
@@ -66,15 +66,30 @@ function IRCode(ir::IR)
66
66
end
67
67
end
68
68
69
+ if VERSION >= v " 1.6.0-DEV.272"
70
+ isgotoifnot (@nospecialize (ex)) = (@assert ! isexpr (ex, :gotoifnot ); ex isa Core. GotoIfNot)
71
+ destruct_gotoifnot (@nospecialize (ex)) = Any[ex. cond, ex. dest]
72
+
73
+ isreturn (@nospecialize (ex)) = (@assert ! isexpr (ex, :return ); ex isa ReturnNode)
74
+ retval (@nospecialize (ex)) = ex. val
75
+ else
76
+ isgotoifnot (@nospecialize (ex)) = isexpr (ex, :gotoifnot )
77
+ destruct_gotoifnot (@nospecialize (ex)) = ex. args
78
+
79
+ isreturn (@nospecialize (ex)) = isexpr (ex, :return )
80
+ retval (@nospecialize (ex)) = ex. args[1 ]
81
+ end
82
+
69
83
function blockstarts (ci:: CodeInfo )
70
84
bs = Int[]
71
85
terminator = false
72
86
for i = 1 : length (ci. code)
73
87
ex = ci. code[i]
74
- if isexpr (ex, :gotoifnot )
75
- push! (bs, ex. args[2 ])
88
+ if isgotoifnot (ex)
89
+ _, dest = destruct_gotoifnot (ex)
90
+ push! (bs, dest)
76
91
terminator = true
77
- elseif isexpr (ex, GotoNode, :return )
92
+ elseif ex isa GotoNode || isreturn (ex )
78
93
ex isa GotoNode && push! (bs, ex. label)
79
94
i < length (ci. code) && push! (bs, i+ 1 )
80
95
terminator = false
@@ -108,13 +123,14 @@ function IR(ci::CodeInfo, nargs::Integer; meta = nothing)
108
123
continue
109
124
elseif isexpr (ex, :enter )
110
125
_rename[Core. SSAValue (i)] = push! (ir, Expr (:enter , findfirst (== (ex. args[1 ]), bs)+ 1 ))
111
- elseif isexpr (ex, GotoNode)
126
+ elseif ex isa GotoNode
112
127
branch! (ir, findfirst (== (ex. label), bs)+ 1 )
113
- elseif isexpr (ex, :gotoifnot )
114
- branch! (ir, findfirst (== (ex. args[2 ]), bs)+ 1 ,
115
- unless = rename (ex. args[1 ]))
116
- elseif isexpr (ex, :return )
117
- return! (ir, rename (ex. args[1 ]))
128
+ elseif isgotoifnot (ex)
129
+ cond, dest = destruct_gotoifnot (ex)
130
+ branch! (ir, findfirst (== (dest), bs)+ 1 ,
131
+ unless = rename (cond))
132
+ elseif isreturn (ex)
133
+ return! (ir, rename (retval (ex)))
118
134
else
119
135
_rename[Core. SSAValue (i)] = push! (ir, IRTools. stmt (rename (ex), line = ci. codelocs[i]))
120
136
end
0 commit comments