< prev index next >

src/share/vm/adlc/dfa.cpp

Print this page
rev 10979 : 8140594: Various minor code improvements (compiler)


 699 void Expr::add(const char *c) {
 700   Expr *cost = new Expr(c);
 701   add(cost);
 702 }
 703 
 704 void Expr::add(const char *c, ArchDesc &AD) {
 705   const Expr *e = AD.globalDefs()[c];
 706   if( e != NULL ) {
 707     // use the value of 'c' defined in <arch>.ad
 708     add(e);
 709   } else {
 710     Expr *cost = new Expr(c);
 711     add(cost);
 712   }
 713 }
 714 
 715 const char *Expr::compute_external(const Expr *c1, const Expr *c2) {
 716   const char * result = NULL;
 717 
 718   // Preserve use of external name which has a zero value
 719   if( c1->_external_name != NULL ) {
 720     sprintf( string_buffer, "%s", c1->as_string());
 721     if( !c2->is_zero() ) {
 722       strcat( string_buffer, "+");
 723       strcat( string_buffer, c2->as_string());
 724     }
 725     result = strdup(string_buffer);
 726   }
 727   else if( c2->_external_name != NULL ) {
 728     if( !c1->is_zero() ) {
 729       sprintf( string_buffer, "%s", c1->as_string());
 730       strcat( string_buffer, " + ");
 731     } else {
 732       string_buffer[0] = '\0';
 733     }
 734     strcat( string_buffer, c2->_external_name );
 735     result = strdup(string_buffer);
 736   }
 737   return result;
 738 }
 739 
 740 const char *Expr::compute_expr(const Expr *c1, const Expr *c2) {
 741   if( !c1->is_zero() ) {
 742     sprintf( string_buffer, "%s", c1->_expr);
 743     if( !c2->is_zero() ) {
 744       strcat( string_buffer, "+");
 745       strcat( string_buffer, c2->_expr);
 746     }
 747   }
 748   else if( !c2->is_zero() ) {
 749     sprintf( string_buffer, "%s", c2->_expr);
 750   }
 751   else {
 752     sprintf( string_buffer, "0");


 753   }
 754   char *cost = strdup(string_buffer);
 755 
 756   return cost;
 757 }
 758 
 759 int Expr::compute_min(const Expr *c1, const Expr *c2) {
 760   int result = c1->_min_value + c2->_min_value;
 761   assert( result >= 0, "Invalid cost computation");
 762 
 763   return result;
 764 }
 765 
 766 int Expr::compute_max(const Expr *c1, const Expr *c2) {
 767   int result = c1->_max_value + c2->_max_value;
 768   if( result < 0 ) {  // check for overflow
 769     result = Expr::Max;
 770   }
 771 
 772   return result;




 699 void Expr::add(const char *c) {
 700   Expr *cost = new Expr(c);
 701   add(cost);
 702 }
 703 
 704 void Expr::add(const char *c, ArchDesc &AD) {
 705   const Expr *e = AD.globalDefs()[c];
 706   if( e != NULL ) {
 707     // use the value of 'c' defined in <arch>.ad
 708     add(e);
 709   } else {
 710     Expr *cost = new Expr(c);
 711     add(cost);
 712   }
 713 }
 714 
 715 const char *Expr::compute_external(const Expr *c1, const Expr *c2) {
 716   const char * result = NULL;
 717 
 718   // Preserve use of external name which has a zero value
 719   if (c1->_external_name != NULL) {
 720     if (c2->is_zero()) {
 721       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c1->as_string());
 722     } else {
 723       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s + %s", c1->as_string(), c2->as_string());
 724     }
 725     result = strdup(string_buffer);
 726   } else if (c2->_external_name != NULL) {
 727     if (!c1->is_zero()) {
 728       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s + %s", c1->as_string(), c2->_external_name);


 729     } else {
 730       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c2->_external_name);
 731     }

 732     result = strdup(string_buffer);
 733   }
 734   return result;
 735 }
 736 
 737 const char *Expr::compute_expr(const Expr *c1, const Expr *c2) {
 738   if (!c1->is_zero()) {
 739     if (c2->is_zero()) {
 740       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s", c1->_expr);
 741     } else {
 742       snprintf(string_buffer, STRING_BUFFER_LENGTH, "%s + %s", c1->_expr, c2->_expr);




 743     }
 744   } else if (!c2->is_zero()) {
 745     sprintf(string_buffer, "%s", c2->_expr);
 746   } else {
 747     sprintf(string_buffer, "0");
 748   }
 749   char *cost = strdup(string_buffer);
 750 
 751   return cost;
 752 }
 753 
 754 int Expr::compute_min(const Expr *c1, const Expr *c2) {
 755   int result = c1->_min_value + c2->_min_value;
 756   assert( result >= 0, "Invalid cost computation");
 757 
 758   return result;
 759 }
 760 
 761 int Expr::compute_max(const Expr *c1, const Expr *c2) {
 762   int result = c1->_max_value + c2->_max_value;
 763   if( result < 0 ) {  // check for overflow
 764     result = Expr::Max;
 765   }
 766 
 767   return result;


< prev index next >