369 // finish line (1) and start line (2)
370 fprintf(fp,") : ");
371 // generate initializers for constants
372 i = 0;
373 fprintf(fp,"_c%d(c%d)", i, i);
374 for( i = 1; i < num_consts; ++i) {
375 fprintf(fp,", _c%d(c%d)", i, i);
376 }
377 // The body for the constructor is empty
378 fprintf(fp," {}\n");
379 }
380
381 // ---------------------------------------------------------------------------
382 // Utilities to generate format rules for machine operands and instructions
383 // ---------------------------------------------------------------------------
384
385 // Generate the format rule for condition codes
386 static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) {
387 assert(oper != NULL, "what");
388 CondInterface* cond = oper->_interface->is_CondInterface();
389 fprintf(fp, " if( _c%d == BoolTest::eq ) st->print(\"%s\");\n",i,cond->_equal_format);
390 fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print(\"%s\");\n",i,cond->_not_equal_format);
391 fprintf(fp, " else if( _c%d == BoolTest::le ) st->print(\"%s\");\n",i,cond->_less_equal_format);
392 fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print(\"%s\");\n",i,cond->_greater_equal_format);
393 fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print(\"%s\");\n",i,cond->_less_format);
394 fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print(\"%s\");\n",i,cond->_greater_format);
395 fprintf(fp, " else if( _c%d == BoolTest::overflow ) st->print(\"%s\");\n",i,cond->_overflow_format);
396 fprintf(fp, " else if( _c%d == BoolTest::no_overflow ) st->print(\"%s\");\n",i,cond->_no_overflow_format);
397 }
398
399 // Output code that dumps constant values, increment "i" if type is constant
400 static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i, OperandForm* oper) {
401 if (!strcmp(ideal_type, "ConI")) {
402 fprintf(fp," st->print(\"#%%d\", _c%d);\n", i);
403 fprintf(fp," st->print(\"/0x%%08x\", _c%d);\n", i);
404 ++i;
405 }
406 else if (!strcmp(ideal_type, "ConP")) {
407 fprintf(fp," _c%d->dump_on(st);\n", i);
408 ++i;
409 }
410 else if (!strcmp(ideal_type, "ConN")) {
411 fprintf(fp," _c%d->dump_on(st);\n", i);
412 ++i;
413 }
414 else if (!strcmp(ideal_type, "ConNKlass")) {
415 fprintf(fp," _c%d->dump_on(st);\n", i);
416 ++i;
417 }
418 else if (!strcmp(ideal_type, "ConL")) {
419 fprintf(fp," st->print(\"#\" INT64_FORMAT, _c%d);\n", i);
420 fprintf(fp," st->print(\"/\" PTR64_FORMAT, _c%d);\n", i);
421 ++i;
422 }
423 else if (!strcmp(ideal_type, "ConF")) {
424 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
425 fprintf(fp," jint _c%di = JavaValue(_c%d).get_jint();\n", i, i);
426 fprintf(fp," st->print(\"/0x%%x/\", _c%di);\n", i);
427 ++i;
428 }
429 else if (!strcmp(ideal_type, "ConD")) {
430 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
431 fprintf(fp," jlong _c%dl = JavaValue(_c%d).get_jlong();\n", i, i);
432 fprintf(fp," st->print(\"/\" PTR64_FORMAT, _c%dl);\n", i);
433 ++i;
434 }
435 else if (!strcmp(ideal_type, "Bool")) {
436 defineCCodeDump(oper, fp,i);
437 ++i;
438 }
439
440 return i;
441 }
442
443 // Generate the format rule for an operand
444 void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {
445 if (!for_c_file) {
446 // invoked after output #ifndef PRODUCT to ad_<arch>.hpp
447 // compile the bodies separately, to cut down on recompilations
448 fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");
449 fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");
450 return;
451 }
452
454 int idx = 0; // position of operand in match rule
455
456 // Generate internal format function, used when stored locally
457 fprintf(fp, "\n#ifndef PRODUCT\n");
458 fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);
459 // Generate the user-defined portion of the format
460 if (oper._format) {
461 if ( oper._format->_strings.count() != 0 ) {
462 // No initialization code for int_format
463
464 // Build the format from the entries in strings and rep_vars
465 const char *string = NULL;
466 oper._format->_rep_vars.reset();
467 oper._format->_strings.reset();
468 while ( (string = oper._format->_strings.iter()) != NULL ) {
469
470 // Check if this is a standard string or a replacement variable
471 if ( string != NameList::_signal ) {
472 // Normal string
473 // Pass through to st->print
474 fprintf(fp," st->print(\"%s\");\n", string);
475 } else {
476 // Replacement variable
477 const char *rep_var = oper._format->_rep_vars.iter();
478 // Check that it is a local name, and an operand
479 const Form* form = oper._localNames[rep_var];
480 if (form == NULL) {
481 globalAD->syntax_err(oper._linenum,
482 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
483 assert(form, "replacement variable was not found in local names");
484 }
485 OperandForm *op = form->is_operand();
486 // Get index if register or constant
487 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
488 idx = oper.register_position( globals, rep_var);
489 }
490 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
491 idx = oper.constant_position( globals, rep_var);
492 } else {
493 idx = 0;
494 }
525 fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);
526 // Generate the user-defined portion of the format
527 if (oper._format) {
528 if ( oper._format->_strings.count() != 0 ) {
529
530 // Check for a replacement string "$..."
531 if ( oper._format->_rep_vars.count() != 0 ) {
532 // Initialization code for ext_format
533 }
534
535 // Build the format from the entries in strings and rep_vars
536 const char *string = NULL;
537 oper._format->_rep_vars.reset();
538 oper._format->_strings.reset();
539 while ( (string = oper._format->_strings.iter()) != NULL ) {
540
541 // Check if this is a standard string or a replacement variable
542 if ( string != NameList::_signal ) {
543 // Normal string
544 // Pass through to st->print
545 fprintf(fp," st->print(\"%s\");\n", string);
546 } else {
547 // Replacement variable
548 const char *rep_var = oper._format->_rep_vars.iter();
549 // Check that it is a local name, and an operand
550 const Form* form = oper._localNames[rep_var];
551 if (form == NULL) {
552 globalAD->syntax_err(oper._linenum,
553 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
554 assert(form, "replacement variable was not found in local names");
555 }
556 OperandForm *op = form->is_operand();
557 // Get index if register or constant
558 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
559 idx = oper.register_position( globals, rep_var);
560 }
561 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
562 idx = oper.constant_position( globals, rep_var);
563 } else {
564 idx = 0;
565 }
652 inst._format->_strings.iter();
653 if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) {
654 Form::DataType constant_type = form->is_operand()->is_base_constant(globals);
655 if ( constant_type == Form::idealD ) {
656 fprintf(fp,"->constantD()");
657 } else if ( constant_type == Form::idealF ) {
658 fprintf(fp,"->constantF()");
659 } else if ( constant_type == Form::idealL ) {
660 fprintf(fp,"->constantL()");
661 } else {
662 fprintf(fp,"->constant()");
663 }
664 } else if ( strcmp(rep_var,"$cmpcode") == 0) {
665 fprintf(fp,"->ccode()");
666 } else {
667 assert( false, "ShouldNotReachHere()");
668 }
669 } else if( string == NameList::_signal2 ) // Raw program text
670 fputs(inst._format->_strings.iter(), fp);
671 else
672 fprintf(fp,"st->print(\"%s\");\n", string);
673 } // Done with all format strings
674 } // Done generating the user-defined portion of the format
675
676 // Add call debug info automatically
677 Form::CallType call_type = inst.is_ideal_call();
678 if( call_type != Form::invalid_type ) {
679 switch( call_type ) {
680 case Form::JAVA_DYNAMIC:
681 fprintf(fp," _method->print_short_name(st);\n");
682 break;
683 case Form::JAVA_STATIC:
684 fprintf(fp," if( _method ) _method->print_short_name(st);\n");
685 fprintf(fp," else st->print(\" wrapper for: %%s\", _name);\n");
686 fprintf(fp," if( !_method ) dump_trap_args(st);\n");
687 break;
688 case Form::JAVA_COMPILED:
689 case Form::JAVA_INTERP:
690 break;
691 case Form::JAVA_RUNTIME:
692 case Form::JAVA_LEAF:
693 case Form::JAVA_NATIVE:
694 fprintf(fp," st->print(\" %%s\", _name);");
695 break;
696 default:
697 assert(0,"ShouldNotReachHere");
698 }
699 fprintf(fp, " st->print_cr(\"\");\n" );
700 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
701 fprintf(fp, " st->print(\" # \");\n" );
702 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
703 }
704 else if(inst.is_ideal_safepoint()) {
705 fprintf(fp, " st->print(\"\");\n" );
706 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
707 fprintf(fp, " st->print(\" # \");\n" );
708 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
709 }
710 else if( inst.is_ideal_if() ) {
711 fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" );
712 }
713 else if( inst.is_ideal_mem() ) {
714 // Print out the field name if available to improve readability
715 fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n");
716 fprintf(fp, " ciField* f = ra->C->alias_type(adr_type())->field();\n");
717 fprintf(fp, " st->print(\" %s Field: \");\n", commentSeperator);
718 fprintf(fp, " if (f->is_volatile())\n");
719 fprintf(fp, " st->print(\"volatile \");\n");
720 fprintf(fp, " f->holder()->name()->print_symbol_on(st);\n");
721 fprintf(fp, " st->print(\".\");\n");
722 fprintf(fp, " f->name()->print_symbol_on(st);\n");
723 fprintf(fp, " if (f->is_constant())\n");
724 fprintf(fp, " st->print(\" (constant)\");\n");
725 fprintf(fp, " } else {\n");
|
369 // finish line (1) and start line (2)
370 fprintf(fp,") : ");
371 // generate initializers for constants
372 i = 0;
373 fprintf(fp,"_c%d(c%d)", i, i);
374 for( i = 1; i < num_consts; ++i) {
375 fprintf(fp,", _c%d(c%d)", i, i);
376 }
377 // The body for the constructor is empty
378 fprintf(fp," {}\n");
379 }
380
381 // ---------------------------------------------------------------------------
382 // Utilities to generate format rules for machine operands and instructions
383 // ---------------------------------------------------------------------------
384
385 // Generate the format rule for condition codes
386 static void defineCCodeDump(OperandForm* oper, FILE *fp, int i) {
387 assert(oper != NULL, "what");
388 CondInterface* cond = oper->_interface->is_CondInterface();
389 fprintf(fp, " if( _c%d == BoolTest::eq ) st->print_raw(\"%s\");\n",i,cond->_equal_format);
390 fprintf(fp, " else if( _c%d == BoolTest::ne ) st->print_raw(\"%s\");\n",i,cond->_not_equal_format);
391 fprintf(fp, " else if( _c%d == BoolTest::le ) st->print_raw(\"%s\");\n",i,cond->_less_equal_format);
392 fprintf(fp, " else if( _c%d == BoolTest::ge ) st->print_raw(\"%s\");\n",i,cond->_greater_equal_format);
393 fprintf(fp, " else if( _c%d == BoolTest::lt ) st->print_raw(\"%s\");\n",i,cond->_less_format);
394 fprintf(fp, " else if( _c%d == BoolTest::gt ) st->print_raw(\"%s\");\n",i,cond->_greater_format);
395 fprintf(fp, " else if( _c%d == BoolTest::overflow ) st->print_raw(\"%s\");\n",i,cond->_overflow_format);
396 fprintf(fp, " else if( _c%d == BoolTest::no_overflow ) st->print_raw(\"%s\");\n",i,cond->_no_overflow_format);
397 }
398
399 // Output code that dumps constant values, increment "i" if type is constant
400 static uint dump_spec_constant(FILE *fp, const char *ideal_type, uint i, OperandForm* oper) {
401 if (!strcmp(ideal_type, "ConI")) {
402 fprintf(fp," st->print(\"#%%d\", _c%d);\n", i);
403 fprintf(fp," st->print(\"/0x%%08x\", _c%d);\n", i);
404 ++i;
405 }
406 else if (!strcmp(ideal_type, "ConP")) {
407 fprintf(fp," _c%d->dump_on(st);\n", i);
408 ++i;
409 }
410 else if (!strcmp(ideal_type, "ConN")) {
411 fprintf(fp," _c%d->dump_on(st);\n", i);
412 ++i;
413 }
414 else if (!strcmp(ideal_type, "ConNKlass")) {
415 fprintf(fp," _c%d->dump_on(st);\n", i);
416 ++i;
417 }
418 else if (!strcmp(ideal_type, "ConL")) {
419 fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", i);
420 fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%d);\n", i);
421 ++i;
422 }
423 else if (!strcmp(ideal_type, "ConF")) {
424 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
425 fprintf(fp," jint _c%di = JavaValue(_c%d).get_jint();\n", i, i);
426 fprintf(fp," st->print(\"/0x%%x/\", _c%di);\n", i);
427 ++i;
428 }
429 else if (!strcmp(ideal_type, "ConD")) {
430 fprintf(fp," st->print(\"#%%f\", _c%d);\n", i);
431 fprintf(fp," jlong _c%dl = JavaValue(_c%d).get_jlong();\n", i, i);
432 fprintf(fp," st->print(\"/\" PTR64_FORMAT, (uint64_t)_c%dl);\n", i);
433 ++i;
434 }
435 else if (!strcmp(ideal_type, "Bool")) {
436 defineCCodeDump(oper, fp,i);
437 ++i;
438 }
439
440 return i;
441 }
442
443 // Generate the format rule for an operand
444 void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file = false) {
445 if (!for_c_file) {
446 // invoked after output #ifndef PRODUCT to ad_<arch>.hpp
447 // compile the bodies separately, to cut down on recompilations
448 fprintf(fp," virtual void int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const;\n");
449 fprintf(fp," virtual void ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const;\n");
450 return;
451 }
452
454 int idx = 0; // position of operand in match rule
455
456 // Generate internal format function, used when stored locally
457 fprintf(fp, "\n#ifndef PRODUCT\n");
458 fprintf(fp,"void %sOper::int_format(PhaseRegAlloc *ra, const MachNode *node, outputStream *st) const {\n", oper._ident);
459 // Generate the user-defined portion of the format
460 if (oper._format) {
461 if ( oper._format->_strings.count() != 0 ) {
462 // No initialization code for int_format
463
464 // Build the format from the entries in strings and rep_vars
465 const char *string = NULL;
466 oper._format->_rep_vars.reset();
467 oper._format->_strings.reset();
468 while ( (string = oper._format->_strings.iter()) != NULL ) {
469
470 // Check if this is a standard string or a replacement variable
471 if ( string != NameList::_signal ) {
472 // Normal string
473 // Pass through to st->print
474 fprintf(fp," st->print_raw(\"%s\");\n", string);
475 } else {
476 // Replacement variable
477 const char *rep_var = oper._format->_rep_vars.iter();
478 // Check that it is a local name, and an operand
479 const Form* form = oper._localNames[rep_var];
480 if (form == NULL) {
481 globalAD->syntax_err(oper._linenum,
482 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
483 assert(form, "replacement variable was not found in local names");
484 }
485 OperandForm *op = form->is_operand();
486 // Get index if register or constant
487 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
488 idx = oper.register_position( globals, rep_var);
489 }
490 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
491 idx = oper.constant_position( globals, rep_var);
492 } else {
493 idx = 0;
494 }
525 fprintf(fp,"void %sOper::ext_format(PhaseRegAlloc *ra, const MachNode *node, int idx, outputStream *st) const {\n", oper._ident);
526 // Generate the user-defined portion of the format
527 if (oper._format) {
528 if ( oper._format->_strings.count() != 0 ) {
529
530 // Check for a replacement string "$..."
531 if ( oper._format->_rep_vars.count() != 0 ) {
532 // Initialization code for ext_format
533 }
534
535 // Build the format from the entries in strings and rep_vars
536 const char *string = NULL;
537 oper._format->_rep_vars.reset();
538 oper._format->_strings.reset();
539 while ( (string = oper._format->_strings.iter()) != NULL ) {
540
541 // Check if this is a standard string or a replacement variable
542 if ( string != NameList::_signal ) {
543 // Normal string
544 // Pass through to st->print
545 fprintf(fp," st->print_raw(\"%s\");\n", string);
546 } else {
547 // Replacement variable
548 const char *rep_var = oper._format->_rep_vars.iter();
549 // Check that it is a local name, and an operand
550 const Form* form = oper._localNames[rep_var];
551 if (form == NULL) {
552 globalAD->syntax_err(oper._linenum,
553 "\'%s\' not found in format for %s\n", rep_var, oper._ident);
554 assert(form, "replacement variable was not found in local names");
555 }
556 OperandForm *op = form->is_operand();
557 // Get index if register or constant
558 if ( op->_matrule && op->_matrule->is_base_register(globals) ) {
559 idx = oper.register_position( globals, rep_var);
560 }
561 else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
562 idx = oper.constant_position( globals, rep_var);
563 } else {
564 idx = 0;
565 }
652 inst._format->_strings.iter();
653 if ( strcmp(rep_var,"$constant") == 0 && opc->is_operand()) {
654 Form::DataType constant_type = form->is_operand()->is_base_constant(globals);
655 if ( constant_type == Form::idealD ) {
656 fprintf(fp,"->constantD()");
657 } else if ( constant_type == Form::idealF ) {
658 fprintf(fp,"->constantF()");
659 } else if ( constant_type == Form::idealL ) {
660 fprintf(fp,"->constantL()");
661 } else {
662 fprintf(fp,"->constant()");
663 }
664 } else if ( strcmp(rep_var,"$cmpcode") == 0) {
665 fprintf(fp,"->ccode()");
666 } else {
667 assert( false, "ShouldNotReachHere()");
668 }
669 } else if( string == NameList::_signal2 ) // Raw program text
670 fputs(inst._format->_strings.iter(), fp);
671 else
672 fprintf(fp,"st->print_raw(\"%s\");\n", string);
673 } // Done with all format strings
674 } // Done generating the user-defined portion of the format
675
676 // Add call debug info automatically
677 Form::CallType call_type = inst.is_ideal_call();
678 if( call_type != Form::invalid_type ) {
679 switch( call_type ) {
680 case Form::JAVA_DYNAMIC:
681 fprintf(fp," _method->print_short_name(st);\n");
682 break;
683 case Form::JAVA_STATIC:
684 fprintf(fp," if( _method ) _method->print_short_name(st);\n");
685 fprintf(fp," else st->print(\" wrapper for: %%s\", _name);\n");
686 fprintf(fp," if( !_method ) dump_trap_args(st);\n");
687 break;
688 case Form::JAVA_COMPILED:
689 case Form::JAVA_INTERP:
690 break;
691 case Form::JAVA_RUNTIME:
692 case Form::JAVA_LEAF:
693 case Form::JAVA_NATIVE:
694 fprintf(fp," st->print(\" %%s\", _name);");
695 break;
696 default:
697 assert(0,"ShouldNotReachHere");
698 }
699 fprintf(fp, " st->cr();\n" );
700 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
701 fprintf(fp, " st->print(\" # \");\n" );
702 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
703 }
704 else if(inst.is_ideal_safepoint()) {
705 fprintf(fp, " st->print_raw(\"\");\n" );
706 fprintf(fp, " if (_jvms) _jvms->format(ra, this, st); else st->print_cr(\" No JVM State Info\");\n" );
707 fprintf(fp, " st->print(\" # \");\n" );
708 fprintf(fp, " if( _jvms && _oop_map ) _oop_map->print_on(st);\n");
709 }
710 else if( inst.is_ideal_if() ) {
711 fprintf(fp, " st->print(\" P=%%f C=%%f\",_prob,_fcnt);\n" );
712 }
713 else if( inst.is_ideal_mem() ) {
714 // Print out the field name if available to improve readability
715 fprintf(fp, " if (ra->C->alias_type(adr_type())->field() != NULL) {\n");
716 fprintf(fp, " ciField* f = ra->C->alias_type(adr_type())->field();\n");
717 fprintf(fp, " st->print(\" %s Field: \");\n", commentSeperator);
718 fprintf(fp, " if (f->is_volatile())\n");
719 fprintf(fp, " st->print(\"volatile \");\n");
720 fprintf(fp, " f->holder()->name()->print_symbol_on(st);\n");
721 fprintf(fp, " st->print(\".\");\n");
722 fprintf(fp, " f->name()->print_symbol_on(st);\n");
723 fprintf(fp, " if (f->is_constant())\n");
724 fprintf(fp, " st->print(\" (constant)\");\n");
725 fprintf(fp, " } else {\n");
|