% This Source Code Form is subject to the terms of the Mozilla Public % License, v. 2.0. If a copy of the MPL was not distributed with this % file, You can obtain one at http://mozilla.org/MPL/2.0/. %defines impl(llvm_array; llvm_const_array; on_the_fly). op(seqaccess). op(randaccess). relation(recommends; satisfied; unsupported). relation_score(satisfied, 0). relation_score(recommends, 1). relation_score(unsupported, -1). score(-1..1). %domain facts: relation_op(seqaccess, on_the_fly, recommends). relation_op(randaccess, llvm_const_array, recommends). relation_op(randaccess, on_the_fly, unsupported). %dfa analysis: % -- %compilation: %-- %domain rules: -impl_fulfill(OP, IMPL) :- relation_op(OP, IMPL, unsupported). impl_fulfill(OP, IMPL, SCORE):- SCORE = #sum{SCORE1, (OP, IMPL, RL): relation_op(OP, IMPL, RL),relation_score(RL, SCORE1)} ; op(OP); impl(IMPL); not -impl_fulfill(OP, IMPL). cluster_root(VAR) :- not dfa_connection(VAR, _, strong), v(VAR). var_cluster(VAR0, VAR_TO) :- dfa_connection(VAR_TO, VAR0, strong), cluster_root(VAR0). var_cluster(VAR0, VAR_TO2) :- dfa_connection(VAR_TO2, VAR_TO1, strong), var_cluster(VAR0, VAR_TO1). var_cluster(VAR0, VAR0):- cluster_root(VAR0). -impl_fulfill_cluster(Var0, Impl) :- var_cluster(Var0, Var_Any); bind(Var_Any, op(Op)); -impl_fulfill(Op, Impl). impl_fulfill_cluster(VAR0, IMPL, Score) :- Score = #sum{SCORE, (OP, IMPL, VAR_ANY): impl_fulfill(OP, IMPL, SCORE), var_cluster(VAR0, VAR_ANY), bind(VAR_ANY, op(OP))} ; bind(VAR0, impl(IMPL)); cluster_root(VAR0); not -impl_fulfill_cluster(VAR0, IMPL). proto_cluster(V0, Vproto) :- cluster_root(V0); cluster_root(Vproto); var_cluster(Vproto, Vp); dfa_connection(V0, Vp, proto). %optimization % #maximize {SCORE, (VAR0, IMPL) : impl_fulfill_cluster(VAR0, IMPL, SCORE)}. #show var_cluster/2. #show impl_fulfill_cluster/3.