SCM Repository
Annotation of /trunk/src/compiler/translate/translate-basis.sml
Parent Directory
|
Revision Log
Revision 392 - (view) (download)
1 : | jhr | 180 | (* translate-basis.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * Translation for basis operations in Simple AST to HighIL code | ||
7 : | *) | ||
8 : | |||
9 : | structure TranslateBasis : sig | ||
10 : | |||
11 : | jhr | 189 | (* translate(lhs, f, mvs, args) translates the application of f (specialized |
12 : | * to the instantiated meta variables mvs) to a list of SSA assignments in | ||
13 : | * reverse order. | ||
14 : | *) | ||
15 : | jhr | 180 | val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list) |
16 : | jhr | 188 | -> HighIL.assign list |
17 : | jhr | 180 | |
18 : | end = struct | ||
19 : | |||
20 : | jhr | 194 | structure BV = BasisVars |
21 : | jhr | 180 | structure IL = HighIL |
22 : | jhr | 392 | structure DstTy = HighILTypes |
23 : | jhr | 180 | structure Op = HighOps |
24 : | jhr | 183 | structure Ty = Types |
25 : | structure TU = TypeUtil | ||
26 : | structure MV = MetaVar | ||
27 : | jhr | 194 | structure VTbl = Var.Tbl |
28 : | jhr | 180 | |
29 : | jhr | 188 | fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))] |
30 : | jhr | 180 | |
31 : | jhr | 194 | fun simpleOp rator (y, [], xs) = assign (y, rator, xs) |
32 : | jhr | 183 | |
33 : | jhr | 197 | fun pruneDim d = (case TU.pruneDim d |
34 : | of (Ty.DimConst n) => n | ||
35 : | | d => raise Fail("unresolved dimension " ^ TU.dimToString d) | ||
36 : | (* end case *)) | ||
37 : | |||
38 : | jhr | 194 | fun tensorOp rator (y, [sv], xs) = (case TU.pruneShape(MV.toShape sv) |
39 : | jhr | 197 | of Ty.Shape dd => |
40 : | jhr | 392 | assign (y, rator(DstTy.TensorTy(List.map pruneDim dd)), xs) |
41 : | jhr | 183 | | shp => raise Fail("unresolved shape " ^ TU.shapeToString shp) |
42 : | (* end case *)) | ||
43 : | |||
44 : | jhr | 197 | fun vectorOp rator (y, [dv], xs) = |
45 : | jhr | 392 | assign (y, rator(DstTy.TensorTy[pruneDim(MV.toDim dv)]), xs) |
46 : | jhr | 197 | |
47 : | fun kernel h (y, [], []) = assign(y, Op.Kernel h, []) | ||
48 : | |||
49 : | jhr | 184 | (* build a table that maps Basis variables to their translation functions *) |
50 : | jhr | 197 | val tbl : ((IL.var * Ty.meta_var list * IL.var list) -> IL.assign list) VTbl.hash_table = let |
51 : | jhr | 194 | val tbl = VTbl.mkTable (128, Fail "Translate table") |
52 : | jhr | 180 | in |
53 : | jhr | 194 | List.app (VTbl.insert tbl) [ |
54 : | jhr | 392 | (BV.add_ii, simpleOp(Op.Add DstTy.IntTy)), |
55 : | jhr | 194 | (BV.add_tt, tensorOp Op.Add), |
56 : | jhr | 392 | (BV.sub_ii, simpleOp(Op.Sub DstTy.IntTy)), |
57 : | jhr | 194 | (BV.sub_tt, tensorOp Op.Sub), |
58 : | jhr | 392 | (BV.mul_ii, simpleOp(Op.Mul DstTy.IntTy)), |
59 : | (BV.mul_rr, simpleOp(Op.Mul(DstTy.TensorTy[]))), | ||
60 : | jhr | 194 | (BV.mul_rt, tensorOp Op.Scale), |
61 : | (BV.mul_tr, fn (y, sv, [t, r]) => tensorOp Op.Scale (y, sv, [r, t])), | ||
62 : | jhr | 392 | (BV.div_ii, simpleOp(Op.Div DstTy.IntTy)), |
63 : | (BV.div_rr, simpleOp(Op.Div(DstTy.TensorTy[]))), | ||
64 : | jhr | 194 | (BV.div_tr, tensorOp Op.InvScale), |
65 : | jhr | 392 | (BV.lt_ii, simpleOp(Op.LT DstTy.IntTy)), |
66 : | (BV.lt_rr, simpleOp(Op.LT(DstTy.TensorTy[]))), | ||
67 : | (BV.lte_ii, simpleOp(Op.LTE DstTy.IntTy)), | ||
68 : | (BV.lte_rr, simpleOp(Op.LTE(DstTy.TensorTy[]))), | ||
69 : | (BV.gte_ii, simpleOp(Op.GTE DstTy.IntTy)), | ||
70 : | (BV.gte_rr, simpleOp(Op.GTE(DstTy.TensorTy[]))), | ||
71 : | (BV.gt_ii, simpleOp(Op.GT DstTy.IntTy)), | ||
72 : | (BV.gt_rr, simpleOp(Op.GT(DstTy.TensorTy[]))), | ||
73 : | (BV.equ_bb, simpleOp(Op.EQ DstTy.BoolTy)), | ||
74 : | (BV.equ_ii, simpleOp(Op.EQ DstTy.IntTy)), | ||
75 : | (BV.equ_ss, simpleOp(Op.EQ DstTy.StringTy)), | ||
76 : | (BV.equ_rr, simpleOp(Op.EQ(DstTy.TensorTy[]))), | ||
77 : | (BV.neq_bb, simpleOp(Op.NEQ DstTy.BoolTy)), | ||
78 : | (BV.neq_ii, simpleOp(Op.NEQ DstTy.IntTy)), | ||
79 : | (BV.neq_ss, simpleOp(Op.NEQ DstTy.StringTy)), | ||
80 : | (BV.neq_rr, simpleOp(Op.NEQ(DstTy.TensorTy[]))), | ||
81 : | (BV.neg_i, simpleOp(Op.Neg DstTy.IntTy)), | ||
82 : | jhr | 194 | (BV.neg_t, tensorOp Op.Neg), |
83 : | jhr | 197 | (BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)), |
84 : | (BV.op_at, fn (y, _, xs) => assign(y, Op.Probe, xs)), | ||
85 : | jhr | 256 | (BV.op_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)), |
86 : | jhr | 197 | (BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)), |
87 : | jhr | 194 | (BV.op_norm, tensorOp Op.Norm), |
88 : | (BV.op_not, simpleOp Op.Not), | ||
89 : | jhr | 197 | (* |
90 : | jhr | 194 | (BV.op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*) |
91 : | jhr | 197 | *) |
92 : | (BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)), | ||
93 : | jhr | 256 | (BV.fn_convolve, fn (y, _, [h, img]) => assign(y, Op.Convolve, [img, h])), |
94 : | jhr | 194 | (BV.fn_cos, simpleOp Op.Cos), |
95 : | jhr | 197 | (BV.fn_dot, vectorOp Op.Dot), |
96 : | (BV.fn_inside, fn (y, _, xs) => assign(y, Op.Inside, xs)), | ||
97 : | (* | ||
98 : | jhr | 194 | (BV.fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*) |
99 : | jhr | 197 | *) |
100 : | jhr | 263 | (BV.fn_max, simpleOp Op.Max), |
101 : | (BV.fn_min, simpleOp Op.Min), | ||
102 : | jhr | 197 | (BV.fn_modulate, vectorOp Op.Mul), |
103 : | jhr | 194 | (BV.fn_pow, simpleOp Op.Pow), |
104 : | jhr | 197 | (BV.fn_principleEvec, vectorOp Op.PrincipleEvec), |
105 : | jhr | 194 | (BV.fn_sin, simpleOp Op.Sin), |
106 : | jhr | 197 | (BV.kn_bspln3, kernel Kernel.bspln3), |
107 : | (BV.kn_bspln5, kernel Kernel.bspln5), | ||
108 : | (BV.kn_ctmr, kernel Kernel.ctmr), | ||
109 : | (BV.kn_tent, kernel Kernel.tent), | ||
110 : | (BV.i2r, simpleOp Op.IntToReal)(*, | ||
111 : | (BV.input, fn (y, [TK], xs) => ??), (*FIXME*) | ||
112 : | (BV.optInput, fn (y, [TK], xs) => ??) (*FIXME*) | ||
113 : | *) | ||
114 : | jhr | 180 | ]; |
115 : | tbl | ||
116 : | end | ||
117 : | |||
118 : | jhr | 194 | fun translate (y, f, mvs, xs) = (case VTbl.find tbl f |
119 : | jhr | 197 | of SOME transFn => transFn(y, mvs, xs) |
120 : | jhr | 256 | | NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.uniqueNameOf f) |
121 : | jhr | 180 | (* end case *)) |
122 : | |||
123 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |