hotspot/src/share/vm/adlc/output_c.cpp
author goetz
Mon, 29 Sep 2014 16:03:30 -0400
changeset 26910 253efabfd968
parent 25930 eae8b7490d2c
child 30202 6f5c48bd9b82
permissions -rw-r--r--
8058880: Introduce identifier TEMP_DEF for effects in adl. Summary: Modified adlc sources. Reviewed-by: kvn, drchase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5536
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// output_c.cpp - Class CPP file output routines for architecture definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
#include "adlc.hpp"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Utilities to characterize effect statements
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
static bool is_def(int usedef) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  switch(usedef) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  case Component::DEF:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  case Component::USE_DEF: return true; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// Define  an array containing the machine register names, strings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
static void defineRegNames(FILE *fp, RegisterForm *registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  if (registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    fprintf(fp,"// An array of character pointers to machine register names.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    fprintf(fp,"const char *Matcher::regName[REG_COUNT] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // Output the register name for each register in the allocation classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    RegDef *reg_def = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    RegDef *next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    registers->reset_RegDefs();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    49
    for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      next = registers->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      const char *comma = (next != NULL) ? "," : " // no trailing comma";
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    52
      fprintf(fp,"  \"%s\"%s\n", reg_def->_regname, comma);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // Finish defining enumeration
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    fprintf(fp,"};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    fprintf(fp,"// An array of character pointers to machine register names.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    reg_def = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    next = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    registers->reset_RegDefs();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    64
    for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      next = registers->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      const char *comma = (next != NULL) ? "," : " // no trailing comma";
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    67
      fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    // Finish defining array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    fprintf(fp,"\t};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    fprintf(fp," OptoReg::Name OptoReg::vm2opto[ConcreteRegisterImpl::number_of_registers];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// Define an array containing the machine register encoding values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
static void defineRegEncodes(FILE *fp, RegisterForm *registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  if (registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    fprintf(fp,"// An array of the machine register encode values\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    fprintf(fp,"const unsigned char Matcher::_regEncode[REG_COUNT] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // Output the register encoding for each register in the allocation classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    RegDef *reg_def = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    RegDef *next    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    registers->reset_RegDefs();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    89
    for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      next = registers->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      const char* register_encode = reg_def->register_encode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      const char *comma = (next != NULL) ? "," : " // no trailing comma";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      int encval;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      if (!ADLParser::is_int_token(register_encode, encval)) {
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    95
        fprintf(fp,"  %s%s  // %s\n", register_encode, comma, reg_def->_regname);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        // Output known constants in hex char format (backward compatibility).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        assert(encval < 256, "Exceeded supported width for register encoding");
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
    99
        fprintf(fp,"  (unsigned char)'\\x%X'%s  // %s\n", encval, comma, reg_def->_regname);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // Finish defining enumeration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    fprintf(fp,"};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  } // Done defining array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
// Output an enumeration of register class names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
static void defineRegClassEnum(FILE *fp, RegisterForm *registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  if (registers) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // Output an enumeration of register class names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    fprintf(fp,"// Enumeration of register class names\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    fprintf(fp, "enum machRegisterClass {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    registers->_rclasses.reset();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   116
    for (const char *class_name = NULL; (class_name = registers->_rclasses.iter()) != NULL;) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   117
      const char * class_name_to_upper = toUpper(class_name);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   118
      fprintf(fp,"  %s,\n", class_name_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   119
      delete[] class_name_to_upper;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // Finish defining enumeration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    fprintf(fp, "  _last_Mach_Reg_Class\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    fprintf(fp, "};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// Declare an enumeration of user-defined register classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// and a list of register masks, one for each class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
void ArchDesc::declare_register_masks(FILE *fp_hpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  const char  *rc_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   132
  if (_register) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    // Build enumeration of user-defined register classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    defineRegClassEnum(fp_hpp, _register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    // Generate a list of register masks, one for each class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    fprintf(fp_hpp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    fprintf(fp_hpp,"// Register masks, one for each register class.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    _register->_rclasses.reset();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   140
    for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   141
      const char *prefix = "";
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   142
      RegClass *reg_class = _register->getRegClass(rc_name);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   143
      assert(reg_class, "Using an undefined register class");
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   144
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   145
      const char* rc_name_to_upper = toUpper(rc_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11190
diff changeset
   147
      if (reg_class->_user_defined == NULL) {
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   148
        fprintf(fp_hpp, "extern const RegMask _%s%s_mask;\n", prefix,  rc_name_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   149
        fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { return _%s%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper);
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11190
diff changeset
   150
      } else {
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   151
        fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { %s }\n", prefix, rc_name_to_upper, reg_class->_user_defined);
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11190
diff changeset
   152
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   154
      if (reg_class->_stack_or_reg) {
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11190
diff changeset
   155
        assert(reg_class->_user_defined == NULL, "no user defined reg class here");
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   156
        fprintf(fp_hpp, "extern const RegMask _%sSTACK_OR_%s_mask;\n", prefix, rc_name_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   157
        fprintf(fp_hpp, "inline const RegMask &%sSTACK_OR_%s_mask() { return _%sSTACK_OR_%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      }
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   159
      delete[] rc_name_to_upper;
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   160
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// Generate an enumeration of user-defined register classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// and a list of register masks, one for each class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
void ArchDesc::build_register_masks(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  const char  *rc_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   170
  if (_register) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    // Generate a list of register masks, one for each class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    fprintf(fp_cpp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    fprintf(fp_cpp,"// Register masks, one for each register class.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    _register->_rclasses.reset();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   175
    for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   176
      const char *prefix = "";
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   177
      RegClass *reg_class = _register->getRegClass(rc_name);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   178
      assert(reg_class, "Using an undefined register class");
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   179
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   180
      if (reg_class->_user_defined != NULL) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   181
        continue;
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   182
      }
11197
158eecd6b330 7090968: Allow adlc register class to depend on runtime conditions
roland
parents: 11190
diff changeset
   183
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      int len = RegisterForm::RegMask_Size();
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   185
      const char* rc_name_to_upper = toUpper(rc_name);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   186
      fprintf(fp_cpp, "const RegMask _%s%s_mask(", prefix, rc_name_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   187
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   188
      {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   189
        int i;
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   190
        for(i = 0; i < len - 1; i++) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   191
          fprintf(fp_cpp," 0x%x,", reg_class->regs_in_word(i, false));
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   192
        }
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   193
        fprintf(fp_cpp," 0x%x );\n", reg_class->regs_in_word(i, false));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   196
      if (reg_class->_stack_or_reg) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        int i;
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   198
        fprintf(fp_cpp, "const RegMask _%sSTACK_OR_%s_mask(", prefix, rc_name_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   199
        for(i = 0; i < len - 1; i++) {
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   200
          fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i, true));
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   201
        }
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   202
        fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i, true));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      }
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
   204
      delete[] rc_name_to_upper;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// Compute an index for an array in the pipeline_reads_NNN arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
static int pipeline_reads_initializer(FILE *fp_cpp, NameList &pipeline_reads, PipeClassForm *pipeclass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  int templen = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  int paramcount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  const char *paramname;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  if (pipeclass->_parameters.count() == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  pipeclass->_parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  paramname = pipeclass->_parameters.iter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  const PipeClassOperandForm *pipeopnd =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal"))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    pipeclass->_parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  while ( (paramname = pipeclass->_parameters.iter()) != NULL ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   227
    const PipeClassOperandForm *tmppipeopnd =
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   230
    if (tmppipeopnd)
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   231
      templen += 10 + (int)strlen(tmppipeopnd->_stage);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      templen += 19;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    paramcount++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // See if the count is zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  if (paramcount == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  char *operand_stages = new char [templen];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  operand_stages[0] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  templen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  pipeclass->_parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  paramname = pipeclass->_parameters.iter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  pipeopnd = (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if (pipeopnd && !pipeopnd->isWrite() && strcmp(pipeopnd->_stage, "Universal"))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    pipeclass->_parameters.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  while ( (paramname = pipeclass->_parameters.iter()) != NULL ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   255
    const PipeClassOperandForm *tmppipeopnd =
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    templen += sprintf(&operand_stages[templen], "  stage_%s%c\n",
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   258
      tmppipeopnd ? tmppipeopnd->_stage : "undefined",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      (++i < paramcount ? ',' : ' ') );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // See if the same string is in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  int ndx = pipeline_reads.index(operand_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // No, add it to the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  if (ndx < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    pipeline_reads.addName(operand_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    ndx = pipeline_reads.index(operand_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    fprintf(fp_cpp, "static const enum machPipelineStages pipeline_reads_%03d[%d] = {\n%s};\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      ndx+1, paramcount, operand_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    delete [] operand_stages;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return (ndx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
// Compute an index for an array in the pipeline_res_stages_NNN arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
static int pipeline_res_stages_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  FILE *fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  PipelineForm *pipeline,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  NameList &pipeline_res_stages,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  PipeClassForm *pipeclass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  const PipeClassResourceForm *piperesource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  int * res_stages = new int [pipeline->_rescount];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  for (i = 0; i < pipeline->_rescount; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
     res_stages[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  for (pipeclass->_resUsage.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
       (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    for (i = 0; i < pipeline->_rescount; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      if ((1 << i) & used_mask) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
        int stage = pipeline->_stages.index(piperesource->_stage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        if (res_stages[i] < stage+1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
          res_stages[i] = stage+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Compute the length needed for the resource list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  int commentlen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  int max_stage = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  for (i = 0; i < pipeline->_rescount; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    if (res_stages[i] == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      if (max_stage < 9)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        max_stage = 9;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      int stagelen = (int)strlen(pipeline->_stages.name(res_stages[i]-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      if (max_stage < stagelen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        max_stage = stagelen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    commentlen += (int)strlen(pipeline->_reslist.name(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  int templen = 1 + commentlen + pipeline->_rescount * (max_stage + 14);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  // Allocate space for the resource list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  char * resource_stages = new char [templen];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  templen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  for (i = 0; i < pipeline->_rescount; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    const char * const resname =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      res_stages[i] == 0 ? "undefined" : pipeline->_stages.name(res_stages[i]-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    templen += sprintf(&resource_stages[templen], "  stage_%s%-*s // %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      resname, max_stage - (int)strlen(resname) + 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      (i < pipeline->_rescount-1) ? "," : "",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      pipeline->_reslist.name(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // See if the same string is in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  int ndx = pipeline_res_stages.index(resource_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // No, add it to the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if (ndx < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    pipeline_res_stages.addName(resource_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    ndx = pipeline_res_stages.index(resource_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    fprintf(fp_cpp, "static const enum machPipelineStages pipeline_res_stages_%03d[%d] = {\n%s};\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      ndx+1, pipeline->_rescount, resource_stages);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    delete [] resource_stages;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  delete [] res_stages;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  return (ndx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
// Compute an index for an array in the pipeline_res_cycles_NNN arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
static int pipeline_res_cycles_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  FILE *fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  PipelineForm *pipeline,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  NameList &pipeline_res_cycles,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  PipeClassForm *pipeclass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  const PipeClassResourceForm *piperesource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  int * res_cycles = new int [pipeline->_rescount];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  for (i = 0; i < pipeline->_rescount; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
     res_cycles[i] = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  for (pipeclass->_resUsage.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
       (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    for (i = 0; i < pipeline->_rescount; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      if ((1 << i) & used_mask) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        int cycles = piperesource->_cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        if (res_cycles[i] < cycles)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
          res_cycles[i] = cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // Pre-compute the string length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  int templen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  int cyclelen = 0, commentlen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  int max_cycles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  char temp[32];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  for (i = 0; i < pipeline->_rescount; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    if (max_cycles < res_cycles[i])
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      max_cycles = res_cycles[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    templen = sprintf(temp, "%d", res_cycles[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    if (cyclelen < templen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      cyclelen = templen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    commentlen += (int)strlen(pipeline->_reslist.name(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  templen = 1 + commentlen + (cyclelen + 8) * pipeline->_rescount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  // Allocate space for the resource list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  char * resource_cycles = new char [templen];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  templen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  for (i = 0; i < pipeline->_rescount; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    templen += sprintf(&resource_cycles[templen], "  %*d%c // %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      cyclelen, res_cycles[i], (i < pipeline->_rescount-1) ? ',' : ' ', pipeline->_reslist.name(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // See if the same string is in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  int ndx = pipeline_res_cycles.index(resource_cycles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  // No, add it to the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  if (ndx < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    pipeline_res_cycles.addName(resource_cycles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    ndx = pipeline_res_cycles.index(resource_cycles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    fprintf(fp_cpp, "static const uint pipeline_res_cycles_%03d[%d] = {\n%s};\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      ndx+1, pipeline->_rescount, resource_cycles);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    delete [] resource_cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  delete [] res_cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  return (ndx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
//typedef unsigned long long uint64_t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// Compute an index for an array in the pipeline_res_mask_NNN arrays
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
static int pipeline_res_mask_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  FILE *fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  PipelineForm *pipeline,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  NameList &pipeline_res_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  NameList &pipeline_res_args,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  PipeClassForm *pipeclass)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  const PipeClassResourceForm *piperesource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  const uint rescount      = pipeline->_rescount;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  const uint maxcycleused  = pipeline->_maxcycleused;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  const uint cyclemasksize = (maxcycleused + 31) >> 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  int i, j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  int element_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  uint *res_mask = new uint [cyclemasksize];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  uint resources_used             = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  uint resources_used_exclusively = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  for (pipeclass->_resUsage.reset();
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   449
       (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    element_count++;
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   451
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // Pre-compute the string length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  int templen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  int commentlen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  int max_cycles = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  int cyclelen = ((maxcycleused + 3) >> 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  int masklen = (rescount + 3) >> 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  int cycledigit = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  for (i = maxcycleused; i > 0; i /= 10)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    cycledigit++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  int maskdigit = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  for (i = rescount; i > 0; i /= 10)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    maskdigit++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   469
  static const char* pipeline_use_cycle_mask = "Pipeline_Use_Cycle_Mask";
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   470
  static const char* pipeline_use_element    = "Pipeline_Use_Element";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  templen = 1 +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    (int)(strlen(pipeline_use_cycle_mask) + (int)strlen(pipeline_use_element) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
     (cyclemasksize * 12) + masklen + (cycledigit * 2) + 30) * element_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  // Allocate space for the resource list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  char * resource_mask = new char [templen];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  char * last_comma = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  templen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  for (pipeclass->_resUsage.reset();
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   483
       (piperesource = (const PipeClassResourceForm*)pipeclass->_resUsage.iter()) != NULL; ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    int used_mask = pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   486
    if (!used_mask) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
      fprintf(stderr, "*** used_mask is 0 ***\n");
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   488
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    resources_used |= used_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    uint lb, ub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    for (lb =  0; (used_mask & (1 << lb)) == 0; lb++);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    for (ub = 31; (used_mask & (1 << ub)) == 0; ub--);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   497
    if (lb == ub) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
      resources_used_exclusively |= used_mask;
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   499
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    int formatlen =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
      sprintf(&resource_mask[templen], "  %s(0x%0*x, %*d, %*d, %s %s(",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
        pipeline_use_element,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
        masklen, used_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
        cycledigit, lb, cycledigit, ub,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
        ((used_mask & (used_mask-1)) != 0) ? "true, " : "false,",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
        pipeline_use_cycle_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    templen += formatlen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    memset(res_mask, 0, cyclemasksize * sizeof(uint));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    int cycles = piperesource->_cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    uint stage          = pipeline->_stages.index(piperesource->_stage);
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   515
    if ((uint)NameList::Not_in_list == stage) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   516
      fprintf(stderr,
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   517
              "pipeline_res_mask_initializer: "
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   518
              "semantic error: "
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   519
              "pipeline stage undeclared: %s\n",
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   520
              piperesource->_stage);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   521
      exit(1);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   522
    }
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   523
    uint upper_limit    = stage + cycles - 1;
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   524
    uint lower_limit    = stage - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    uint upper_idx      = upper_limit >> 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    uint lower_idx      = lower_limit >> 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    uint upper_position = upper_limit & 0x1f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    uint lower_position = lower_limit & 0x1f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    uint mask = (((uint)1) << upper_position) - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   532
    while (upper_idx > lower_idx) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      res_mask[upper_idx--] |= mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      mask = (uint)-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    mask -= (((uint)1) << lower_position) - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    res_mask[upper_idx] |= mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    for (j = cyclemasksize-1; j >= 0; j--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      formatlen =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
        sprintf(&resource_mask[templen], "0x%08x%s", res_mask[j], j > 0 ? ", " : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      templen += formatlen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    resource_mask[templen++] = ')';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    resource_mask[templen++] = ')';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    last_comma = &resource_mask[templen];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    resource_mask[templen++] = ',';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    resource_mask[templen++] = '\n';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  resource_mask[templen] = 0;
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   554
  if (last_comma) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    last_comma[0] = ' ';
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   556
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  // See if the same string is in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  int ndx = pipeline_res_mask.index(resource_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  // No, add it to the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  if (ndx < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    pipeline_res_mask.addName(resource_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    ndx = pipeline_res_mask.index(resource_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    if (strlen(resource_mask) > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      fprintf(fp_cpp, "static const Pipeline_Use_Element pipeline_res_mask_%03d[%d] = {\n%s};\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        ndx+1, element_count, resource_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   570
    char* args = new char [9 + 2*masklen + maskdigit];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    sprintf(args, "0x%0*x, 0x%0*x, %*d",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      masklen, resources_used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      masklen, resources_used_exclusively,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      maskdigit, element_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    pipeline_res_args.addName(args);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  }
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   579
  else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    delete [] resource_mask;
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
   581
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  delete [] res_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
//delete [] res_masks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  return (ndx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
void ArchDesc::build_pipe_classes(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  const char *classname;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  const char *resourcename;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  int resourcenamelen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  NameList pipeline_reads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  NameList pipeline_res_stages;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  NameList pipeline_res_cycles;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  NameList pipeline_res_masks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  NameList pipeline_res_args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  const int default_latency = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  const int non_operand_latency = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  const int node_latency = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  if (!_pipeline) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    fprintf(fp_cpp, "uint Node::latency(uint i) const {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    fprintf(fp_cpp, "  // assert(false, \"pipeline functionality is not defined\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    fprintf(fp_cpp, "  return %d;\n", non_operand_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  fprintf(fp_cpp, "//------------------Pipeline Methods-----------------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  fprintf(fp_cpp, "#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  fprintf(fp_cpp, "const char * Pipeline::stageName(uint s) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  fprintf(fp_cpp, "  static const char * const _stage_names[] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  fprintf(fp_cpp, "    \"undefined\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  for (int s = 0; s < _pipeline->_stagecnt; s++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    fprintf(fp_cpp, ", \"%s\"", _pipeline->_stages.name(s));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  fprintf(fp_cpp, "\n  };\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  fprintf(fp_cpp, "  return (s <= %d ? _stage_names[s] : \"???\");\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    _pipeline->_stagecnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  fprintf(fp_cpp, "uint Pipeline::functional_unit_latency(uint start, const Pipeline *pred) const {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  fprintf(fp_cpp, "  // See if the functional units overlap\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  fprintf(fp_cpp, "  if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  fprintf(fp_cpp, "    tty->print(\"#   functional_unit_latency: start == %%d, this->exclusively == 0x%%03x, pred->exclusively == 0x%%03x\\n\", start, resourcesUsedExclusively(), pred->resourcesUsedExclusively());\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  fprintf(fp_cpp, "  uint mask = resourcesUsedExclusively() & pred->resourcesUsedExclusively();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  fprintf(fp_cpp, "  if (mask == 0)\n    return (start);\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  fprintf(fp_cpp, "  if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  fprintf(fp_cpp, "    tty->print(\"#   functional_unit_latency: mask == 0x%%x\\n\", mask);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  fprintf(fp_cpp, "  for (uint i = 0; i < pred->resourceUseCount(); i++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  fprintf(fp_cpp, "    const Pipeline_Use_Element *predUse = pred->resourceUseElement(i);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  fprintf(fp_cpp, "    if (predUse->multiple())\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  fprintf(fp_cpp, "      continue;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  fprintf(fp_cpp, "    for (uint j = 0; j < resourceUseCount(); j++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  fprintf(fp_cpp, "      const Pipeline_Use_Element *currUse = resourceUseElement(j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  fprintf(fp_cpp, "      if (currUse->multiple())\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  fprintf(fp_cpp, "        continue;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  fprintf(fp_cpp, "      if (predUse->used() & currUse->used()) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  fprintf(fp_cpp, "        Pipeline_Use_Cycle_Mask x = predUse->mask();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  fprintf(fp_cpp, "        Pipeline_Use_Cycle_Mask y = currUse->mask();\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  fprintf(fp_cpp, "        for ( y <<= start; x.overlaps(y); start++ )\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  fprintf(fp_cpp, "          y <<= 1;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  fprintf(fp_cpp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  fprintf(fp_cpp, "  }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  fprintf(fp_cpp, "  // There is the potential for overlap\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  fprintf(fp_cpp, "  return (start);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  fprintf(fp_cpp, "// The following two routines assume that the root Pipeline_Use entity\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  fprintf(fp_cpp, "// consists of exactly 1 element for each functional unit\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  fprintf(fp_cpp, "// start is relative to the current cycle; used for latency-based info\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  fprintf(fp_cpp, "uint Pipeline_Use::full_latency(uint delay, const Pipeline_Use &pred) const {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  fprintf(fp_cpp, "  for (uint i = 0; i < pred._count; i++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  fprintf(fp_cpp, "    const Pipeline_Use_Element *predUse = pred.element(i);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  fprintf(fp_cpp, "    if (predUse->_multiple) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  fprintf(fp_cpp, "      uint min_delay = %d;\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    _pipeline->_maxcycleused+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  fprintf(fp_cpp, "      // Multiple possible functional units, choose first unused one\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  fprintf(fp_cpp, "      for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  fprintf(fp_cpp, "        const Pipeline_Use_Element *currUse = element(j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  fprintf(fp_cpp, "        uint curr_delay = delay;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  fprintf(fp_cpp, "        if (predUse->_used & currUse->_used) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  fprintf(fp_cpp, "          Pipeline_Use_Cycle_Mask x = predUse->_mask;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  fprintf(fp_cpp, "          Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  fprintf(fp_cpp, "          for ( y <<= curr_delay; x.overlaps(y); curr_delay++ )\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  fprintf(fp_cpp, "            y <<= 1;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  fprintf(fp_cpp, "        }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  fprintf(fp_cpp, "        if (min_delay > curr_delay)\n          min_delay = curr_delay;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  fprintf(fp_cpp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  fprintf(fp_cpp, "      if (delay < min_delay)\n      delay = min_delay;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  fprintf(fp_cpp, "    else {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  fprintf(fp_cpp, "      for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  fprintf(fp_cpp, "        const Pipeline_Use_Element *currUse = element(j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  fprintf(fp_cpp, "        if (predUse->_used & currUse->_used) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  fprintf(fp_cpp, "          Pipeline_Use_Cycle_Mask x = predUse->_mask;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  fprintf(fp_cpp, "          Pipeline_Use_Cycle_Mask y = currUse->_mask;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  fprintf(fp_cpp, "          for ( y <<= delay; x.overlaps(y); delay++ )\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  fprintf(fp_cpp, "            y <<= 1;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  fprintf(fp_cpp, "        }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  fprintf(fp_cpp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  fprintf(fp_cpp, "  }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  fprintf(fp_cpp, "  return (delay);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  fprintf(fp_cpp, "void Pipeline_Use::add_usage(const Pipeline_Use &pred) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  fprintf(fp_cpp, "  for (uint i = 0; i < pred._count; i++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  fprintf(fp_cpp, "    const Pipeline_Use_Element *predUse = pred.element(i);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  fprintf(fp_cpp, "    if (predUse->_multiple) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  fprintf(fp_cpp, "      // Multiple possible functional units, choose first unused one\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  fprintf(fp_cpp, "      for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  fprintf(fp_cpp, "        Pipeline_Use_Element *currUse = element(j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  fprintf(fp_cpp, "        if ( !predUse->_mask.overlaps(currUse->_mask) ) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  fprintf(fp_cpp, "          currUse->_used |= (1 << j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  fprintf(fp_cpp, "          _resources_used |= (1 << j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  fprintf(fp_cpp, "          currUse->_mask.Or(predUse->_mask);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  fprintf(fp_cpp, "          break;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  fprintf(fp_cpp, "        }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  fprintf(fp_cpp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  fprintf(fp_cpp, "    else {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  fprintf(fp_cpp, "      for (uint j = predUse->_lb; j <= predUse->_ub; j++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  fprintf(fp_cpp, "        Pipeline_Use_Element *currUse = element(j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  fprintf(fp_cpp, "        currUse->_used |= (1 << j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  fprintf(fp_cpp, "        _resources_used |= (1 << j);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  fprintf(fp_cpp, "        currUse->_mask.Or(predUse->_mask);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  fprintf(fp_cpp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  fprintf(fp_cpp, "uint Pipeline::operand_latency(uint opnd, const Pipeline *pred) const {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  fprintf(fp_cpp, "  int const default_latency = 1;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  fprintf(fp_cpp, "#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  fprintf(fp_cpp, "  if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  fprintf(fp_cpp, "    tty->print(\"#   operand_latency(%%d), _read_stage_count = %%d\\n\", opnd, _read_stage_count);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
#endif
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 4751
diff changeset
   736
  fprintf(fp_cpp, "  assert(this, \"NULL pipeline info\");\n");
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 4751
diff changeset
   737
  fprintf(fp_cpp, "  assert(pred, \"NULL predecessor pipline info\");\n\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  fprintf(fp_cpp, "  if (pred->hasFixedLatency())\n    return (pred->fixedLatency());\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  fprintf(fp_cpp, "  // If this is not an operand, then assume a dependence with 0 latency\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  fprintf(fp_cpp, "  if (opnd > _read_stage_count)\n    return (0);\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  fprintf(fp_cpp, "  uint writeStage = pred->_write_stage;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  fprintf(fp_cpp, "  uint readStage  = _read_stages[opnd-1];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  fprintf(fp_cpp, "  if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  fprintf(fp_cpp, "    tty->print(\"#   operand_latency: writeStage=%%s readStage=%%s, opnd=%%d\\n\", stageName(writeStage), stageName(readStage), opnd);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  fprintf(fp_cpp, "  if (writeStage == stage_undefined || readStage == stage_undefined)\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  fprintf(fp_cpp, "    return (default_latency);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  fprintf(fp_cpp, "  int delta = writeStage - readStage;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  fprintf(fp_cpp, "  if (delta < 0) delta = 0;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  fprintf(fp_cpp, "\n#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  fprintf(fp_cpp, "  if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  fprintf(fp_cpp, "    tty->print(\"# operand_latency: delta=%%d\\n\", delta);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  fprintf(fp_cpp, "#endif\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  fprintf(fp_cpp, "  return (delta);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  if (!_pipeline)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    /* Do Nothing */;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  else if (_pipeline->_maxcycleused <=
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
#ifdef SPARC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    fprintf(fp_cpp, "  return Pipeline_Use_Cycle_Mask(in1._mask & in2._mask);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    fprintf(fp_cpp, "  return Pipeline_Use_Cycle_Mask(in1._mask | in2._mask);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
    fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    uint l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator&(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    fprintf(fp_cpp, "  return Pipeline_Use_Cycle_Mask(");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    for (l = 1; l <= masklen; l++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      fprintf(fp_cpp, "in1._mask%d & in2._mask%d%s\n", l, l, l < masklen ? ", " : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    fprintf(fp_cpp, ");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    fprintf(fp_cpp, "Pipeline_Use_Cycle_Mask operator|(const Pipeline_Use_Cycle_Mask &in1, const Pipeline_Use_Cycle_Mask &in2) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    fprintf(fp_cpp, "  return Pipeline_Use_Cycle_Mask(");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    for (l = 1; l <= masklen; l++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      fprintf(fp_cpp, "in1._mask%d | in2._mask%d%s", l, l, l < masklen ? ", " : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    fprintf(fp_cpp, ");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    fprintf(fp_cpp, "void Pipeline_Use_Cycle_Mask::Or(const Pipeline_Use_Cycle_Mask &in2) {\n ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    for (l = 1; l <= masklen; l++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
      fprintf(fp_cpp, " _mask%d |= in2._mask%d;", l, l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    fprintf(fp_cpp, "\n}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  /* Get the length of all the resource names */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  for (_pipeline->_reslist.reset(), resourcenamelen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
       (resourcename = _pipeline->_reslist.iter()) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
       resourcenamelen += (int)strlen(resourcename));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  // Create the pipeline class description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  fprintf(fp_cpp, "static const Pipeline pipeline_class_Zero_Instructions(0, 0, true, 0, 0, false, false, false, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  fprintf(fp_cpp, "static const Pipeline pipeline_class_Unknown_Instructions(0, 0, true, 0, 0, false, true, true, false, NULL, NULL, NULL, Pipeline_Use(0, 0, 0, NULL));\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  fprintf(fp_cpp, "const Pipeline_Use_Element Pipeline_Use::elaborated_elements[%d] = {\n", _pipeline->_rescount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  for (int i1 = 0; i1 < _pipeline->_rescount; i1++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    fprintf(fp_cpp, "  Pipeline_Use_Element(0, %d, %d, false, Pipeline_Use_Cycle_Mask(", i1, i1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    uint masklen = (_pipeline->_maxcycleused + 31) >> 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    for (int i2 = masklen-1; i2 >= 0; i2--)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      fprintf(fp_cpp, "0%s", i2 > 0 ? ", " : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    fprintf(fp_cpp, "))%s\n", i1 < (_pipeline->_rescount-1) ? "," : "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  fprintf(fp_cpp, "const Pipeline_Use Pipeline_Use::elaborated_use(0, 0, %d, (Pipeline_Use_Element *)&elaborated_elements[0]);\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    _pipeline->_rescount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  for (_pipeline->_classlist.reset(); (classname = _pipeline->_classlist.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
    fprintf(fp_cpp, "// Pipeline Class \"%s\"\n", classname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    PipeClassForm *pipeclass = _pipeline->_classdict[classname]->is_pipeclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
    int maxWriteStage = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
    int maxMoreInstrs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    int paramcount = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    const char *paramname;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    int resource_count = (_pipeline->_rescount + 3) >> 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    // Scan the operands, looking for last output stage and number of inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    for (pipeclass->_parameters.reset(); (paramname = pipeclass->_parameters.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
      const PipeClassOperandForm *pipeopnd =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
          (const PipeClassOperandForm *)pipeclass->_localUsage[paramname];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      if (pipeopnd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
        if (pipeopnd->_iswrite) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
           int stagenum  = _pipeline->_stages.index(pipeopnd->_stage);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
           int moreinsts = pipeopnd->_more_instrs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
          if ((maxWriteStage+maxMoreInstrs) < (stagenum+moreinsts)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
            maxWriteStage = stagenum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
            maxMoreInstrs = moreinsts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
      if (i++ > 0 || (pipeopnd && !pipeopnd->isWrite()))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
        paramcount++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    // Create the list of stages for the operands that are read
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
    // Note that we will build a NameList to reduce the number of copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    int pipeline_reads_index = pipeline_reads_initializer(fp_cpp, pipeline_reads, pipeclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    int pipeline_res_stages_index = pipeline_res_stages_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
      fp_cpp, _pipeline, pipeline_res_stages, pipeclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    int pipeline_res_cycles_index = pipeline_res_cycles_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      fp_cpp, _pipeline, pipeline_res_cycles, pipeclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    int pipeline_res_mask_index = pipeline_res_mask_initializer(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      fp_cpp, _pipeline, pipeline_res_masks, pipeline_res_args, pipeclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    // Process the Resources
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    const PipeClassResourceForm *piperesource;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
    unsigned resources_used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
    unsigned exclusive_resources_used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
    unsigned resource_groups = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    for (pipeclass->_resUsage.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
         (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
      int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      if (used_mask)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
        resource_groups++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
      resources_used |= used_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
      if ((used_mask & (used_mask-1)) == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
        exclusive_resources_used |= used_mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    if (resource_groups > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
      fprintf(fp_cpp, "static const uint pipeline_res_or_masks_%03d[%d] = {",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
        pipeclass->_num, resource_groups);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
      for (pipeclass->_resUsage.reset(), i = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
           (piperesource = (const PipeClassResourceForm *)pipeclass->_resUsage.iter()) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
           i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
        int used_mask = _pipeline->_resdict[piperesource->_resource]->is_resource()->mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
        if (used_mask) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
          fprintf(fp_cpp, " 0x%0*x%c", resource_count, used_mask, i < (int)resource_groups ? ',' : ' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
      fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
    // Create the pipeline class description
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
    fprintf(fp_cpp, "static const Pipeline pipeline_class_%03d(",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
      pipeclass->_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    if (maxWriteStage < 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      fprintf(fp_cpp, "(uint)stage_undefined");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    else if (maxMoreInstrs == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
      fprintf(fp_cpp, "(uint)stage_%s", _pipeline->_stages.name(maxWriteStage));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      fprintf(fp_cpp, "((uint)stage_%s)+%d", _pipeline->_stages.name(maxWriteStage), maxMoreInstrs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
    fprintf(fp_cpp, ", %d, %s, %d, %d, %s, %s, %s, %s,\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
      paramcount,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
      pipeclass->hasFixedLatency() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
      pipeclass->fixedLatency(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
      pipeclass->InstructionCount(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
      pipeclass->hasBranchDelay() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
      pipeclass->hasMultipleBundles() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
      pipeclass->forceSerialization() ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
      pipeclass->mayHaveNoCode() ? "true" : "false" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
    if (paramcount > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
      fprintf(fp_cpp, "\n  (enum machPipelineStages * const) pipeline_reads_%03d,\n ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
        pipeline_reads_index+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
      fprintf(fp_cpp, " NULL,");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    fprintf(fp_cpp, "  (enum machPipelineStages * const) pipeline_res_stages_%03d,\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
      pipeline_res_stages_index+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    fprintf(fp_cpp, "  (uint * const) pipeline_res_cycles_%03d,\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
      pipeline_res_cycles_index+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    fprintf(fp_cpp, "  Pipeline_Use(%s, (Pipeline_Use_Element *)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
      pipeline_res_args.name(pipeline_res_mask_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    if (strlen(pipeline_res_masks.name(pipeline_res_mask_index)) > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      fprintf(fp_cpp, "&pipeline_res_mask_%03d[0]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
        pipeline_res_mask_index+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
      fprintf(fp_cpp, "NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
    fprintf(fp_cpp, "));\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  // Generate the Node::latency method if _pipeline defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  fprintf(fp_cpp, "//------------------Inter-Instruction Latency--------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  fprintf(fp_cpp, "uint Node::latency(uint i) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  if (_pipeline) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
#if 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    fprintf(fp_cpp, "#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
    fprintf(fp_cpp, " if (TraceOptoOutput) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
    fprintf(fp_cpp, "    tty->print(\"# %%4d->latency(%%d)\\n\", _idx, i);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    fprintf(fp_cpp, " }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
    fprintf(fp_cpp, "#endif\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
    fprintf(fp_cpp, "  uint j;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    fprintf(fp_cpp, "  // verify in legal range for inputs\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
    fprintf(fp_cpp, "  assert(i < len(), \"index not in range\");\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    fprintf(fp_cpp, "  // verify input is not null\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    fprintf(fp_cpp, "  Node *pred = in(i);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    fprintf(fp_cpp, "  if (!pred)\n    return %d;\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
      non_operand_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    fprintf(fp_cpp, "  if (pred->is_Proj())\n    pred = pred->in(0);\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    fprintf(fp_cpp, "  // if either node does not have pipeline info, use default\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    fprintf(fp_cpp, "  const Pipeline *predpipe = pred->pipeline();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    fprintf(fp_cpp, "  assert(predpipe, \"no predecessor pipeline info\");\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    fprintf(fp_cpp, "  if (predpipe->hasFixedLatency())\n    return predpipe->fixedLatency();\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    fprintf(fp_cpp, "  const Pipeline *currpipe = pipeline();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    fprintf(fp_cpp, "  assert(currpipe, \"no pipeline info\");\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    fprintf(fp_cpp, "  if (!is_Mach())\n    return %d;\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
      node_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    fprintf(fp_cpp, "  const MachNode *m = as_Mach();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    fprintf(fp_cpp, "  j = m->oper_input_base();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    fprintf(fp_cpp, "  if (i < j)\n    return currpipe->functional_unit_latency(%d, predpipe);\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      non_operand_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    fprintf(fp_cpp, "  // determine which operand this is in\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    fprintf(fp_cpp, "  uint n = m->num_opnds();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    fprintf(fp_cpp, "  int delta = %d;\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
      non_operand_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    fprintf(fp_cpp, "  uint k;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    fprintf(fp_cpp, "  for (k = 1; k < n; k++) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    fprintf(fp_cpp, "    j += m->_opnds[k]->num_edges();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
    fprintf(fp_cpp, "    if (i < j)\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
    fprintf(fp_cpp, "      break;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    fprintf(fp_cpp, "  if (k < n)\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    fprintf(fp_cpp, "    delta = currpipe->operand_latency(k,predpipe);\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    fprintf(fp_cpp, "  return currpipe->functional_unit_latency(delta, predpipe);\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    fprintf(fp_cpp, "  // assert(false, \"pipeline functionality is not defined\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    fprintf(fp_cpp, "  return %d;\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      non_operand_latency);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  // Output the list of nop nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  fprintf(fp_cpp, "// Descriptions for emitting different functional unit nops\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  const char *nop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  int nopcnt = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; nopcnt++ );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1000
  fprintf(fp_cpp, "void Bundle::initialize_nops(MachNode * nop_list[%d]) {\n", nopcnt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  for ( _pipeline->_noplist.reset(); (nop = _pipeline->_noplist.iter()) != NULL; i++ ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1003
    fprintf(fp_cpp, "  nop_list[%d] = (MachNode *) new %sNode();\n", i, nop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  fprintf(fp_cpp, "#ifndef PRODUCT\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1007
  fprintf(fp_cpp, "void Bundle::dump(outputStream *st) const {\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  fprintf(fp_cpp, "  static const char * bundle_flags[] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  fprintf(fp_cpp, "    \"\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  fprintf(fp_cpp, "    \"use nop delay\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  fprintf(fp_cpp, "    \"use unconditional delay\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
  fprintf(fp_cpp, "    \"use conditional delay\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  fprintf(fp_cpp, "    \"used in conditional delay\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  fprintf(fp_cpp, "    \"used in unconditional delay\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  fprintf(fp_cpp, "    \"used in all conditional delays\",\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  fprintf(fp_cpp, "  };\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  fprintf(fp_cpp, "  static const char *resource_names[%d] = {", _pipeline->_rescount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  for (i = 0; i < _pipeline->_rescount; i++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
    fprintf(fp_cpp, " \"%s\"%c", _pipeline->_reslist.name(i), i < _pipeline->_rescount-1 ? ',' : ' ');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  // See if the same string is in the table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  fprintf(fp_cpp, "  bool needs_comma = false;\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  fprintf(fp_cpp, "  if (_flags) {\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1026
  fprintf(fp_cpp, "    st->print(\"%%s\", bundle_flags[_flags]);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
  fprintf(fp_cpp, "    needs_comma = true;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  fprintf(fp_cpp, "  };\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  fprintf(fp_cpp, "  if (instr_count()) {\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1030
  fprintf(fp_cpp, "    st->print(\"%%s%%d instr%%s\", needs_comma ? \", \" : \"\", instr_count(), instr_count() != 1 ? \"s\" : \"\");\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
  fprintf(fp_cpp, "    needs_comma = true;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
  fprintf(fp_cpp, "  };\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  fprintf(fp_cpp, "  uint r = resources_used();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  fprintf(fp_cpp, "  if (r) {\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1035
  fprintf(fp_cpp, "    st->print(\"%%sresource%%s:\", needs_comma ? \", \" : \"\", (r & (r-1)) != 0 ? \"s\" : \"\");\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  fprintf(fp_cpp, "    for (uint i = 0; i < %d; i++)\n", _pipeline->_rescount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  fprintf(fp_cpp, "      if ((r & (1 << i)) != 0)\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1038
  fprintf(fp_cpp, "        st->print(\" %%s\", resource_names[i]);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  fprintf(fp_cpp, "    needs_comma = true;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  fprintf(fp_cpp, "  };\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1041
  fprintf(fp_cpp, "  st->print(\"\\n\");\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  fprintf(fp_cpp, "#endif\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
// ---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
//------------------------------Utilities to build Instruction Classes--------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
// ---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
static void defineOut_RegMask(FILE *fp, const char *node, const char *regMask) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  fprintf(fp,"const RegMask &%sNode::out_RegMask() const { return (%s); }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
          node, regMask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1055
static void print_block_index(FILE *fp, int inst_position) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  assert( inst_position >= 0, "Instruction number less than zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
  fprintf(fp, "block_index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  if( inst_position != 0 ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1059
    fprintf(fp, " - %d", inst_position);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
// Scan the peepmatch and output a test for each instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
static void check_peepmatch_instruction_sequence(FILE *fp, PeepMatch *pmatch, PeepConstraint *pconstraint) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1065
  int         parent        = -1;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1066
  int         inst_position = 0;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1067
  const char* inst_name     = NULL;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1068
  int         input         = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  fprintf(fp, "  // Check instruction sub-tree\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  pmatch->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  for( pmatch->next_instruction( parent, inst_position, inst_name, input );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
       inst_name != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
       pmatch->next_instruction( parent, inst_position, inst_name, input ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    // If this is not a placeholder
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    if( ! pmatch->is_placeholder() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
      // Define temporaries 'inst#', based on parent and parent's input index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
      if( parent != -1 ) {                // root was initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
        fprintf(fp, "  // Identify previous instruction if inside this block\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
        fprintf(fp, "  if( ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
        print_block_index(fp, inst_position);
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 17871
diff changeset
  1081
        fprintf(fp, " > 0 ) {\n    Node *n = block->get_node(");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
        print_block_index(fp, inst_position);
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1083
        fprintf(fp, ");\n    inst%d = (n->is_Mach()) ? ", inst_position);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
        fprintf(fp, "n->as_Mach() : NULL;\n  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
      // When not the root
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
      // Test we have the correct instruction by comparing the rule.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
      if( parent != -1 ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1090
        fprintf(fp, "  matches = matches && (inst%d != NULL) && (inst%d->rule() == %s_rule);\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
                inst_position, inst_position, inst_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
      // Check that user did not try to constrain a placeholder
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
      assert( ! pconstraint->constrains_instruction(inst_position),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
              "fatal(): Can not constrain a placeholder instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
// Build mapping for register indices, num_edges to input
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
static void build_instruction_index_mapping( FILE *fp, FormDict &globals, PeepMatch *pmatch ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1103
  int         parent        = -1;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1104
  int         inst_position = 0;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1105
  const char* inst_name     = NULL;
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1106
  int         input         = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  fprintf(fp, "      // Build map to register info\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  pmatch->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  for( pmatch->next_instruction( parent, inst_position, inst_name, input );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
       inst_name != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
       pmatch->next_instruction( parent, inst_position, inst_name, input ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
    // If this is not a placeholder
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
    if( ! pmatch->is_placeholder() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
      // Define temporaries 'inst#', based on self's inst_position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
      InstructForm *inst = globals[inst_name]->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      if( inst != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
        char inst_prefix[]  = "instXXXX_";
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1118
        sprintf(inst_prefix, "inst%d_",   inst_position);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
        char receiver[]     = "instXXXX->";
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1120
        sprintf(receiver,    "inst%d->", inst_position);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
        inst->index_temps( fp, globals, inst_prefix, receiver );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
// Generate tests for the constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
static void check_peepconstraints(FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  fprintf(fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  fprintf(fp, "      // Check constraints on sub-tree-leaves\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  // Build mapping from num_edges to local variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  build_instruction_index_mapping( fp, globals, pmatch );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  // Build constraint tests
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
  if( pconstraint != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    fprintf(fp, "      matches = matches &&");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
    bool   first_constraint = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    while( pconstraint != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
      // indentation and connecting '&&'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      const char *indentation = "      ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
      fprintf(fp, "\n%s%s", indentation, (!first_constraint ? "&& " : "  "));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
      // Only have '==' relation implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
      if( strcmp(pconstraint->_relation,"==") != 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
        assert( false, "Unimplemented()" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
      // LEFT
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1150
      int left_index       = pconstraint->_left_inst;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
      const char *left_op  = pconstraint->_left_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      // Access info on the instructions whose operands are compared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
      InstructForm *inst_left = globals[pmatch->instruction_name(left_index)]->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      assert( inst_left, "Parser should guaranty this is an instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
      int left_op_base  = inst_left->oper_input_base(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
      // Access info on the operands being compared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      int left_op_index  = inst_left->operand_position(left_op, Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
      if( left_op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
        left_op_index = inst_left->operand_position(left_op, Component::DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
        if( left_op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
          left_op_index = inst_left->operand_position(left_op, Component::USE_DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
      assert( left_op_index  != NameList::Not_in_list, "Did not find operand in instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
      ComponentList components_left = inst_left->_components;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
      const char *left_comp_type = components_left.at(left_op_index)->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
      OpClassForm *left_opclass = globals[left_comp_type]->is_opclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
      Form::InterfaceType left_interface_type = left_opclass->interface_type(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
      // RIGHT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
      int right_op_index = -1;
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1173
      int right_index      = pconstraint->_right_inst;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
      const char *right_op = pconstraint->_right_op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
      if( right_index != -1 ) { // Match operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
        // Access info on the instructions whose operands are compared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
        InstructForm *inst_right = globals[pmatch->instruction_name(right_index)]->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
        assert( inst_right, "Parser should guaranty this is an instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
        int right_op_base = inst_right->oper_input_base(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
        // Access info on the operands being compared
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
        right_op_index = inst_right->operand_position(right_op, Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
        if( right_op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
          right_op_index = inst_right->operand_position(right_op, Component::DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
          if( right_op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
            right_op_index = inst_right->operand_position(right_op, Component::USE_DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
        assert( right_op_index != NameList::Not_in_list, "Did not find operand in instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
        ComponentList components_right = inst_right->_components;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
        const char *right_comp_type = components_right.at(right_op_index)->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
        OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
        Form::InterfaceType right_interface_type = right_opclass->interface_type(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
        assert( right_interface_type == left_interface_type, "Both must be same interface");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
      } else {                  // Else match register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
        // assert( false, "should be a register" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
      // Check for equivalence
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
      // fprintf(fp, "phase->eqv( ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
      // fprintf(fp, "inst%d->in(%d+%d) /* %s */, inst%d->in(%d+%d) /* %s */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
      //         left_index,  left_op_base,  left_op_index,  left_op,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
      //         right_index, right_op_base, right_op_index, right_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
      // fprintf(fp, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
      switch( left_interface_type ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
      case Form::register_interface: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
        // Check that they are allocated to the same register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
        // Need parameter for index position if not result operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
        char left_reg_index[] = ",instXXXX_idxXXXX";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
        if( left_op_index != 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
          assert( (left_index <= 9999) && (left_op_index <= 9999), "exceed string size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
          // Must have index into operands
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1216
          sprintf(left_reg_index,",inst%d_idx%d", (int)left_index, left_op_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
          strcpy(left_reg_index, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
        fprintf(fp, "(inst%d->_opnds[%d]->reg(ra_,inst%d%s)  /* %d.%s */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
                left_index,  left_op_index, left_index, left_reg_index, left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
        if( right_index != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
          char right_reg_index[18] = ",instXXXX_idxXXXX";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
          if( right_op_index != 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
            assert( (right_index <= 9999) && (right_op_index <= 9999), "exceed string size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
            // Must have index into operands
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1229
            sprintf(right_reg_index,",inst%d_idx%d", (int)right_index, right_op_index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
            strcpy(right_reg_index, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
          fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->reg(ra_,inst%d%s)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
                  right_index, right_op, right_index, right_op_index, right_index, right_reg_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
          fprintf(fp, "%s_enc", right_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
        fprintf(fp,")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
      case Form::constant_interface: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
        // Compare the '->constant()' values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
        fprintf(fp, "(inst%d->_opnds[%d]->constant()  /* %d.%s */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
                left_index,  left_op_index,  left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
        fprintf(fp, "/* %d.%s */ inst%d->_opnds[%d]->constant())",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
                right_index, right_op, right_index, right_op_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
      case Form::memory_interface: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
        // Compare 'base', 'index', 'scale', and 'disp'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
        // base
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
        fprintf(fp, "( \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
        fprintf(fp, "  (inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d)  /* %d.%s$$base */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
          left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
        fprintf(fp, "/* %d.%s$$base */ inst%d->_opnds[%d]->base(ra_,inst%d,inst%d_idx%d)) &&\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
                right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
        // index
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
        fprintf(fp, "  (inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d)  /* %d.%s$$index */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
                left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
        fprintf(fp, "/* %d.%s$$index */ inst%d->_opnds[%d]->index(ra_,inst%d,inst%d_idx%d)) &&\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
                right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
        // scale
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
        fprintf(fp, "  (inst%d->_opnds[%d]->scale()  /* %d.%s$$scale */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
                left_index,  left_op_index,  left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
        fprintf(fp, "/* %d.%s$$scale */ inst%d->_opnds[%d]->scale()) &&\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
                right_index, right_op, right_index, right_op_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
        // disp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
        fprintf(fp, "  (inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d)  /* %d.%s$$disp */",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
                left_index, left_op_index, left_index, left_index, left_op_index, left_index, left_op );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
        fprintf(fp, " == ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
        fprintf(fp, "/* %d.%s$$disp */ inst%d->_opnds[%d]->disp(ra_,inst%d,inst%d_idx%d))\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
                right_index, right_op, right_index, right_op_index, right_index, right_index, right_op_index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
        fprintf(fp, ") \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
      case Form::conditional_interface: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
        // Compare the condition code being tested
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
        assert( false, "Unimplemented()" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      default: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
        assert( false, "ShouldNotReachHere()" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
      // Advance to next constraint
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
      pconstraint = pconstraint->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
      first_constraint = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
    fprintf(fp, ";\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
// // EXPERIMENTAL -- TEMPORARY code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
// static Form::DataType get_operand_type(FormDict &globals, InstructForm *instr, const char *op_name ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
//   int op_index = instr->operand_position(op_name, Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
//   if( op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
//     op_index = instr->operand_position(op_name, Component::DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
//     if( op_index == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
//       op_index = instr->operand_position(op_name, Component::USE_DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
//     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
//   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
//   assert( op_index != NameList::Not_in_list, "Did not find operand in instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
//   ComponentList components_right = instr->_components;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
//   char *right_comp_type = components_right.at(op_index)->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
//   OpClassForm *right_opclass = globals[right_comp_type]->is_opclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
//   Form::InterfaceType  right_interface_type = right_opclass->interface_type(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
//   return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
// }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
// Construct the new sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
static void generate_peepreplace( FILE *fp, FormDict &globals, PeepMatch *pmatch, PeepConstraint *pconstraint, PeepReplace *preplace, int max_position ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  fprintf(fp, "      // IF instructions and constraints matched\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
  fprintf(fp, "      if( matches ) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
  fprintf(fp, "        // generate the new sub-tree\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
  fprintf(fp, "        assert( true, \"Debug stopping point\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  if( preplace != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
    // Get the root of the new sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
    const char *root_inst = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
    preplace->next_instruction(root_inst);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
    InstructForm *root_form = globals[root_inst]->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
    assert( root_form != NULL, "Replacement instruction was not previously defined");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1331
    fprintf(fp, "        %sNode *root = new %sNode();\n", root_inst, root_inst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1333
    int         inst_num;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
    const char *op_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
    int         opnds_index = 0;            // define result operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
    // Then install the use-operands for the new sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
    // preplace->reset();             // reset breaks iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
    for( preplace->next_operand( inst_num, op_name );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
         op_name != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
         preplace->next_operand( inst_num, op_name ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
      InstructForm *inst_form;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
      inst_form  = globals[pmatch->instruction_name(inst_num)]->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1343
      assert( inst_form, "Parser should guaranty this is an instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
      int inst_op_num = inst_form->operand_position(op_name, Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
      if( inst_op_num == NameList::Not_in_list )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
        inst_op_num = inst_form->operand_position(op_name, Component::USE_DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
      assert( inst_op_num != NameList::Not_in_list, "Did not find operand as USE");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
      // find the name of the OperandForm from the local name
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
      const Form *form   = inst_form->_localNames[op_name];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
      OperandForm  *op_form = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
      if( opnds_index == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
        // Initial setup of new instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
        fprintf(fp, "        // ----- Initial setup -----\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
        //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
        // Add control edge for this node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
        fprintf(fp, "        root->add_req(_in[0]);                // control edge\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
        // Add unmatched edges from root of match tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
        int op_base = root_form->oper_input_base(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
        for( int unmatched_edge = 1; unmatched_edge < op_base; ++unmatched_edge ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1360
          fprintf(fp, "        root->add_req(inst%d->in(%d));        // unmatched ideal edge\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
                                          inst_num, unmatched_edge);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
        // If new instruction captures bottom type
5536
f23c4e2e0d5e 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 5402
diff changeset
  1364
        if( root_form->captures_bottom_type(globals) ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
          // Get bottom type from instruction whose result we are replacing
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1366
          fprintf(fp, "        root->_bottom_type = inst%d->bottom_type();\n", inst_num);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
        // Define result register and result operand
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1369
        fprintf(fp, "        ra_->add_reference(root, inst%d);\n", inst_num);
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1370
        fprintf(fp, "        ra_->set_oop (root, ra_->is_oop(inst%d));\n", inst_num);
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1371
        fprintf(fp, "        ra_->set_pair(root->_idx, ra_->get_reg_second(inst%d), ra_->get_reg_first(inst%d));\n", inst_num, inst_num);
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1372
        fprintf(fp, "        root->_opnds[0] = inst%d->_opnds[0]->clone(); // result\n", inst_num);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
        fprintf(fp, "        // ----- Done with initial setup -----\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
        if( (op_form == NULL) || (op_form->is_base_constant(globals) == Form::none) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
          // Do not have ideal edges for constants after matching
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1377
          fprintf(fp, "        for( unsigned x%d = inst%d_idx%d; x%d < inst%d_idx%d; x%d++ )\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
                  inst_op_num, inst_num, inst_op_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1379
                  inst_op_num, inst_num, inst_op_num+1, inst_op_num );
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1380
          fprintf(fp, "          root->add_req( inst%d->in(x%d) );\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
                  inst_num, inst_op_num );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
          fprintf(fp, "        // no ideal edge for constants after matching\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
        }
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1385
        fprintf(fp, "        root->_opnds[%d] = inst%d->_opnds[%d]->clone();\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
                opnds_index, inst_num, inst_op_num );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
      ++opnds_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
  }else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
    // Replacing subtree with empty-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
    assert( false, "ShouldNotReachHere();");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  // Return the new sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  fprintf(fp, "        deleted = %d;\n", max_position+1 /*zero to one based*/);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1397
  fprintf(fp, "        return root;  // return new root;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
  fprintf(fp, "      }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1400
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
// Define the Peephole method for an instruction node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
void ArchDesc::definePeephole(FILE *fp, InstructForm *node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  // Generate Peephole function header
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1405
  fprintf(fp, "MachNode *%sNode::peephole(Block *block, int block_index, PhaseRegAlloc *ra_, int &deleted) {\n", node->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
  fprintf(fp, "  bool  matches = true;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  // Identify the maximum instruction position,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
  // generate temporaries that hold current instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  //   MachNode  *inst0 = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
  //   ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
  //   MachNode  *instMAX = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  int max_position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  Peephole *peep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
  for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
    PeepMatch *pmatch = peep->match();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
    assert( pmatch != NULL, "fatal(), missing peepmatch rule");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
    if( max_position < pmatch->max_position() )  max_position = pmatch->max_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  for( int i = 0; i <= max_position; ++i ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
    if( i == 0 ) {
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1424
      fprintf(fp, "  MachNode *inst0 = this;\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
      fprintf(fp, "  MachNode *inst%d = NULL;\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
  // For each peephole rule in architecture description
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
  //   Construct a test for the desired instruction sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
  //   then check the constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
  //   If these match, Generate the new subtree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
  for( peep = node->peepholes(); peep != NULL; peep = peep->next() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
    int         peephole_number = peep->peephole_number();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
    PeepMatch      *pmatch      = peep->match();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    PeepConstraint *pconstraint = peep->constraints();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
    PeepReplace    *preplace    = peep->replacement();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
    // Root of this peephole is the current MachNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
    assert( true, // %%name?%% strcmp( node->_ident, pmatch->name(0) ) == 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
            "root of PeepMatch does not match instruction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
    // Make each peephole rule individually selectable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
    fprintf(fp, "  if( (OptoPeepholeAt == -1) || (OptoPeepholeAt==%d) ) {\n", peephole_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
    fprintf(fp, "    matches = true;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
    // Scan the peepmatch and output a test for each instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
    check_peepmatch_instruction_sequence( fp, pmatch, pconstraint );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
    // Check constraints and build replacement inside scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
    fprintf(fp, "    // If instruction subtree matches\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
    fprintf(fp, "    if( matches ) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
    // Generate tests for the constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
    check_peepconstraints( fp, _globalNames, pmatch, pconstraint );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
    // Construct the new sub-tree
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
    generate_peepreplace( fp, _globalNames, pmatch, pconstraint, preplace, max_position );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
    // End of scope for this peephole's constraints
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    fprintf(fp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
    // Closing brace '}' to make each peephole rule individually selectable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
    fprintf(fp, "  } // end of peephole rule #%d\n", peephole_number);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
    fprintf(fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
  fprintf(fp, "  return NULL;  // No peephole rules matched\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
  fprintf(fp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
  fprintf(fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
// Define the Expand method for an instruction node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
void ArchDesc::defineExpand(FILE *fp, InstructForm *node) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  unsigned      cnt  = 0;          // Count nodes we have expand into
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
  unsigned      i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
  // Generate Expand function header
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1478
  fprintf(fp, "MachNode* %sNode::Expand(State* state, Node_List& proj_list, Node* mem) {\n", node->_ident);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1479
  fprintf(fp, "  Compile* C = Compile::current();\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
  // Generate expand code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
  if( node->expands() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    const char   *opid;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
    int           new_pos, exp_pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    const char   *new_id   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
    const Form   *frm      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
    InstructForm *new_inst = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
    OperandForm  *new_oper = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
    unsigned      numo     = node->num_opnds() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
                                node->_exprule->_newopers.count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
    // If necessary, generate any operands created in expand rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
    if (node->_exprule->_newopers.count()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
      for(node->_exprule->_newopers.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
          (new_id = node->_exprule->_newopers.iter()) != NULL; cnt++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
        frm = node->_localNames[new_id];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
        assert(frm, "Invalid entry in new operands list of expand rule");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
        new_oper = frm->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
        char *tmp = (char *)node->_exprule->_newopconst[new_id];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
        if (tmp == NULL) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1500
          fprintf(fp,"  MachOper *op%d = new %sOper();\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
                  cnt, new_oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
        else {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1504
          fprintf(fp,"  MachOper *op%d = new %sOper(%s);\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
                  cnt, new_oper->_ident, tmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
    cnt = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
    // Generate the temps to use for DAG building
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
    for(i = 0; i < numo; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
      if (i < node->num_opnds()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
        fprintf(fp,"  MachNode *tmp%d = this;\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
        fprintf(fp,"  MachNode *tmp%d = NULL;\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
    // Build mapping from num_edges to local variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
    fprintf(fp,"  unsigned num0 = 0;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
    for( i = 1; i < node->num_opnds(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
      fprintf(fp,"  unsigned num%d = opnd_array(%d)->num_edges();\n",i,i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
    // Build a mapping from operand index to input edges
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
    fprintf(fp,"  unsigned idx0 = oper_input_base();\n");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1527
4751
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1528
    // The order in which the memory input is added to a node is very
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1529
    // strange.  Store nodes get a memory input before Expand is
4751
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1530
    // called and other nodes get it afterwards or before depending on
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1531
    // match order so oper_input_base is wrong during expansion.  This
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1532
    // code adjusts it so that expansion will work correctly.
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1533
    int has_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames);
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1534
    if (has_memory_edge) {
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1535
      fprintf(fp,"  if (mem == (Node*)1) {\n");
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1536
      fprintf(fp,"    idx0--; // Adjust base because memory edge hasn't been inserted yet\n");
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1537
      fprintf(fp,"  }\n");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1538
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1539
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
    for( i = 0; i < node->num_opnds(); i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
      fprintf(fp,"  unsigned idx%d = idx%d + num%d;\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
              i+1,i,i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
    // Declare variable to hold root of expansion
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
    fprintf(fp,"  MachNode *result = NULL;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
    // Iterate over the instructions 'node' expands into
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
    ExpandRule  *expand       = node->_exprule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
    NameAndList *expand_instr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
    for(expand->reset_instructions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
        (expand_instr = expand->iter_instructions()) != NULL; cnt++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
      new_id = expand_instr->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
      InstructForm* expand_instruction = (InstructForm*)globalAD->globalNames()[new_id];
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1556
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1557
      if (!expand_instruction) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1558
        globalAD->syntax_err(node->_linenum, "In %s: instruction %s used in expand not declared\n",
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1559
                             node->_ident, new_id);
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1560
        continue;
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1561
      }
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1562
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
      if (expand_instruction->has_temps()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
        globalAD->syntax_err(node->_linenum, "In %s: expand rules using instructs with TEMPs aren't supported: %s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
                             node->_ident, new_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
      // Build the node for the instruction
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1569
      fprintf(fp,"\n  %sNode *n%d = new %sNode();\n", new_id, cnt, new_id);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
      // Add control edge for this node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
      fprintf(fp,"  n%d->add_req(_in[0]);\n", cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
      // Build the operand for the value this node defines.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
      Form *form = (Form*)_globalNames[new_id];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
      assert( form, "'new_id' must be a defined form name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
      // Grab the InstructForm for the new instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
      new_inst = form->is_instruction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
      assert( new_inst, "'new_id' must be an instruction name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
      if( node->is_ideal_if() && new_inst->is_ideal_if() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
        fprintf(fp, "  ((MachIfNode*)n%d)->_prob = _prob;\n",cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
        fprintf(fp, "  ((MachIfNode*)n%d)->_fcnt = _fcnt;\n",cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
      if( node->is_ideal_fastlock() && new_inst->is_ideal_fastlock() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
        fprintf(fp, "  ((MachFastLockNode*)n%d)->_counters = _counters;\n",cnt);
23491
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents: 22875
diff changeset
  1585
        fprintf(fp, "  ((MachFastLockNode*)n%d)->_rtm_counters = _rtm_counters;\n",cnt);
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents: 22875
diff changeset
  1586
        fprintf(fp, "  ((MachFastLockNode*)n%d)->_stack_rtm_counters = _stack_rtm_counters;\n",cnt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
13893
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1589
      // Fill in the bottom_type where requested
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1590
      if (node->captures_bottom_type(_globalNames) &&
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1591
          new_inst->captures_bottom_type(_globalNames)) {
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1592
        fprintf(fp, "  ((MachTypeNode*)n%d)->_bottom_type = bottom_type();\n", cnt);
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1593
      }
8ffaa5b97ca6 7200233: C2: can't use expand rules for vector instruction rules
kvn
parents: 13728
diff changeset
  1594
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
      const char *resultOper = new_inst->reduce_result();
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1596
      fprintf(fp,"  n%d->set_opnd_array(0, state->MachOperGenerator(%s));\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
              cnt, machOperEnum(resultOper));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
      // get the formal operand NameList
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
      NameList *formal_lst = &new_inst->_parameters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
      formal_lst->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
      // Handle any memory operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
      int memory_operand = new_inst->memory_operand(_globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
      if( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
        int node_mem_op = node->memory_operand(_globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
        assert( node_mem_op != InstructForm::NO_MEMORY_OPERAND,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
                "expand rule member needs memory but top-level inst doesn't have any" );
4751
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1609
        if (has_memory_edge) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1610
          // Copy memory edge
4751
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1611
          fprintf(fp,"  if (mem != (Node*)1) {\n");
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1612
          fprintf(fp,"    n%d->add_req(_in[1]);\t// Add memory edge\n", cnt);
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1613
          fprintf(fp,"  }\n");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1614
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
      // Iterate over the new instruction's operands
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1618
      int prev_pos = -1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
      for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
        // Use 'parameter' at current position in list of new instruction's formals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
        // instead of 'opid' when looking up info internal to new_inst
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
        const char *parameter = formal_lst->iter();
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1623
        if (!parameter) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1624
          globalAD->syntax_err(node->_linenum, "Operand %s of expand instruction %s has"
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1625
                               " no equivalent in new instruction %s.",
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1626
                               opid, node->_ident, new_inst->_ident);
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1627
          assert(0, "Wrong expand");
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1628
        }
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  1629
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
        // Check for an operand which is created in the expand rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
        if ((exp_pos = node->_exprule->_newopers.index(opid)) != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
          new_pos = new_inst->operand_position(parameter,Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
          exp_pos += node->num_opnds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
          // If there is no use of the created operand, just skip it
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1635
          if (new_pos != NameList::Not_in_list) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
            //Copy the operand from the original made above
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1637
            fprintf(fp,"  n%d->set_opnd_array(%d, op%d->clone()); // %s\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
                    cnt, new_pos, exp_pos-node->num_opnds(), opid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
            // Check for who defines this operand & add edge if needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
            fprintf(fp,"  if(tmp%d != NULL)\n", exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
            fprintf(fp,"    n%d->add_req(tmp%d);\n", cnt, exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
        else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
          // Use operand name to get an index into instruction component list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
          // ins = (InstructForm *) _globalNames[new_id];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
          exp_pos = node->operand_position_format(opid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
          assert(exp_pos != -1, "Bad expand rule");
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1649
          if (prev_pos > exp_pos && expand_instruction->_matrule != NULL) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1650
            // For the add_req calls below to work correctly they need
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1651
            // to added in the same order that a match would add them.
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1652
            // This means that they would need to be in the order of
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1653
            // the components list instead of the formal parameters.
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1654
            // This is a sort of hidden invariant that previously
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1655
            // wasn't checked and could lead to incorrectly
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1656
            // constructed nodes.
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1657
            syntax_err(node->_linenum, "For expand in %s to work, parameter declaration order in %s must follow matchrule\n",
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1658
                       node->_ident, new_inst->_ident);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1659
          }
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  1660
          prev_pos = exp_pos;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
          new_pos = new_inst->operand_position(parameter,Component::USE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
          if (new_pos != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
            // Copy the operand from the ExpandNode to the new node
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1665
            fprintf(fp,"  n%d->set_opnd_array(%d, opnd_array(%d)->clone()); // %s\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
                    cnt, new_pos, exp_pos, opid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
            // For each operand add appropriate input edges by looking at tmp's
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
            fprintf(fp,"  if(tmp%d == this) {\n", exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
            // Grab corresponding edges from ExpandNode and insert them here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
            fprintf(fp,"    for(unsigned i = 0; i < num%d; i++) {\n", exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
            fprintf(fp,"      n%d->add_req(_in[i + idx%d]);\n", cnt, exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
            fprintf(fp,"    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
            fprintf(fp,"  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
            // This value is generated by one of the new instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
            fprintf(fp,"  else n%d->add_req(tmp%d);\n", cnt, exp_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
        // Update the DAG tmp's for values defined by this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
        int new_def_pos = new_inst->operand_position(parameter,Component::DEF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
        Effect *eform = (Effect *)new_inst->_effects[parameter];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
        // If this operand is a definition in either an effects rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
        // or a match rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
        if((eform) && (is_def(eform->_use_def))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
          // Update the temp associated with this operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
          fprintf(fp,"  tmp%d = n%d;\n", exp_pos, cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
        else if( new_def_pos != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
          // Instruction defines a value but user did not declare it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
          // in the 'effect' clause
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
          fprintf(fp,"  tmp%d = n%d;\n", exp_pos, cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
      } // done iterating over a new instruction's operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
      // Invoke Expand() for the newly created instruction.
4751
9418f690831d 6916644: C2 compiler crash on x86
never
parents: 2872
diff changeset
  1696
      fprintf(fp,"  result = n%d->Expand( state, proj_list, mem );\n", cnt);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
      assert( !new_inst->expands(), "Do not have complete support for recursive expansion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
    } // done iterating over new instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
    fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  } // done generating expand rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1702
  // Generate projections for instruction's additional DEFs and KILLs
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1703
  if( ! node->expands() && (node->needs_projections() || node->has_temps())) {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1704
    // Get string representing the MachNode that projections point at
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1705
    const char *machNode = "this";
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1706
    // Generate the projections
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1707
    fprintf(fp,"  // Add projection edges for additional defs or kills\n");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1708
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1709
    // Examine each component to see if it is a DEF or KILL
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1710
    node->_components.reset();
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1711
    // Skip the first component, if already handled as (SET dst (...))
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1712
    Component *comp = NULL;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1713
    // For kills, the choice of projection numbers is arbitrary
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1714
    int proj_no = 1;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1715
    bool declared_def  = false;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1716
    bool declared_kill = false;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1717
26910
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1718
    while ((comp = node->_components.iter()) != NULL) {
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1719
      // Lookup register class associated with operand type
26910
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1720
      Form *form = (Form*)_globalNames[comp->_type];
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1721
      assert(form, "component type must be a defined form");
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1722
      OperandForm *op = form->is_operand();
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1723
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1724
      if (comp->is(Component::TEMP) ||
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1725
          comp->is(Component::TEMP_DEF)) {
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1726
        fprintf(fp, "  // TEMP %s\n", comp->_name);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1727
        if (!declared_def) {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1728
          // Define the variable "def" to hold new MachProjNodes
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1729
          fprintf(fp, "  MachTempNode *def;\n");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1730
          declared_def = true;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1731
        }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1732
        if (op && op->_interface && op->_interface->is_RegInterface()) {
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1733
          fprintf(fp,"  def = new MachTempNode(state->MachOperGenerator(%s));\n",
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1734
                  machOperEnum(op->_ident));
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1735
          fprintf(fp,"  add_req(def);\n");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1736
          // The operand for TEMP is already constructed during
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1737
          // this mach node construction, see buildMachNode().
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1738
          //
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1739
          // int idx  = node->operand_position_format(comp->_name);
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1740
          // fprintf(fp,"  set_opnd_array(%d, state->MachOperGenerator(%s));\n",
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1741
          //         idx, machOperEnum(op->_ident));
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1742
        } else {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1743
          assert(false, "can't have temps which aren't registers");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1744
        }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1745
      } else if (comp->isa(Component::KILL)) {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1746
        fprintf(fp, "  // DEF/KILL %s\n", comp->_name);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1747
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1748
        if (!declared_kill) {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1749
          // Define the variable "kill" to hold new MachProjNodes
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1750
          fprintf(fp, "  MachProjNode *kill;\n");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1751
          declared_kill = true;
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1752
        }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1753
26910
253efabfd968 8058880: Introduce identifier TEMP_DEF for effects in adl.
goetz
parents: 25930
diff changeset
  1754
        assert(op, "Support additional KILLS for base operands");
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1755
        const char *regmask    = reg_mask(*op);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1756
        const char *ideal_type = op->ideal_type(_globalNames, _register);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1757
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1758
        if (!op->is_bound_register()) {
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1759
          syntax_err(node->_linenum, "In %s only bound registers can be killed: %s %s\n",
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1760
                     node->_ident, comp->_type, comp->_name);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1761
        }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1762
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1763
        fprintf(fp,"  kill = ");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  1764
        fprintf(fp,"new MachProjNode( %s, %d, (%s), Op_%s );\n",
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1765
                machNode, proj_no++, regmask, ideal_type);
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1766
        fprintf(fp,"  proj_list.push(kill);\n");
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1767
      }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1768
    }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1769
  }
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1770
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  1771
  if( !node->expands() && node->_matrule != NULL ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
    // Remove duplicated operands and inputs which use the same name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
    // Seach through match operands for the same name usage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1774
    uint cur_num_opnds = node->num_opnds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
    if( cur_num_opnds > 1 && cur_num_opnds != node->num_unique_opnds() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
      Component *comp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
      // Build mapping from num_edges to local variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
      fprintf(fp,"  unsigned num0 = 0;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
      for( i = 1; i < cur_num_opnds; i++ ) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1780
        fprintf(fp,"  unsigned num%d = opnd_array(%d)->num_edges();",i,i);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1781
        fprintf(fp, " \t// %s\n", node->opnd_ident(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
      // Build a mapping from operand index to input edges
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
      fprintf(fp,"  unsigned idx0 = oper_input_base();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
      for( i = 0; i < cur_num_opnds; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
        fprintf(fp,"  unsigned idx%d = idx%d + num%d;\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
                i+1,i,i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
      uint new_num_opnds = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
      node->_components.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
      // Skip first unique operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
      for( i = 1; i < cur_num_opnds; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
        comp = node->_components.iter();
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
  1795
        if (i != node->unique_opnds_idx(i)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
        new_num_opnds++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
      // Replace not unique operands with next unique operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
      for( ; i < cur_num_opnds; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
        comp = node->_components.iter();
17871
6669c8d6f6b3 8015266: fix some -Wsign-compare warnings in adlc
twisti
parents: 16687
diff changeset
  1803
        uint j = node->unique_opnds_idx(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
        // unique_opnds_idx(i) is unique if unique_opnds_idx(j) is not unique.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
        if( j != node->unique_opnds_idx(j) ) {
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  1806
          fprintf(fp,"  set_opnd_array(%d, opnd_array(%d)->clone()); // %s\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
                  new_num_opnds, i, comp->_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
          // delete not unique edges here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
          fprintf(fp,"  for(unsigned i = 0; i < num%d; i++) {\n", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1810
          fprintf(fp,"    set_req(i + idx%d, _in[i + idx%d]);\n", new_num_opnds, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
          fprintf(fp,"  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
          fprintf(fp,"  num%d = num%d;\n", new_num_opnds, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
          fprintf(fp,"  idx%d = idx%d + num%d;\n", new_num_opnds+1, new_num_opnds, new_num_opnds);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
          new_num_opnds++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
      // delete the rest of edges
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
      fprintf(fp,"  for(int i = idx%d - 1; i >= (int)idx%d; i--) {\n", cur_num_opnds, new_num_opnds);
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
  1819
      fprintf(fp,"    del_req(i);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
      fprintf(fp,"  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
      fprintf(fp,"  _num_opnds = %d;\n", new_num_opnds);
2872
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  1822
      assert(new_num_opnds == node->num_unique_opnds(), "what?");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1826
  // If the node is a MachConstantNode, insert the MachConstantBaseNode edge.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1827
  // NOTE: this edge must be the last input (see MachConstantNode::mach_constant_base_node_input).
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  1828
  // There are nodes that don't use $constantablebase, but still require that it
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  1829
  // is an input to the node. Example: divF_reg_immN, Repl32B_imm on x86_64.
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  1830
  if (node->is_mach_constant() || node->needs_constant_base()) {
22865
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1831
    if (node->is_ideal_call() != Form::invalid_type &&
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1832
        node->is_ideal_call() != Form::JAVA_LEAF) {
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1833
      fprintf(fp, "  // MachConstantBaseNode added in matcher.\n");
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1834
      _needs_clone_jvms = true;
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1835
    } else {
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1836
      fprintf(fp, "  add_req(C->mach_constant_base_node());\n");
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1837
    }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1838
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1839
22865
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1840
  fprintf(fp, "\n");
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1841
  if (node->expands()) {
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1842
    fprintf(fp, "  return result;\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
  } else {
22865
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1844
    fprintf(fp, "  return this;\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
  }
22865
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1846
  fprintf(fp, "}\n");
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  1847
  fprintf(fp, "\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
//------------------------------Emit Routines----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
// Special classes and routines for defining node emit routines which output
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
// target specific instruction object encodings.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
// Define the ___Node::emit() routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
// (1) void  ___Node::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
// (2)   // ...  encoding defined by user
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
// (3)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
// (4) }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
class DefineEmitState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
  enum reloc_format { RELOC_NONE        = -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
                      RELOC_IMMEDIATE   =  0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
                      RELOC_DISP        =  1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
                      RELOC_CALL_DISP   =  2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
  enum literal_status{ LITERAL_NOT_SEEN  = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
                       LITERAL_SEEN      = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
                       LITERAL_ACCESSED  = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
                       LITERAL_OUTPUT    = 3 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
  // Temporaries that describe current operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
  bool          _cleared;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  OpClassForm  *_opclass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  OperandForm  *_operand;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  int           _operand_idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
  const char   *_local_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
  const char   *_operand_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
  bool          _doing_disp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
  bool          _doing_constant;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
  Form::DataType _constant_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
  DefineEmitState::literal_status _constant_status;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
  DefineEmitState::literal_status _reg_status;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
  bool          _doing_emit8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
  bool          _doing_emit_d32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  bool          _doing_emit_d16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
  bool          _doing_emit_hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  bool          _doing_emit_lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
  bool          _may_reloc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  reloc_format  _reloc_form;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
  const char *  _reloc_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1892
  bool          _processing_noninput;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1893
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1894
  NameList      _strings_to_emit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1895
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1896
  // Stable state, set by constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
  ArchDesc     &_AD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1898
  FILE         *_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1899
  EncClass     &_encoding;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1900
  InsEncode    &_ins_encode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
  InstructForm &_inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
  DefineEmitState(FILE *fp, ArchDesc &AD, EncClass &encoding,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
                  InsEncode &ins_encode, InstructForm &inst)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
    : _AD(AD), _fp(fp), _encoding(encoding), _ins_encode(ins_encode), _inst(inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
      clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
  void clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
    _cleared       = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
    _opclass       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1913
    _operand       = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1914
    _operand_idx   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1915
    _local_name    = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1916
    _operand_name  = "";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1917
    _doing_disp    = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1918
    _doing_constant= false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1919
    _constant_type = Form::none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1920
    _constant_status = LITERAL_NOT_SEEN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1921
    _reg_status      = LITERAL_NOT_SEEN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1922
    _doing_emit8   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1923
    _doing_emit_d32= false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1924
    _doing_emit_d16= false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1925
    _doing_emit_hi = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1926
    _doing_emit_lo = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1927
    _may_reloc     = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1928
    _reloc_form    = RELOC_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1929
    _reloc_type    = AdlcVMDeps::none_reloc_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1930
    _strings_to_emit.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1931
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1932
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1933
  // Track necessary state when identifying a replacement variable
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1934
  // @arg rep_var: The formal parameter of the encoding.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1935
  void update_state(const char *rep_var) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1936
    // A replacement variable or one of its subfields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1937
    // Obtain replacement variable from list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1938
    if ( (*rep_var) != '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1939
      // A replacement variable, '$' prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1940
      // check_rep_var( rep_var );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1941
      if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1942
        // No state needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1943
        assert( _opclass == NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1944
                "'primary', 'secondary' and 'tertiary' don't follow operand.");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1945
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1946
      else if ((strcmp(rep_var, "constanttablebase") == 0) ||
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1947
               (strcmp(rep_var, "constantoffset")    == 0) ||
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1948
               (strcmp(rep_var, "constantaddress")   == 0)) {
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  1949
        if (!(_inst.is_mach_constant() || _inst.needs_constant_base())) {
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1950
          _AD.syntax_err(_encoding._linenum,
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  1951
                         "Replacement variable %s not allowed in instruct %s (only in MachConstantNode or MachCall).\n",
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1952
                         rep_var, _encoding._name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1953
        }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1954
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  1955
      else {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1956
        // Lookup its position in (formal) parameter list of encoding
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1957
        int   param_no  = _encoding.rep_var_index(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1958
        if ( param_no == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1959
          _AD.syntax_err( _encoding._linenum,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1960
                          "Replacement variable %s not found in enc_class %s.\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1961
                          rep_var, _encoding._name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1962
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1963
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1964
        // Lookup the corresponding ins_encode parameter
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  1965
        // This is the argument (actual parameter) to the encoding.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1966
        const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1967
        if (inst_rep_var == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1968
          _AD.syntax_err( _ins_encode._linenum,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1969
                          "Parameter %s not passed to enc_class %s from instruct %s.\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1970
                          rep_var, _encoding._name, _inst._ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1971
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1973
        // Check if instruction's actual parameter is a local name in the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1974
        const Form  *local     = _inst._localNames[inst_rep_var];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1975
        OpClassForm *opc       = (local != NULL) ? local->is_opclass() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1976
        // Note: assert removed to allow constant and symbolic parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1977
        // assert( opc, "replacement variable was not found in local names");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1978
        // Lookup the index position iff the replacement variable is a localName
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1979
        int idx  = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1980
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1981
        if ( idx != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1982
          // This is a local in the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1983
          // Update local state info.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1984
          _opclass        = opc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1985
          _operand_idx    = idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1986
          _local_name     = rep_var;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1987
          _operand_name   = inst_rep_var;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1988
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1989
          // !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1990
          // Do not support consecutive operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1991
          assert( _operand == NULL, "Unimplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1992
          _operand = opc->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1993
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1994
        else if( ADLParser::is_literal_constant(inst_rep_var) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1995
          // Instruction provided a constant expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1996
          // Check later that encoding specifies $$$constant to resolve as constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1997
          _constant_status   = LITERAL_SEEN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1998
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1999
        else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2000
          // Instruction provided an opcode: "primary", "secondary", "tertiary"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2001
          // Check later that encoding specifies $$$constant to resolve as constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2002
          _constant_status   = LITERAL_SEEN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2003
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2004
        else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2005
          // Instruction provided a literal register name for this parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2006
          // Check that encoding specifies $$$reg to resolve.as register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2007
          _reg_status        = LITERAL_SEEN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2008
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2009
        else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2010
          // Check for unimplemented functionality before hard failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2011
          assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2012
          assert( false, "ShouldNotReachHere()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2013
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2014
      } // done checking which operand this is.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2015
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2016
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2017
      // A subfield variable, '$$' prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2018
      // Check for fields that may require relocation information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2019
      // Then check that literal register parameters are accessed with 'reg' or 'constant'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2020
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2021
      if ( strcmp(rep_var,"$disp") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2022
        _doing_disp = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2023
        assert( _opclass, "Must use operand or operand class before '$disp'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2024
        if( _operand == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2025
          // Only have an operand class, generate run-time check for relocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2026
          _may_reloc    = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2027
          _reloc_form   = RELOC_DISP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2028
          _reloc_type   = AdlcVMDeps::oop_reloc_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2029
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2030
          // Do precise check on operand: is it a ConP or not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2031
          //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2032
          // Check interface for value of displacement
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2033
          assert( ( _operand->_interface != NULL ),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2034
                  "$disp can only follow memory interface operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2035
          MemInterface *mem_interface= _operand->_interface->is_MemInterface();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2036
          assert( mem_interface != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2037
                  "$disp can only follow memory interface operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2038
          const char *disp = mem_interface->_disp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2039
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2040
          if( disp != NULL && (*disp == '$') ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2041
            // MemInterface::disp contains a replacement variable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2042
            // Check if this matches a ConP
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2043
            //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2044
            // Lookup replacement variable, in operand's component list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2045
            const char *rep_var_name = disp + 1; // Skip '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2046
            const Component *comp = _operand->_components.search(rep_var_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2047
            assert( comp != NULL,"Replacement variable not found in components");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2048
            const char      *type = comp->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2049
            // Lookup operand form for replacement variable's type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2050
            const Form *form = _AD.globalNames()[type];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2051
            assert( form != NULL, "Replacement variable's type not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2052
            OperandForm *op = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2053
            assert( op, "Attempting to emit a non-register or non-constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2054
            // Check if this is a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2055
            if (op->_matrule && op->_matrule->is_base_constant(_AD.globalNames())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2056
              // Check which constant this name maps to: _c0, _c1, ..., _cn
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2057
              // const int idx = _operand.constant_position(_AD.globalNames(), comp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2058
              // assert( idx != -1, "Constant component not found in operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2059
              Form::DataType dtype = op->is_base_constant(_AD.globalNames());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2060
              if ( dtype == Form::idealP ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2061
                _may_reloc    = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2062
                // No longer true that idealP is always an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2063
                _reloc_form   = RELOC_DISP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2064
                _reloc_type   = AdlcVMDeps::oop_reloc_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2065
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2066
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2068
            else if( _operand->is_user_name_for_sReg() != Form::none ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2069
              // The only non-constant allowed access to disp is an operand sRegX in a stackSlotX
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2070
              assert( op->ideal_to_sReg_type(type) != Form::none, "StackSlots access displacements using 'sRegs'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2071
              _may_reloc   = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2072
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2073
              assert( false, "fatal(); Only stackSlots can access a non-constant using 'disp'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2074
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2075
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2076
        } // finished with precise check of operand for relocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2077
      } // finished with subfield variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2078
      else if ( strcmp(rep_var,"$constant") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2079
        _doing_constant = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2080
        if ( _constant_status == LITERAL_NOT_SEEN ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2081
          // Check operand for type of constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2082
          assert( _operand, "Must use operand before '$$constant'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2083
          Form::DataType dtype = _operand->is_base_constant(_AD.globalNames());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2084
          _constant_type = dtype;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2085
          if ( dtype == Form::idealP ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2086
            _may_reloc    = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2087
            // No longer true that idealP is always an oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2088
            // // _must_reloc   = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2089
            _reloc_form   = RELOC_IMMEDIATE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2090
            _reloc_type   = AdlcVMDeps::oop_reloc_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2091
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2092
            // No relocation information needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2093
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2094
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2095
          // User-provided literals may not require relocation information !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2096
          assert( _constant_status == LITERAL_SEEN, "Must know we are processing a user-provided literal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2097
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2098
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2099
      else if ( strcmp(rep_var,"$label") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2100
        // Calls containing labels require relocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2101
        if ( _inst.is_ideal_call() )  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2102
          _may_reloc    = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2103
          // !!!!! !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2104
          _reloc_type   = AdlcVMDeps::none_reloc_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2105
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2106
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2107
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2108
      // literal register parameter must be accessed as a 'reg' field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2109
      if ( _reg_status != LITERAL_NOT_SEEN ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2110
        assert( _reg_status == LITERAL_SEEN, "Must have seen register literal before now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2111
        if (strcmp(rep_var,"$reg") == 0 || reg_conversion(rep_var) != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2112
          _reg_status  = LITERAL_ACCESSED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2113
        } else {
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2114
          _AD.syntax_err(_encoding._linenum,
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2115
                         "Invalid access to literal register parameter '%s' in %s.\n",
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2116
                         rep_var, _encoding._name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2117
          assert( false, "invalid access to literal register parameter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2118
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2119
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2120
      // literal constant parameters must be accessed as a 'constant' field
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2121
      if (_constant_status != LITERAL_NOT_SEEN) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2122
        assert(_constant_status == LITERAL_SEEN, "Must have seen constant literal before now");
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2123
        if (strcmp(rep_var,"$constant") == 0) {
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2124
          _constant_status = LITERAL_ACCESSED;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2125
        } else {
22847
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2126
          _AD.syntax_err(_encoding._linenum,
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2127
                         "Invalid access to literal constant parameter '%s' in %s.\n",
603ad1f10e16 8028401: PPC (part 117): Improve usability of adlc and format() functionality.
goetz
parents: 22844
diff changeset
  2128
                         rep_var, _encoding._name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2129
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2130
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2131
    } // end replacement and/or subfield
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2132
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2134
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2135
  void add_rep_var(const char *rep_var) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2136
    // Handle subfield and replacement variables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2137
    if ( ( *rep_var == '$' ) && ( *(rep_var+1) == '$' ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2138
      // Check for emit prefix, '$$emit32'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2139
      assert( _cleared, "Can not nest $$$emit32");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2140
      if ( strcmp(rep_var,"$$emit32") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2141
        _doing_emit_d32 = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2142
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2143
      else if ( strcmp(rep_var,"$$emit16") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2144
        _doing_emit_d16 = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2145
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2146
      else if ( strcmp(rep_var,"$$emit_hi") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2147
        _doing_emit_hi  = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2148
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2149
      else if ( strcmp(rep_var,"$$emit_lo") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2150
        _doing_emit_lo  = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2151
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2152
      else if ( strcmp(rep_var,"$$emit8") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2153
        _doing_emit8    = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2155
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2156
        _AD.syntax_err(_encoding._linenum, "Unsupported $$operation '%s'\n",rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2157
        assert( false, "fatal();");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2158
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2160
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2161
      // Update state for replacement variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2162
      update_state( rep_var );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2163
      _strings_to_emit.addName(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2164
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2165
    _cleared  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2166
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2167
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2168
  void emit_replacement() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2169
    // A replacement variable or one of its subfields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2170
    // Obtain replacement variable from list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2171
    // const char *ec_rep_var = encoding->_rep_vars.iter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2172
    const char *rep_var;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2173
    _strings_to_emit.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2174
    while ( (rep_var = _strings_to_emit.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2176
      if ( (*rep_var) == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2177
        // A subfield variable, '$$' prefix
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2178
        emit_field( rep_var );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2179
      } else {
2150
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2180
        if (_strings_to_emit.peek() != NULL &&
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2181
            strcmp(_strings_to_emit.peek(), "$Address") == 0) {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2182
          fprintf(_fp, "Address::make_raw(");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2183
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2184
          emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2185
          fprintf(_fp,"->base(ra_,this,idx%d), ", _operand_idx);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2186
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2187
          _reg_status = LITERAL_ACCESSED;
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2188
          emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2189
          fprintf(_fp,"->index(ra_,this,idx%d), ", _operand_idx);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2190
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2191
          _reg_status = LITERAL_ACCESSED;
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2192
          emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2193
          fprintf(_fp,"->scale(), ");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2194
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2195
          _reg_status = LITERAL_ACCESSED;
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2196
          emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2197
          Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none;
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2198
          if( _operand  && _operand_idx==0 && stack_type != Form::none ) {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2199
            fprintf(_fp,"->disp(ra_,this,0), ");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2200
          } else {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2201
            fprintf(_fp,"->disp(ra_,this,idx%d), ", _operand_idx);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2202
          }
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2203
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2204
          _reg_status = LITERAL_ACCESSED;
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2205
          emit_rep_var( rep_var );
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2206
          fprintf(_fp,"->disp_reloc())");
2150
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2207
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2208
          // skip trailing $Address
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2209
          _strings_to_emit.iter();
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2210
        } else {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2211
          // A replacement variable, '$' prefix
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2212
          const char* next = _strings_to_emit.peek();
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2213
          const char* next2 = _strings_to_emit.peek(2);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2214
          if (next != NULL && next2 != NULL && strcmp(next2, "$Register") == 0 &&
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2215
              (strcmp(next, "$base") == 0 || strcmp(next, "$index") == 0)) {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2216
            // handle $rev_var$$base$$Register and $rev_var$$index$$Register by
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2217
            // producing as_Register(opnd_array(#)->base(ra_,this,idx1)).
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2218
            fprintf(_fp, "as_Register(");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2219
            // emit the operand reference
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2220
            emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2221
            rep_var = _strings_to_emit.iter();
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2222
            assert(strcmp(rep_var, "$base") == 0 || strcmp(rep_var, "$index") == 0, "bad pattern");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2223
            // handle base or index
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2224
            emit_field(rep_var);
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2225
            rep_var = _strings_to_emit.iter();
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2226
            assert(strcmp(rep_var, "$Register") == 0, "bad pattern");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2227
            // close up the parens
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2228
            fprintf(_fp, ")");
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2229
          } else {
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2230
            emit_rep_var( rep_var );
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2231
          }
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
  2232
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2233
      } // end replacement and/or subfield
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2237
  void emit_reloc_type(const char* type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2238
    fprintf(_fp, "%s", type)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2239
      ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2242
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2243
  void emit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2244
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2245
    //   "emit_d32_reloc(" or "emit_hi_reloc" or "emit_lo_reloc"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2246
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2247
    // Emit the function name when generating an emit function
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2248
    if ( _doing_emit_d32 || _doing_emit_hi || _doing_emit_lo ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2249
      const char *d32_hi_lo = _doing_emit_d32 ? "d32" : (_doing_emit_hi ? "hi" : "lo");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2250
      // In general, relocatable isn't known at compiler compile time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2251
      // Check results of prior scan
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2252
      if ( ! _may_reloc ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2253
        // Definitely don't need relocation information
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2254
        fprintf( _fp, "emit_%s(cbuf, ", d32_hi_lo );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2255
        emit_replacement(); fprintf(_fp, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2256
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2257
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2258
        // Emit RUNTIME CHECK to see if value needs relocation info
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2259
        // If emitting a relocatable address, use 'emit_d32_reloc'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2260
        const char *disp_constant = _doing_disp ? "disp" : _doing_constant ? "constant" : "INVALID";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2261
        assert( (_doing_disp || _doing_constant)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2262
                && !(_doing_disp && _doing_constant),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2263
                "Must be emitting either a displacement or a constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2264
        fprintf(_fp,"\n");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2265
        fprintf(_fp,"if ( opnd_array(%d)->%s_reloc() != relocInfo::none ) {\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2266
                _operand_idx, disp_constant);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2267
        fprintf(_fp,"  ");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2268
        fprintf(_fp,"emit_%s_reloc(cbuf, ", d32_hi_lo );
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2269
        emit_replacement();             fprintf(_fp,", ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2270
        fprintf(_fp,"opnd_array(%d)->%s_reloc(), ",
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2271
                _operand_idx, disp_constant);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2272
        fprintf(_fp, "%d", _reloc_form);fprintf(_fp, ");");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11197
diff changeset
  2273
        fprintf(_fp,"\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2274
        fprintf(_fp,"} else {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2275
        fprintf(_fp,"  emit_%s(cbuf, ", d32_hi_lo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2276
        emit_replacement(); fprintf(_fp, ");\n"); fprintf(_fp,"}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2277
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2278
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2279
    else if ( _doing_emit_d16 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2280
      // Relocation of 16-bit values is not supported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2281
      fprintf(_fp,"emit_d16(cbuf, ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2282
      emit_replacement(); fprintf(_fp, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2283
      // No relocation done for 16-bit values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2284
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2285
    else if ( _doing_emit8 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2286
      // Relocation of 8-bit values is not supported
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2287
      fprintf(_fp,"emit_d8(cbuf, ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2288
      emit_replacement(); fprintf(_fp, ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2289
      // No relocation done for 8-bit values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2290
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2291
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2292
      // Not an emit# command, just output the replacement string.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2293
      emit_replacement();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2294
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2295
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2296
    // Get ready for next state collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2297
    clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2299
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2300
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2301
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2302
  // recognizes names which represent MacroAssembler register types
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2303
  // and return the conversion function to build them from OptoReg
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2304
  const char* reg_conversion(const char* rep_var) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2305
    if (strcmp(rep_var,"$Register") == 0)      return "as_Register";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2306
    if (strcmp(rep_var,"$FloatRegister") == 0) return "as_FloatRegister";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2307
#if defined(IA32) || defined(AMD64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2308
    if (strcmp(rep_var,"$XMMRegister") == 0)   return "as_XMMRegister";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2309
#endif
22860
80a845ab5e4a 8029888: PPC64: (part 219): adl replacement variable CondRegister
goetz
parents: 22850
diff changeset
  2310
    if (strcmp(rep_var,"$CondRegister") == 0)  return "as_ConditionRegister";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2311
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2314
  void emit_field(const char *rep_var) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2315
    const char* reg_convert = reg_conversion(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2316
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2317
    // A subfield variable, '$$subfield'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2318
    if ( strcmp(rep_var, "$reg") == 0 || reg_convert != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2319
      // $reg form or the $Register MacroAssembler type conversions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2320
      assert( _operand_idx != -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2321
              "Must use this subfield after operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2322
      if( _reg_status == LITERAL_NOT_SEEN ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2323
        if (_processing_noninput) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2324
          const Form  *local     = _inst._localNames[_operand_name];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2325
          OperandForm *oper      = local->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2326
          const RegDef* first = oper->get_RegClass()->find_first_elem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2327
          if (reg_convert != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2328
            fprintf(_fp, "%s(%s_enc)", reg_convert, first->_regname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2329
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2330
            fprintf(_fp, "%s_enc", first->_regname);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2331
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2332
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2333
          fprintf(_fp,"->%s(ra_,this", reg_convert != NULL ? reg_convert : "reg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2334
          // Add parameter for index position, if not result operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2335
          if( _operand_idx != 0 ) fprintf(_fp,",idx%d", _operand_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2336
          fprintf(_fp,")");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2337
          fprintf(_fp, "/* %s */", _operand_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2338
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2339
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2340
        assert( _reg_status == LITERAL_OUTPUT, "should have output register literal in emit_rep_var");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2341
        // Register literal has already been sent to output file, nothing more needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2342
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2343
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2344
    else if ( strcmp(rep_var,"$base") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2345
      assert( _operand_idx != -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2346
              "Must use this subfield after operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2347
      assert( ! _may_reloc, "UnImplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2348
      fprintf(_fp,"->base(ra_,this,idx%d)", _operand_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2349
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2350
    else if ( strcmp(rep_var,"$index") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2351
      assert( _operand_idx != -1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2352
              "Must use this subfield after operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2353
      assert( ! _may_reloc, "UnImplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2354
      fprintf(_fp,"->index(ra_,this,idx%d)", _operand_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2355
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2356
    else if ( strcmp(rep_var,"$scale") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2357
      assert( ! _may_reloc, "UnImplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2358
      fprintf(_fp,"->scale()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2359
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2360
    else if ( strcmp(rep_var,"$cmpcode") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2361
      assert( ! _may_reloc, "UnImplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2362
      fprintf(_fp,"->ccode()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2363
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2364
    else if ( strcmp(rep_var,"$constant") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2365
      if( _constant_status == LITERAL_NOT_SEEN ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2366
        if ( _constant_type == Form::idealD ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2367
          fprintf(_fp,"->constantD()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2368
        } else if ( _constant_type == Form::idealF ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2369
          fprintf(_fp,"->constantF()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2370
        } else if ( _constant_type == Form::idealL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2371
          fprintf(_fp,"->constantL()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2372
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2373
          fprintf(_fp,"->constant()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2374
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2375
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2376
        assert( _constant_status == LITERAL_OUTPUT, "should have output constant literal in emit_rep_var");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2377
        // Constant literal has already been sent to output file, nothing more needed
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2378
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2379
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2380
    else if ( strcmp(rep_var,"$disp") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2381
      Form::DataType stack_type = _operand ? _operand->is_user_name_for_sReg() : Form::none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2382
      if( _operand  && _operand_idx==0 && stack_type != Form::none ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2383
        fprintf(_fp,"->disp(ra_,this,0)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2384
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2385
        fprintf(_fp,"->disp(ra_,this,idx%d)", _operand_idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2386
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2387
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2388
    else if ( strcmp(rep_var,"$label") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2389
      fprintf(_fp,"->label()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2390
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2391
    else if ( strcmp(rep_var,"$method") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2392
      fprintf(_fp,"->method()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2393
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2394
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2395
      printf("emit_field: %s\n",rep_var);
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2396
      globalAD->syntax_err(_inst._linenum, "Unknown replacement variable %s in format statement of %s.",
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2397
                           rep_var, _inst._ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2398
      assert( false, "UnImplemented()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2399
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2402
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2403
  void emit_rep_var(const char *rep_var) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2404
    _processing_noninput = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2405
    // A replacement variable, originally '$'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2406
    if ( Opcode::as_opcode_type(rep_var) != Opcode::NOT_AN_OPCODE ) {
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2407
      if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(rep_var) )) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2408
        // Missing opcode
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2409
        _AD.syntax_err( _inst._linenum,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2410
                        "Missing $%s opcode definition in %s, used by encoding %s\n",
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2411
                        rep_var, _inst._ident, _encoding._name);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2412
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2413
    }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2414
    else if (strcmp(rep_var, "constanttablebase") == 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2415
      fprintf(_fp, "as_Register(ra_->get_encode(in(mach_constant_base_node_input())))");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2416
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2417
    else if (strcmp(rep_var, "constantoffset") == 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2418
      fprintf(_fp, "constant_offset()");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2419
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2420
    else if (strcmp(rep_var, "constantaddress") == 0) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2421
      fprintf(_fp, "InternalAddress(__ code()->consts()->start() + constant_offset())");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2422
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2423
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2424
      // Lookup its position in parameter list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2425
      int   param_no  = _encoding.rep_var_index(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2426
      if ( param_no == -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2427
        _AD.syntax_err( _encoding._linenum,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2428
                        "Replacement variable %s not found in enc_class %s.\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2429
                        rep_var, _encoding._name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2430
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2431
      // Lookup the corresponding ins_encode parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2432
      const char *inst_rep_var = _ins_encode.rep_var_name(_inst, param_no);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2433
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2434
      // Check if instruction's actual parameter is a local name in the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2435
      const Form  *local     = _inst._localNames[inst_rep_var];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2436
      OpClassForm *opc       = (local != NULL) ? local->is_opclass() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2437
      // Note: assert removed to allow constant and symbolic parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2438
      // assert( opc, "replacement variable was not found in local names");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2439
      // Lookup the index position iff the replacement variable is a localName
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2440
      int idx  = (opc != NULL) ? _inst.operand_position_format(inst_rep_var) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2441
      if( idx != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2442
        if (_inst.is_noninput_operand(idx)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2443
          // This operand isn't a normal input so printing it is done
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2444
          // specially.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2445
          _processing_noninput = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2446
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2447
          // Output the emit code for this operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2448
          fprintf(_fp,"opnd_array(%d)",idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2449
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2450
        assert( _operand == opc->is_operand(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2451
                "Previous emit $operand does not match current");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2452
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2453
      else if( ADLParser::is_literal_constant(inst_rep_var) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2454
        // else check if it is a constant expression
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2455
        // Removed following assert to allow primitive C types as arguments to encodings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2456
        // assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2457
        fprintf(_fp,"(%s)", inst_rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2458
        _constant_status = LITERAL_OUTPUT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2459
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2460
      else if( Opcode::as_opcode_type(inst_rep_var) != Opcode::NOT_AN_OPCODE ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2461
        // else check if "primary", "secondary", "tertiary"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2462
        assert( _constant_status == LITERAL_ACCESSED, "Must be processing a literal constant parameter");
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2463
        if (!_inst._opcode->print_opcode(_fp, Opcode::as_opcode_type(inst_rep_var) )) {
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2464
          // Missing opcode
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2465
          _AD.syntax_err( _inst._linenum,
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2466
                          "Missing $%s opcode definition in %s\n",
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2467
                          rep_var, _inst._ident);
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2468
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
  2469
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2470
        _constant_status = LITERAL_OUTPUT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2471
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2472
      else if((_AD.get_registers() != NULL ) && (_AD.get_registers()->getRegDef(inst_rep_var) != NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2473
        // Instruction provided a literal register name for this parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2474
        // Check that encoding specifies $$$reg to resolve.as register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2475
        assert( _reg_status == LITERAL_ACCESSED, "Must be processing a literal register parameter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2476
        fprintf(_fp,"(%s_enc)", inst_rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2477
        _reg_status = LITERAL_OUTPUT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2478
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2479
      else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2480
        // Check for unimplemented functionality before hard failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2481
        assert( strcmp(opc->_ident,"label")==0, "Unimplemented() Label");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2482
        assert( false, "ShouldNotReachHere()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2483
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2484
      // all done
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2485
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2486
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2487
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2488
};  // end class DefineEmitState
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2489
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2490
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2491
void ArchDesc::defineSize(FILE *fp, InstructForm &inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2493
  //(1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2494
  // Output instruction's emit prototype
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2495
  fprintf(fp,"uint %sNode::size(PhaseRegAlloc *ra_) const {\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2496
          inst._ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2497
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2498
  fprintf(fp, "  assert(VerifyOops || MachNode::size(ra_) <= %s, \"bad fixed size\");\n", inst._size);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  2499
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2500
  //(2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2501
  // Print the size
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2502
  fprintf(fp, "  return (VerifyOops ? MachNode::size(ra_) : %s);\n", inst._size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2503
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2504
  // (3) and (4)
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2505
  fprintf(fp,"}\n\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2506
}
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2507
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2508
// Emit postalloc expand function.
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2509
void ArchDesc::define_postalloc_expand(FILE *fp, InstructForm &inst) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2510
  InsEncode *ins_encode = inst._insencode;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2511
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2512
  // Output instruction's postalloc_expand prototype.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2513
  fprintf(fp, "void  %sNode::postalloc_expand(GrowableArray <Node *> *nodes, PhaseRegAlloc *ra_) {\n",
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2514
          inst._ident);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2515
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2516
  assert((_encode != NULL) && (ins_encode != NULL), "You must define an encode section.");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2517
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2518
  // Output each operand's offset into the array of registers.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2519
  inst.index_temps(fp, _globalNames);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2520
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2521
  // Output variables "unsigned idx_<par_name>", Node *n_<par_name> and "MachOpnd *op_<par_name>"
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2522
  // for each parameter <par_name> specified in the encoding.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2523
  ins_encode->reset();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2524
  const char *ec_name = ins_encode->encode_class_iter();
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2525
  assert(ec_name != NULL, "Postalloc expand must specify an encoding.");
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2526
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2527
  EncClass *encoding = _encode->encClass(ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2528
  if (encoding == NULL) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2529
    fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2530
    abort();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2531
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2532
  if (ins_encode->current_encoding_num_args() != encoding->num_args()) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2533
    globalAD->syntax_err(ins_encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2534
                         inst._ident, ins_encode->current_encoding_num_args(),
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2535
                         ec_name, encoding->num_args());
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2536
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2537
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2538
  fprintf(fp, "  // Access to ins and operands for postalloc expand.\n");
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2539
  const int buflen = 2000;
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2540
  char idxbuf[buflen]; char *ib = idxbuf; idxbuf[0] = '\0';
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2541
  char nbuf  [buflen]; char *nb = nbuf;   nbuf[0]   = '\0';
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2542
  char opbuf [buflen]; char *ob = opbuf;  opbuf[0]  = '\0';
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2543
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2544
  encoding->_parameter_type.reset();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2545
  encoding->_parameter_name.reset();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2546
  const char *type = encoding->_parameter_type.iter();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2547
  const char *name = encoding->_parameter_name.iter();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2548
  int param_no = 0;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2549
  for (; (type != NULL) && (name != NULL);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2550
       (type = encoding->_parameter_type.iter()), (name = encoding->_parameter_name.iter())) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2551
    const char* arg_name = ins_encode->rep_var_name(inst, param_no);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2552
    int idx = inst.operand_position_format(arg_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2553
    if (strcmp(arg_name, "constanttablebase") == 0) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2554
      ib += sprintf(ib, "  unsigned idx_%-5s = mach_constant_base_node_input(); \t// %s, \t%s\n",
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2555
                    name, type, arg_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2556
      nb += sprintf(nb, "  Node    *n_%-7s = lookup(idx_%s);\n", name, name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2557
      // There is no operand for the constanttablebase.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2558
    } else if (inst.is_noninput_operand(idx)) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2559
      globalAD->syntax_err(inst._linenum,
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2560
                           "In %s: you can not pass the non-input %s to a postalloc expand encoding.\n",
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2561
                           inst._ident, arg_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2562
    } else {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2563
      ib += sprintf(ib, "  unsigned idx_%-5s = idx%d; \t// %s, \t%s\n",
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2564
                    name, idx, type, arg_name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2565
      nb += sprintf(nb, "  Node    *n_%-7s = lookup(idx_%s);\n", name, name);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2566
      ob += sprintf(ob, "  %sOper *op_%s = (%sOper *)opnd_array(%d);\n", type, name, type, idx);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2567
    }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2568
    param_no++;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2569
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2570
  assert(ib < &idxbuf[buflen-1] && nb < &nbuf[buflen-1] && ob < &opbuf[buflen-1], "buffer overflow");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2571
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2572
  fprintf(fp, "%s", idxbuf);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2573
  fprintf(fp, "  Node    *n_region  = lookup(0);\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2574
  fprintf(fp, "%s%s", nbuf, opbuf);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2575
  fprintf(fp, "  Compile *C = ra_->C;\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2576
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2577
  // Output this instruction's encodings.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2578
  fprintf(fp, "  {");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2579
  const char *ec_code    = NULL;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2580
  const char *ec_rep_var = NULL;
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2581
  assert(encoding == _encode->encClass(ec_name), "");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2582
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2583
  DefineEmitState pending(fp, *this, *encoding, *ins_encode, inst);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2584
  encoding->_code.reset();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2585
  encoding->_rep_vars.reset();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2586
  // Process list of user-defined strings,
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2587
  // and occurrences of replacement variables.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2588
  // Replacement Vars are pushed into a list and then output.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2589
  while ((ec_code = encoding->_code.iter()) != NULL) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2590
    if (! encoding->_code.is_signal(ec_code)) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2591
      // Emit pending code.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2592
      pending.emit();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2593
      pending.clear();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2594
      // Emit this code section.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2595
      fprintf(fp, "%s", ec_code);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2596
    } else {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2597
      // A replacement variable or one of its subfields.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2598
      // Obtain replacement variable from list.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2599
      ec_rep_var = encoding->_rep_vars.iter();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2600
      pending.add_rep_var(ec_rep_var);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2601
    }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2602
  }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2603
  // Emit pending code.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2604
  pending.emit();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2605
  pending.clear();
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2606
  fprintf(fp, "  }\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2607
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2608
  fprintf(fp, "}\n\n");
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2609
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2610
  ec_name = ins_encode->encode_class_iter();
22875
a88f7103ce0e 8033168: PPC64: gcc 4.8 warning in output_c.cpp
goetz
parents: 22872
diff changeset
  2611
  assert(ec_name == NULL, "Postalloc expand may only have one encoding.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2612
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2613
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2614
// defineEmit -----------------------------------------------------------------
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2615
void ArchDesc::defineEmit(FILE* fp, InstructForm& inst) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2616
  InsEncode* encode = inst._insencode;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2617
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2618
  // (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2619
  // Output instruction's emit prototype
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2620
  fprintf(fp, "void %sNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const {\n", inst._ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2621
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2622
  // If user did not define an encode section,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2623
  // provide stub that does not generate any machine code.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2624
  if( (_encode == NULL) || (encode == NULL) ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2625
    fprintf(fp, "  // User did not define an encode section.\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2626
    fprintf(fp, "}\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2627
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2628
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2629
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2630
  // Save current instruction's starting address (helps with relocation).
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2631
  fprintf(fp, "  cbuf.set_insts_mark();\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2632
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2633
  // For MachConstantNodes which are ideal jump nodes, fill the jump table.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2634
  if (inst.is_mach_constant() && inst.is_ideal_jump()) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2635
    fprintf(fp, "  ra_->C->constant_table().fill_jump_table(cbuf, (MachConstantNode*) this, _index2label);\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2636
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2637
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2638
  // Output each operand's offset into the array of registers.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2639
  inst.index_temps(fp, _globalNames);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2640
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2641
  // Output this instruction's encodings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2642
  const char *ec_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2643
  bool        user_defined = false;
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2644
  encode->reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2645
  while ((ec_name = encode->encode_class_iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2646
    fprintf(fp, "  {\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2647
    // Output user-defined encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2648
    user_defined           = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2650
    const char *ec_code    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2651
    const char *ec_rep_var = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2652
    EncClass   *encoding   = _encode->encClass(ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2653
    if (encoding == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2654
      fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2655
      abort();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2656
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2657
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2658
    if (encode->current_encoding_num_args() != encoding->num_args()) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2659
      globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2660
                           inst._ident, encode->current_encoding_num_args(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2661
                           ec_name, encoding->num_args());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2662
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2663
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2664
    DefineEmitState pending(fp, *this, *encoding, *encode, inst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2665
    encoding->_code.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2666
    encoding->_rep_vars.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2667
    // Process list of user-defined strings,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2668
    // and occurrences of replacement variables.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2669
    // Replacement Vars are pushed into a list and then output
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2670
    while ((ec_code = encoding->_code.iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2671
      if (!encoding->_code.is_signal(ec_code)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2672
        // Emit pending code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2673
        pending.emit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2674
        pending.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2675
        // Emit this code section
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2676
        fprintf(fp, "%s", ec_code);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2677
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2678
        // A replacement variable or one of its subfields
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2679
        // Obtain replacement variable from list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2680
        ec_rep_var  = encoding->_rep_vars.iter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2681
        pending.add_rep_var(ec_rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2682
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2683
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2684
    // Emit pending code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2685
    pending.emit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2686
    pending.clear();
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2687
    fprintf(fp, "  }\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2688
  } // end while instruction's encodings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2689
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2690
  // Check if user stated which encoding to user
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2691
  if ( user_defined == false ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2692
    fprintf(fp, "  // User did not define which encode class to use.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2693
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2694
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2695
  // (3) and (4)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2696
  fprintf(fp, "}\n\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2697
}
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2698
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2699
// defineEvalConstant ---------------------------------------------------------
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2700
void ArchDesc::defineEvalConstant(FILE* fp, InstructForm& inst) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2701
  InsEncode* encode = inst._constant;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2702
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2703
  // (1)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2704
  // Output instruction's emit prototype
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2705
  fprintf(fp, "void %sNode::eval_constant(Compile* C) {\n", inst._ident);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2706
11190
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10266
diff changeset
  2707
  // For ideal jump nodes, add a jump-table entry.
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2708
  if (inst.is_ideal_jump()) {
11190
d561d41f241a 7003454: order constants in constant table by number of references in code
twisti
parents: 10266
diff changeset
  2709
    fprintf(fp, "  _constant = C->constant_table().add_jump_table(this);\n");
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2710
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2711
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2712
  // If user did not define an encode section,
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2713
  // provide stub that does not generate any machine code.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2714
  if ((_encode == NULL) || (encode == NULL)) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2715
    fprintf(fp, "  // User did not define an encode section.\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2716
    fprintf(fp, "}\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2717
    return;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2718
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2719
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2720
  // Output this instruction's encodings
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2721
  const char *ec_name;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2722
  bool        user_defined = false;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2723
  encode->reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2724
  while ((ec_name = encode->encode_class_iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2725
    fprintf(fp, "  {\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2726
    // Output user-defined encoding
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2727
    user_defined           = true;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2728
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2729
    const char *ec_code    = NULL;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2730
    const char *ec_rep_var = NULL;
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2731
    EncClass   *encoding   = _encode->encClass(ec_name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2732
    if (encoding == NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2733
      fprintf(stderr, "User did not define contents of this encode_class: %s\n", ec_name);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2734
      abort();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2735
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2736
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2737
    if (encode->current_encoding_num_args() != encoding->num_args()) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2738
      globalAD->syntax_err(encode->_linenum, "In %s: passing %d arguments to %s but expecting %d",
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2739
                           inst._ident, encode->current_encoding_num_args(),
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2740
                           ec_name, encoding->num_args());
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2741
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2742
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2743
    DefineEmitState pending(fp, *this, *encoding, *encode, inst);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2744
    encoding->_code.reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2745
    encoding->_rep_vars.reset();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2746
    // Process list of user-defined strings,
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2747
    // and occurrences of replacement variables.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2748
    // Replacement Vars are pushed into a list and then output
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2749
    while ((ec_code = encoding->_code.iter()) != NULL) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2750
      if (!encoding->_code.is_signal(ec_code)) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2751
        // Emit pending code
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2752
        pending.emit();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2753
        pending.clear();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2754
        // Emit this code section
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2755
        fprintf(fp, "%s", ec_code);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2756
      } else {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2757
        // A replacement variable or one of its subfields
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2758
        // Obtain replacement variable from list
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2759
        ec_rep_var  = encoding->_rep_vars.iter();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2760
        pending.add_rep_var(ec_rep_var);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2761
      }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2762
    }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2763
    // Emit pending code
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2764
    pending.emit();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2765
    pending.clear();
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2766
    fprintf(fp, "  }\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2767
  } // end while instruction's encodings
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2768
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2769
  // Check if user stated which encoding to user
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2770
  if (user_defined == false) {
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2771
    fprintf(fp, "  // User did not define which encode class to use.\n");
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2772
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2773
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2774
  // (3) and (4)
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  2775
  fprintf(fp, "}\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2776
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2777
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2778
// ---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2779
//--------Utilities to build MachOper and MachNode derived Classes------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2780
// ---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2781
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2782
//------------------------------Utilities to build Operand Classes------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2783
static void defineIn_RegMask(FILE *fp, FormDict &globals, OperandForm &oper) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2784
  uint num_edges = oper.num_edges(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2785
  if( num_edges != 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2786
    // Method header
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2787
    fprintf(fp, "const RegMask *%sOper::in_RegMask(int index) const {\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2788
            oper._ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2790
    // Assert that the index is in range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2791
    fprintf(fp, "  assert(0 <= index && index < %d, \"index out of range\");\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2792
            num_edges);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2793
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2794
    // Figure out if all RegMasks are the same.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2795
    const char* first_reg_class = oper.in_reg_class(0, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2796
    bool all_same = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2797
    assert(first_reg_class != NULL, "did not find register mask");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2798
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2799
    for (uint index = 1; all_same && index < num_edges; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2800
      const char* some_reg_class = oper.in_reg_class(index, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2801
      assert(some_reg_class != NULL, "did not find register mask");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2802
      if (strcmp(first_reg_class, some_reg_class) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2803
        all_same = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2804
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2805
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2806
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2807
    if (all_same) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2808
      // Return the sole RegMask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2809
      if (strcmp(first_reg_class, "stack_slots") == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2810
        fprintf(fp,"  return &(Compile::current()->FIRST_STACK_mask());\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2811
      } else {
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2812
        const char* first_reg_class_to_upper = toUpper(first_reg_class);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2813
        fprintf(fp,"  return &%s_mask();\n", first_reg_class_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2814
        delete[] first_reg_class_to_upper;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2815
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2816
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2817
      // Build a switch statement to return the desired mask.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2818
      fprintf(fp,"  switch (index) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2819
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2820
      for (uint index = 0; index < num_edges; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2821
        const char *reg_class = oper.in_reg_class(index, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2822
        assert(reg_class != NULL, "did not find register mask");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2823
        if( !strcmp(reg_class, "stack_slots") ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2824
          fprintf(fp, "  case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2825
        } else {
16687
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2826
          const char* reg_class_to_upper = toUpper(reg_class);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2827
          fprintf(fp, "  case %d: return &%s_mask();\n", index, reg_class_to_upper);
ffab289acdc1 8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
neliasso
parents: 13971
diff changeset
  2828
          delete[] reg_class_to_upper;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2829
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2830
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2831
      fprintf(fp,"  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2832
      fprintf(fp,"  ShouldNotReachHere();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2833
      fprintf(fp,"  return NULL;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2834
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2835
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2836
    // Method close
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2837
    fprintf(fp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2838
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2839
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2840
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2841
// generate code to create a clone for a class derived from MachOper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2842
//
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  2843
// (0)  MachOper  *MachOperXOper::clone() const {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  2844
// (1)    return new MachXOper( _ccode, _c0, _c1, ..., _cn);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2845
// (2)  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2846
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2847
static void defineClone(FILE *fp, FormDict &globalNames, OperandForm &oper) {
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  2848
  fprintf(fp,"MachOper *%sOper::clone() const {\n", oper._ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2849
  // Check for constants that need to be copied over
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2850
  const int  num_consts    = oper.num_consts(globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2851
  const bool is_ideal_bool = oper.is_ideal_bool();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2852
  if( (num_consts > 0) ) {
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  2853
    fprintf(fp,"  return new %sOper(", oper._ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2854
    // generate parameters for constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2855
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2856
    fprintf(fp,"_c%d", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2857
    for( i = 1; i < num_consts; ++i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2858
      fprintf(fp,", _c%d", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2859
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2860
    // finish line (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2861
    fprintf(fp,");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2862
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2863
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2864
    assert( num_consts == 0, "Currently support zero or one constant per operand clone function");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  2865
    fprintf(fp,"  return new %sOper();\n", oper._ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2866
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2867
  // finish method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2868
  fprintf(fp,"}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2869
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2870
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2871
// Helper functions for bug 4796752, abstracted with minimal modification
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2872
// from define_oper_interface()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2873
OperandForm *rep_var_to_operand(const char *encoding, OperandForm &oper, FormDict &globals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2874
  OperandForm *op = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2875
  // Check for replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2876
  if( *encoding == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2877
    // Replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2878
    const char *rep_var = encoding + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2879
    // Lookup replacement variable, rep_var, in operand's component list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2880
    const Component *comp = oper._components.search(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2881
    assert( comp != NULL, "Replacement variable not found in components");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2882
    // Lookup operand form for replacement variable's type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2883
    const char      *type = comp->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2884
    Form            *form = (Form*)globals[type];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2885
    assert( form != NULL, "Replacement variable's type not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2886
    op = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2887
    assert( op, "Attempting to emit a non-register or non-constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2890
  return op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2891
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2892
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2893
int rep_var_to_constant_index(const char *encoding, OperandForm &oper, FormDict &globals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2894
  int idx = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2895
  // Check for replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2896
  if( *encoding == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2897
    // Replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2898
    const char *rep_var = encoding + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2899
    // Lookup replacement variable, rep_var, in operand's component list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2900
    const Component *comp = oper._components.search(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2901
    assert( comp != NULL, "Replacement variable not found in components");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2902
    // Lookup operand form for replacement variable's type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2903
    const char      *type = comp->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2904
    Form            *form = (Form*)globals[type];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2905
    assert( form != NULL, "Replacement variable's type not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2906
    OperandForm *op = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2907
    assert( op, "Attempting to emit a non-register or non-constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2908
    // Check that this is a constant and find constant's index:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2909
    if (op->_matrule && op->_matrule->is_base_constant(globals)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2910
      idx  = oper.constant_position(globals, comp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2911
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2912
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2913
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2914
  return idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2915
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2916
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2917
bool is_regI(const char *encoding, OperandForm &oper, FormDict &globals ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2918
  bool is_regI = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2919
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2920
  OperandForm *op = rep_var_to_operand(encoding, oper, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2921
  if( op != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2922
    // Check that this is a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2923
    if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2924
      // Register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2925
      const char* ideal  = op->ideal_type(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2926
      is_regI = (ideal && (op->ideal_to_Reg_type(ideal) == Form::idealI));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2927
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2928
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2929
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2930
  return is_regI;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2931
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2932
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2933
bool is_conP(const char *encoding, OperandForm &oper, FormDict &globals ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2934
  bool is_conP = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2935
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2936
  OperandForm *op = rep_var_to_operand(encoding, oper, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2937
  if( op != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2938
    // Check that this is a constant pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2939
    if (op->_matrule && op->_matrule->is_base_constant(globals)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2940
      // Constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2941
      Form::DataType dtype = op->is_base_constant(globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2942
      is_conP = (dtype == Form::idealP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2943
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2944
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2945
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2946
  return is_conP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2947
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2948
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2949
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2950
// Define a MachOper interface methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2951
void ArchDesc::define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2952
                                     const char *name, const char *encoding) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2953
  bool emit_position = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2954
  int position = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2955
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2956
  fprintf(fp,"  virtual int            %s", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2957
  // Generate access method for base, index, scale, disp, ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2958
  if( (strcmp(name,"base") == 0) || (strcmp(name,"index") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2959
    fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2960
    emit_position = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2961
  } else if ( (strcmp(name,"disp") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2962
    fprintf(fp,"(PhaseRegAlloc *ra_, const Node *node, int idx) const { \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2963
  } else {
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  2964
    fprintf(fp, "() const {\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2965
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2966
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2967
  // Check for hexadecimal value OR replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2968
  if( *encoding == '$' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2969
    // Replacement variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2970
    const char *rep_var = encoding + 1;
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2971
    fprintf(fp,"    // Replacement variable: %s\n", encoding+1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2972
    // Lookup replacement variable, rep_var, in operand's component list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2973
    const Component *comp = oper._components.search(rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2974
    assert( comp != NULL, "Replacement variable not found in components");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2975
    // Lookup operand form for replacement variable's type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2976
    const char      *type = comp->_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2977
    Form            *form = (Form*)globals[type];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2978
    assert( form != NULL, "Replacement variable's type not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2979
    OperandForm *op = form->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2980
    assert( op, "Attempting to emit a non-register or non-constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2981
    // Check that this is a register or a constant and generate code:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2982
    if ( (op->_matrule && op->_matrule->is_base_register(globals)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2983
      // Register
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2984
      int idx_offset = oper.register_position( globals, rep_var);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2985
      position = idx_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2986
      fprintf(fp,"    return (int)ra_->get_encode(node->in(idx");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2987
      if ( idx_offset > 0 ) fprintf(fp,                      "+%d",idx_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2988
      fprintf(fp,"));\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2989
    } else if ( op->ideal_to_sReg_type(op->_ident) != Form::none ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2990
      // StackSlot for an sReg comes either from input node or from self, when idx==0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2991
      fprintf(fp,"    if( idx != 0 ) {\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2992
      fprintf(fp,"      // Access stack offset (register number) for input operand\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2993
      fprintf(fp,"      return ra_->reg2offset(ra_->get_reg_first(node->in(idx)));/* sReg */\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2994
      fprintf(fp,"    }\n");
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  2995
      fprintf(fp,"    // Access stack offset (register number) from myself\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2996
      fprintf(fp,"    return ra_->reg2offset(ra_->get_reg_first(node));/* sReg */\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2997
    } else if (op->_matrule && op->_matrule->is_base_constant(globals)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2998
      // Constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  2999
      // Check which constant this name maps to: _c0, _c1, ..., _cn
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3000
      const int idx = oper.constant_position(globals, comp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3001
      assert( idx != -1, "Constant component not found in operand");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3002
      // Output code for this constant, type dependent.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3003
      fprintf(fp,"    return (int)" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3004
      oper.access_constant(fp, globals, (uint)idx /* , const_type */);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3005
      fprintf(fp,";\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3006
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3007
      assert( false, "Attempting to emit a non-register or non-constant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3008
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3009
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3010
  else if( *encoding == '0' && *(encoding+1) == 'x' ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3011
    // Hex value
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3012
    fprintf(fp,"    return %s;\n", encoding);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3013
  } else {
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3014
    globalAD->syntax_err(oper._linenum, "In operand %s: Do not support this encode constant: '%s' for %s.",
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3015
                         oper._ident, encoding, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3016
    assert( false, "Do not support octal or decimal encode constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3017
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3018
  fprintf(fp,"  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3020
  if( emit_position && (position != -1) && (oper.num_edges(globals) > 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3021
    fprintf(fp,"  virtual int            %s_position() const { return %d; }\n", name, position);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3022
    MemInterface *mem_interface = oper._interface->is_MemInterface();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3023
    const char *base = mem_interface->_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3024
    const char *disp = mem_interface->_disp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3025
    if( emit_position && (strcmp(name,"base") == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3026
        && base != NULL && is_regI(base, oper, globals)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3027
        && disp != NULL && is_conP(disp, oper, globals) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3028
      // Found a memory access using a constant pointer for a displacement
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3029
      // and a base register containing an integer offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3030
      // In this case the base and disp are reversed with respect to what
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3031
      // is expected by MachNode::get_base_and_disp() and MachNode::adr_type().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3032
      // Provide a non-NULL return for disp_as_type() that will allow adr_type()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3033
      // to correctly compute the access type for alias analysis.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3034
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3035
      // See BugId 4796752, operand indOffset32X in i486.ad
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3036
      int idx = rep_var_to_constant_index(disp, oper, globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3037
      fprintf(fp,"  virtual const TypePtr *disp_as_type() const { return _c%d; }\n", idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3038
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3039
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3040
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3042
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3043
// Construct the method to copy _idx, inputs and operands to new node.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3044
static void define_fill_new_machnode(bool used, FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3045
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3046
  fprintf(fp_cpp, "// Copy _idx, inputs and operands to new node\n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3047
  fprintf(fp_cpp, "void MachNode::fill_new_machnode(MachNode* node) const {\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3048
  if( !used ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3049
    fprintf(fp_cpp, "  // This architecture does not have cisc or short branch instructions\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3050
    fprintf(fp_cpp, "  ShouldNotCallThis();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3051
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3052
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3053
    // New node must use same node index for access through allocator's tables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3054
    fprintf(fp_cpp, "  // New node must use same node index\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3055
    fprintf(fp_cpp, "  node->set_idx( _idx );\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3056
    // Copy machine-independent inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3057
    fprintf(fp_cpp, "  // Copy machine-independent inputs\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3058
    fprintf(fp_cpp, "  for( uint j = 0; j < req(); j++ ) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3059
    fprintf(fp_cpp, "    node->add_req(in(j));\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3060
    fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3061
    // Copy machine operands to new MachNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3062
    fprintf(fp_cpp, "  // Copy my operands, except for cisc position\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3063
    fprintf(fp_cpp, "  int nopnds = num_opnds();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3064
    fprintf(fp_cpp, "  assert( node->num_opnds() == (uint)nopnds, \"Must have same number of operands\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3065
    fprintf(fp_cpp, "  MachOper **to = node->_opnds;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3066
    fprintf(fp_cpp, "  for( int i = 0; i < nopnds; i++ ) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3067
    fprintf(fp_cpp, "    if( i != cisc_operand() ) \n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3068
    fprintf(fp_cpp, "      to[i] = _opnds[i]->clone();\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3069
    fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3070
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3071
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3072
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3073
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3074
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3075
//------------------------------defineClasses----------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3076
// Define members of MachNode and MachOper classes based on
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3077
// operand and instruction lists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3078
void ArchDesc::defineClasses(FILE *fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3079
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3080
  // Define the contents of an array containing the machine register names
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3081
  defineRegNames(fp, _register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3082
  // Define an array containing the machine register encoding values
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3083
  defineRegEncodes(fp, _register);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3084
  // Generate an enumeration of user-defined register classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3085
  // and a list of register masks, one for each class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3086
  // Only define the RegMask value objects in the expand file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3087
  // Declare each as an extern const RegMask ...; in ad_<arch>.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3088
  declare_register_masks(_HPP_file._fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3089
  // build_register_masks(fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3090
  build_register_masks(_CPP_EXPAND_file._fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3091
  // Define the pipe_classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3092
  build_pipe_classes(_CPP_PIPELINE_file._fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3093
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3094
  // Generate Machine Classes for each operand defined in AD file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3095
  fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3096
  fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3097
  fprintf(fp,"//------------------Define classes derived from MachOper---------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3098
  // Iterate through all operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3099
  _operands.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3100
  OperandForm *oper;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3101
  for( ; (oper = (OperandForm*)_operands.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3102
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3103
    if ( oper->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3104
    // !!!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3105
    // The declaration of labelOper is in machine-independent file: machnode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3106
    if ( strcmp(oper->_ident,"label") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3107
      defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3108
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3109
      fprintf(fp,"MachOper  *%sOper::clone() const {\n", oper->_ident);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  3110
      fprintf(fp,"  return  new %sOper(_label, _block_num);\n", oper->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3111
      fprintf(fp,"}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3113
      fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3114
              oper->_ident, machOperEnum(oper->_ident));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3115
      // // Currently all XXXOper::Hash() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3116
      // define_hash(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3117
      // // Currently all XXXOper::Cmp() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3118
      // define_cmp(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3119
      fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3120
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3121
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3124
    // The declaration of methodOper is in machine-independent file: machnode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3125
    if ( strcmp(oper->_ident,"method") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3126
      defineIn_RegMask(_CPP_MISC_file._fp, _globalNames, *oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3127
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3128
      fprintf(fp,"MachOper  *%sOper::clone() const {\n", oper->_ident);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  3129
      fprintf(fp,"  return  new %sOper(_method);\n", oper->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3130
      fprintf(fp,"}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3132
      fprintf(fp,"uint %sOper::opcode() const { return %s; }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3133
              oper->_ident, machOperEnum(oper->_ident));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3134
      // // Currently all XXXOper::Hash() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3135
      // define_hash(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3136
      // // Currently all XXXOper::Cmp() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3137
      // define_cmp(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3138
      fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3139
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3140
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3143
    defineIn_RegMask(fp, _globalNames, *oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3144
    defineClone(_CPP_CLONE_file._fp, _globalNames, *oper);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3145
    // // Currently all XXXOper::Hash() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3146
    // define_hash(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3147
    // // Currently all XXXOper::Cmp() methods are identical (990820)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3148
    // define_cmp(fp, oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3149
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3150
    // side-call to generate output that used to be in the header file:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3151
    extern void gen_oper_format(FILE *fp, FormDict &globals, OperandForm &oper, bool for_c_file);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3152
    gen_oper_format(_CPP_FORMAT_file._fp, _globalNames, *oper, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3153
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3155
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3157
  // Generate Machine Classes for each instruction defined in AD file
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3158
  fprintf(fp,"//------------------Define members for classes derived from MachNode----------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3159
  // Output the definitions for out_RegMask() // & kill_RegMask()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3160
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3161
  InstructForm *instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3162
  MachNodeForm *machnode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3163
  for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3164
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3165
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3166
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3167
    defineOut_RegMask(_CPP_MISC_file._fp, instr->_ident, reg_mask(*instr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3169
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3170
  bool used = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3171
  // Output the definitions for expand rules & peephole rules
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3172
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3173
  for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3174
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3175
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3176
    // If there are multiple defs/kills, or an explicit expand rule, build rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3177
    if( instr->expands() || instr->needs_projections() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3178
        instr->has_temps() ||
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  3179
        instr->is_mach_constant() ||
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3180
        instr->needs_constant_base() ||
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3181
        instr->_matrule != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3182
        instr->num_opnds() != instr->num_unique_opnds() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3183
      defineExpand(_CPP_EXPAND_file._fp, instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3184
    // If there is an explicit peephole rule, build it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3185
    if ( instr->peepholes() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3186
      definePeephole(_CPP_PEEPHOLE_file._fp, instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3187
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3188
    // Output code to convert to the cisc version, if applicable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3189
    used |= instr->define_cisc_version(*this, fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3191
    // Output code to convert to the short branch version, if applicable
5536
f23c4e2e0d5e 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 5402
diff changeset
  3192
    used |= instr->define_short_branch_methods(*this, fp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3194
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3195
  // Construct the method called by cisc_version() to copy inputs and operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3196
  define_fill_new_machnode(used, fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3198
  // Output the definitions for labels
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3199
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3200
  while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3201
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3202
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3203
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3204
    // Access the fields for operand Label
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3205
    int label_position = instr->label_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3206
    if( label_position != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3207
      // Set the label
10252
0981ce1c3eef 7063628: Use cbcond on T4
kvn
parents: 8921
diff changeset
  3208
      fprintf(fp,"void %sNode::label_set( Label* label, uint block_num ) {\n", instr->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3209
      fprintf(fp,"  labelOper* oper  = (labelOper*)(opnd_array(%d));\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3210
              label_position );
10252
0981ce1c3eef 7063628: Use cbcond on T4
kvn
parents: 8921
diff changeset
  3211
      fprintf(fp,"  oper->_label     = label;\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3212
      fprintf(fp,"  oper->_block_num = block_num;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3213
      fprintf(fp,"}\n");
10266
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3214
      // Save the label
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3215
      fprintf(fp,"void %sNode::save_label( Label** label, uint* block_num ) {\n", instr->_ident);
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3216
      fprintf(fp,"  labelOper* oper  = (labelOper*)(opnd_array(%d));\n",
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3217
              label_position );
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3218
      fprintf(fp,"  *label = oper->_label;\n");
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3219
      fprintf(fp,"  *block_num = oper->_block_num;\n");
2ea344c79e33 7079317: Incorrect branch's destination block in PrintoOptoAssembly output
kvn
parents: 10252
diff changeset
  3220
      fprintf(fp,"}\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3223
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3224
  // Output the definitions for methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3225
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3226
  while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3227
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3228
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3229
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3230
    // Access the fields for operand Label
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3231
    int method_position = instr->method_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3232
    if( method_position != -1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3233
      // Access the method's address
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3234
      fprintf(fp,"void %sNode::method_set( intptr_t method ) {\n", instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3235
      fprintf(fp,"  ((methodOper*)opnd_array(%d))->_method = method;\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3236
              method_position );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3237
      fprintf(fp,"}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3238
      fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3240
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3241
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3242
  // Define this instruction's number of relocation entries, base is '0'
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3243
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3244
  while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3245
    // Output the definition for number of relocation entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3246
    uint reloc_size = instr->reloc(_globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3247
    if ( reloc_size != 0 ) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3248
      fprintf(fp,"int %sNode::reloc() const {\n", instr->_ident);
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3249
      fprintf(fp,"  return %d;\n", reloc_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3250
      fprintf(fp,"}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3251
      fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3252
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3254
  fprintf(fp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3255
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3256
  // Output the definitions for code generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3257
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3258
  // address  ___Node::emit(address ptr, PhaseRegAlloc *ra_) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3259
  //   // ...  encoding defined by user
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3260
  //   return ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3261
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3262
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3263
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3264
  for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3265
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3266
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3267
22844
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3268
    if (instr->_insencode) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3269
      if (instr->postalloc_expands()) {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3270
        // Don't write this to _CPP_EXPAND_file, as the code generated calls C-code
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3271
        // from code sections in ad file that is dumped to fp.
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3272
        define_postalloc_expand(fp, *instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3273
      } else {
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3274
        defineEmit(fp, *instr);
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3275
      }
90f76a40ed8a 8003854: PPC64 (part 115): Introduce PostallocExpand that expands nodes after register allocation
goetz
parents: 19717
diff changeset
  3276
    }
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  3277
    if (instr->is_mach_constant()) defineEvalConstant(fp, *instr);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 6418
diff changeset
  3278
    if (instr->_size)              defineSize        (fp, *instr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3279
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3280
    // side-call to generate output that used to be in the header file:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3281
    extern void gen_inst_format(FILE *fp, FormDict &globals, InstructForm &oper, bool for_c_file);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3282
    gen_inst_format(_CPP_FORMAT_file._fp, _globalNames, *instr, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3285
  // Output the definitions for alias analysis
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3286
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3287
  for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3288
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3289
    if ( instr->ideal_only() ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3290
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3291
    // Analyze machine instructions that either USE or DEF memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3292
    int memory_operand = instr->memory_operand(_globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3293
    // Some guys kill all of memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3294
    if ( instr->is_wide_memory_kill(_globalNames) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3295
      memory_operand = InstructForm::MANY_MEMORY_OPERANDS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3296
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3298
    if ( memory_operand != InstructForm::NO_MEMORY_OPERAND ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3299
      if( memory_operand == InstructForm::MANY_MEMORY_OPERANDS ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3300
        fprintf(fp,"const TypePtr *%sNode::adr_type() const { return TypePtr::BOTTOM; }\n", instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3301
        fprintf(fp,"const MachOper* %sNode::memory_operand() const { return (MachOper*)-1; }\n", instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3302
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3303
        fprintf(fp,"const MachOper* %sNode::memory_operand() const { return _opnds[%d]; }\n", instr->_ident, memory_operand);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3307
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3308
  // Get the length of the longest identifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3309
  int max_ident_len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3310
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3312
  for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3313
    if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3314
      int ident_len = (int)strlen(instr->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3315
      if( max_ident_len < ident_len )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3316
        max_ident_len = ident_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3317
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3319
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3320
  // Emit specifically for Node(s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3321
  fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3322
    max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3323
  fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return %s; }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3324
    max_ident_len, "Node", _pipeline ? "(&pipeline_class_Zero_Instructions)" : "NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3325
  fprintf(_CPP_PIPELINE_file._fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3326
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3327
  fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline_class() { return %s; }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3328
    max_ident_len, "MachNode", _pipeline ? "(&pipeline_class_Unknown_Instructions)" : "NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3329
  fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*s::pipeline() const { return pipeline_class(); }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3330
    max_ident_len, "MachNode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3331
  fprintf(_CPP_PIPELINE_file._fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3332
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3333
  // Output the definitions for machine node specific pipeline data
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3334
  _machnodes.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3335
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3336
  for ( ; (machnode = (MachNodeForm*)_machnodes.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3337
    fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3338
      machnode->_ident, ((class PipeClassForm *)_pipeline->_classdict[machnode->_machnode_pipe])->_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3340
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3341
  fprintf(_CPP_PIPELINE_file._fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3342
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3343
  // Output the definitions for instruction pipeline static data references
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3344
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3345
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3346
  for ( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3347
    if (instr->_ins_pipe && _pipeline->_classlist.search(instr->_ins_pipe)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3348
      fprintf(_CPP_PIPELINE_file._fp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3349
      fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline_class() { return (&pipeline_class_%03d); }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3350
        max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3351
      fprintf(_CPP_PIPELINE_file._fp, "const Pipeline * %*sNode::pipeline() const { return (&pipeline_class_%03d); }\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3352
        max_ident_len, instr->_ident, ((class PipeClassForm *)_pipeline->_classdict[instr->_ins_pipe])->_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3353
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3355
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3356
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3357
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3358
// -------------------------------- maps ------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3359
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3360
// Information needed to generate the ReduceOp mapping for the DFA
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3361
class OutputReduceOp : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3362
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3363
  OutputReduceOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3364
    : OutputMap(hpp, cpp, globals, AD, "reduceOp") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3365
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3366
  void declaration() { fprintf(_hpp, "extern const int   reduceOp[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3367
  void definition()  { fprintf(_cpp, "const        int   reduceOp[] = {\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3368
  void closing()     { fprintf(_cpp, "  0 // no trailing comma\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3369
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3371
  void map(OpClassForm &opc)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3372
    const char *reduce = opc._ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3373
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3374
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3375
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3376
  void map(OperandForm &oper) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3377
    // Most operands without match rules, e.g.  eFlagsReg, do not have a result operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3378
    const char *reduce = (oper._matrule ? oper.reduce_result() : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3379
    // operand stackSlot does not have a match rule, but produces a stackSlot
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3380
    if( oper.is_user_name_for_sReg() != Form::none ) reduce = oper.reduce_result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3381
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3382
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3383
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3384
  void map(InstructForm &inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3385
    const char *reduce = (inst._matrule ? inst.reduce_result() : NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3386
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3387
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3389
  void map(char         *reduce) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3390
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3391
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3392
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3393
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3394
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3395
// Information needed to generate the LeftOp mapping for the DFA
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3396
class OutputLeftOp : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3397
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3398
  OutputLeftOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3399
    : OutputMap(hpp, cpp, globals, AD, "leftOp") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3400
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3401
  void declaration() { fprintf(_hpp, "extern const int   leftOp[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3402
  void definition()  { fprintf(_cpp, "const        int   leftOp[] = {\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3403
  void closing()     { fprintf(_cpp, "  0 // no trailing comma\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3404
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3406
  void map(OpClassForm &opc)  { fprintf(_cpp, "  0"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3407
  void map(OperandForm &oper) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3408
    const char *reduce = oper.reduce_left(_globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3409
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3410
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3411
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3412
  void map(char        *name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3413
    const char *reduce = _AD.reduceLeft(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3414
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3415
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3417
  void map(InstructForm &inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3418
    const char *reduce = inst.reduce_left(_globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3419
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3420
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3421
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3422
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3423
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3424
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3425
// Information needed to generate the RightOp mapping for the DFA
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3426
class OutputRightOp : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3427
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3428
  OutputRightOp(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3429
    : OutputMap(hpp, cpp, globals, AD, "rightOp") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3431
  void declaration() { fprintf(_hpp, "extern const int   rightOp[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3432
  void definition()  { fprintf(_cpp, "const        int   rightOp[] = {\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3433
  void closing()     { fprintf(_cpp, "  0 // no trailing comma\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3434
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3435
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3436
  void map(OpClassForm &opc)  { fprintf(_cpp, "  0"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3437
  void map(OperandForm &oper) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3438
    const char *reduce = oper.reduce_right(_globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3439
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3440
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3441
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3442
  void map(char        *name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3443
    const char *reduce = _AD.reduceRight(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3444
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3445
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3447
  void map(InstructForm &inst) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3448
    const char *reduce = inst.reduce_right(_globals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3449
    if( reduce )  fprintf(_cpp, "  %s_rule", reduce);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3450
    else          fprintf(_cpp, "  0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3452
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3453
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3454
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3455
// Information needed to generate the Rule names for the DFA
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3456
class OutputRuleName : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3457
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3458
  OutputRuleName(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3459
    : OutputMap(hpp, cpp, globals, AD, "ruleName") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3460
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3461
  void declaration() { fprintf(_hpp, "extern const char *ruleName[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3462
  void definition()  { fprintf(_cpp, "const char        *ruleName[] = {\n"); }
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3463
  void closing()     { fprintf(_cpp, "  \"invalid rule name\" // no trailing comma\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3464
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3466
  void map(OpClassForm &opc)  { fprintf(_cpp, "  \"%s\"", _AD.machOperEnum(opc._ident) ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3467
  void map(OperandForm &oper) { fprintf(_cpp, "  \"%s\"", _AD.machOperEnum(oper._ident) ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3468
  void map(char        *name) { fprintf(_cpp, "  \"%s\"", name ? name : "0"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3469
  void map(InstructForm &inst){ fprintf(_cpp, "  \"%s\"", inst._ident ? inst._ident : "0"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3470
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3471
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3472
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3473
// Information needed to generate the swallowed mapping for the DFA
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3474
class OutputSwallowed : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3475
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3476
  OutputSwallowed(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3477
    : OutputMap(hpp, cpp, globals, AD, "swallowed") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3478
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3479
  void declaration() { fprintf(_hpp, "extern const bool  swallowed[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3480
  void definition()  { fprintf(_cpp, "const        bool  swallowed[] = {\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3481
  void closing()     { fprintf(_cpp, "  false // no trailing comma\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3482
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3483
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3484
  void map(OperandForm &oper) { // Generate the entry for this opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3485
    const char *swallowed = oper.swallowed(_globals) ? "true" : "false";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3486
    fprintf(_cpp, "  %s", swallowed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3488
  void map(OpClassForm &opc)  { fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3489
  void map(char        *name) { fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3490
  void map(InstructForm &inst){ fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3491
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3492
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3494
// Information needed to generate the decision array for instruction chain rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3495
class OutputInstChainRule : public OutputMap {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3496
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3497
  OutputInstChainRule(FILE *hpp, FILE *cpp, FormDict &globals, ArchDesc &AD)
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3498
    : OutputMap(hpp, cpp, globals, AD, "instruction_chain_rule") {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3499
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3500
  void declaration() { fprintf(_hpp, "extern const bool  instruction_chain_rule[];\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3501
  void definition()  { fprintf(_cpp, "const        bool  instruction_chain_rule[] = {\n"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3502
  void closing()     { fprintf(_cpp, "  false // no trailing comma\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3503
                       OutputMap::closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3505
  void map(OpClassForm &opc)   { fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3506
  void map(OperandForm &oper)  { fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3507
  void map(char        *name)  { fprintf(_cpp, "  false"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3508
  void map(InstructForm &inst) { // Check for simple chain rule
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3509
    const char *chain = inst.is_simple_chain_rule(_globals) ? "true" : "false";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3510
    fprintf(_cpp, "  %s", chain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3511
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3512
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3513
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3514
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3515
//---------------------------build_map------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3516
// Build  mapping from enumeration for densely packed operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3517
// TO result and child types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3518
void ArchDesc::build_map(OutputMap &map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3519
  FILE         *fp_hpp = map.decl_file();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3520
  FILE         *fp_cpp = map.def_file();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3521
  int           idx    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3522
  OperandForm  *op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3523
  OpClassForm  *opc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3524
  InstructForm *inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3525
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3526
  // Construct this mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3527
  map.declaration();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3528
  fprintf(fp_cpp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3529
  map.definition();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3531
  // Output the mapping for operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3532
  map.record_position(OutputMap::BEGIN_OPERANDS, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3533
  _operands.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3534
  for(; (op = (OperandForm*)_operands.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3535
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3536
    if ( op->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3537
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3538
    // Generate the entry for this opcode
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3539
    fprintf(fp_cpp, "  /* %4d */", idx); map.map(*op); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3540
    ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3541
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3542
  fprintf(fp_cpp, "  // last operand\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3543
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3544
  // Place all user-defined operand classes into the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3545
  map.record_position(OutputMap::BEGIN_OPCLASSES, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3546
  _opclass.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3547
  for(; (opc = (OpClassForm*)_opclass.iter()) != NULL; ) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3548
    fprintf(fp_cpp, "  /* %4d */", idx); map.map(*opc); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3549
    ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3550
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3551
  fprintf(fp_cpp, "  // last operand class\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3553
  // Place all internally defined operands into the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3554
  map.record_position(OutputMap::BEGIN_INTERNALS, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3555
  _internalOpNames.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3556
  char *name = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3557
  for(; (name = (char *)_internalOpNames.iter()) != NULL; ) {
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3558
    fprintf(fp_cpp, "  /* %4d */", idx); map.map(name); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3559
    ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3560
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3561
  fprintf(fp_cpp, "  // last internally defined operand\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3562
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3563
  // Place all user-defined instructions into the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3564
  if( map.do_instructions() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3565
    map.record_position(OutputMap::BEGIN_INSTRUCTIONS, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3566
    // Output all simple instruction chain rules first
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3567
    map.record_position(OutputMap::BEGIN_INST_CHAIN_RULES, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3568
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3569
      _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3570
      for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3571
        // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3572
        if ( inst->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3573
        if ( ! inst->is_simple_chain_rule(_globalNames) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3574
        if ( inst->rematerialize(_globalNames, get_registers()) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3575
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3576
        fprintf(fp_cpp, "  /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3577
        ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3578
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3579
      map.record_position(OutputMap::BEGIN_REMATERIALIZE, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3580
      _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3581
      for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3582
        // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3583
        if ( inst->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3584
        if ( ! inst->is_simple_chain_rule(_globalNames) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3585
        if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3586
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3587
        fprintf(fp_cpp, "  /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3588
        ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3589
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3590
      map.record_position(OutputMap::END_INST_CHAIN_RULES, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3591
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3592
    // Output all instructions that are NOT simple chain rules
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3593
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3594
      _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3595
      for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3596
        // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3597
        if ( inst->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3598
        if ( inst->is_simple_chain_rule(_globalNames) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3599
        if ( ! inst->rematerialize(_globalNames, get_registers()) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3600
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3601
        fprintf(fp_cpp, "  /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3602
        ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3603
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3604
      map.record_position(OutputMap::END_REMATERIALIZE, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3605
      _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3606
      for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3607
        // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3608
        if ( inst->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3609
        if ( inst->is_simple_chain_rule(_globalNames) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3610
        if ( inst->rematerialize(_globalNames, get_registers()) ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3611
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3612
        fprintf(fp_cpp, "  /* %4d */", idx); map.map(*inst); fprintf(fp_cpp, ",\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3613
        ++idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3614
      };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3615
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3616
    fprintf(fp_cpp, "  // last instruction\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3617
    map.record_position(OutputMap::END_INSTRUCTIONS, idx );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3619
  // Finish defining table
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3620
  map.closing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3621
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3622
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3623
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3624
// Helper function for buildReduceMaps
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3625
char reg_save_policy(const char *calling_convention) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3626
  char callconv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3627
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3628
  if      (!strcmp(calling_convention, "NS"))  callconv = 'N';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3629
  else if (!strcmp(calling_convention, "SOE")) callconv = 'E';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3630
  else if (!strcmp(calling_convention, "SOC")) callconv = 'C';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3631
  else if (!strcmp(calling_convention, "AS"))  callconv = 'A';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3632
  else                                         callconv = 'Z';
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3634
  return callconv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3635
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3636
22865
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  3637
void ArchDesc::generate_needs_clone_jvms(FILE *fp_cpp) {
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  3638
  fprintf(fp_cpp, "bool Compile::needs_clone_jvms() { return %s; }\n\n",
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  3639
          _needs_clone_jvms ? "true" : "false");
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  3640
}
3b8857d7b3cc 8030863: PPC64: (part 220): ConstantTableBase for calls between args and jvms
goetz
parents: 22860
diff changeset
  3641
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3642
//---------------------------generate_assertion_checks-------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3643
void ArchDesc::generate_adlc_verification(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3644
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3645
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3646
  fprintf(fp_cpp, "#ifndef PRODUCT\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3647
  fprintf(fp_cpp, "void Compile::adlc_verification() {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3648
  globalDefs().print_asserts(fp_cpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3649
  fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3650
  fprintf(fp_cpp, "#endif\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3651
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3652
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3653
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3654
//---------------------------addSourceBlocks-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3655
void ArchDesc::addSourceBlocks(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3656
  if (_source.count() > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3657
    _source.output(fp_cpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3658
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3659
  generate_adlc_verification(fp_cpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3660
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3661
//---------------------------addHeaderBlocks-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3662
void ArchDesc::addHeaderBlocks(FILE *fp_hpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3663
  if (_header.count() > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3664
    _header.output(fp_hpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3665
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3666
//-------------------------addPreHeaderBlocks----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3667
void ArchDesc::addPreHeaderBlocks(FILE *fp_hpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3668
  // Output #defines from definition block
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3669
  globalDefs().print_defines(fp_hpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3670
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3671
  if (_pre_header.count() > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3672
    _pre_header.output(fp_hpp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3673
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3674
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3675
//---------------------------buildReduceMaps-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3676
// Build  mapping from enumeration for densely packed operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3677
// TO result and child types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3678
void ArchDesc::buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3679
  RegDef       *rdef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3680
  RegDef       *next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3681
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3682
  // The emit bodies currently require functions defined in the source block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3683
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3684
  // Build external declarations for mappings
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3685
  fprintf(fp_hpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3686
  fprintf(fp_hpp, "extern const char  register_save_policy[];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3687
  fprintf(fp_hpp, "extern const char  c_reg_save_policy[];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3688
  fprintf(fp_hpp, "extern const int   register_save_type[];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3689
  fprintf(fp_hpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3690
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3691
  // Construct Save-Policy array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3692
  fprintf(fp_cpp, "// Map from machine-independent register number to register_save_policy\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3693
  fprintf(fp_cpp, "const        char register_save_policy[] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3694
  _register->reset_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3695
  for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3696
    next              = _register->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3697
    char policy       = reg_save_policy(rdef->_callconv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3698
    const char *comma = (next != NULL) ? "," : " // no trailing comma";
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3699
    fprintf(fp_cpp, "  '%c'%s // %s\n", policy, comma, rdef->_regname);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3700
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3701
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3702
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3703
  // Construct Native Save-Policy array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3704
  fprintf(fp_cpp, "// Map from machine-independent register number to c_reg_save_policy\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3705
  fprintf(fp_cpp, "const        char c_reg_save_policy[] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3706
  _register->reset_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3707
  for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3708
    next        = _register->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3709
    char policy = reg_save_policy(rdef->_c_conv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3710
    const char *comma = (next != NULL) ? "," : " // no trailing comma";
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3711
    fprintf(fp_cpp, "  '%c'%s // %s\n", policy, comma, rdef->_regname);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3712
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3713
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3714
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3715
  // Construct Register Save Type array
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3716
  fprintf(fp_cpp, "// Map from machine-independent register number to register_save_type\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3717
  fprintf(fp_cpp, "const        int register_save_type[] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3718
  _register->reset_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3719
  for( rdef = _register->iter_RegDefs(); rdef != NULL; rdef = next ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3720
    next = _register->iter_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3721
    const char *comma = (next != NULL) ? "," : " // no trailing comma";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3722
    fprintf(fp_cpp, "  %s%s\n", rdef->_idealtype, comma);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3724
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3725
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3726
  // Construct the table for reduceOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3727
  OutputReduceOp output_reduce_op(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3728
  build_map(output_reduce_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3729
  // Construct the table for leftOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3730
  OutputLeftOp output_left_op(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3731
  build_map(output_left_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3732
  // Construct the table for rightOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3733
  OutputRightOp output_right_op(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3734
  build_map(output_right_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3735
  // Construct the table of rule names
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3736
  OutputRuleName output_rule_name(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3737
  build_map(output_rule_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3738
  // Construct the boolean table for subsumed operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3739
  OutputSwallowed output_swallowed(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3740
  build_map(output_swallowed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3741
  // // // Preserve in case we decide to use this table instead of another
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3742
  //// Construct the boolean table for instruction chain rules
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3743
  //OutputInstChainRule output_inst_chain(fp_hpp, fp_cpp, _globalNames, *this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3744
  //build_map(output_inst_chain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3745
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3746
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3747
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3748
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3749
//---------------------------buildMachOperGenerator---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3750
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3751
// Recurse through match tree, building path through corresponding state tree,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3752
// Until we reach the constant we are looking for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3753
static void path_to_constant(FILE *fp, FormDict &globals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3754
                             MatchNode *mnode, uint idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3755
  if ( ! mnode) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3756
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3757
  unsigned    position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3758
  const char *result   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3759
  const char *name     = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3760
  const char *optype   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3761
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3762
  // Base Case: access constant in ideal node linked to current state node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3763
  // Each type of constant has its own access function
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3764
  if ( (mnode->_lChild == NULL) && (mnode->_rChild == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3765
       && mnode->base_operand(position, globals, result, name, optype) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3766
    if (         strcmp(optype,"ConI") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3767
      fprintf(fp, "_leaf->get_int()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3768
    } else if ( (strcmp(optype,"ConP") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3769
      fprintf(fp, "_leaf->bottom_type()->is_ptr()");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  3770
    } else if ( (strcmp(optype,"ConN") == 0) ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  3771
      fprintf(fp, "_leaf->bottom_type()->is_narrowoop()");
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
  3772
    } else if ( (strcmp(optype,"ConNKlass") == 0) ) {
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13895
diff changeset
  3773
      fprintf(fp, "_leaf->bottom_type()->is_narrowklass()");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3774
    } else if ( (strcmp(optype,"ConF") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3775
      fprintf(fp, "_leaf->getf()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3776
    } else if ( (strcmp(optype,"ConD") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3777
      fprintf(fp, "_leaf->getd()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3778
    } else if ( (strcmp(optype,"ConL") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3779
      fprintf(fp, "_leaf->get_long()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3780
    } else if ( (strcmp(optype,"Con")==0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3781
      // !!!!! - Update if adding a machine-independent constant type
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3782
      fprintf(fp, "_leaf->get_int()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3783
      assert( false, "Unsupported constant type, pointer or indefinite");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3784
    } else if ( (strcmp(optype,"Bool") == 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3785
      fprintf(fp, "_leaf->as_Bool()->_test._test");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3786
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3787
      assert( false, "Unsupported constant type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3788
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3789
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3790
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3791
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3792
  // If constant is in left child, build path and recurse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3793
  uint lConsts = (mnode->_lChild) ? (mnode->_lChild->num_consts(globals) ) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3794
  uint rConsts = (mnode->_rChild) ? (mnode->_rChild->num_consts(globals) ) : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3795
  if ( (mnode->_lChild) && (lConsts > idx) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3796
    fprintf(fp, "_kids[0]->");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3797
    path_to_constant(fp, globals, mnode->_lChild, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3798
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3799
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3800
  // If constant is in right child, build path and recurse
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3801
  if ( (mnode->_rChild) && (rConsts > (idx - lConsts) ) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3802
    idx = idx - lConsts;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3803
    fprintf(fp, "_kids[1]->");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3804
    path_to_constant(fp, globals, mnode->_rChild, idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3805
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3806
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3807
  assert( false, "ShouldNotReachHere()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3809
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3810
// Generate code that is executed when generating a specific Machine Operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3811
static void genMachOperCase(FILE *fp, FormDict &globalNames, ArchDesc &AD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3812
                            OperandForm &op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3813
  const char *opName         = op._ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3814
  const char *opEnumName     = AD.machOperEnum(opName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3815
  uint        num_consts     = op.num_consts(globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3817
  // Generate the case statement for this opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3818
  fprintf(fp, "  case %s:", opEnumName);
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  3819
  fprintf(fp, "\n    return new %sOper(", opName);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3820
  // Access parameters for constructor from the stat object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3821
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3822
  // Build access to condition code value
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3823
  if ( (num_consts > 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3824
    uint i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3825
    path_to_constant(fp, globalNames, op._matrule, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3826
    for ( i = 1; i < num_consts; ++i ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3827
      fprintf(fp, ", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3828
      path_to_constant(fp, globalNames, op._matrule, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3829
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3830
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3831
  fprintf(fp, " );\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3832
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3833
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3834
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3835
// Build switch to invoke "new" MachNode or MachOper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3836
void ArchDesc::buildMachOperGenerator(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3837
  int idx = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3838
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3839
  // Build switch to invoke 'new' for a specific MachOper
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3840
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3841
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3842
  fprintf(fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3843
          "//------------------------- MachOper Generator ---------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3844
  fprintf(fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3845
          "// A switch statement on the dense-packed user-defined type system\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3846
          "// that invokes 'new' on the corresponding class constructor.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3847
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3848
  fprintf(fp_cpp, "MachOper *State::MachOperGenerator");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3849
  fprintf(fp_cpp, "(int opcode)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3850
  fprintf(fp_cpp, "{\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3851
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3852
  fprintf(fp_cpp, "  switch(opcode) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3853
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3854
  // Place all user-defined operands into the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3855
  _operands.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3856
  int  opIndex = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3857
  OperandForm *op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3858
  for( ; (op =  (OperandForm*)_operands.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3859
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3860
    if ( op->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3861
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3862
    genMachOperCase(fp_cpp, _globalNames, *this, *op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3863
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3864
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3865
  // Do not iterate over operand classes for the  operand generator!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3866
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3867
  // Place all internal operands into the mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3868
  _internalOpNames.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3869
  const char *iopn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3870
  for( ; (iopn =  _internalOpNames.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3871
    const char *opEnumName = machOperEnum(iopn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3872
    // Generate the case statement for this opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3873
    fprintf(fp_cpp, "  case %s:", opEnumName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3874
    fprintf(fp_cpp, "    return NULL;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3875
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3876
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3877
  // Generate the default case for switch(opcode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3878
  fprintf(fp_cpp, "  \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3879
  fprintf(fp_cpp, "  default:\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3880
  fprintf(fp_cpp, "    fprintf(stderr, \"Default MachOper Generator invoked for: \\n\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3881
  fprintf(fp_cpp, "    fprintf(stderr, \"   opcode = %cd\\n\", opcode);\n", '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3882
  fprintf(fp_cpp, "    break;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3883
  fprintf(fp_cpp, "  }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3884
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3885
  // Generate the closing for method Matcher::MachOperGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3886
  fprintf(fp_cpp, "  return NULL;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3887
  fprintf(fp_cpp, "};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3888
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3890
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3891
//---------------------------buildMachNode-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3892
// Build a new MachNode, for MachNodeGenerator or cisc-spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3893
void ArchDesc::buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3894
  const char *opType  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3895
  const char *opClass = inst->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3896
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3897
  // Create the MachNode object
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  3898
  fprintf(fp_cpp, "%s %sNode *node = new %sNode();\n",indent, opClass,opClass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3899
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3900
  if ( (inst->num_post_match_opnds() != 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3901
    // Instruction that contains operands which are not in match rule.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3902
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3903
    // Check if the first post-match component may be an interesting def
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3904
    bool           dont_care = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3905
    ComponentList &comp_list = inst->_components;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3906
    Component     *comp      = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3907
    comp_list.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3908
    if ( comp_list.match_iter() != NULL )    dont_care = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3909
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3910
    // Insert operands that are not in match-rule.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3911
    // Only insert a DEF if the do_care flag is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3912
    comp_list.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3913
    while ( comp = comp_list.post_match_iter() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3914
      // Check if we don't care about DEFs or KILLs that are not USEs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3915
      if ( dont_care && (! comp->isa(Component::USE)) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3916
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3917
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3918
      dont_care = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3919
      // For each operand not in the match rule, call MachOperGenerator
8324
a9933c6c5a95 7017746: Regression : C2 compiler crash due to SIGSEGV in PhaseCFG::schedule_early()
kvn
parents: 7433
diff changeset
  3920
      // with the enum for the opcode that needs to be built.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3921
      ComponentList clist = inst->_components;
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  3922
      int         index  = clist.operand_position(comp->_name, comp->_usedef, inst);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3923
      const char *opcode = machOperEnum(comp->_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3924
      fprintf(fp_cpp, "%s node->set_opnd_array(%d, ", indent, index);
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3925
      fprintf(fp_cpp, "MachOperGenerator(%s));\n", opcode);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3926
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3927
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3928
  else if ( inst->is_chain_of_constant(_globalNames, opType) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3929
    // An instruction that chains from a constant!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3930
    // In this case, we need to subsume the constant into the node
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3931
    // at operand position, oper_input_base().
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3932
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3933
    // Fill in the constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3934
    fprintf(fp_cpp, "%s node->_opnd_array[%d] = ", indent,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3935
            inst->oper_input_base(_globalNames));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3936
    // #####
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3937
    // Check for multiple constants and then fill them in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3938
    // Just like MachOperGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3939
    const char *opName = inst->_matrule->_rChild->_opType;
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  3940
    fprintf(fp_cpp, "new %sOper(", opName);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3941
    // Grab operand form
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3942
    OperandForm *op = (_globalNames[opName])->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3943
    // Look up the number of constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3944
    uint num_consts = op->num_consts(_globalNames);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3945
    if ( (num_consts > 0) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3946
      uint i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3947
      path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3948
      for ( i = 1; i < num_consts; ++i ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3949
        fprintf(fp_cpp, ", ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3950
        path_to_constant(fp_cpp, _globalNames, op->_matrule, i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3951
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3952
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3953
    fprintf(fp_cpp, " );\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3954
    // #####
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3955
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3956
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3957
  // Fill in the bottom_type where requested
22850
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3958
  if (inst->captures_bottom_type(_globalNames)) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3959
    if (strncmp("MachCall", inst->mach_base_class(_globalNames), strlen("MachCall"))) {
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3960
      fprintf(fp_cpp, "%s node->_bottom_type = _leaf->bottom_type();\n", indent);
4e69ce7e1101 8028580: PPC64 (part 114/120): Support for Call nodes with constants.
goetz
parents: 22847
diff changeset
  3961
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3962
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3963
  if( inst->is_ideal_if() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3964
    fprintf(fp_cpp, "%s node->_prob = _leaf->as_If()->_prob;\n", indent);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3965
    fprintf(fp_cpp, "%s node->_fcnt = _leaf->as_If()->_fcnt;\n", indent);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3966
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3967
  if( inst->is_ideal_fastlock() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3968
    fprintf(fp_cpp, "%s node->_counters = _leaf->as_FastLock()->counters();\n", indent);
23491
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents: 22875
diff changeset
  3969
    fprintf(fp_cpp, "%s node->_rtm_counters = _leaf->as_FastLock()->rtm_counters();\n", indent);
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents: 22875
diff changeset
  3970
    fprintf(fp_cpp, "%s node->_stack_rtm_counters = _leaf->as_FastLock()->stack_rtm_counters();\n", indent);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3971
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3972
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3973
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3974
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3975
//---------------------------declare_cisc_version------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3976
// Build CISC version of this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3977
void InstructForm::declare_cisc_version(ArchDesc &AD, FILE *fp_hpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3978
  if( AD.can_cisc_spill() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3979
    InstructForm *inst_cisc = cisc_spill_alternate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3980
    if (inst_cisc != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3981
      fprintf(fp_hpp, "  virtual int            cisc_operand() const { return %d; }\n", cisc_spill_operand());
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  3982
      fprintf(fp_hpp, "  virtual MachNode      *cisc_version(int offset);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3983
      fprintf(fp_hpp, "  virtual void           use_cisc_RegMask();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3984
      fprintf(fp_hpp, "  virtual const RegMask *cisc_RegMask() const { return _cisc_RegMask; }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3985
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3986
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3987
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3988
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3989
//---------------------------define_cisc_version-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3990
// Build CISC version of this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3991
bool InstructForm::define_cisc_version(ArchDesc &AD, FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3992
  InstructForm *inst_cisc = this->cisc_spill_alternate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3993
  if( AD.can_cisc_spill() && (inst_cisc != NULL) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3994
    const char   *name      = inst_cisc->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3995
    assert( inst_cisc->num_opnds() == this->num_opnds(), "Must have same number of operands");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3996
    OperandForm *cisc_oper = AD.cisc_spill_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3997
    assert( cisc_oper != NULL, "insanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3998
    const char *cisc_oper_name  = cisc_oper->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  3999
    assert( cisc_oper_name != NULL, "insanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4000
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4001
    // Set the correct reg_mask_or_stack for the cisc operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4002
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4003
    fprintf(fp_cpp, "void %sNode::use_cisc_RegMask() {\n", this->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4004
    // Lookup the correct reg_mask_or_stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4005
    const char *reg_mask_name = cisc_reg_mask_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4006
    fprintf(fp_cpp, "  _cisc_RegMask = &STACK_OR_%s;\n", reg_mask_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4007
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4008
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4009
    // Construct CISC version of this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4010
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4011
    fprintf(fp_cpp, "// Build CISC version of this instruction\n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4012
    fprintf(fp_cpp, "MachNode *%sNode::cisc_version(int offset) {\n", this->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4013
    // Create the MachNode object
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  4014
    fprintf(fp_cpp, "  %sNode *node = new %sNode();\n", name, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4015
    // Fill in the bottom_type where requested
5536
f23c4e2e0d5e 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 5402
diff changeset
  4016
    if ( this->captures_bottom_type(AD.globalNames()) ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4017
      fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4018
    }
2872
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4019
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4020
    uint cur_num_opnds = num_opnds();
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4021
    if (cur_num_opnds > 1 && cur_num_opnds != num_unique_opnds()) {
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4022
      fprintf(fp_cpp,"  node->_num_opnds = %d;\n", num_unique_opnds());
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4023
    }
93eb5ac6cfb0 6814842: Load shortening optimizations
twisti
parents: 2150
diff changeset
  4024
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4025
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4026
    fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4027
    fprintf(fp_cpp, "  fill_new_machnode(node);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4028
    // Construct operand to access [stack_pointer + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4029
    fprintf(fp_cpp, "  // Construct operand to access [stack_pointer + offset]\n");
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  4030
    fprintf(fp_cpp, "  node->set_opnd_array(cisc_operand(), new %sOper(offset));\n", cisc_oper_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4031
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4033
    // Return result and exit scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4034
    fprintf(fp_cpp, "  return node;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4035
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4036
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4037
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4038
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4039
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4040
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4042
//---------------------------declare_short_branch_methods----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4043
// Build prototypes for short branch methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4044
void InstructForm::declare_short_branch_methods(FILE *fp_hpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4045
  if (has_short_branch_form()) {
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4046
    fprintf(fp_hpp, "  virtual MachNode      *short_branch_version();\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4047
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4048
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4049
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4050
//---------------------------define_short_branch_methods-----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4051
// Build definitions for short branch methods
5536
f23c4e2e0d5e 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 5402
diff changeset
  4052
bool InstructForm::define_short_branch_methods(ArchDesc &AD, FILE *fp_cpp) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4053
  if (has_short_branch_form()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4054
    InstructForm *short_branch = short_branch_form();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4055
    const char   *name         = short_branch->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4056
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4057
    // Construct short_branch_version() method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4058
    fprintf(fp_cpp, "// Build short branch version of this instruction\n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4059
    fprintf(fp_cpp, "MachNode *%sNode::short_branch_version() {\n", this->_ident);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4060
    // Create the MachNode object
24923
9631f7d691dc 8034812: remove IDX_INIT macro hack in Node class
thartmann
parents: 23491
diff changeset
  4061
    fprintf(fp_cpp, "  %sNode *node = new %sNode();\n", name, name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4062
    if( is_ideal_if() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4063
      fprintf(fp_cpp, "  node->_prob = _prob;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4064
      fprintf(fp_cpp, "  node->_fcnt = _fcnt;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4065
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4066
    // Fill in the bottom_type where requested
5536
f23c4e2e0d5e 6953576: bottom_type for matched AddPNodes doesn't always agree with ideal
never
parents: 5402
diff changeset
  4067
    if ( this->captures_bottom_type(AD.globalNames()) ) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4068
      fprintf(fp_cpp, "  node->_bottom_type = bottom_type();\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4069
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4071
    fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4072
    // Short branch version must use same node index for access
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4073
    // through allocator's tables
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4074
    fprintf(fp_cpp, "  // Copy _idx, inputs and operands to new node\n");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4075
    fprintf(fp_cpp, "  fill_new_machnode(node);\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4077
    // Return result and exit scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4078
    fprintf(fp_cpp, "  return node;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4079
    fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4080
    fprintf(fp_cpp,"\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4081
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4082
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4083
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4084
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4086
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4087
//---------------------------buildMachNodeGenerator----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4088
// Build switch to invoke appropriate "new" MachNode for an opcode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4089
void ArchDesc::buildMachNodeGenerator(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4090
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4091
  // Build switch to invoke 'new' for a specific MachNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4092
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4093
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4094
  fprintf(fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4095
          "//------------------------- MachNode Generator ---------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4096
  fprintf(fp_cpp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4097
          "// A switch statement on the dense-packed user-defined type system\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4098
          "// that invokes 'new' on the corresponding class constructor.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4099
  fprintf(fp_cpp, "\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4100
  fprintf(fp_cpp, "MachNode *State::MachNodeGenerator");
25930
eae8b7490d2c 8054033: Remove unused references to Compile*
thartmann
parents: 24923
diff changeset
  4101
  fprintf(fp_cpp, "(int opcode)");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4102
  fprintf(fp_cpp, "{\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4103
  fprintf(fp_cpp, "  switch(opcode) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4104
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4105
  // Provide constructor for all user-defined instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4106
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4107
  int  opIndex = operandFormCount();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4108
  InstructForm *inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4109
  for( ; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4110
    // Ensure that matrule is defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4111
    if ( inst->_matrule == NULL ) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4112
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4113
    int         opcode  = opIndex++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4114
    const char *opClass = inst->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4115
    char       *opType  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4117
    // Generate the case statement for this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4118
    fprintf(fp_cpp, "  case %s_rule:", opClass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4120
    // Start local scope
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  4121
    fprintf(fp_cpp, " {\n");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4122
    // Generate code to construct the new MachNode
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4123
    buildMachNode(fp_cpp, inst, "     ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4124
    // Return result and exit scope
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4125
    fprintf(fp_cpp, "      return node;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4126
    fprintf(fp_cpp, "    }\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4128
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4129
  // Generate the default case for switch(opcode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4130
  fprintf(fp_cpp, "  \n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4131
  fprintf(fp_cpp, "  default:\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4132
  fprintf(fp_cpp, "    fprintf(stderr, \"Default MachNode Generator invoked for: \\n\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4133
  fprintf(fp_cpp, "    fprintf(stderr, \"   opcode = %cd\\n\", opcode);\n", '%');
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4134
  fprintf(fp_cpp, "    break;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4135
  fprintf(fp_cpp, "  };\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4137
  // Generate the closing for method Matcher::MachNodeGenerator
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4138
  fprintf(fp_cpp, "  return NULL;\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4139
  fprintf(fp_cpp, "}\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4141
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4142
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4143
//---------------------------buildInstructMatchCheck--------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4144
// Output the method to Matcher which checks whether or not a specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4145
// instruction has a matching rule for the host architecture.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4146
void ArchDesc::buildInstructMatchCheck(FILE *fp_cpp) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4147
  fprintf(fp_cpp, "\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4148
  fprintf(fp_cpp, "const bool Matcher::has_match_rule(int opcode) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4149
  fprintf(fp_cpp, "  assert(_last_machine_leaf < opcode && opcode < _last_opcode, \"opcode in range\");\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4150
  fprintf(fp_cpp, "  return _hasMatchRule[opcode];\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4151
  fprintf(fp_cpp, "}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4152
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4153
  fprintf(fp_cpp, "const bool Matcher::_hasMatchRule[_last_opcode] = {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4154
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4155
  for (i = 0; i < _last_opcode - 1; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4156
    fprintf(fp_cpp, "    %-5s,  // %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4157
            _has_match_rule[i] ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4158
            NodeClassNames[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4160
  fprintf(fp_cpp, "    %-5s   // %s\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4161
          _has_match_rule[i] ? "true" : "false",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4162
          NodeClassNames[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4163
  fprintf(fp_cpp, "};\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4165
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4166
//---------------------------buildFrameMethods---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4167
// Output the methods to Matcher which specify frame behavior
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4168
void ArchDesc::buildFrameMethods(FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4169
  fprintf(fp_cpp,"\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4170
  // Stack Direction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4171
  fprintf(fp_cpp,"bool Matcher::stack_direction() const { return %s; }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4172
          _frame->_direction ? "true" : "false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4173
  // Sync Stack Slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4174
  fprintf(fp_cpp,"int Compile::sync_stack_slots() const { return %s; }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4175
          _frame->_sync_stack_slots);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4176
  // Java Stack Alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4177
  fprintf(fp_cpp,"uint Matcher::stack_alignment_in_bytes() { return %s; }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4178
          _frame->_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4179
  // Java Return Address Location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4180
  fprintf(fp_cpp,"OptoReg::Name Matcher::return_addr() const {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4181
  if (_frame->_return_addr_loc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4182
    fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4183
            _frame->_return_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4185
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4186
    fprintf(fp_cpp," return OptoReg::stack2reg(%s); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4187
            _frame->_return_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4189
  // Java Stack Slot Preservation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4190
  fprintf(fp_cpp,"uint Compile::in_preserve_stack_slots() ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4191
  fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_in_preserve_slots);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4192
  // Top Of Stack Slot Preservation, for both Java and C
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4193
  fprintf(fp_cpp,"uint Compile::out_preserve_stack_slots() ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4194
  fprintf(fp_cpp,"{ return SharedRuntime::out_preserve_stack_slots(); }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4195
  // varargs C out slots killed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4196
  fprintf(fp_cpp,"uint Compile::varargs_C_out_slots_killed() const ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4197
  fprintf(fp_cpp,"{ return %s; }\n\n", _frame->_varargs_C_out_slots_killed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4198
  // Java Argument Position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4199
  fprintf(fp_cpp,"void Matcher::calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length, bool is_outgoing) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4200
  fprintf(fp_cpp,"%s\n", _frame->_calling_convention);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4201
  fprintf(fp_cpp,"}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4202
  // Native Argument Position
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4203
  fprintf(fp_cpp,"void Matcher::c_calling_convention(BasicType *sig_bt, VMRegPair *regs, uint length) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4204
  fprintf(fp_cpp,"%s\n", _frame->_c_calling_convention);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4205
  fprintf(fp_cpp,"}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4206
  // Java Return Value Location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4207
  fprintf(fp_cpp,"OptoRegPair Matcher::return_value(int ideal_reg, bool is_outgoing) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4208
  fprintf(fp_cpp,"%s\n", _frame->_return_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4209
  fprintf(fp_cpp,"}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4210
  // Native Return Value Location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4211
  fprintf(fp_cpp,"OptoRegPair Matcher::c_return_value(int ideal_reg, bool is_outgoing) {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4212
  fprintf(fp_cpp,"%s\n", _frame->_c_return_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4213
  fprintf(fp_cpp,"}\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4214
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4215
  // Inline Cache Register, mask definition, and encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4216
  fprintf(fp_cpp,"OptoReg::Name Matcher::inline_cache_reg() {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4217
  fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4218
          _frame->_inline_cache_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4219
  fprintf(fp_cpp,"int Matcher::inline_cache_reg_encode() {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4220
  fprintf(fp_cpp," return _regEncode[inline_cache_reg()]; }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4221
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4222
  // Interpreter's Method Oop Register, mask definition, and encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4223
  fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_method_oop_reg() {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4224
  fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4225
          _frame->_interpreter_method_oop_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4226
  fprintf(fp_cpp,"int Matcher::interpreter_method_oop_reg_encode() {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4227
  fprintf(fp_cpp," return _regEncode[interpreter_method_oop_reg()]; }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4229
  // Interpreter's Frame Pointer Register, mask definition, and encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4230
  fprintf(fp_cpp,"OptoReg::Name Matcher::interpreter_frame_pointer_reg() {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4231
  if (_frame->_interpreter_frame_pointer_reg == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4232
    fprintf(fp_cpp," return OptoReg::Bad; }\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4233
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4234
    fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4235
            _frame->_interpreter_frame_pointer_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4237
  // Frame Pointer definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4238
  /* CNC - I can not contemplate having a different frame pointer between
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4239
     Java and native code; makes my head hurt to think about it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4240
  fprintf(fp_cpp,"OptoReg::Name Matcher::frame_pointer() const {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4241
  fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4242
          _frame->_frame_pointer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4243
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4244
  // (Native) Frame Pointer definition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4245
  fprintf(fp_cpp,"OptoReg::Name Matcher::c_frame_pointer() const {");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4246
  fprintf(fp_cpp," return OptoReg::Name(%s_num); }\n\n",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4247
          _frame->_frame_pointer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4248
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4249
  // Number of callee-save + always-save registers for calling convention
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4250
  fprintf(fp_cpp, "// Number of callee-save + always-save registers\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4251
  fprintf(fp_cpp, "int  Matcher::number_of_saved_registers() {\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4252
  RegDef *rdef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4253
  int nof_saved_registers = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4254
  _register->reset_RegDefs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4255
  while( (rdef = _register->iter_RegDefs()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4256
    if( !strcmp(rdef->_callconv, "SOE") ||  !strcmp(rdef->_callconv, "AS") )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4257
      ++nof_saved_registers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4259
  fprintf(fp_cpp, "  return %d;\n", nof_saved_registers);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4260
  fprintf(fp_cpp, "};\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4261
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4262
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4263
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4266
static int PrintAdlcCisc = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4267
//---------------------------identify_cisc_spilling----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4268
// Get info for the CISC_oracle and MachNode::cisc_version()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4269
void ArchDesc::identify_cisc_spill_instructions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4270
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  4271
  if (_frame == NULL)
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  4272
    return;
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
  4273
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4274
  // Find the user-defined operand for cisc-spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4275
  if( _frame->_cisc_spilling_operand_name != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4276
    const Form *form = _globalNames[_frame->_cisc_spilling_operand_name];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4277
    OperandForm *oper = form ? form->is_operand() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4278
    // Verify the user's suggestion
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4279
    if( oper != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4280
      // Ensure that match field is defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4281
      if ( oper->_matrule != NULL )  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4282
        MatchRule &mrule = *oper->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4283
        if( strcmp(mrule._opType,"AddP") == 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4284
          MatchNode *left = mrule._lChild;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4285
          MatchNode *right= mrule._rChild;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4286
          if( left != NULL && right != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4287
            const Form *left_op  = _globalNames[left->_opType]->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4288
            const Form *right_op = _globalNames[right->_opType]->is_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4289
            if(  (left_op != NULL && right_op != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4290
              && (left_op->interface_type(_globalNames) == Form::register_interface)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4291
              && (right_op->interface_type(_globalNames) == Form::constant_interface) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4292
              // Successfully verified operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4293
              set_cisc_spill_operand( oper );
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4294
              if( _cisc_spill_debug ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4295
                fprintf(stderr, "\n\nVerified CISC-spill operand %s\n\n", oper->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4296
             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4297
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4298
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4299
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4300
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4301
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4304
  if( cisc_spill_operand() != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4305
    // N^2 comparison of instructions looking for a cisc-spilling version
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4306
    _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4307
    InstructForm *instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4308
    for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4309
      // Ensure that match field is defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4310
      if ( instr->_matrule == NULL )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4311
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4312
      MatchRule &mrule = *instr->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4313
      Predicate *pred  =  instr->build_predicate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4315
      // Grab the machine type of the operand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4316
      const char *rootOp = instr->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4317
      mrule._machType    = rootOp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4318
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4319
      // Find result type for match
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4320
      const char *result = instr->reduce_result();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4322
      if( PrintAdlcCisc ) fprintf(stderr, "  new instruction %s \n", instr->_ident ? instr->_ident : " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4323
      bool  found_cisc_alternate = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4324
      _instructions.reset2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4325
      InstructForm *instr2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4326
      for( ; !found_cisc_alternate && (instr2 = (InstructForm*)_instructions.iter2()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4327
        // Ensure that match field is defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4328
        if( PrintAdlcCisc ) fprintf(stderr, "  instr2 == %s \n", instr2->_ident ? instr2->_ident : " ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4329
        if ( instr2->_matrule != NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4330
            && (instr != instr2 )                // Skip self
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4331
            && (instr2->reduce_result() != NULL) // want same result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4332
            && (strcmp(result, instr2->reduce_result()) == 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4333
          MatchRule &mrule2 = *instr2->_matrule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4334
          Predicate *pred2  =  instr2->build_predicate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4335
          found_cisc_alternate = instr->cisc_spills_to(*this, instr2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4336
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4337
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4338
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4339
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4341
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4342
//---------------------------build_cisc_spilling-------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4343
// Get info for the CISC_oracle and MachNode::cisc_version()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4344
void ArchDesc::build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4345
  // Output the table for cisc spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4346
  fprintf(fp_cpp, "//  The following instructions can cisc-spill\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4347
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4348
  InstructForm *inst = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4349
  for(; (inst = (InstructForm*)_instructions.iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4350
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4351
    if ( inst->ideal_only() )  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4352
    const char *inst_name = inst->_ident;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4353
    int   operand   = inst->cisc_spill_operand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4354
    if( operand != AdlcVMDeps::Not_cisc_spillable ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4355
      InstructForm *inst2 = inst->cisc_spill_alternate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4356
      fprintf(fp_cpp, "//  %s can cisc-spill operand %d to %s\n", inst->_ident, operand, inst2->_ident);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4357
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4359
  fprintf(fp_cpp, "\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4360
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4361
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4362
//---------------------------identify_short_branches----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4363
// Get info for our short branch replacement oracle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4364
void ArchDesc::identify_short_branches() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4365
  // Walk over all instructions, checking to see if they match a short
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4366
  // branching alternate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4367
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4368
  InstructForm *instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4369
  while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4370
    // The instruction must have a match rule.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4371
    if (instr->_matrule != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4372
        instr->is_short_branch()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4373
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4374
      _instructions.reset2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4375
      InstructForm *instr2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4376
      while( (instr2 = (InstructForm*)_instructions.iter2()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4377
        instr2->check_branch_variant(*this, instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4378
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4379
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4382
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4383
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4384
//---------------------------identify_unique_operands---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4385
// Identify unique operands.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4386
void ArchDesc::identify_unique_operands() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4387
  // Walk over all instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4388
  _instructions.reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4389
  InstructForm *instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4390
  while( (instr = (InstructForm*)_instructions.iter()) != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4391
    // Ensure this is a machine-world instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4392
    if (!instr->ideal_only()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4393
      instr->set_unique_opnds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4394
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  4396
}