comparison src/share/vm/adlc/output_c.cpp @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents 194e8b7fe9ca
children 89152779163c
comparison
equal deleted inserted replaced
14908:8db6e76cb658 14909:4ca6dc0799b6
1 /* 1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
29 // Utilities to characterize effect statements 29 // Utilities to characterize effect statements
30 static bool is_def(int usedef) { 30 static bool is_def(int usedef) {
31 switch(usedef) { 31 switch(usedef) {
32 case Component::DEF: 32 case Component::DEF:
33 case Component::USE_DEF: return true; break; 33 case Component::USE_DEF: return true; break;
34 }
35 return false;
36 }
37
38 static bool is_use(int usedef) {
39 switch(usedef) {
40 case Component::USE:
41 case Component::USE_DEF:
42 case Component::USE_KILL: return true; break;
43 }
44 return false;
45 }
46
47 static bool is_kill(int usedef) {
48 switch(usedef) {
49 case Component::KILL:
50 case Component::USE_KILL: return true; break;
34 } 51 }
35 return false; 52 return false;
36 } 53 }
37 54
38 // Define an array containing the machine register names, strings. 55 // Define an array containing the machine register names, strings.
1551 for(expand->reset_instructions(); 1568 for(expand->reset_instructions();
1552 (expand_instr = expand->iter_instructions()) != NULL; cnt++) { 1569 (expand_instr = expand->iter_instructions()) != NULL; cnt++) {
1553 new_id = expand_instr->name(); 1570 new_id = expand_instr->name();
1554 1571
1555 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id]; 1572 InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id];
1556
1557 if (!expand_instruction) {
1558 globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n",
1559 node->_ident, new_id);
1560 continue;
1561 }
1562
1563 if (expand_instruction->has_temps()) { 1573 if (expand_instruction->has_temps()) {
1564 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s", 1574 globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s",
1565 node->_ident, new_id); 1575 node->_ident, new_id);
1566 } 1576 }
1567 1577
1616 int prev_pos = -1; 1626 int prev_pos = -1;
1617 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) { 1627 for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) {
1618 // Use 'parameter' at current position in list of new instruction's formals 1628 // Use 'parameter' at current position in list of new instruction's formals
1619 // instead of 'opid' when looking up info internal to new_inst 1629 // instead of 'opid' when looking up info internal to new_inst
1620 const char *parameter = formal_lst->iter(); 1630 const char *parameter = formal_lst->iter();
1621 if (!parameter) {
1622 globalAD->syntax_err(node->_linenum, "Operand %s of expand instruction %s has"
1623 " no equivalent in new instruction %s.",
1624 opid, node->_ident, new_inst->_ident);
1625 assert(0, "Wrong expand");
1626 }
1627
1628 // Check for an operand which is created in the expand rule 1631 // Check for an operand which is created in the expand rule
1629 if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) { 1632 if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) {
1630 new_pos = new_inst->operand_position(parameter,Component::USE); 1633 new_pos = new_inst->operand_position(parameter,Component::USE);
1631 exp_pos += node->num_opnds(); 1634 exp_pos += node->num_opnds();
1632 // If there is no use of the created operand, just skip it 1635 // If there is no use of the created operand, just skip it
1820 } 1823 }
1821 } 1824 }
1822 1825
1823 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge. 1826 // If the node is a MachConstantNode, insert the MachConstantBaseNode edge.
1824 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input). 1827 // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input).
1825 // There are nodes that don't use $constantablebase, but still require that it 1828 if (node->is_mach_constant()) {
1826 // is an input to the node. Example: divF_reg_immN, Repl32B_imm on x86_64. 1829 fprintf(fp," add_req(C->mach_constant_base_node());\n");
1827 if (node->is_mach_constant() || node->needs_constant_base()) { 1830 }
1828 if (node->is_ideal_call() != Form::invalid_type && 1831
1829 node->is_ideal_call() != Form::JAVA_LEAF) { 1832 fprintf(fp,"\n");
1830 fprintf(fp, " // MachConstantBaseNode added in matcher.\n"); 1833 if( node->expands() ) {
1831 _needs_clone_jvms = true; 1834 fprintf(fp," return result;\n");
1832 } else {
1833 fprintf(fp, " add_req(C->mach_constant_base_node());\n");
1834 }
1835 }
1836
1837 fprintf(fp, "\n");
1838 if (node->expands()) {
1839 fprintf(fp, " return result;\n");
1840 } else { 1835 } else {
1841 fprintf(fp, " return this;\n"); 1836 fprintf(fp," return this;\n");
1842 } 1837 }
1843 fprintf(fp, "}\n"); 1838 fprintf(fp,"}\n");
1844 fprintf(fp, "\n"); 1839 fprintf(fp,"\n");
1845 } 1840 }
1846 1841
1847 1842
1848 //------------------------------Emit Routines---------------------------------- 1843 //------------------------------Emit Routines----------------------------------
1849 // Special classes and routines for defining node emit routines which output 1844 // Special classes and routines for defining node emit routines which output
1941 "'primary', 'secondary' and 'tertiary' don't follow operand."); 1936 "'primary', 'secondary' and 'tertiary' don't follow operand.");
1942 } 1937 }
1943 else if ((strcmp(rep_var, "constanttablebase") == 0) || 1938 else if ((strcmp(rep_var, "constanttablebase") == 0) ||
1944 (strcmp(rep_var, "constantoffset") == 0) || 1939 (strcmp(rep_var, "constantoffset") == 0) ||
1945 (strcmp(rep_var, "constantaddress") == 0)) { 1940 (strcmp(rep_var, "constantaddress") == 0)) {
1946 if (!(_inst.is_mach_constant() || _inst.needs_constant_base())) { 1941 if (!_inst.is_mach_constant()) {
1947 _AD.syntax_err(_encoding._linenum, 1942 _AD.syntax_err(_encoding._linenum,
1948 "Replacement variable %s not allowed in instruct %s (only in MachConstantNode or MachCall).\n", 1943 "Replacement variable %s not allowed in instruct %s (only in MachConstantNode).\n",
1949 rep_var, _encoding._name); 1944 rep_var, _encoding._name);
1950 } 1945 }
1951 } 1946 }
1952 else { 1947 else {
1953 // Lookup its position in (formal) parameter list of encoding 1948 // Lookup its position in (formal) parameter list of encoding
2106 if ( _reg_status != LITERAL_NOT_SEEN ) { 2101 if ( _reg_status != LITERAL_NOT_SEEN ) {
2107 assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now"); 2102 assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now");
2108 if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) { 2103 if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) {
2109 _reg_status = LITERAL_ACCESSED; 2104 _reg_status = LITERAL_ACCESSED;
2110 } else { 2105 } else {
2111 _AD.syntax_err(_encoding._linenum,
2112 "Invalid access to literal register parameter '%s' in %s.\n",
2113 rep_var, _encoding._name);
2114 assert( false, "invalid access to literal register parameter"); 2106 assert( false, "invalid access to literal register parameter");
2115 } 2107 }
2116 } 2108 }
2117 // literal constant parameters must be accessed as a 'constant' field 2109 // literal constant parameters must be accessed as a 'constant' field
2118 if (_constant_status != LITERAL_NOT_SEEN) { 2110 if ( _constant_status != LITERAL_NOT_SEEN ) {
2119 assert(_constant_status == LITERAL_SEEN, "Must have seen constant literal before now"); 2111 assert( _constant_status == LITERAL_SEEN, "Must have seen constant literal before now");
2120 if (strcmp(rep_var,"$constant") == 0) { 2112 if( strcmp(rep_var,"$constant") == 0 ) {
2121 _constant_status = LITERAL_ACCESSED; 2113 _constant_status = LITERAL_ACCESSED;
2122 } else { 2114 } else {
2123 _AD.syntax_err(_encoding._linenum, 2115 assert( false, "invalid access to literal constant parameter");
2124 "Invalid access to literal constant parameter '%s' in %s.\n",
2125 rep_var, _encoding._name);
2126 } 2116 }
2127 } 2117 }
2128 } // end replacement and/or subfield 2118 } // end replacement and/or subfield
2129 2119
2130 } 2120 }
2302 if (strcmp(rep_var,"$Register") == 0) return "as_Register"; 2292 if (strcmp(rep_var,"$Register") == 0) return "as_Register";
2303 if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister"; 2293 if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister";
2304 #if defined(IA32) || defined(AMD64) 2294 #if defined(IA32) || defined(AMD64)
2305 if (strcmp(rep_var,"$XMMRegister") == 0) return "as_XMMRegister"; 2295 if (strcmp(rep_var,"$XMMRegister") == 0) return "as_XMMRegister";
2306 #endif 2296 #endif
2307 if (strcmp(rep_var,"$CondRegister") == 0) return "as_ConditionRegister";
2308 return NULL; 2297 return NULL;
2309 } 2298 }
2310 2299
2311 void emit_field(const char *rep_var) { 2300 void emit_field(const char *rep_var) {
2312 const char* reg_convert = reg_conversion(rep_var); 2301 const char* reg_convert = reg_conversion(rep_var);
2497 //(2) 2486 //(2)
2498 // Print the size 2487 // Print the size
2499 fprintf(fp, " return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size); 2488 fprintf(fp, " return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size);
2500 2489
2501 // (3) and (4) 2490 // (3) and (4)
2502 fprintf(fp,"}\n\n"); 2491 fprintf(fp,"}\n");
2503 }
2504
2505 // Emit postalloc expand function.
2506 void ArchDesc::define_postalloc_expand(FILE *fp, InstructForm &inst) {
2507 InsEncode *ins_encode = inst._insencode;
2508
2509 // Output instruction's postalloc_expand prototype.
2510 fprintf(fp, "void %sNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {\n",
2511 inst._ident);
2512
2513 assert((_encode != NULL) && (ins_encode != NULL), "You must define an encode section.");
2514
2515 // Output each operand's offset into the array of registers.
2516 inst.index_temps(fp, _globalNames);
2517
2518 // Output variables "unsigned idx_<par_name>", Node *n_<par_name> and "MachOpnd *op_<par_name>"
2519 // for each parameter <par_name> specified in the encoding.
2520 ins_encode->reset();
2521 const char *ec_name = ins_encode->encode_class_iter();
2522 assert(ec_name != NULL, "Postalloc expand must specify an encoding.");
2523
2524 EncClass *encoding = _encode->encClass(ec_name);
2525 if (encoding == NULL) {
2526 fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
2527 abort();
2528 }
2529 if (ins_encode->current_encoding_num_args() != encoding->num_args()) {
2530 globalAD->syntax_err(ins_encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
2531 inst._ident, ins_encode->current_encoding_num_args(),
2532 ec_name, encoding->num_args());
2533 }
2534
2535 fprintf(fp, " // Access to ins and operands for postalloc expand.\n");
2536 const int buflen = 2000;
2537 char idxbuf[buflen]; char *ib = idxbuf; idxbuf[0] = '\0';
2538 char nbuf [buflen]; char *nb = nbuf; nbuf[0] = '\0';
2539 char opbuf [buflen]; char *ob = opbuf; opbuf[0] = '\0';
2540
2541 encoding->_parameter_type.reset();
2542 encoding->_parameter_name.reset();
2543 const char *type = encoding->_parameter_type.iter();
2544 const char *name = encoding->_parameter_name.iter();
2545 int param_no = 0;
2546 for (; (type != NULL) && (name != NULL);
2547 (type = encoding->_parameter_type.iter()), (name = encoding->_parameter_name.iter())) {
2548 const char* arg_name = ins_encode->rep_var_name(inst, param_no);
2549 int idx = inst.operand_position_format(arg_name);
2550 if (strcmp(arg_name, "constanttablebase") == 0) {
2551 ib += sprintf(ib, " unsigned idx_%-5s = mach_constant_base_node_input(); \t// %s, \t%s\n",
2552 name, type, arg_name);
2553 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name);
2554 // There is no operand for the constanttablebase.
2555 } else if (inst.is_noninput_operand(idx)) {
2556 globalAD->syntax_err(inst._linenum,
2557 "In %s: you can not pass the non-input %s to a postalloc expand encoding.\n",
2558 inst._ident, arg_name);
2559 } else {
2560 ib += sprintf(ib, " unsigned idx_%-5s = idx%d; \t// %s, \t%s\n",
2561 name, idx, type, arg_name);
2562 nb += sprintf(nb, " Node *n_%-7s = lookup(idx_%s);\n", name, name);
2563 ob += sprintf(ob, " %sOper *op_%s = (%sOper *)opnd_array(%d);\n", type, name, type, idx);
2564 }
2565 param_no++;
2566 }
2567 assert(ib < &idxbuf[buflen-1] && nb < &nbuf[buflen-1] && ob < &opbuf[buflen-1], "buffer overflow");
2568
2569 fprintf(fp, "%s", idxbuf);
2570 fprintf(fp, " Node *n_region = lookup(0);\n");
2571 fprintf(fp, "%s%s", nbuf, opbuf);
2572 fprintf(fp, " Compile *C = ra_->C;\n");
2573
2574 // Output this instruction's encodings.
2575 fprintf(fp, " {");
2576 const char *ec_code = NULL;
2577 const char *ec_rep_var = NULL;
2578 assert(encoding == _encode->encClass(ec_name), "");
2579
2580 DefineEmitState pending(fp, *this, *encoding, *ins_encode, inst);
2581 encoding->_code.reset();
2582 encoding->_rep_vars.reset();
2583 // Process list of user-defined strings,
2584 // and occurrences of replacement variables.
2585 // Replacement Vars are pushed into a list and then output.
2586 while ((ec_code = encoding->_code.iter()) != NULL) {
2587 if (! encoding->_code.is_signal(ec_code)) {
2588 // Emit pending code.
2589 pending.emit();
2590 pending.clear();
2591 // Emit this code section.
2592 fprintf(fp, "%s", ec_code);
2593 } else {
2594 // A replacement variable or one of its subfields.
2595 // Obtain replacement variable from list.
2596 ec_rep_var = encoding->_rep_vars.iter();
2597 pending.add_rep_var(ec_rep_var);
2598 }
2599 }
2600 // Emit pending code.
2601 pending.emit();
2602 pending.clear();
2603 fprintf(fp, " }\n");
2604
2605 fprintf(fp, "}\n\n");
2606
2607 ec_name = ins_encode->encode_class_iter();
2608 assert(ec_name == NULL, "Postalloc expand may only have one encoding.");
2609 } 2492 }
2610 2493
2611 // defineEmit ----------------------------------------------------------------- 2494 // defineEmit -----------------------------------------------------------------
2612 void ArchDesc::defineEmit(FILE* fp, InstructForm& inst) { 2495 void ArchDesc::defineEmit(FILE* fp, InstructForm& inst) {
2613 InsEncode* encode = inst._insencode; 2496 InsEncode* encode = inst._insencode;
2956 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); 2839 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
2957 emit_position = true; 2840 emit_position = true;
2958 } else if ( (strcmp(name,"disp") == 0) ) { 2841 } else if ( (strcmp(name,"disp") == 0) ) {
2959 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n"); 2842 fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
2960 } else { 2843 } else {
2961 fprintf(fp, "() const {\n"); 2844 fprintf(fp,"() const { \n");
2962 } 2845 }
2963 2846
2964 // Check for hexadecimal value OR replacement variable 2847 // Check for hexadecimal value OR replacement variable
2965 if( *encoding == '$' ) { 2848 if( *encoding == '$' ) {
2966 // Replacement variable 2849 // Replacement variable
3006 } 2889 }
3007 else if( *encoding == '0' && *(encoding+1) == 'x' ) { 2890 else if( *encoding == '0' && *(encoding+1) == 'x' ) {
3008 // Hex value 2891 // Hex value
3009 fprintf(fp," return %s;\n", encoding); 2892 fprintf(fp," return %s;\n", encoding);
3010 } else { 2893 } else {
3011 globalAD->syntax_err(oper._linenum, "In operand %s: Do not support this encode constant: '%s' for %s.",
3012 oper._ident, encoding, name);
3013 assert( false, "Do not support octal or decimal encode constants"); 2894 assert( false, "Do not support octal or decimal encode constants");
3014 } 2895 }
3015 fprintf(fp," }\n"); 2896 fprintf(fp," }\n");
3016 2897
3017 if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) { 2898 if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) {
3172 if ( instr->ideal_only() ) continue; 3053 if ( instr->ideal_only() ) continue;
3173 // If there are multiple defs/kills, or an explicit expand rule, build rule 3054 // If there are multiple defs/kills, or an explicit expand rule, build rule
3174 if( instr->expands() || instr->needs_projections() || 3055 if( instr->expands() || instr->needs_projections() ||
3175 instr->has_temps() || 3056 instr->has_temps() ||
3176 instr->is_mach_constant() || 3057 instr->is_mach_constant() ||
3177 instr->needs_constant_base() ||
3178 instr->_matrule != NULL && 3058 instr->_matrule != NULL &&
3179 instr->num_opnds() != instr->num_unique_opnds() ) 3059 instr->num_opnds() != instr->num_unique_opnds() )
3180 defineExpand(_CPP_EXPAND_file._fp, instr); 3060 defineExpand(_CPP_EXPAND_file._fp, instr);
3181 // If there is an explicit peephole rule, build it 3061 // If there is an explicit peephole rule, build it
3182 if ( instr->peepholes() ) 3062 if ( instr->peepholes() )
3260 _instructions.reset(); 3140 _instructions.reset();
3261 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { 3141 for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
3262 // Ensure this is a machine-world instruction 3142 // Ensure this is a machine-world instruction
3263 if ( instr->ideal_only() ) continue; 3143 if ( instr->ideal_only() ) continue;
3264 3144
3265 if (instr->_insencode) { 3145 if (instr->_insencode) defineEmit (fp, *instr);
3266 if (instr->postalloc_expands()) {
3267 // Don't write this to _CPP_EXPAND_file, as the code generated calls C-code
3268 // from code sections in ad file that is dumped to fp.
3269 define_postalloc_expand(fp, *instr);
3270 } else {
3271 defineEmit(fp, *instr);
3272 }
3273 }
3274 if (instr->is_mach_constant()) defineEvalConstant(fp, *instr); 3146 if (instr->is_mach_constant()) defineEvalConstant(fp, *instr);
3275 if (instr->_size) defineSize (fp, *instr); 3147 if (instr->_size) defineSize (fp, *instr);
3276 3148
3277 // side-call to generate output that used to be in the header file: 3149 // side-call to generate output that used to be in the header file:
3278 extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file); 3150 extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file);
3627 else if (!strcmp(calling_convention, "SOC")) callconv = 'C'; 3499 else if (!strcmp(calling_convention, "SOC")) callconv = 'C';
3628 else if (!strcmp(calling_convention, "AS")) callconv = 'A'; 3500 else if (!strcmp(calling_convention, "AS")) callconv = 'A';
3629 else callconv = 'Z'; 3501 else callconv = 'Z';
3630 3502
3631 return callconv; 3503 return callconv;
3632 }
3633
3634 void ArchDesc::generate_needs_clone_jvms(FILE *fp_cpp) {
3635 fprintf(fp_cpp, "bool Compile::needs_clone_jvms() { return %s; }\n\n",
3636 _needs_clone_jvms ? "true" : "false");
3637 } 3504 }
3638 3505
3639 //---------------------------generate_assertion_checks------------------- 3506 //---------------------------generate_assertion_checks-------------------
3640 void ArchDesc::generate_adlc_verification(FILE *fp_cpp) { 3507 void ArchDesc::generate_adlc_verification(FILE *fp_cpp) {
3641 fprintf(fp_cpp, "\n"); 3508 fprintf(fp_cpp, "\n");
3950 fprintf(fp_cpp, " );\n"); 3817 fprintf(fp_cpp, " );\n");
3951 // ##### 3818 // #####
3952 } 3819 }
3953 3820
3954 // Fill in the bottom_type where requested 3821 // Fill in the bottom_type where requested
3955 if (inst->captures_bottom_type(_globalNames)) { 3822 if ( inst->captures_bottom_type(_globalNames) ) {
3956 if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) { 3823 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3957 fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
3958 }
3959 } 3824 }
3960 if( inst->is_ideal_if() ) { 3825 if( inst->is_ideal_if() ) {
3961 fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent); 3826 fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent);
3962 fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent); 3827 fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent);
3963 } 3828 }