Esempio n. 1
0
 // Check each predicate in the MatchList for common sub-expressions
 static void cse_matchlist(MatchList *matchList) {
     for( MatchList *mList = matchList; mList != NULL; mList = mList->get_next() ) {
         Predicate* predicate = mList->get_pred_obj();
         char*      pred      = mList->get_pred();
         if( pred != NULL ) {
             for(int index = 0; index < count; ++index ) {
                 const char *shared_pred      = dfa_shared_preds::pred(index);
                 const char *shared_pred_var  = dfa_shared_preds::var(index);
                 bool result = dfa_shared_preds::cse_predicate(predicate, shared_pred, shared_pred_var);
                 if( result ) dfa_shared_preds::set_found(index, true);
             }
         }
     }
 }
Esempio n. 2
0
//---------------------------gen_match-----------------------------------------
void ArchDesc::gen_match(FILE *fp, MatchList &mList, ProductionState &status, Dict &operands_chained_from) {
    const char *spaces4 = "    ";
    const char *spaces6 = "      ";

    fprintf(fp, "%s", spaces4);
    // Only generate child tests if this is not a leaf node
    bool has_child_constraints = mList._lchild || mList._rchild;
    const char *predicate_test        = mList.get_pred();
    if( has_child_constraints || predicate_test ) {
        // Open the child-and-predicate-test braces
        fprintf(fp, "if( ");
        status.set_constraint(hasConstraint);
        child_test(fp, mList);
        // Only generate predicate test if one exists for this match
        if( predicate_test ) {
            if( has_child_constraints ) {
                fprintf(fp," &&\n");
            }
            fprintf(fp, "%s  %s", spaces6, predicate_test);
        }
        // End of outer tests
        fprintf(fp," ) ");
    } else {
        // No child or predicate test needed
        status.set_constraint(noConstraint);
    }

    // End of outer tests
    fprintf(fp,"{\n");

    // Calculate cost of this match
    const Expr *cost = calc_cost(fp, spaces6, mList, status);
    // Check against other match costs, and update cost & rule vectors
    cost_check(fp, spaces6, ArchDesc::getMachOperEnum(mList._resultStr), cost, mList._opcode, status);

    // If this is a member of an operand class, update the class cost & rule
    expand_opclass( fp, spaces6, cost, mList._resultStr, status);

    // Check if this rule should be used to generate the chains as well.
    const char *rule = /* set rule to "Invalid" for internal operands */
        strcmp(mList._opcode,mList._resultStr) ? mList._opcode : "Invalid";

    // If this rule produces an operand which has associated chain rules,
    // update the operands with the chain rule + this rule cost & this rule.
    chain_rule(fp, spaces6, mList._resultStr, cost, rule, operands_chained_from, status);

    // Close the child-and-predicate-test braces
    fprintf(fp, "    }\n");

}