251 pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
251 pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
252 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) |
252 if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal")) |
253 pipeclass->_parameters.reset(); |
253 pipeclass->_parameters.reset(); |
254 |
254 |
255 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { |
255 while ( (paramname = pipeclass->_parameters.iter()) != NULL ) { |
256 const PipeClassOperandForm *pipeopnd = |
256 const PipeClassOperandForm *tmppipeopnd = |
257 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
257 (const PipeClassOperandForm *)pipeclass->_localUsage[paramname]; |
258 templen += sprintf(&operand_stages[templen], " stage_%s%c\n", |
258 templen += sprintf(&operand_stages[templen], " stage_%s%c\n", |
259 pipeopnd ? pipeopnd->_stage : "undefined", |
259 tmppipeopnd ? tmppipeopnd->_stage : "undefined", |
260 (++i < paramcount ? ',' : ' ') ); |
260 (++i < paramcount ? ',' : ' ') ); |
261 } |
261 } |
262 |
262 |
263 // See if the same string is in the table |
263 // See if the same string is in the table |
264 int ndx = pipeline_reads.index(operand_stages); |
264 int ndx = pipeline_reads.index(operand_stages); |
1040 node, regMask); |
1040 node, regMask); |
1041 } |
1041 } |
1042 |
1042 |
1043 // Scan the peepmatch and output a test for each instruction |
1043 // Scan the peepmatch and output a test for each instruction |
1044 static void check_peepmatch_instruction_tree(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
1044 static void check_peepmatch_instruction_tree(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
1045 intptr_t parent = -1; |
1045 int parent = -1; |
1046 intptr_t inst_position = 0; |
1046 int inst_position = 0; |
1047 const char *inst_name = NULL; |
1047 const char* inst_name = NULL; |
1048 intptr_t input = 0; |
1048 int input = 0; |
1049 fprintf(fp, " // Check instruction sub-tree\n"); |
1049 fprintf(fp, " // Check instruction sub-tree\n"); |
1050 pmatch->reset(); |
1050 pmatch->reset(); |
1051 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1051 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1052 inst_name != NULL; |
1052 inst_name != NULL; |
1053 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1053 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1054 // If this is not a placeholder |
1054 // If this is not a placeholder |
1055 if( ! pmatch->is_placeholder() ) { |
1055 if( ! pmatch->is_placeholder() ) { |
1056 // Define temporaries 'inst#', based on parent and parent's input index |
1056 // Define temporaries 'inst#', based on parent and parent's input index |
1057 if( parent != -1 ) { // root was initialized |
1057 if( parent != -1 ) { // root was initialized |
1058 fprintf(fp, " inst%ld = inst%ld->in(%ld);\n", |
1058 fprintf(fp, " inst%d = inst%d->in(%d);\n", |
1059 inst_position, parent, input); |
1059 inst_position, parent, input); |
1060 } |
1060 } |
1061 |
1061 |
1062 // When not the root |
1062 // When not the root |
1063 // Test we have the correct instruction by comparing the rule |
1063 // Test we have the correct instruction by comparing the rule |
1064 if( parent != -1 ) { |
1064 if( parent != -1 ) { |
1065 fprintf(fp, " matches = matches && ( inst%ld->rule() == %s_rule );", |
1065 fprintf(fp, " matches = matches && ( inst%d->rule() == %s_rule );", |
1066 inst_position, inst_name); |
1066 inst_position, inst_name); |
1067 } |
1067 } |
1068 } else { |
1068 } else { |
1069 // Check that user did not try to constrain a placeholder |
1069 // Check that user did not try to constrain a placeholder |
1070 assert( ! pconstraint->constrains_instruction(inst_position), |
1070 assert( ! pconstraint->constrains_instruction(inst_position), |
1071 "fatal(): Can not constrain a placeholder instruction"); |
1071 "fatal(): Can not constrain a placeholder instruction"); |
1072 } |
1072 } |
1073 } |
1073 } |
1074 } |
1074 } |
1075 |
1075 |
1076 static void print_block_index(FILE *fp, intptr_t inst_position) { |
1076 static void print_block_index(FILE *fp, int inst_position) { |
1077 assert( inst_position >= 0, "Instruction number less than zero"); |
1077 assert( inst_position >= 0, "Instruction number less than zero"); |
1078 fprintf(fp, "block_index"); |
1078 fprintf(fp, "block_index"); |
1079 if( inst_position != 0 ) { |
1079 if( inst_position != 0 ) { |
1080 fprintf(fp, " - %ld", inst_position); |
1080 fprintf(fp, " - %d", inst_position); |
1081 } |
1081 } |
1082 } |
1082 } |
1083 |
1083 |
1084 // Scan the peepmatch and output a test for each instruction |
1084 // Scan the peepmatch and output a test for each instruction |
1085 static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
1085 static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) { |
1086 intptr_t parent = -1; |
1086 int parent = -1; |
1087 intptr_t inst_position = 0; |
1087 int inst_position = 0; |
1088 const char *inst_name = NULL; |
1088 const char* inst_name = NULL; |
1089 intptr_t input = 0; |
1089 int input = 0; |
1090 fprintf(fp, " // Check instruction sub-tree\n"); |
1090 fprintf(fp, " // Check instruction sub-tree\n"); |
1091 pmatch->reset(); |
1091 pmatch->reset(); |
1092 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1092 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1093 inst_name != NULL; |
1093 inst_name != NULL; |
1094 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1094 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1099 fprintf(fp, " // Identify previous instruction if inside this block\n"); |
1099 fprintf(fp, " // Identify previous instruction if inside this block\n"); |
1100 fprintf(fp, " if( "); |
1100 fprintf(fp, " if( "); |
1101 print_block_index(fp, inst_position); |
1101 print_block_index(fp, inst_position); |
1102 fprintf(fp, " > 0 ) {\n Node *n = block->_nodes.at("); |
1102 fprintf(fp, " > 0 ) {\n Node *n = block->_nodes.at("); |
1103 print_block_index(fp, inst_position); |
1103 print_block_index(fp, inst_position); |
1104 fprintf(fp, ");\n inst%ld = (n->is_Mach()) ? ", inst_position); |
1104 fprintf(fp, ");\n inst%d = (n->is_Mach()) ? ", inst_position); |
1105 fprintf(fp, "n->as_Mach() : NULL;\n }\n"); |
1105 fprintf(fp, "n->as_Mach() : NULL;\n }\n"); |
1106 } |
1106 } |
1107 |
1107 |
1108 // When not the root |
1108 // When not the root |
1109 // Test we have the correct instruction by comparing the rule. |
1109 // Test we have the correct instruction by comparing the rule. |
1110 if( parent != -1 ) { |
1110 if( parent != -1 ) { |
1111 fprintf(fp, " matches = matches && (inst%ld != NULL) && (inst%ld->rule() == %s_rule);\n", |
1111 fprintf(fp, " matches = matches && (inst%d != NULL) && (inst%d->rule() == %s_rule);\n", |
1112 inst_position, inst_position, inst_name); |
1112 inst_position, inst_position, inst_name); |
1113 } |
1113 } |
1114 } else { |
1114 } else { |
1115 // Check that user did not try to constrain a placeholder |
1115 // Check that user did not try to constrain a placeholder |
1116 assert( ! pconstraint->constrains_instruction(inst_position), |
1116 assert( ! pconstraint->constrains_instruction(inst_position), |
1119 } |
1119 } |
1120 } |
1120 } |
1121 |
1121 |
1122 // Build mapping for register indices, num_edges to input |
1122 // Build mapping for register indices, num_edges to input |
1123 static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) { |
1123 static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) { |
1124 intptr_t parent = -1; |
1124 int parent = -1; |
1125 intptr_t inst_position = 0; |
1125 int inst_position = 0; |
1126 const char *inst_name = NULL; |
1126 const char* inst_name = NULL; |
1127 intptr_t input = 0; |
1127 int input = 0; |
1128 fprintf(fp, " // Build map to register info\n"); |
1128 fprintf(fp, " // Build map to register info\n"); |
1129 pmatch->reset(); |
1129 pmatch->reset(); |
1130 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1130 for( pmatch->next_instruction( parent, inst_position, inst_name, input ); |
1131 inst_name != NULL; |
1131 inst_name != NULL; |
1132 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1132 pmatch->next_instruction( parent, inst_position, inst_name, input ) ) { |
1134 if( ! pmatch->is_placeholder() ) { |
1134 if( ! pmatch->is_placeholder() ) { |
1135 // Define temporaries 'inst#', based on self's inst_position |
1135 // Define temporaries 'inst#', based on self's inst_position |
1136 InstructForm *inst = globals[inst_name]->is_instruction(); |
1136 InstructForm *inst = globals[inst_name]->is_instruction(); |
1137 if( inst != NULL ) { |
1137 if( inst != NULL ) { |
1138 char inst_prefix[] = "instXXXX_"; |
1138 char inst_prefix[] = "instXXXX_"; |
1139 sprintf(inst_prefix, "inst%ld_", inst_position); |
1139 sprintf(inst_prefix, "inst%d_", inst_position); |
1140 char receiver[] = "instXXXX->"; |
1140 char receiver[] = "instXXXX->"; |
1141 sprintf(receiver, "inst%ld->", inst_position); |
1141 sprintf(receiver, "inst%d->", inst_position); |
1142 inst->index_temps( fp, globals, inst_prefix, receiver ); |
1142 inst->index_temps( fp, globals, inst_prefix, receiver ); |
1143 } |
1143 } |
1144 } |
1144 } |
1145 } |
1145 } |
1146 } |
1146 } |
1166 if( strcmp(pconstraint->_relation,"==") != 0 ) { |
1166 if( strcmp(pconstraint->_relation,"==") != 0 ) { |
1167 assert( false, "Unimplemented()" ); |
1167 assert( false, "Unimplemented()" ); |
1168 } |
1168 } |
1169 |
1169 |
1170 // LEFT |
1170 // LEFT |
1171 intptr_t left_index = pconstraint->_left_inst; |
1171 int left_index = pconstraint->_left_inst; |
1172 const char *left_op = pconstraint->_left_op; |
1172 const char *left_op = pconstraint->_left_op; |
1173 // Access info on the instructions whose operands are compared |
1173 // Access info on the instructions whose operands are compared |
1174 InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction(); |
1174 InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction(); |
1175 assert( inst_left, "Parser should guaranty this is an instruction"); |
1175 assert( inst_left, "Parser should guaranty this is an instruction"); |
1176 int left_op_base = inst_left->oper_input_base(globals); |
1176 int left_op_base = inst_left->oper_input_base(globals); |
1349 preplace->next_instruction(root_inst); |
1349 preplace->next_instruction(root_inst); |
1350 InstructForm *root_form = globals[root_inst]->is_instruction(); |
1350 InstructForm *root_form = globals[root_inst]->is_instruction(); |
1351 assert( root_form != NULL, "Replacement instruction was not previously defined"); |
1351 assert( root_form != NULL, "Replacement instruction was not previously defined"); |
1352 fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst); |
1352 fprintf(fp, " %sNode *root = new (C) %sNode();\n", root_inst, root_inst); |
1353 |
1353 |
1354 intptr_t inst_num; |
1354 int inst_num; |
1355 const char *op_name; |
1355 const char *op_name; |
1356 int opnds_index = 0; // define result operand |
1356 int opnds_index = 0; // define result operand |
1357 // Then install the use-operands for the new sub-tree |
1357 // Then install the use-operands for the new sub-tree |
1358 // preplace->reset(); // reset breaks iteration |
1358 // preplace->reset(); // reset breaks iteration |
1359 for( preplace->next_operand( inst_num, op_name ); |
1359 for( preplace->next_operand( inst_num, op_name ); |
1360 op_name != NULL; |
1360 op_name != NULL; |
1361 preplace->next_operand( inst_num, op_name ) ) { |
1361 preplace->next_operand( inst_num, op_name ) ) { |
1362 InstructForm *inst_form; |
1362 InstructForm *inst_form; |
1363 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction(); |
1363 inst_form = globals[pmatch->instruction_name(inst_num)]->is_instruction(); |
1364 assert( inst_form, "Parser should guaranty this is an instruction"); |
1364 assert( inst_form, "Parser should guaranty this is an instruction"); |
1365 int op_base = inst_form->oper_input_base(globals); |
|
1366 int inst_op_num = inst_form->operand_position(op_name, Component::USE); |
1365 int inst_op_num = inst_form->operand_position(op_name, Component::USE); |
1367 if( inst_op_num == NameList::Not_in_list ) |
1366 if( inst_op_num == NameList::Not_in_list ) |
1368 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF); |
1367 inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF); |
1369 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE"); |
1368 assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE"); |
1370 // find the name of the OperandForm from the local name |
1369 // find the name of the OperandForm from the local name |
1377 // Add control edge for this node |
1376 // Add control edge for this node |
1378 fprintf(fp, " root->add_req(_in[0]); // control edge\n"); |
1377 fprintf(fp, " root->add_req(_in[0]); // control edge\n"); |
1379 // Add unmatched edges from root of match tree |
1378 // Add unmatched edges from root of match tree |
1380 int op_base = root_form->oper_input_base(globals); |
1379 int op_base = root_form->oper_input_base(globals); |
1381 for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) { |
1380 for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) { |
1382 fprintf(fp, " root->add_req(inst%ld->in(%d)); // unmatched ideal edge\n", |
1381 fprintf(fp, " root->add_req(inst%d->in(%d)); // unmatched ideal edge\n", |
1383 inst_num, unmatched_edge); |
1382 inst_num, unmatched_edge); |
1384 } |
1383 } |
1385 // If new instruction captures bottom type |
1384 // If new instruction captures bottom type |
1386 if( root_form->captures_bottom_type() ) { |
1385 if( root_form->captures_bottom_type() ) { |
1387 // Get bottom type from instruction whose result we are replacing |
1386 // Get bottom type from instruction whose result we are replacing |
1388 fprintf(fp, " root->_bottom_type = inst%ld->bottom_type();\n", inst_num); |
1387 fprintf(fp, " root->_bottom_type = inst%d->bottom_type();\n", inst_num); |
1389 } |
1388 } |
1390 // Define result register and result operand |
1389 // Define result register and result operand |
1391 fprintf(fp, " ra_->add_reference(root, inst%ld);\n", inst_num); |
1390 fprintf(fp, " ra_->add_reference(root, inst%d);\n", inst_num); |
1392 fprintf(fp, " ra_->set_oop (root, ra_->is_oop(inst%ld));\n", inst_num); |
1391 fprintf(fp, " ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num); |
1393 fprintf(fp, " ra_->set_pair(root->_idx, ra_->get_reg_second(inst%ld), ra_->get_reg_first(inst%ld));\n", inst_num, inst_num); |
1392 fprintf(fp, " ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num); |
1394 fprintf(fp, " root->_opnds[0] = inst%ld->_opnds[0]->clone(C); // result\n", inst_num); |
1393 fprintf(fp, " root->_opnds[0] = inst%d->_opnds[0]->clone(C); // result\n", inst_num); |
1395 fprintf(fp, " // ----- Done with initial setup -----\n"); |
1394 fprintf(fp, " // ----- Done with initial setup -----\n"); |
1396 } else { |
1395 } else { |
1397 if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) { |
1396 if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) { |
1398 // Do not have ideal edges for constants after matching |
1397 // Do not have ideal edges for constants after matching |
1399 fprintf(fp, " for( unsigned x%d = inst%ld_idx%d; x%d < inst%ld_idx%d; x%d++ )\n", |
1398 fprintf(fp, " for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n", |
1400 inst_op_num, inst_num, inst_op_num, |
1399 inst_op_num, inst_num, inst_op_num, |
1401 inst_op_num, inst_num, inst_op_num+1, inst_op_num ); |
1400 inst_op_num, inst_num, inst_op_num+1, inst_op_num ); |
1402 fprintf(fp, " root->add_req( inst%ld->in(x%d) );\n", |
1401 fprintf(fp, " root->add_req( inst%d->in(x%d) );\n", |
1403 inst_num, inst_op_num ); |
1402 inst_num, inst_op_num ); |
1404 } else { |
1403 } else { |
1405 fprintf(fp, " // no ideal edge for constants after matching\n"); |
1404 fprintf(fp, " // no ideal edge for constants after matching\n"); |
1406 } |
1405 } |
1407 fprintf(fp, " root->_opnds[%d] = inst%ld->_opnds[%d]->clone(C);\n", |
1406 fprintf(fp, " root->_opnds[%d] = inst%d->_opnds[%d]->clone(C);\n", |
1408 opnds_index, inst_num, inst_op_num ); |
1407 opnds_index, inst_num, inst_op_num ); |
1409 } |
1408 } |
1410 ++opnds_index; |
1409 ++opnds_index; |
1411 } |
1410 } |
1412 }else { |
1411 }else { |