| 1 |
(* mltree-hash.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies. |
| 4 |
*) |
| 5 |
|
| 6 |
functor MLTreeHash |
| 7 |
(structure T : MLTREE |
| 8 |
(* Hashing extensions *) |
| 9 |
val hashSext : T.hasher -> T.sext -> word |
| 10 |
val hashRext : T.hasher -> T.rext -> word |
| 11 |
val hashFext : T.hasher -> T.fext -> word |
| 12 |
val hashCCext : T.hasher -> T.ccext -> word |
| 13 |
) : MLTREE_HASH = |
| 14 |
struct |
| 15 |
structure T = T |
| 16 |
structure I = T.I |
| 17 |
structure Constant = T.Constant |
| 18 |
structure B = T.Basis |
| 19 |
structure C = CellsBasis |
| 20 |
structure W = Word |
| 21 |
|
| 22 |
val w = W.fromInt |
| 23 |
val i2s = Int.toString |
| 24 |
val toLower = String.map Char.toLower |
| 25 |
|
| 26 |
fun error msg = MLRiscErrorMsg.error("LabelExp",msg) |
| 27 |
fun wv(C.CELL{id, ...}) = w id |
| 28 |
fun wvs is = |
| 29 |
let fun f([],h) = h |
| 30 |
| f(i::is,h) = f(is,wv i+h) |
| 31 |
in f(is,0w0) end |
| 32 |
|
| 33 |
(* |
| 34 |
* Hashing |
| 35 |
*) |
| 36 |
val hashLabel = Label.hash |
| 37 |
fun hasher() = {stm=hashStm, rexp=hashRexp, fexp=hashFexp, ccexp=hashCCexp} |
| 38 |
and hashCtrl ctrl = wv ctrl |
| 39 |
and hashStm stm = |
| 40 |
case stm of |
| 41 |
T.MV(t,dst,rexp) => 0w123 + w t + wv dst + hashRexp rexp |
| 42 |
| T.CCMV(dst,ccexp) => 0w1234 + wv dst + hashCCexp ccexp |
| 43 |
| T.FMV(fty,dst,fexp) => 0w12345 + w fty + wv dst + hashFexp fexp |
| 44 |
| T.COPY(ty,dst,src) => 0w234 + w ty + wvs dst + wvs src |
| 45 |
| T.FCOPY(fty,dst,src) => 0w456 + w fty + wvs dst + wvs src |
| 46 |
| T.JMP(ea,labels) => 0w45 + hashRexp ea |
| 47 |
| T.CALL{funct,targets,defs,uses,region,pops} => |
| 48 |
hashRexp funct + hashMlriscs defs + hashMlriscs uses |
| 49 |
| T.RET _ => 0w567 |
| 50 |
| T.STORE(ty,ea,data,mem) => 0w888 + w ty + hashRexp ea + hashRexp data |
| 51 |
| T.FSTORE(fty,ea,data,mem) => 0w7890 + w fty + hashRexp ea + hashFexp data |
| 52 |
| T.BCC(a,lab) => 0w233 + hashCCexp a + hashLabel lab |
| 53 |
| T.IF(a,b,c) => 0w233 + hashCCexp a + hashStm b + hashStm c |
| 54 |
| T.ANNOTATION(stm, a) => hashStm stm |
| 55 |
| T.PHI{preds,block} => w block |
| 56 |
| T.SOURCE => 0w123 |
| 57 |
| T.SINK => 0w423 |
| 58 |
| T.REGION(stm,ctrl) => hashStm stm + hashCtrl ctrl |
| 59 |
| T.RTL{hash,...} => hash |
| 60 |
| T.SEQ ss => hashStms(ss, 0w23) |
| 61 |
| T.ASSIGN(ty,lhs,rhs) => w ty + hashRexp lhs + hashRexp rhs |
| 62 |
| _ => error "hashStm" |
| 63 |
|
| 64 |
and hashStms([],h) = h |
| 65 |
| hashStms(s::ss,h) = hashStms(ss,hashStm s + h) |
| 66 |
|
| 67 |
and hashMlrisc(T.CCR ccexp) = hashCCexp ccexp |
| 68 |
| hashMlrisc(T.GPR rexp) = hashRexp rexp |
| 69 |
| hashMlrisc(T.FPR fexp) = hashFexp fexp |
| 70 |
|
| 71 |
and hashMlriscs [] = 0w123 |
| 72 |
| hashMlriscs(m::ms) = hashMlrisc m + hashMlriscs ms |
| 73 |
|
| 74 |
and hash2(ty,x,y) = w ty + hashRexp x + hashRexp y |
| 75 |
|
| 76 |
and hashm T.DIV_TO_ZERO = 0w158 |
| 77 |
| hashm T.DIV_TO_NEGINF = 0w159 |
| 78 |
|
| 79 |
and hash3(m,ty,x,y) = hashm m + w ty + hashRexp x + hashRexp y |
| 80 |
|
| 81 |
and hashRexp rexp = |
| 82 |
case rexp |
| 83 |
of T.REG(ty, src) => w ty + wv src |
| 84 |
| T.LI i => I.hash i |
| 85 |
| T.LABEL l => hashLabel l |
| 86 |
| T.LABEXP le => hashRexp rexp |
| 87 |
| T.CONST c => Constant.hash c |
| 88 |
| T.NEG(ty, x) => w ty + hashRexp x + 0w24 |
| 89 |
| T.ADD x => hash2 x + 0w234 |
| 90 |
| T.SUB x => hash2 x + 0w456 |
| 91 |
| T.MULS x => hash2 x + 0w2131 |
| 92 |
| T.DIVS x => hash3 x + 0w156 |
| 93 |
| T.REMS x => hash3 x + 0w231 |
| 94 |
| T.MULU x => hash2 x + 0w123 |
| 95 |
| T.DIVU x => hash2 x + 0w1234 |
| 96 |
| T.REMU x => hash2 x + 0w211 |
| 97 |
| T.NEGT(ty, x) => w ty + hashRexp x + 0w1224 |
| 98 |
| T.ADDT x => hash2 x + 0w1219 |
| 99 |
| T.SUBT x => hash2 x + 0w999 |
| 100 |
| T.MULT x => hash2 x + 0w7887 |
| 101 |
| T.DIVT x => hash3 x + 0w88884 |
| 102 |
| T.ANDB x => hash2 x + 0w12312 |
| 103 |
| T.ORB x => hash2 x + 0w558 |
| 104 |
| T.XORB x => hash2 x + 0w234 |
| 105 |
| T.EQVB x => hash2 x + 0w734 |
| 106 |
| T.NOTB(ty, x) => w ty + hashRexp x |
| 107 |
| T.SRA x => hash2 x + 0w874 |
| 108 |
| T.SRL x => hash2 x + 0w223 |
| 109 |
| T.SLL x => hash2 x + 0w499 |
| 110 |
| T.COND(ty,e,e1,e2) => w ty + hashCCexp e + hashRexp e1 + hashRexp e2 |
| 111 |
| T.SX(ty, ty', rexp) => 0w232 + w ty + w ty' + hashRexp rexp |
| 112 |
| T.ZX(ty, ty', rexp) => 0w737 + w ty + w ty' + hashRexp rexp |
| 113 |
| T.CVTF2I(ty, round, ty', fexp) => |
| 114 |
w ty + B.hashRoundingMode round + w ty' + hashFexp fexp |
| 115 |
| T.LOAD(ty, ea, mem) => w ty + hashRexp ea + 0w342 |
| 116 |
| T.LET(stm, rexp) => hashStm stm + hashRexp rexp |
| 117 |
| T.PRED(e, ctrl) => hashRexp e + hashCtrl ctrl |
| 118 |
| T.MARK(e, _) => hashRexp e |
| 119 |
| T.REXT(ty, rext) => w ty + hashRext (hasher()) rext |
| 120 |
| T.??? => 0w485 |
| 121 |
| T.OP(ty,oper,es) => hashRexps(es, w ty + hashOper oper) |
| 122 |
| T.ARG _ => 0w23 |
| 123 |
| T.$(ty, k, e) => w ty + hashRexp e |
| 124 |
| T.PARAM n => w n |
| 125 |
| T.BITSLICE(ty, sl, e) => w ty + hashRexp e |
| 126 |
|
| 127 |
and hashOper(T.OPER{hash, ...}) = hash |
| 128 |
|
| 129 |
and hashRexps([],h) = h |
| 130 |
| hashRexps(e::es,h) = hashRexps(es,hashRexp e + h) |
| 131 |
|
| 132 |
and hash2'(ty,x,y) = w ty + hashFexp x + hashFexp y |
| 133 |
|
| 134 |
and hashFexp fexp = |
| 135 |
case fexp of |
| 136 |
T.FREG(fty, src) => w fty + wv src |
| 137 |
| T.FLOAD(fty, ea, mem) => w fty + hashRexp ea |
| 138 |
| T.FADD x => hash2' x + 0w123 |
| 139 |
| T.FMUL x => hash2' x + 0w1234 |
| 140 |
| T.FSUB x => hash2' x + 0w12345 |
| 141 |
| T.FDIV x => hash2' x + 0w234 |
| 142 |
| T.FCOPYSIGN x => hash2' x + 0w883 |
| 143 |
| T.FCOND(fty,c,x,y) => w fty + hashCCexp c + hashFexp x + hashFexp y |
| 144 |
| T.FABS(fty, fexp) => w fty + hashFexp fexp + 0w2345 |
| 145 |
| T.FNEG(fty, fexp) => w fty + hashFexp fexp + 0w23456 |
| 146 |
| T.FSQRT(fty, fexp) => w fty + hashFexp fexp + 0w345 |
| 147 |
| T.CVTI2F(fty, ty, rexp) => w fty + w ty + hashRexp rexp |
| 148 |
| T.CVTF2F(fty, fty', fexp) => w fty + hashFexp fexp + w fty' |
| 149 |
| T.FMARK(e, _) => hashFexp e |
| 150 |
| T.FPRED(e, ctrl) => hashFexp e + hashCtrl ctrl |
| 151 |
| T.FEXT(fty, fext) => w fty + hashFext (hasher()) fext |
| 152 |
|
| 153 |
and hashFexps([],h) = h |
| 154 |
| hashFexps(e::es,h) = hashFexps(es,hashFexp e + h) |
| 155 |
|
| 156 |
and hashCCexp ccexp = |
| 157 |
case ccexp of |
| 158 |
T.CC(cc, src) => B.hashCond cc + wv src |
| 159 |
| T.FCC(fcc, src) => B.hashFcond fcc + wv src |
| 160 |
| T.CMP(ty, cond, x, y) => |
| 161 |
w ty + B.hashCond cond + hashRexp x + hashRexp y |
| 162 |
| T.FCMP(fty, fcond, x, y) => |
| 163 |
w fty + B.hashFcond fcond + hashFexp x + hashFexp y |
| 164 |
| T.NOT x => 0w2321 + hashCCexp x |
| 165 |
| T.AND(x,y) => 0w2321 + hashCCexp x + hashCCexp y |
| 166 |
| T.OR(x,y) => 0w8721 + hashCCexp x + hashCCexp y |
| 167 |
| T.XOR(x,y) => 0w6178 + hashCCexp x + hashCCexp y |
| 168 |
| T.EQV(x,y) => 0w178 + hashCCexp x + hashCCexp y |
| 169 |
| T.TRUE => 0w0 |
| 170 |
| T.FALSE => 0w1232 |
| 171 |
| T.CCMARK(e, _) => hashCCexp e |
| 172 |
| T.CCEXT(ty,ccext) => w ty + hashCCext (hasher()) ccext |
| 173 |
|
| 174 |
and hashCCexps([],h) = h |
| 175 |
| hashCCexps(e::es,h) = hashCCexps(es,hashCCexp e + h) |
| 176 |
|
| 177 |
|
| 178 |
val hash = hashRexp |
| 179 |
end |