@@ -40,6 +40,55 @@ function return_empty_reductinit(op::Operation, var::Symbol)
40
40
end
41
41
42
42
43
+
44
+ function constant_symbol! (ls:: LoopSet , op:: Operation )
45
+ # hack
46
+ # relowers, but should make it work
47
+ # TODO : DRY with `lower_licm_constants!` from `src/codegen/lower_constants.jl`
48
+ skip_constant (instruction (op)) || return instruction (op). instr
49
+ idcheck = identifier (op)
50
+ symname = constantopname (op)
51
+ for (id, sym) ∈ ls. preamble_symsym
52
+ (idcheck ≢ nothing ) && ((idcheck == id) && continue )
53
+ pushpreamble! (ls, Expr (:(= ), symname, sym))
54
+ return symname
55
+ # setconstantop!(ls, op, sym)
56
+ # setconstantop!(ls, op, Expr(:call, lv(:maybeconvert), ls.T, sym))
57
+ end
58
+ for (id,(intval,intsz,signed)) ∈ ls. preamble_symint
59
+ (idcheck ≢ nothing ) && ((idcheck == id) && continue )
60
+ if intsz == 1
61
+ pushpreamble! (ls, Expr (:(= ), symname, intval % Bool))
62
+ else
63
+ pushpreamble! (ls, Expr (:(= ), symname, sizeequivalent_symint_expr (intval, signed)))
64
+ end
65
+ return symname
66
+ end
67
+ for (id,floatval) ∈ ls. preamble_symfloat
68
+ (idcheck ≢ nothing ) && ((idcheck == id) && continue )
69
+ pushpreamble! (ls, Expr (:(= ), symname, Expr (:call , lv (:sizeequivalentfloat ), ELTYPESYMBOL, floatval)))
70
+ return symname
71
+ end
72
+ for (id,typ) ∈ ls. preamble_zeros
73
+ (idcheck ≢ nothing ) && ((idcheck == id) && continue )
74
+ instruction (op) === LOOPCONSTANT || continue
75
+ if typ == IntOrFloat
76
+ pushpreamble! (ls, Expr (:(= ), symname, Expr (:call , :zero , ELTYPESYMBOL)))
77
+ elseif typ == HardInt
78
+ pushpreamble! (ls, Expr (:(= ), symname, Expr (:call , lv (:zerointeger ), ELTYPESYMBOL)))
79
+ else # if typ == HardFloat
80
+ pushpreamble! (ls, Expr (:(= ), symname, Expr (:call , lv (:zerofloat ), ELTYPESYMBOL)))
81
+ end
82
+ return symname
83
+ end
84
+ for (id,f) ∈ ls. preamble_funcofeltypes
85
+ (idcheck ≢ nothing ) && ((idcheck == id) && continue )
86
+ pushpreamble! (ls, Expr (:(= ), symname, Expr (:call , reduction_zero (f), ELTYPESYMBOL)))
87
+ return symname
88
+ end
89
+ throw (" Constant operation symbol not found." )
90
+ end
91
+
43
92
function hoist_constant_store! (q:: Expr , ls:: LoopSet , op:: Operation )
44
93
op. instruction = DROPPEDCONSTANT
45
94
op. node_type = constant
@@ -52,7 +101,10 @@ function hoist_constant_store!(q::Expr, ls::LoopSet, op::Operation)
52
101
end
53
102
push! (ls. outer_reductions, identifier (opr))
54
103
55
- init = return_empty_reductinit (opr, name (opr)). instruction. instr
104
+ initop = return_empty_reductinit (opr, name (opr))
105
+ # @show last(ls.preamble.args)
106
+ init = constant_symbol! (ls, initop)
107
+ # @show last(ls.preamble.args)
56
108
pushpreamble! (ls, Expr (:(= ), outer_reduct_init_typename (opr), Expr (:call , lv (:typeof ), init)))
57
109
qpre = Expr (:block )
58
110
push! (q. args, Expr (:call , lv (:unsafe_store! ), Expr (:call , lv (:pointer ), op. ref. ptr), outer_reduction_to_scalar_reduceq! (qpre, opr, init)))
0 commit comments