< prev index next >

src/share/vm/adlc/dfa.cpp

Print this page




 354     }
 355   }
 356 }
 357 
 358 //---------------------------prune_matchlist-----------------------------------
 359 // Check for duplicate entries in a matchlist, and prune out the higher cost
 360 // entry.
 361 void ArchDesc::prune_matchlist(Dict &minimize, MatchList &mlist) {
 362 
 363 }
 364 
 365 //---------------------------buildDFA------------------------------------------
 366 // DFA is a large switch with case statements for each ideal opcode encountered
 367 // in any match rule in the ad file.  Each case has a series of if's to handle
 368 // the match or fail decisions.  The matches test the cost function of that
 369 // rule, and prune any cases which are higher cost for the same reduction.
 370 // In order to generate the DFA we walk the table of ideal opcode/MatchList
 371 // pairs generated by the ADLC front end to build the contents of the case
 372 // statements (a series of if statements).
 373 void ArchDesc::buildDFA(FILE* fp) {
 374   int i;
 375   // Remember operands that are the starting points for chain rules.
 376   // Prevent cycles by checking if we have already generated chain.
 377   Dict operands_chained_from(cmpstr, hashstr, Form::arena);
 378 
 379   // Hash inputs to match rules so that final DFA contains only one entry for
 380   // each match pattern which is the low cost entry.
 381   Dict minimize(cmpstr, hashstr, Form::arena);
 382 
 383   // Track status of dfa for each resulting production
 384   // reset for each ideal root.
 385   ProductionState status(Form::arena);
 386 
 387   // Output the start of the DFA method into the output file
 388 
 389   fprintf(fp, "\n");
 390   fprintf(fp, "//------------------------- Source -----------------------------------------\n");
 391   // Do not put random source code into the DFA.
 392   // If there are constants which need sharing, put them in "source_hpp" forms.
 393   // _source.output(fp);
 394   fprintf(fp, "\n");


 407   fprintf(fp, "#define %s(result, rule, cost)\\\n", dfa_production_set_valid);
 408   fprintf(fp, "  %s( (result), (rule), (cost) ); STATE__SET_VALID( (result) );\n", dfa_production);
 409   fprintf(fp, "\n");
 410 
 411   fprintf(fp, "//------------------------- DFA --------------------------------------------\n");
 412 
 413   fprintf(fp,
 414 "// DFA is a large switch with case statements for each ideal opcode encountered\n"
 415 "// in any match rule in the ad file.  Each case has a series of if's to handle\n"
 416 "// the match or fail decisions.  The matches test the cost function of that\n"
 417 "// rule, and prune any cases which are higher cost for the same reduction.\n"
 418 "// In order to generate the DFA we walk the table of ideal opcode/MatchList\n"
 419 "// pairs generated by the ADLC front end to build the contents of the case\n"
 420 "// statements (a series of if statements).\n"
 421 );
 422   fprintf(fp, "\n");
 423   fprintf(fp, "\n");
 424   if (_dfa_small) {
 425     // Now build the individual routines just like the switch entries in large version
 426     // Iterate over the table of MatchLists, start at first valid opcode of 1
 427     for (i = 1; i < _last_opcode; i++) {
 428       if (_mlistab[i] == NULL) continue;
 429       // Generate the routine header statement for this opcode
 430       fprintf(fp, "void  State::_sub_Op_%s(const Node *n){\n", NodeClassNames[i]);
 431       // Generate body. Shared for both inline and out-of-line version
 432       gen_dfa_state_body(fp, minimize, status, operands_chained_from, i);
 433       // End of routine
 434       fprintf(fp, "}\n");
 435     }
 436   }
 437   fprintf(fp, "bool State::DFA");
 438   fprintf(fp, "(int opcode, const Node *n) {\n");
 439   fprintf(fp, "  switch(opcode) {\n");
 440 
 441   // Iterate over the table of MatchLists, start at first valid opcode of 1
 442   for (i = 1; i < _last_opcode; i++) {
 443     if (_mlistab[i] == NULL) continue;
 444     // Generate the case statement for this opcode
 445     if (_dfa_small) {
 446       fprintf(fp, "  case Op_%s: { _sub_Op_%s(n);\n", NodeClassNames[i], NodeClassNames[i]);
 447     } else {
 448       fprintf(fp, "  case Op_%s: {\n", NodeClassNames[i]);
 449       // Walk the list, compacting it
 450       gen_dfa_state_body(fp, minimize, status, operands_chained_from, i);
 451     }
 452     // Print the "break"
 453     fprintf(fp, "    break;\n");
 454     fprintf(fp, "  }\n");
 455   }
 456 
 457   // Generate the default case for switch(opcode)
 458   fprintf(fp, "  \n");
 459   fprintf(fp, "  default:\n");
 460   fprintf(fp, "    tty->print(\"Default case invoked for: \\n\");\n");
 461   fprintf(fp, "    tty->print(\"   opcode  = %cd, \\\"%cs\\\"\\n\", opcode, NodeClassNames[opcode]);\n", '%', '%');
 462   fprintf(fp, "    return false;\n");
 463   fprintf(fp, "  }\n");
 464 
 465   // Return status, indicating a successful match.
 466   fprintf(fp, "  return true;\n");
 467   // Generate the closing brace for method Matcher::DFA
 468   fprintf(fp, "}\n");
 469   Expr::check_buffers();
 470 }
 471 
 472 
 473 class dfa_shared_preds {
 474   enum { count = 4 };
 475 
 476   static bool        _found[count];
 477   static const char* _type [count];
 478   static const char* _var  [count];
 479   static const char* _pred [count];
 480 
 481   static void check_index(int index) { assert( 0 <= index && index < count, "Invalid index"); }




 354     }
 355   }
 356 }
 357 
 358 //---------------------------prune_matchlist-----------------------------------
 359 // Check for duplicate entries in a matchlist, and prune out the higher cost
 360 // entry.
 361 void ArchDesc::prune_matchlist(Dict &minimize, MatchList &mlist) {
 362 
 363 }
 364 
 365 //---------------------------buildDFA------------------------------------------
 366 // DFA is a large switch with case statements for each ideal opcode encountered
 367 // in any match rule in the ad file.  Each case has a series of if's to handle
 368 // the match or fail decisions.  The matches test the cost function of that
 369 // rule, and prune any cases which are higher cost for the same reduction.
 370 // In order to generate the DFA we walk the table of ideal opcode/MatchList
 371 // pairs generated by the ADLC front end to build the contents of the case
 372 // statements (a series of if statements).
 373 void ArchDesc::buildDFA(FILE* fp) {
 374   uint i;
 375   // Remember operands that are the starting points for chain rules.
 376   // Prevent cycles by checking if we have already generated chain.
 377   Dict operands_chained_from(cmpstr, hashstr, Form::arena);
 378 
 379   // Hash inputs to match rules so that final DFA contains only one entry for
 380   // each match pattern which is the low cost entry.
 381   Dict minimize(cmpstr, hashstr, Form::arena);
 382 
 383   // Track status of dfa for each resulting production
 384   // reset for each ideal root.
 385   ProductionState status(Form::arena);
 386 
 387   // Output the start of the DFA method into the output file
 388 
 389   fprintf(fp, "\n");
 390   fprintf(fp, "//------------------------- Source -----------------------------------------\n");
 391   // Do not put random source code into the DFA.
 392   // If there are constants which need sharing, put them in "source_hpp" forms.
 393   // _source.output(fp);
 394   fprintf(fp, "\n");


 407   fprintf(fp, "#define %s(result, rule, cost)\\\n", dfa_production_set_valid);
 408   fprintf(fp, "  %s( (result), (rule), (cost) ); STATE__SET_VALID( (result) );\n", dfa_production);
 409   fprintf(fp, "\n");
 410 
 411   fprintf(fp, "//------------------------- DFA --------------------------------------------\n");
 412 
 413   fprintf(fp,
 414 "// DFA is a large switch with case statements for each ideal opcode encountered\n"
 415 "// in any match rule in the ad file.  Each case has a series of if's to handle\n"
 416 "// the match or fail decisions.  The matches test the cost function of that\n"
 417 "// rule, and prune any cases which are higher cost for the same reduction.\n"
 418 "// In order to generate the DFA we walk the table of ideal opcode/MatchList\n"
 419 "// pairs generated by the ADLC front end to build the contents of the case\n"
 420 "// statements (a series of if statements).\n"
 421 );
 422   fprintf(fp, "\n");
 423   fprintf(fp, "\n");
 424   if (_dfa_small) {
 425     // Now build the individual routines just like the switch entries in large version
 426     // Iterate over the table of MatchLists, start at first valid opcode of 1
 427     for (i = 1; i < static_cast<uint>(Opcodes::_last_opcode); i++) {
 428       if (_mlistab[i] == NULL) continue;
 429       // Generate the routine header statement for this opcode
 430       fprintf(fp, "void  State::_sub_Op_%s(const Node *n){\n", NodeClassNames[i]);
 431       // Generate body. Shared for both inline and out-of-line version
 432       gen_dfa_state_body(fp, minimize, status, operands_chained_from, i);
 433       // End of routine
 434       fprintf(fp, "}\n");
 435     }
 436   }
 437   fprintf(fp, "bool State::DFA");
 438   fprintf(fp, "(Opcodes opcode, const Node *n) {\n");
 439   fprintf(fp, "  switch(opcode) {\n");
 440 
 441   // Iterate over the table of MatchLists, start at first valid opcode of 1
 442   for (i = 1; i < static_cast<uint>(Opcodes::_last_opcode); i++) {
 443     if (_mlistab[i] == NULL) continue;
 444     // Generate the case statement for this opcode
 445     if (_dfa_small) {
 446       fprintf(fp, "  case Opcodes::Op_%s: { _sub_Op_%s(n);\n", NodeClassNames[i], NodeClassNames[i]);
 447     } else {
 448       fprintf(fp, "  case Opcodes::Op_%s: {\n", NodeClassNames[i]);
 449       // Walk the list, compacting it
 450       gen_dfa_state_body(fp, minimize, status, operands_chained_from, i);
 451     }
 452     // Print the "break"
 453     fprintf(fp, "    break;\n");
 454     fprintf(fp, "  }\n");
 455   }
 456 
 457   // Generate the default case for switch(opcode)
 458   fprintf(fp, "  \n");
 459   fprintf(fp, "  default:\n");
 460   fprintf(fp, "    tty->print(\"Default case invoked for: \\n\");\n");
 461   fprintf(fp, "    tty->print(\"   opcode  = %cu, \\\"%cs\\\"\\n\", static_cast<uint>(opcode), NodeClassNames[static_cast<uint>(opcode)]);\n", '%', '%');
 462   fprintf(fp, "    return false;\n");
 463   fprintf(fp, "  }\n");
 464 
 465   // Return status, indicating a successful match.
 466   fprintf(fp, "  return true;\n");
 467   // Generate the closing brace for method Matcher::DFA
 468   fprintf(fp, "}\n");
 469   Expr::check_buffers();
 470 }
 471 
 472 
 473 class dfa_shared_preds {
 474   enum { count = 4 };
 475 
 476   static bool        _found[count];
 477   static const char* _type [count];
 478   static const char* _var  [count];
 479   static const char* _pred [count];
 480 
 481   static void check_index(int index) { assert( 0 <= index && index < count, "Invalid index"); }


< prev index next >