Thu, 24 May 2018 18:41:44 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | // FORMS.CPP - Definitions for ADL Parser Forms Classes |
aoqi@0 | 26 | #include "adlc.hpp" |
aoqi@0 | 27 | |
aoqi@0 | 28 | //==============================Instructions=================================== |
aoqi@0 | 29 | //------------------------------InstructForm----------------------------------- |
aoqi@0 | 30 | InstructForm::InstructForm(const char *id, bool ideal_only) |
aoqi@0 | 31 | : _ident(id), _ideal_only(ideal_only), |
aoqi@0 | 32 | _localNames(cmpstr, hashstr, Form::arena), |
aoqi@0 | 33 | _effects(cmpstr, hashstr, Form::arena), |
aoqi@0 | 34 | _is_mach_constant(false), |
aoqi@0 | 35 | _needs_constant_base(false), |
aoqi@0 | 36 | _has_call(false) |
aoqi@0 | 37 | { |
aoqi@0 | 38 | _ftype = Form::INS; |
aoqi@0 | 39 | |
aoqi@0 | 40 | _matrule = NULL; |
aoqi@0 | 41 | _insencode = NULL; |
aoqi@0 | 42 | _constant = NULL; |
aoqi@0 | 43 | _is_postalloc_expand = false; |
aoqi@0 | 44 | _opcode = NULL; |
aoqi@0 | 45 | _size = NULL; |
aoqi@0 | 46 | _attribs = NULL; |
aoqi@0 | 47 | _predicate = NULL; |
aoqi@0 | 48 | _exprule = NULL; |
aoqi@0 | 49 | _rewrule = NULL; |
aoqi@0 | 50 | _format = NULL; |
aoqi@0 | 51 | _peephole = NULL; |
aoqi@0 | 52 | _ins_pipe = NULL; |
aoqi@0 | 53 | _uniq_idx = NULL; |
aoqi@0 | 54 | _num_uniq = 0; |
aoqi@0 | 55 | _cisc_spill_operand = Not_cisc_spillable;// Which operand may cisc-spill |
aoqi@0 | 56 | _cisc_spill_alternate = NULL; // possible cisc replacement |
aoqi@0 | 57 | _cisc_reg_mask_name = NULL; |
aoqi@0 | 58 | _is_cisc_alternate = false; |
aoqi@0 | 59 | _is_short_branch = false; |
aoqi@0 | 60 | _short_branch_form = NULL; |
aoqi@0 | 61 | _alignment = 1; |
aoqi@0 | 62 | } |
aoqi@0 | 63 | |
aoqi@0 | 64 | InstructForm::InstructForm(const char *id, InstructForm *instr, MatchRule *rule) |
aoqi@0 | 65 | : _ident(id), _ideal_only(false), |
aoqi@0 | 66 | _localNames(instr->_localNames), |
aoqi@0 | 67 | _effects(instr->_effects), |
aoqi@0 | 68 | _is_mach_constant(false), |
aoqi@0 | 69 | _needs_constant_base(false), |
aoqi@0 | 70 | _has_call(false) |
aoqi@0 | 71 | { |
aoqi@0 | 72 | _ftype = Form::INS; |
aoqi@0 | 73 | |
aoqi@0 | 74 | _matrule = rule; |
aoqi@0 | 75 | _insencode = instr->_insencode; |
aoqi@0 | 76 | _constant = instr->_constant; |
aoqi@0 | 77 | _is_postalloc_expand = instr->_is_postalloc_expand; |
aoqi@0 | 78 | _opcode = instr->_opcode; |
aoqi@0 | 79 | _size = instr->_size; |
aoqi@0 | 80 | _attribs = instr->_attribs; |
aoqi@0 | 81 | _predicate = instr->_predicate; |
aoqi@0 | 82 | _exprule = instr->_exprule; |
aoqi@0 | 83 | _rewrule = instr->_rewrule; |
aoqi@0 | 84 | _format = instr->_format; |
aoqi@0 | 85 | _peephole = instr->_peephole; |
aoqi@0 | 86 | _ins_pipe = instr->_ins_pipe; |
aoqi@0 | 87 | _uniq_idx = instr->_uniq_idx; |
aoqi@0 | 88 | _num_uniq = instr->_num_uniq; |
aoqi@0 | 89 | _cisc_spill_operand = Not_cisc_spillable; // Which operand may cisc-spill |
aoqi@0 | 90 | _cisc_spill_alternate = NULL; // possible cisc replacement |
aoqi@0 | 91 | _cisc_reg_mask_name = NULL; |
aoqi@0 | 92 | _is_cisc_alternate = false; |
aoqi@0 | 93 | _is_short_branch = false; |
aoqi@0 | 94 | _short_branch_form = NULL; |
aoqi@0 | 95 | _alignment = 1; |
aoqi@0 | 96 | // Copy parameters |
aoqi@0 | 97 | const char *name; |
aoqi@0 | 98 | instr->_parameters.reset(); |
aoqi@0 | 99 | for (; (name = instr->_parameters.iter()) != NULL;) |
aoqi@0 | 100 | _parameters.addName(name); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | InstructForm::~InstructForm() { |
aoqi@0 | 104 | } |
aoqi@0 | 105 | |
aoqi@0 | 106 | InstructForm *InstructForm::is_instruction() const { |
aoqi@0 | 107 | return (InstructForm*)this; |
aoqi@0 | 108 | } |
aoqi@0 | 109 | |
aoqi@0 | 110 | bool InstructForm::ideal_only() const { |
aoqi@0 | 111 | return _ideal_only; |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | bool InstructForm::sets_result() const { |
aoqi@0 | 115 | return (_matrule != NULL && _matrule->sets_result()); |
aoqi@0 | 116 | } |
aoqi@0 | 117 | |
aoqi@0 | 118 | bool InstructForm::needs_projections() { |
aoqi@0 | 119 | _components.reset(); |
aoqi@0 | 120 | for( Component *comp; (comp = _components.iter()) != NULL; ) { |
aoqi@0 | 121 | if (comp->isa(Component::KILL)) { |
aoqi@0 | 122 | return true; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | } |
aoqi@0 | 125 | return false; |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | |
aoqi@0 | 129 | bool InstructForm::has_temps() { |
aoqi@0 | 130 | if (_matrule) { |
aoqi@0 | 131 | // Examine each component to see if it is a TEMP |
aoqi@0 | 132 | _components.reset(); |
aoqi@0 | 133 | // Skip the first component, if already handled as (SET dst (...)) |
aoqi@0 | 134 | Component *comp = NULL; |
aoqi@0 | 135 | if (sets_result()) comp = _components.iter(); |
aoqi@0 | 136 | while ((comp = _components.iter()) != NULL) { |
aoqi@0 | 137 | if (comp->isa(Component::TEMP)) { |
aoqi@0 | 138 | return true; |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | } |
aoqi@0 | 142 | |
aoqi@0 | 143 | return false; |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | uint InstructForm::num_defs_or_kills() { |
aoqi@0 | 147 | uint defs_or_kills = 0; |
aoqi@0 | 148 | |
aoqi@0 | 149 | _components.reset(); |
aoqi@0 | 150 | for( Component *comp; (comp = _components.iter()) != NULL; ) { |
aoqi@0 | 151 | if( comp->isa(Component::DEF) || comp->isa(Component::KILL) ) { |
aoqi@0 | 152 | ++defs_or_kills; |
aoqi@0 | 153 | } |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | return defs_or_kills; |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | // This instruction has an expand rule? |
aoqi@0 | 160 | bool InstructForm::expands() const { |
aoqi@0 | 161 | return ( _exprule != NULL ); |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | // This instruction has a late expand rule? |
aoqi@0 | 165 | bool InstructForm::postalloc_expands() const { |
aoqi@0 | 166 | return _is_postalloc_expand; |
aoqi@0 | 167 | } |
aoqi@0 | 168 | |
aoqi@0 | 169 | // This instruction has a peephole rule? |
aoqi@0 | 170 | Peephole *InstructForm::peepholes() const { |
aoqi@0 | 171 | return _peephole; |
aoqi@0 | 172 | } |
aoqi@0 | 173 | |
aoqi@0 | 174 | // This instruction has a peephole rule? |
aoqi@0 | 175 | void InstructForm::append_peephole(Peephole *peephole) { |
aoqi@0 | 176 | if( _peephole == NULL ) { |
aoqi@0 | 177 | _peephole = peephole; |
aoqi@0 | 178 | } else { |
aoqi@0 | 179 | _peephole->append_peephole(peephole); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | |
aoqi@0 | 184 | // ideal opcode enumeration |
aoqi@0 | 185 | const char *InstructForm::ideal_Opcode( FormDict &globalNames ) const { |
aoqi@0 | 186 | if( !_matrule ) return "Node"; // Something weird |
aoqi@0 | 187 | // Chain rules do not really have ideal Opcodes; use their source |
aoqi@0 | 188 | // operand ideal Opcode instead. |
aoqi@0 | 189 | if( is_simple_chain_rule(globalNames) ) { |
aoqi@0 | 190 | const char *src = _matrule->_rChild->_opType; |
aoqi@0 | 191 | OperandForm *src_op = globalNames[src]->is_operand(); |
aoqi@0 | 192 | assert( src_op, "Not operand class of chain rule" ); |
aoqi@0 | 193 | if( !src_op->_matrule ) return "Node"; |
aoqi@0 | 194 | return src_op->_matrule->_opType; |
aoqi@0 | 195 | } |
aoqi@0 | 196 | // Operand chain rules do not really have ideal Opcodes |
aoqi@0 | 197 | if( _matrule->is_chain_rule(globalNames) ) |
aoqi@0 | 198 | return "Node"; |
aoqi@0 | 199 | return strcmp(_matrule->_opType,"Set") |
aoqi@0 | 200 | ? _matrule->_opType |
aoqi@0 | 201 | : _matrule->_rChild->_opType; |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | // Recursive check on all operands' match rules in my match rule |
aoqi@0 | 205 | bool InstructForm::is_pinned(FormDict &globals) { |
aoqi@0 | 206 | if ( ! _matrule) return false; |
aoqi@0 | 207 | |
aoqi@0 | 208 | int index = 0; |
aoqi@0 | 209 | if (_matrule->find_type("Goto", index)) return true; |
aoqi@0 | 210 | if (_matrule->find_type("If", index)) return true; |
aoqi@0 | 211 | if (_matrule->find_type("CountedLoopEnd",index)) return true; |
aoqi@0 | 212 | if (_matrule->find_type("Return", index)) return true; |
aoqi@0 | 213 | if (_matrule->find_type("Rethrow", index)) return true; |
aoqi@0 | 214 | if (_matrule->find_type("TailCall", index)) return true; |
aoqi@0 | 215 | if (_matrule->find_type("TailJump", index)) return true; |
aoqi@0 | 216 | if (_matrule->find_type("Halt", index)) return true; |
aoqi@0 | 217 | if (_matrule->find_type("Jump", index)) return true; |
aoqi@0 | 218 | |
aoqi@0 | 219 | return is_parm(globals); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | // Recursive check on all operands' match rules in my match rule |
aoqi@0 | 223 | bool InstructForm::is_projection(FormDict &globals) { |
aoqi@0 | 224 | if ( ! _matrule) return false; |
aoqi@0 | 225 | |
aoqi@0 | 226 | int index = 0; |
aoqi@0 | 227 | if (_matrule->find_type("Goto", index)) return true; |
aoqi@0 | 228 | if (_matrule->find_type("Return", index)) return true; |
aoqi@0 | 229 | if (_matrule->find_type("Rethrow", index)) return true; |
aoqi@0 | 230 | if (_matrule->find_type("TailCall",index)) return true; |
aoqi@0 | 231 | if (_matrule->find_type("TailJump",index)) return true; |
aoqi@0 | 232 | if (_matrule->find_type("Halt", index)) return true; |
aoqi@0 | 233 | |
aoqi@0 | 234 | return false; |
aoqi@0 | 235 | } |
aoqi@0 | 236 | |
aoqi@0 | 237 | // Recursive check on all operands' match rules in my match rule |
aoqi@0 | 238 | bool InstructForm::is_parm(FormDict &globals) { |
aoqi@0 | 239 | if ( ! _matrule) return false; |
aoqi@0 | 240 | |
aoqi@0 | 241 | int index = 0; |
aoqi@0 | 242 | if (_matrule->find_type("Parm",index)) return true; |
aoqi@0 | 243 | |
aoqi@0 | 244 | return false; |
aoqi@0 | 245 | } |
aoqi@0 | 246 | |
aoqi@0 | 247 | bool InstructForm::is_ideal_negD() const { |
aoqi@0 | 248 | return (_matrule && _matrule->_rChild && strcmp(_matrule->_rChild->_opType, "NegD") == 0); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | // Return 'true' if this instruction matches an ideal 'Copy*' node |
aoqi@0 | 252 | int InstructForm::is_ideal_copy() const { |
aoqi@0 | 253 | return _matrule ? _matrule->is_ideal_copy() : 0; |
aoqi@0 | 254 | } |
aoqi@0 | 255 | |
aoqi@0 | 256 | // Return 'true' if this instruction is too complex to rematerialize. |
aoqi@0 | 257 | int InstructForm::is_expensive() const { |
aoqi@0 | 258 | // We can prove it is cheap if it has an empty encoding. |
aoqi@0 | 259 | // This helps with platform-specific nops like ThreadLocal and RoundFloat. |
aoqi@0 | 260 | if (is_empty_encoding()) |
aoqi@0 | 261 | return 0; |
aoqi@0 | 262 | |
aoqi@0 | 263 | if (is_tls_instruction()) |
aoqi@0 | 264 | return 1; |
aoqi@0 | 265 | |
aoqi@0 | 266 | if (_matrule == NULL) return 0; |
aoqi@0 | 267 | |
aoqi@0 | 268 | return _matrule->is_expensive(); |
aoqi@0 | 269 | } |
aoqi@0 | 270 | |
aoqi@0 | 271 | // Has an empty encoding if _size is a constant zero or there |
aoqi@0 | 272 | // are no ins_encode tokens. |
aoqi@0 | 273 | int InstructForm::is_empty_encoding() const { |
aoqi@0 | 274 | if (_insencode != NULL) { |
aoqi@0 | 275 | _insencode->reset(); |
aoqi@0 | 276 | if (_insencode->encode_class_iter() == NULL) { |
aoqi@0 | 277 | return 1; |
aoqi@0 | 278 | } |
aoqi@0 | 279 | } |
aoqi@0 | 280 | if (_size != NULL && strcmp(_size, "0") == 0) { |
aoqi@0 | 281 | return 1; |
aoqi@0 | 282 | } |
aoqi@0 | 283 | return 0; |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | int InstructForm::is_tls_instruction() const { |
aoqi@0 | 287 | if (_ident != NULL && |
aoqi@0 | 288 | ( ! strcmp( _ident,"tlsLoadP") || |
aoqi@0 | 289 | ! strncmp(_ident,"tlsLoadP_",9)) ) { |
aoqi@0 | 290 | return 1; |
aoqi@0 | 291 | } |
aoqi@0 | 292 | |
aoqi@0 | 293 | if (_matrule != NULL && _insencode != NULL) { |
aoqi@0 | 294 | const char* opType = _matrule->_opType; |
aoqi@0 | 295 | if (strcmp(opType, "Set")==0) |
aoqi@0 | 296 | opType = _matrule->_rChild->_opType; |
aoqi@0 | 297 | if (strcmp(opType,"ThreadLocal")==0) { |
aoqi@0 | 298 | fprintf(stderr, "Warning: ThreadLocal instruction %s should be named 'tlsLoadP_*'\n", |
aoqi@0 | 299 | (_ident == NULL ? "NULL" : _ident)); |
aoqi@0 | 300 | return 1; |
aoqi@0 | 301 | } |
aoqi@0 | 302 | } |
aoqi@0 | 303 | |
aoqi@0 | 304 | return 0; |
aoqi@0 | 305 | } |
aoqi@0 | 306 | |
aoqi@0 | 307 | |
aoqi@0 | 308 | // Return 'true' if this instruction matches an ideal 'If' node |
aoqi@0 | 309 | bool InstructForm::is_ideal_if() const { |
aoqi@0 | 310 | if( _matrule == NULL ) return false; |
aoqi@0 | 311 | |
aoqi@0 | 312 | return _matrule->is_ideal_if(); |
aoqi@0 | 313 | } |
aoqi@0 | 314 | |
aoqi@0 | 315 | // Return 'true' if this instruction matches an ideal 'FastLock' node |
aoqi@0 | 316 | bool InstructForm::is_ideal_fastlock() const { |
aoqi@0 | 317 | if( _matrule == NULL ) return false; |
aoqi@0 | 318 | |
aoqi@0 | 319 | return _matrule->is_ideal_fastlock(); |
aoqi@0 | 320 | } |
aoqi@0 | 321 | |
aoqi@0 | 322 | // Return 'true' if this instruction matches an ideal 'MemBarXXX' node |
aoqi@0 | 323 | bool InstructForm::is_ideal_membar() const { |
aoqi@0 | 324 | if( _matrule == NULL ) return false; |
aoqi@0 | 325 | |
aoqi@0 | 326 | return _matrule->is_ideal_membar(); |
aoqi@0 | 327 | } |
aoqi@0 | 328 | |
aoqi@0 | 329 | // Return 'true' if this instruction matches an ideal 'LoadPC' node |
aoqi@0 | 330 | bool InstructForm::is_ideal_loadPC() const { |
aoqi@0 | 331 | if( _matrule == NULL ) return false; |
aoqi@0 | 332 | |
aoqi@0 | 333 | return _matrule->is_ideal_loadPC(); |
aoqi@0 | 334 | } |
aoqi@0 | 335 | |
aoqi@0 | 336 | // Return 'true' if this instruction matches an ideal 'Box' node |
aoqi@0 | 337 | bool InstructForm::is_ideal_box() const { |
aoqi@0 | 338 | if( _matrule == NULL ) return false; |
aoqi@0 | 339 | |
aoqi@0 | 340 | return _matrule->is_ideal_box(); |
aoqi@0 | 341 | } |
aoqi@0 | 342 | |
aoqi@0 | 343 | // Return 'true' if this instruction matches an ideal 'Goto' node |
aoqi@0 | 344 | bool InstructForm::is_ideal_goto() const { |
aoqi@0 | 345 | if( _matrule == NULL ) return false; |
aoqi@0 | 346 | |
aoqi@0 | 347 | return _matrule->is_ideal_goto(); |
aoqi@0 | 348 | } |
aoqi@0 | 349 | |
aoqi@0 | 350 | // Return 'true' if this instruction matches an ideal 'Jump' node |
aoqi@0 | 351 | bool InstructForm::is_ideal_jump() const { |
aoqi@0 | 352 | if( _matrule == NULL ) return false; |
aoqi@0 | 353 | |
aoqi@0 | 354 | return _matrule->is_ideal_jump(); |
aoqi@0 | 355 | } |
aoqi@0 | 356 | |
aoqi@0 | 357 | // Return 'true' if instruction matches ideal 'If' | 'Goto' | 'CountedLoopEnd' |
aoqi@0 | 358 | bool InstructForm::is_ideal_branch() const { |
aoqi@0 | 359 | if( _matrule == NULL ) return false; |
aoqi@0 | 360 | |
aoqi@0 | 361 | return _matrule->is_ideal_if() || _matrule->is_ideal_goto(); |
aoqi@0 | 362 | } |
aoqi@0 | 363 | |
aoqi@0 | 364 | |
aoqi@0 | 365 | // Return 'true' if this instruction matches an ideal 'Return' node |
aoqi@0 | 366 | bool InstructForm::is_ideal_return() const { |
aoqi@0 | 367 | if( _matrule == NULL ) return false; |
aoqi@0 | 368 | |
aoqi@0 | 369 | // Check MatchRule to see if the first entry is the ideal "Return" node |
aoqi@0 | 370 | int index = 0; |
aoqi@0 | 371 | if (_matrule->find_type("Return",index)) return true; |
aoqi@0 | 372 | if (_matrule->find_type("Rethrow",index)) return true; |
aoqi@0 | 373 | if (_matrule->find_type("TailCall",index)) return true; |
aoqi@0 | 374 | if (_matrule->find_type("TailJump",index)) return true; |
aoqi@0 | 375 | |
aoqi@0 | 376 | return false; |
aoqi@0 | 377 | } |
aoqi@0 | 378 | |
aoqi@0 | 379 | // Return 'true' if this instruction matches an ideal 'Halt' node |
aoqi@0 | 380 | bool InstructForm::is_ideal_halt() const { |
aoqi@0 | 381 | int index = 0; |
aoqi@0 | 382 | return _matrule && _matrule->find_type("Halt",index); |
aoqi@0 | 383 | } |
aoqi@0 | 384 | |
aoqi@0 | 385 | // Return 'true' if this instruction matches an ideal 'SafePoint' node |
aoqi@0 | 386 | bool InstructForm::is_ideal_safepoint() const { |
aoqi@0 | 387 | int index = 0; |
aoqi@0 | 388 | return _matrule && _matrule->find_type("SafePoint",index); |
aoqi@0 | 389 | } |
aoqi@0 | 390 | |
aoqi@0 | 391 | // Return 'true' if this instruction matches an ideal 'Nop' node |
aoqi@0 | 392 | bool InstructForm::is_ideal_nop() const { |
aoqi@0 | 393 | return _ident && _ident[0] == 'N' && _ident[1] == 'o' && _ident[2] == 'p' && _ident[3] == '_'; |
aoqi@0 | 394 | } |
aoqi@0 | 395 | |
aoqi@0 | 396 | bool InstructForm::is_ideal_control() const { |
aoqi@0 | 397 | if ( ! _matrule) return false; |
aoqi@0 | 398 | |
aoqi@0 | 399 | return is_ideal_return() || is_ideal_branch() || _matrule->is_ideal_jump() || is_ideal_halt(); |
aoqi@0 | 400 | } |
aoqi@0 | 401 | |
aoqi@0 | 402 | // Return 'true' if this instruction matches an ideal 'Call' node |
aoqi@0 | 403 | Form::CallType InstructForm::is_ideal_call() const { |
aoqi@0 | 404 | if( _matrule == NULL ) return Form::invalid_type; |
aoqi@0 | 405 | |
aoqi@0 | 406 | // Check MatchRule to see if the first entry is the ideal "Call" node |
aoqi@0 | 407 | int idx = 0; |
aoqi@0 | 408 | if(_matrule->find_type("CallStaticJava",idx)) return Form::JAVA_STATIC; |
aoqi@0 | 409 | idx = 0; |
aoqi@0 | 410 | if(_matrule->find_type("Lock",idx)) return Form::JAVA_STATIC; |
aoqi@0 | 411 | idx = 0; |
aoqi@0 | 412 | if(_matrule->find_type("Unlock",idx)) return Form::JAVA_STATIC; |
aoqi@0 | 413 | idx = 0; |
aoqi@0 | 414 | if(_matrule->find_type("CallDynamicJava",idx)) return Form::JAVA_DYNAMIC; |
aoqi@0 | 415 | idx = 0; |
aoqi@0 | 416 | if(_matrule->find_type("CallRuntime",idx)) return Form::JAVA_RUNTIME; |
aoqi@0 | 417 | idx = 0; |
aoqi@0 | 418 | if(_matrule->find_type("CallLeaf",idx)) return Form::JAVA_LEAF; |
aoqi@0 | 419 | idx = 0; |
aoqi@0 | 420 | if(_matrule->find_type("CallLeafNoFP",idx)) return Form::JAVA_LEAF; |
aoqi@0 | 421 | idx = 0; |
aoqi@0 | 422 | |
aoqi@0 | 423 | return Form::invalid_type; |
aoqi@0 | 424 | } |
aoqi@0 | 425 | |
aoqi@0 | 426 | // Return 'true' if this instruction matches an ideal 'Load?' node |
aoqi@0 | 427 | Form::DataType InstructForm::is_ideal_load() const { |
aoqi@0 | 428 | if( _matrule == NULL ) return Form::none; |
aoqi@0 | 429 | |
aoqi@0 | 430 | return _matrule->is_ideal_load(); |
aoqi@0 | 431 | } |
aoqi@0 | 432 | |
aoqi@0 | 433 | // Return 'true' if this instruction matches an ideal 'LoadKlass' node |
aoqi@0 | 434 | bool InstructForm::skip_antidep_check() const { |
aoqi@0 | 435 | if( _matrule == NULL ) return false; |
aoqi@0 | 436 | |
aoqi@0 | 437 | return _matrule->skip_antidep_check(); |
aoqi@0 | 438 | } |
aoqi@0 | 439 | |
aoqi@0 | 440 | // Return 'true' if this instruction matches an ideal 'Load?' node |
aoqi@0 | 441 | Form::DataType InstructForm::is_ideal_store() const { |
aoqi@0 | 442 | if( _matrule == NULL ) return Form::none; |
aoqi@0 | 443 | |
aoqi@0 | 444 | return _matrule->is_ideal_store(); |
aoqi@0 | 445 | } |
aoqi@0 | 446 | |
aoqi@0 | 447 | // Return 'true' if this instruction matches an ideal vector node |
aoqi@0 | 448 | bool InstructForm::is_vector() const { |
aoqi@0 | 449 | if( _matrule == NULL ) return false; |
aoqi@0 | 450 | |
aoqi@0 | 451 | return _matrule->is_vector(); |
aoqi@0 | 452 | } |
aoqi@0 | 453 | |
aoqi@0 | 454 | |
aoqi@0 | 455 | // Return the input register that must match the output register |
aoqi@0 | 456 | // If this is not required, return 0 |
aoqi@0 | 457 | uint InstructForm::two_address(FormDict &globals) { |
aoqi@0 | 458 | uint matching_input = 0; |
aoqi@0 | 459 | if(_components.count() == 0) return 0; |
aoqi@0 | 460 | |
aoqi@0 | 461 | _components.reset(); |
aoqi@0 | 462 | Component *comp = _components.iter(); |
aoqi@0 | 463 | // Check if there is a DEF |
aoqi@0 | 464 | if( comp->isa(Component::DEF) ) { |
aoqi@0 | 465 | // Check that this is a register |
aoqi@0 | 466 | const char *def_type = comp->_type; |
aoqi@0 | 467 | const Form *form = globals[def_type]; |
aoqi@0 | 468 | OperandForm *op = form->is_operand(); |
aoqi@0 | 469 | if( op ) { |
aoqi@0 | 470 | if( op->constrained_reg_class() != NULL && |
aoqi@0 | 471 | op->interface_type(globals) == Form::register_interface ) { |
aoqi@0 | 472 | // Remember the local name for equality test later |
aoqi@0 | 473 | const char *def_name = comp->_name; |
aoqi@0 | 474 | // Check if a component has the same name and is a USE |
aoqi@0 | 475 | do { |
aoqi@0 | 476 | if( comp->isa(Component::USE) && strcmp(comp->_name,def_name)==0 ) { |
aoqi@0 | 477 | return operand_position_format(def_name); |
aoqi@0 | 478 | } |
aoqi@0 | 479 | } while( (comp = _components.iter()) != NULL); |
aoqi@0 | 480 | } |
aoqi@0 | 481 | } |
aoqi@0 | 482 | } |
aoqi@0 | 483 | |
aoqi@0 | 484 | return 0; |
aoqi@0 | 485 | } |
aoqi@0 | 486 | |
aoqi@0 | 487 | |
aoqi@0 | 488 | // when chaining a constant to an instruction, returns 'true' and sets opType |
aoqi@0 | 489 | Form::DataType InstructForm::is_chain_of_constant(FormDict &globals) { |
aoqi@0 | 490 | const char *dummy = NULL; |
aoqi@0 | 491 | const char *dummy2 = NULL; |
aoqi@0 | 492 | return is_chain_of_constant(globals, dummy, dummy2); |
aoqi@0 | 493 | } |
aoqi@0 | 494 | Form::DataType InstructForm::is_chain_of_constant(FormDict &globals, |
aoqi@0 | 495 | const char * &opTypeParam) { |
aoqi@0 | 496 | const char *result = NULL; |
aoqi@0 | 497 | |
aoqi@0 | 498 | return is_chain_of_constant(globals, opTypeParam, result); |
aoqi@0 | 499 | } |
aoqi@0 | 500 | |
aoqi@0 | 501 | Form::DataType InstructForm::is_chain_of_constant(FormDict &globals, |
aoqi@0 | 502 | const char * &opTypeParam, const char * &resultParam) { |
aoqi@0 | 503 | Form::DataType data_type = Form::none; |
aoqi@0 | 504 | if ( ! _matrule) return data_type; |
aoqi@0 | 505 | |
aoqi@0 | 506 | // !!!!! |
aoqi@0 | 507 | // The source of the chain rule is 'position = 1' |
aoqi@0 | 508 | uint position = 1; |
aoqi@0 | 509 | const char *result = NULL; |
aoqi@0 | 510 | const char *name = NULL; |
aoqi@0 | 511 | const char *opType = NULL; |
aoqi@0 | 512 | // Here base_operand is looking for an ideal type to be returned (opType). |
aoqi@0 | 513 | if ( _matrule->is_chain_rule(globals) |
aoqi@0 | 514 | && _matrule->base_operand(position, globals, result, name, opType) ) { |
aoqi@0 | 515 | data_type = ideal_to_const_type(opType); |
aoqi@0 | 516 | |
aoqi@0 | 517 | // if it isn't an ideal constant type, just return |
aoqi@0 | 518 | if ( data_type == Form::none ) return data_type; |
aoqi@0 | 519 | |
aoqi@0 | 520 | // Ideal constant types also adjust the opType parameter. |
aoqi@0 | 521 | resultParam = result; |
aoqi@0 | 522 | opTypeParam = opType; |
aoqi@0 | 523 | return data_type; |
aoqi@0 | 524 | } |
aoqi@0 | 525 | |
aoqi@0 | 526 | return data_type; |
aoqi@0 | 527 | } |
aoqi@0 | 528 | |
aoqi@0 | 529 | // Check if a simple chain rule |
aoqi@0 | 530 | bool InstructForm::is_simple_chain_rule(FormDict &globals) const { |
aoqi@0 | 531 | if( _matrule && _matrule->sets_result() |
aoqi@0 | 532 | && _matrule->_rChild->_lChild == NULL |
aoqi@0 | 533 | && globals[_matrule->_rChild->_opType] |
aoqi@0 | 534 | && globals[_matrule->_rChild->_opType]->is_opclass() ) { |
aoqi@0 | 535 | return true; |
aoqi@0 | 536 | } |
aoqi@0 | 537 | return false; |
aoqi@0 | 538 | } |
aoqi@0 | 539 | |
aoqi@0 | 540 | // check for structural rematerialization |
aoqi@0 | 541 | bool InstructForm::rematerialize(FormDict &globals, RegisterForm *registers ) { |
aoqi@0 | 542 | bool rematerialize = false; |
aoqi@0 | 543 | |
aoqi@0 | 544 | Form::DataType data_type = is_chain_of_constant(globals); |
aoqi@0 | 545 | if( data_type != Form::none ) |
aoqi@0 | 546 | rematerialize = true; |
aoqi@0 | 547 | |
aoqi@0 | 548 | // Constants |
aoqi@0 | 549 | if( _components.count() == 1 && _components[0]->is(Component::USE_DEF) ) |
aoqi@0 | 550 | rematerialize = true; |
aoqi@0 | 551 | |
aoqi@0 | 552 | // Pseudo-constants (values easily available to the runtime) |
aoqi@0 | 553 | if (is_empty_encoding() && is_tls_instruction()) |
aoqi@0 | 554 | rematerialize = true; |
aoqi@0 | 555 | |
aoqi@0 | 556 | // 1-input, 1-output, such as copies or increments. |
aoqi@0 | 557 | if( _components.count() == 2 && |
aoqi@0 | 558 | _components[0]->is(Component::DEF) && |
aoqi@0 | 559 | _components[1]->isa(Component::USE) ) |
aoqi@0 | 560 | rematerialize = true; |
aoqi@0 | 561 | |
aoqi@0 | 562 | // Check for an ideal 'Load?' and eliminate rematerialize option |
aoqi@0 | 563 | if ( is_ideal_load() != Form::none || // Ideal load? Do not rematerialize |
aoqi@0 | 564 | is_ideal_copy() != Form::none || // Ideal copy? Do not rematerialize |
aoqi@0 | 565 | is_expensive() != Form::none) { // Expensive? Do not rematerialize |
aoqi@0 | 566 | rematerialize = false; |
aoqi@0 | 567 | } |
aoqi@0 | 568 | |
aoqi@0 | 569 | // Always rematerialize the flags. They are more expensive to save & |
aoqi@0 | 570 | // restore than to recompute (and possibly spill the compare's inputs). |
aoqi@0 | 571 | if( _components.count() >= 1 ) { |
aoqi@0 | 572 | Component *c = _components[0]; |
aoqi@0 | 573 | const Form *form = globals[c->_type]; |
aoqi@0 | 574 | OperandForm *opform = form->is_operand(); |
aoqi@0 | 575 | if( opform ) { |
aoqi@0 | 576 | // Avoid the special stack_slots register classes |
aoqi@0 | 577 | const char *rc_name = opform->constrained_reg_class(); |
aoqi@0 | 578 | if( rc_name ) { |
aoqi@0 | 579 | if( strcmp(rc_name,"stack_slots") ) { |
aoqi@0 | 580 | // Check for ideal_type of RegFlags |
aoqi@0 | 581 | const char *type = opform->ideal_type( globals, registers ); |
aoqi@0 | 582 | if( (type != NULL) && !strcmp(type, "RegFlags") ) |
aoqi@0 | 583 | rematerialize = true; |
aoqi@0 | 584 | } else |
aoqi@0 | 585 | rematerialize = false; // Do not rematerialize things target stk |
aoqi@0 | 586 | } |
aoqi@0 | 587 | } |
aoqi@0 | 588 | } |
aoqi@0 | 589 | |
aoqi@0 | 590 | return rematerialize; |
aoqi@0 | 591 | } |
aoqi@0 | 592 | |
aoqi@0 | 593 | // loads from memory, so must check for anti-dependence |
aoqi@0 | 594 | bool InstructForm::needs_anti_dependence_check(FormDict &globals) const { |
aoqi@0 | 595 | if ( skip_antidep_check() ) return false; |
aoqi@0 | 596 | |
aoqi@0 | 597 | // Machine independent loads must be checked for anti-dependences |
aoqi@0 | 598 | if( is_ideal_load() != Form::none ) return true; |
aoqi@0 | 599 | |
aoqi@0 | 600 | // !!!!! !!!!! !!!!! |
aoqi@0 | 601 | // TEMPORARY |
aoqi@0 | 602 | // if( is_simple_chain_rule(globals) ) return false; |
aoqi@0 | 603 | |
aoqi@0 | 604 | // String.(compareTo/equals/indexOf) and Arrays.equals use many memorys edges, |
aoqi@0 | 605 | // but writes none |
aoqi@0 | 606 | if( _matrule && _matrule->_rChild && |
aoqi@0 | 607 | ( strcmp(_matrule->_rChild->_opType,"StrComp" )==0 || |
aoqi@0 | 608 | strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 || |
aoqi@0 | 609 | strcmp(_matrule->_rChild->_opType,"StrIndexOf" )==0 || |
aoqi@0 | 610 | strcmp(_matrule->_rChild->_opType,"AryEq" )==0 )) |
aoqi@0 | 611 | return true; |
aoqi@0 | 612 | |
aoqi@0 | 613 | // Check if instruction has a USE of a memory operand class, but no defs |
aoqi@0 | 614 | bool USE_of_memory = false; |
aoqi@0 | 615 | bool DEF_of_memory = false; |
aoqi@0 | 616 | Component *comp = NULL; |
aoqi@0 | 617 | ComponentList &components = (ComponentList &)_components; |
aoqi@0 | 618 | |
aoqi@0 | 619 | components.reset(); |
aoqi@0 | 620 | while( (comp = components.iter()) != NULL ) { |
aoqi@0 | 621 | const Form *form = globals[comp->_type]; |
aoqi@0 | 622 | if( !form ) continue; |
aoqi@0 | 623 | OpClassForm *op = form->is_opclass(); |
aoqi@0 | 624 | if( !op ) continue; |
aoqi@0 | 625 | if( form->interface_type(globals) == Form::memory_interface ) { |
aoqi@0 | 626 | if( comp->isa(Component::USE) ) USE_of_memory = true; |
aoqi@0 | 627 | if( comp->isa(Component::DEF) ) { |
aoqi@0 | 628 | OperandForm *oper = form->is_operand(); |
aoqi@0 | 629 | if( oper && oper->is_user_name_for_sReg() ) { |
aoqi@0 | 630 | // Stack slots are unaliased memory handled by allocator |
aoqi@0 | 631 | oper = oper; // debug stopping point !!!!! |
aoqi@0 | 632 | } else { |
aoqi@0 | 633 | DEF_of_memory = true; |
aoqi@0 | 634 | } |
aoqi@0 | 635 | } |
aoqi@0 | 636 | } |
aoqi@0 | 637 | } |
aoqi@0 | 638 | return (USE_of_memory && !DEF_of_memory); |
aoqi@0 | 639 | } |
aoqi@0 | 640 | |
aoqi@0 | 641 | |
aoqi@0 | 642 | bool InstructForm::is_wide_memory_kill(FormDict &globals) const { |
aoqi@0 | 643 | if( _matrule == NULL ) return false; |
aoqi@0 | 644 | if( !_matrule->_opType ) return false; |
aoqi@0 | 645 | |
aoqi@0 | 646 | if( strcmp(_matrule->_opType,"MemBarRelease") == 0 ) return true; |
aoqi@0 | 647 | if( strcmp(_matrule->_opType,"MemBarAcquire") == 0 ) return true; |
aoqi@0 | 648 | if( strcmp(_matrule->_opType,"MemBarReleaseLock") == 0 ) return true; |
aoqi@0 | 649 | if( strcmp(_matrule->_opType,"MemBarAcquireLock") == 0 ) return true; |
aoqi@0 | 650 | if( strcmp(_matrule->_opType,"MemBarStoreStore") == 0 ) return true; |
mdoerr@8670 | 651 | if( strcmp(_matrule->_opType,"MemBarVolatile") == 0 ) return true; |
aoqi@0 | 652 | if( strcmp(_matrule->_opType,"StoreFence") == 0 ) return true; |
aoqi@0 | 653 | if( strcmp(_matrule->_opType,"LoadFence") == 0 ) return true; |
aoqi@0 | 654 | |
aoqi@0 | 655 | return false; |
aoqi@0 | 656 | } |
aoqi@0 | 657 | |
aoqi@0 | 658 | int InstructForm::memory_operand(FormDict &globals) const { |
aoqi@0 | 659 | // Machine independent loads must be checked for anti-dependences |
aoqi@0 | 660 | // Check if instruction has a USE of a memory operand class, or a def. |
aoqi@0 | 661 | int USE_of_memory = 0; |
aoqi@0 | 662 | int DEF_of_memory = 0; |
aoqi@0 | 663 | const char* last_memory_DEF = NULL; // to test DEF/USE pairing in asserts |
aoqi@0 | 664 | const char* last_memory_USE = NULL; |
aoqi@0 | 665 | Component *unique = NULL; |
aoqi@0 | 666 | Component *comp = NULL; |
aoqi@0 | 667 | ComponentList &components = (ComponentList &)_components; |
aoqi@0 | 668 | |
aoqi@0 | 669 | components.reset(); |
aoqi@0 | 670 | while( (comp = components.iter()) != NULL ) { |
aoqi@0 | 671 | const Form *form = globals[comp->_type]; |
aoqi@0 | 672 | if( !form ) continue; |
aoqi@0 | 673 | OpClassForm *op = form->is_opclass(); |
aoqi@0 | 674 | if( !op ) continue; |
aoqi@0 | 675 | if( op->stack_slots_only(globals) ) continue; |
aoqi@0 | 676 | if( form->interface_type(globals) == Form::memory_interface ) { |
aoqi@0 | 677 | if( comp->isa(Component::DEF) ) { |
aoqi@0 | 678 | last_memory_DEF = comp->_name; |
aoqi@0 | 679 | DEF_of_memory++; |
aoqi@0 | 680 | unique = comp; |
aoqi@0 | 681 | } else if( comp->isa(Component::USE) ) { |
aoqi@0 | 682 | if( last_memory_DEF != NULL ) { |
aoqi@0 | 683 | assert(0 == strcmp(last_memory_DEF, comp->_name), "every memory DEF is followed by a USE of the same name"); |
aoqi@0 | 684 | last_memory_DEF = NULL; |
aoqi@0 | 685 | } |
aoqi@0 | 686 | // Handles same memory being used multiple times in the case of BMI1 instructions. |
aoqi@0 | 687 | if (last_memory_USE != NULL) { |
aoqi@0 | 688 | if (strcmp(comp->_name, last_memory_USE) != 0) { |
aoqi@0 | 689 | USE_of_memory++; |
aoqi@0 | 690 | } |
aoqi@0 | 691 | } else { |
aoqi@0 | 692 | USE_of_memory++; |
aoqi@0 | 693 | } |
aoqi@0 | 694 | last_memory_USE = comp->_name; |
aoqi@0 | 695 | |
aoqi@0 | 696 | if (DEF_of_memory == 0) // defs take precedence |
aoqi@0 | 697 | unique = comp; |
aoqi@0 | 698 | } else { |
aoqi@0 | 699 | assert(last_memory_DEF == NULL, "unpaired memory DEF"); |
aoqi@0 | 700 | } |
aoqi@0 | 701 | } |
aoqi@0 | 702 | } |
aoqi@0 | 703 | assert(last_memory_DEF == NULL, "unpaired memory DEF"); |
aoqi@0 | 704 | assert(USE_of_memory >= DEF_of_memory, "unpaired memory DEF"); |
aoqi@0 | 705 | USE_of_memory -= DEF_of_memory; // treat paired DEF/USE as one occurrence |
aoqi@0 | 706 | if( (USE_of_memory + DEF_of_memory) > 0 ) { |
aoqi@0 | 707 | if( is_simple_chain_rule(globals) ) { |
aoqi@0 | 708 | //fprintf(stderr, "Warning: chain rule is not really a memory user.\n"); |
aoqi@0 | 709 | //((InstructForm*)this)->dump(); |
aoqi@0 | 710 | // Preceding code prints nothing on sparc and these insns on intel: |
aoqi@0 | 711 | // leaP8 leaP32 leaPIdxOff leaPIdxScale leaPIdxScaleOff leaP8 leaP32 |
aoqi@0 | 712 | // leaPIdxOff leaPIdxScale leaPIdxScaleOff |
aoqi@0 | 713 | return NO_MEMORY_OPERAND; |
aoqi@0 | 714 | } |
aoqi@0 | 715 | |
aoqi@0 | 716 | if( DEF_of_memory == 1 ) { |
aoqi@0 | 717 | assert(unique != NULL, ""); |
aoqi@0 | 718 | if( USE_of_memory == 0 ) { |
aoqi@0 | 719 | // unique def, no uses |
aoqi@0 | 720 | } else { |
aoqi@0 | 721 | // // unique def, some uses |
aoqi@0 | 722 | // // must return bottom unless all uses match def |
aoqi@0 | 723 | // unique = NULL; |
aoqi@0 | 724 | } |
aoqi@0 | 725 | } else if( DEF_of_memory > 0 ) { |
aoqi@0 | 726 | // multiple defs, don't care about uses |
aoqi@0 | 727 | unique = NULL; |
aoqi@0 | 728 | } else if( USE_of_memory == 1) { |
aoqi@0 | 729 | // unique use, no defs |
aoqi@0 | 730 | assert(unique != NULL, ""); |
aoqi@0 | 731 | } else if( USE_of_memory > 0 ) { |
aoqi@0 | 732 | // multiple uses, no defs |
aoqi@0 | 733 | unique = NULL; |
aoqi@0 | 734 | } else { |
aoqi@0 | 735 | assert(false, "bad case analysis"); |
aoqi@0 | 736 | } |
aoqi@0 | 737 | // process the unique DEF or USE, if there is one |
aoqi@0 | 738 | if( unique == NULL ) { |
aoqi@0 | 739 | return MANY_MEMORY_OPERANDS; |
aoqi@0 | 740 | } else { |
aoqi@0 | 741 | int pos = components.operand_position(unique->_name); |
aoqi@0 | 742 | if( unique->isa(Component::DEF) ) { |
aoqi@0 | 743 | pos += 1; // get corresponding USE from DEF |
aoqi@0 | 744 | } |
aoqi@0 | 745 | assert(pos >= 1, "I was just looking at it!"); |
aoqi@0 | 746 | return pos; |
aoqi@0 | 747 | } |
aoqi@0 | 748 | } |
aoqi@0 | 749 | |
aoqi@0 | 750 | // missed the memory op?? |
aoqi@0 | 751 | if( true ) { // %%% should not be necessary |
aoqi@0 | 752 | if( is_ideal_store() != Form::none ) { |
aoqi@0 | 753 | fprintf(stderr, "Warning: cannot find memory opnd in instr.\n"); |
aoqi@0 | 754 | ((InstructForm*)this)->dump(); |
aoqi@0 | 755 | // pretend it has multiple defs and uses |
aoqi@0 | 756 | return MANY_MEMORY_OPERANDS; |
aoqi@0 | 757 | } |
aoqi@0 | 758 | if( is_ideal_load() != Form::none ) { |
aoqi@0 | 759 | fprintf(stderr, "Warning: cannot find memory opnd in instr.\n"); |
aoqi@0 | 760 | ((InstructForm*)this)->dump(); |
aoqi@0 | 761 | // pretend it has multiple uses and no defs |
aoqi@0 | 762 | return MANY_MEMORY_OPERANDS; |
aoqi@0 | 763 | } |
aoqi@0 | 764 | } |
aoqi@0 | 765 | |
aoqi@0 | 766 | return NO_MEMORY_OPERAND; |
aoqi@0 | 767 | } |
aoqi@0 | 768 | |
aoqi@0 | 769 | |
aoqi@0 | 770 | // This instruction captures the machine-independent bottom_type |
aoqi@0 | 771 | // Expected use is for pointer vs oop determination for LoadP |
aoqi@0 | 772 | bool InstructForm::captures_bottom_type(FormDict &globals) const { |
aoqi@0 | 773 | if( _matrule && _matrule->_rChild && |
aoqi@0 | 774 | (!strcmp(_matrule->_rChild->_opType,"CastPP") || // new result type |
aoqi@0 | 775 | !strcmp(_matrule->_rChild->_opType,"CastX2P") || // new result type |
aoqi@0 | 776 | !strcmp(_matrule->_rChild->_opType,"DecodeN") || |
aoqi@0 | 777 | !strcmp(_matrule->_rChild->_opType,"EncodeP") || |
aoqi@0 | 778 | !strcmp(_matrule->_rChild->_opType,"DecodeNKlass") || |
aoqi@0 | 779 | !strcmp(_matrule->_rChild->_opType,"EncodePKlass") || |
aoqi@0 | 780 | !strcmp(_matrule->_rChild->_opType,"LoadN") || |
aoqi@0 | 781 | !strcmp(_matrule->_rChild->_opType,"LoadNKlass") || |
aoqi@0 | 782 | !strcmp(_matrule->_rChild->_opType,"CreateEx") || // type of exception |
aoqi@0 | 783 | !strcmp(_matrule->_rChild->_opType,"CheckCastPP") || |
aoqi@0 | 784 | !strcmp(_matrule->_rChild->_opType,"GetAndSetP") || |
aoqi@0 | 785 | !strcmp(_matrule->_rChild->_opType,"GetAndSetN")) ) return true; |
aoqi@0 | 786 | else if ( is_ideal_load() == Form::idealP ) return true; |
aoqi@0 | 787 | else if ( is_ideal_store() != Form::none ) return true; |
aoqi@0 | 788 | |
aoqi@0 | 789 | if (needs_base_oop_edge(globals)) return true; |
aoqi@0 | 790 | |
aoqi@0 | 791 | if (is_vector()) return true; |
aoqi@0 | 792 | if (is_mach_constant()) return true; |
aoqi@0 | 793 | |
aoqi@0 | 794 | return false; |
aoqi@0 | 795 | } |
aoqi@0 | 796 | |
aoqi@0 | 797 | |
aoqi@0 | 798 | // Access instr_cost attribute or return NULL. |
aoqi@0 | 799 | const char* InstructForm::cost() { |
aoqi@0 | 800 | for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) { |
aoqi@0 | 801 | if( strcmp(cur->_ident,AttributeForm::_ins_cost) == 0 ) { |
aoqi@0 | 802 | return cur->_val; |
aoqi@0 | 803 | } |
aoqi@0 | 804 | } |
aoqi@0 | 805 | return NULL; |
aoqi@0 | 806 | } |
aoqi@0 | 807 | |
aoqi@0 | 808 | // Return count of top-level operands. |
aoqi@0 | 809 | uint InstructForm::num_opnds() { |
aoqi@0 | 810 | int num_opnds = _components.num_operands(); |
aoqi@0 | 811 | |
aoqi@0 | 812 | // Need special handling for matching some ideal nodes |
aoqi@0 | 813 | // i.e. Matching a return node |
aoqi@0 | 814 | /* |
aoqi@0 | 815 | if( _matrule ) { |
aoqi@0 | 816 | if( strcmp(_matrule->_opType,"Return" )==0 || |
aoqi@0 | 817 | strcmp(_matrule->_opType,"Halt" )==0 ) |
aoqi@0 | 818 | return 3; |
aoqi@0 | 819 | } |
aoqi@0 | 820 | */ |
aoqi@0 | 821 | return num_opnds; |
aoqi@0 | 822 | } |
aoqi@0 | 823 | |
aoqi@0 | 824 | const char* InstructForm::opnd_ident(int idx) { |
aoqi@0 | 825 | return _components.at(idx)->_name; |
aoqi@0 | 826 | } |
aoqi@0 | 827 | |
aoqi@0 | 828 | const char* InstructForm::unique_opnd_ident(uint idx) { |
aoqi@0 | 829 | uint i; |
aoqi@0 | 830 | for (i = 1; i < num_opnds(); ++i) { |
aoqi@0 | 831 | if (unique_opnds_idx(i) == idx) { |
aoqi@0 | 832 | break; |
aoqi@0 | 833 | } |
aoqi@0 | 834 | } |
aoqi@0 | 835 | return (_components.at(i) != NULL) ? _components.at(i)->_name : ""; |
aoqi@0 | 836 | } |
aoqi@0 | 837 | |
aoqi@0 | 838 | // Return count of unmatched operands. |
aoqi@0 | 839 | uint InstructForm::num_post_match_opnds() { |
aoqi@0 | 840 | uint num_post_match_opnds = _components.count(); |
aoqi@0 | 841 | uint num_match_opnds = _components.match_count(); |
aoqi@0 | 842 | num_post_match_opnds = num_post_match_opnds - num_match_opnds; |
aoqi@0 | 843 | |
aoqi@0 | 844 | return num_post_match_opnds; |
aoqi@0 | 845 | } |
aoqi@0 | 846 | |
aoqi@0 | 847 | // Return the number of leaves below this complex operand |
aoqi@0 | 848 | uint InstructForm::num_consts(FormDict &globals) const { |
aoqi@0 | 849 | if ( ! _matrule) return 0; |
aoqi@0 | 850 | |
aoqi@0 | 851 | // This is a recursive invocation on all operands in the matchrule |
aoqi@0 | 852 | return _matrule->num_consts(globals); |
aoqi@0 | 853 | } |
aoqi@0 | 854 | |
aoqi@0 | 855 | // Constants in match rule with specified type |
aoqi@0 | 856 | uint InstructForm::num_consts(FormDict &globals, Form::DataType type) const { |
aoqi@0 | 857 | if ( ! _matrule) return 0; |
aoqi@0 | 858 | |
aoqi@0 | 859 | // This is a recursive invocation on all operands in the matchrule |
aoqi@0 | 860 | return _matrule->num_consts(globals, type); |
aoqi@0 | 861 | } |
aoqi@0 | 862 | |
aoqi@0 | 863 | |
aoqi@0 | 864 | // Return the register class associated with 'leaf'. |
aoqi@0 | 865 | const char *InstructForm::out_reg_class(FormDict &globals) { |
aoqi@0 | 866 | assert( false, "InstructForm::out_reg_class(FormDict &globals); Not Implemented"); |
aoqi@0 | 867 | |
aoqi@0 | 868 | return NULL; |
aoqi@0 | 869 | } |
aoqi@0 | 870 | |
aoqi@0 | 871 | |
aoqi@0 | 872 | |
aoqi@0 | 873 | // Lookup the starting position of inputs we are interested in wrt. ideal nodes |
aoqi@0 | 874 | uint InstructForm::oper_input_base(FormDict &globals) { |
aoqi@0 | 875 | if( !_matrule ) return 1; // Skip control for most nodes |
aoqi@0 | 876 | |
aoqi@0 | 877 | // Need special handling for matching some ideal nodes |
aoqi@0 | 878 | // i.e. Matching a return node |
aoqi@0 | 879 | if( strcmp(_matrule->_opType,"Return" )==0 || |
aoqi@0 | 880 | strcmp(_matrule->_opType,"Rethrow" )==0 || |
aoqi@0 | 881 | strcmp(_matrule->_opType,"TailCall" )==0 || |
aoqi@0 | 882 | strcmp(_matrule->_opType,"TailJump" )==0 || |
aoqi@0 | 883 | strcmp(_matrule->_opType,"SafePoint" )==0 || |
aoqi@0 | 884 | strcmp(_matrule->_opType,"Halt" )==0 ) |
aoqi@0 | 885 | return AdlcVMDeps::Parms; // Skip the machine-state edges |
aoqi@0 | 886 | |
aoqi@0 | 887 | if( _matrule->_rChild && |
aoqi@0 | 888 | ( strcmp(_matrule->_rChild->_opType,"AryEq" )==0 || |
aoqi@0 | 889 | strcmp(_matrule->_rChild->_opType,"StrComp" )==0 || |
aoqi@0 | 890 | strcmp(_matrule->_rChild->_opType,"StrEquals" )==0 || |
aoqi@0 | 891 | strcmp(_matrule->_rChild->_opType,"StrIndexOf")==0 || |
aoqi@0 | 892 | strcmp(_matrule->_rChild->_opType,"EncodeISOArray")==0)) { |
aoqi@0 | 893 | // String.(compareTo/equals/indexOf) and Arrays.equals |
aoqi@0 | 894 | // and sun.nio.cs.iso8859_1$Encoder.EncodeISOArray |
aoqi@0 | 895 | // take 1 control and 1 memory edges. |
aoqi@0 | 896 | return 2; |
aoqi@0 | 897 | } |
aoqi@0 | 898 | |
aoqi@0 | 899 | // Check for handling of 'Memory' input/edge in the ideal world. |
aoqi@0 | 900 | // The AD file writer is shielded from knowledge of these edges. |
aoqi@0 | 901 | int base = 1; // Skip control |
aoqi@0 | 902 | base += _matrule->needs_ideal_memory_edge(globals); |
aoqi@0 | 903 | |
aoqi@0 | 904 | // Also skip the base-oop value for uses of derived oops. |
aoqi@0 | 905 | // The AD file writer is shielded from knowledge of these edges. |
aoqi@0 | 906 | base += needs_base_oop_edge(globals); |
aoqi@0 | 907 | |
aoqi@0 | 908 | return base; |
aoqi@0 | 909 | } |
aoqi@0 | 910 | |
aoqi@0 | 911 | // This function determines the order of the MachOper in _opnds[] |
aoqi@0 | 912 | // by writing the operand names into the _components list. |
aoqi@0 | 913 | // |
aoqi@0 | 914 | // Implementation does not modify state of internal structures |
aoqi@0 | 915 | void InstructForm::build_components() { |
aoqi@0 | 916 | // Add top-level operands to the components |
aoqi@0 | 917 | if (_matrule) _matrule->append_components(_localNames, _components); |
aoqi@0 | 918 | |
aoqi@0 | 919 | // Add parameters that "do not appear in match rule". |
aoqi@0 | 920 | bool has_temp = false; |
aoqi@0 | 921 | const char *name; |
aoqi@0 | 922 | const char *kill_name = NULL; |
aoqi@0 | 923 | for (_parameters.reset(); (name = _parameters.iter()) != NULL;) { |
aoqi@0 | 924 | OperandForm *opForm = (OperandForm*)_localNames[name]; |
aoqi@0 | 925 | |
aoqi@0 | 926 | Effect* e = NULL; |
aoqi@0 | 927 | { |
aoqi@0 | 928 | const Form* form = _effects[name]; |
aoqi@0 | 929 | e = form ? form->is_effect() : NULL; |
aoqi@0 | 930 | } |
aoqi@0 | 931 | |
aoqi@0 | 932 | if (e != NULL) { |
aoqi@0 | 933 | has_temp |= e->is(Component::TEMP); |
aoqi@0 | 934 | |
aoqi@0 | 935 | // KILLs must be declared after any TEMPs because TEMPs are real |
aoqi@0 | 936 | // uses so their operand numbering must directly follow the real |
aoqi@0 | 937 | // inputs from the match rule. Fixing the numbering seems |
aoqi@0 | 938 | // complex so simply enforce the restriction during parse. |
aoqi@0 | 939 | if (kill_name != NULL && |
aoqi@0 | 940 | e->isa(Component::TEMP) && !e->isa(Component::DEF)) { |
aoqi@0 | 941 | OperandForm* kill = (OperandForm*)_localNames[kill_name]; |
aoqi@0 | 942 | globalAD->syntax_err(_linenum, "%s: %s %s must be at the end of the argument list\n", |
aoqi@0 | 943 | _ident, kill->_ident, kill_name); |
aoqi@0 | 944 | } else if (e->isa(Component::KILL) && !e->isa(Component::USE)) { |
aoqi@0 | 945 | kill_name = name; |
aoqi@0 | 946 | } |
aoqi@0 | 947 | } |
aoqi@0 | 948 | |
aoqi@0 | 949 | const Component *component = _components.search(name); |
aoqi@0 | 950 | if ( component == NULL ) { |
aoqi@0 | 951 | if (e) { |
aoqi@0 | 952 | _components.insert(name, opForm->_ident, e->_use_def, false); |
aoqi@0 | 953 | component = _components.search(name); |
aoqi@0 | 954 | if (component->isa(Component::USE) && !component->isa(Component::TEMP) && _matrule) { |
aoqi@0 | 955 | const Form *form = globalAD->globalNames()[component->_type]; |
aoqi@0 | 956 | assert( form, "component type must be a defined form"); |
aoqi@0 | 957 | OperandForm *op = form->is_operand(); |
aoqi@0 | 958 | if (op->_interface && op->_interface->is_RegInterface()) { |
aoqi@0 | 959 | globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n", |
aoqi@0 | 960 | _ident, opForm->_ident, name); |
aoqi@0 | 961 | } |
aoqi@0 | 962 | } |
aoqi@0 | 963 | } else { |
aoqi@0 | 964 | // This would be a nice warning but it triggers in a few places in a benign way |
aoqi@0 | 965 | // if (_matrule != NULL && !expands()) { |
aoqi@0 | 966 | // globalAD->syntax_err(_linenum, "%s: %s %s not mentioned in effect or match rule\n", |
aoqi@0 | 967 | // _ident, opForm->_ident, name); |
aoqi@0 | 968 | // } |
aoqi@0 | 969 | _components.insert(name, opForm->_ident, Component::INVALID, false); |
aoqi@0 | 970 | } |
aoqi@0 | 971 | } |
aoqi@0 | 972 | else if (e) { |
aoqi@0 | 973 | // Component was found in the list |
aoqi@0 | 974 | // Check if there is a new effect that requires an extra component. |
aoqi@0 | 975 | // This happens when adding 'USE' to a component that is not yet one. |
aoqi@0 | 976 | if ((!component->isa( Component::USE) && ((e->_use_def & Component::USE) != 0))) { |
aoqi@0 | 977 | if (component->isa(Component::USE) && _matrule) { |
aoqi@0 | 978 | const Form *form = globalAD->globalNames()[component->_type]; |
aoqi@0 | 979 | assert( form, "component type must be a defined form"); |
aoqi@0 | 980 | OperandForm *op = form->is_operand(); |
aoqi@0 | 981 | if (op->_interface && op->_interface->is_RegInterface()) { |
aoqi@0 | 982 | globalAD->syntax_err(_linenum, "%s: illegal USE of non-input: %s %s\n", |
aoqi@0 | 983 | _ident, opForm->_ident, name); |
aoqi@0 | 984 | } |
aoqi@0 | 985 | } |
aoqi@0 | 986 | _components.insert(name, opForm->_ident, e->_use_def, false); |
aoqi@0 | 987 | } else { |
aoqi@0 | 988 | Component *comp = (Component*)component; |
aoqi@0 | 989 | comp->promote_use_def_info(e->_use_def); |
aoqi@0 | 990 | } |
aoqi@0 | 991 | // Component positions are zero based. |
aoqi@0 | 992 | int pos = _components.operand_position(name); |
aoqi@0 | 993 | assert( ! (component->isa(Component::DEF) && (pos >= 1)), |
aoqi@0 | 994 | "Component::DEF can only occur in the first position"); |
aoqi@0 | 995 | } |
aoqi@0 | 996 | } |
aoqi@0 | 997 | |
aoqi@0 | 998 | // Resolving the interactions between expand rules and TEMPs would |
aoqi@0 | 999 | // be complex so simply disallow it. |
aoqi@0 | 1000 | if (_matrule == NULL && has_temp) { |
aoqi@0 | 1001 | globalAD->syntax_err(_linenum, "%s: TEMPs without match rule isn't supported\n", _ident); |
aoqi@0 | 1002 | } |
aoqi@0 | 1003 | |
aoqi@0 | 1004 | return; |
aoqi@0 | 1005 | } |
aoqi@0 | 1006 | |
aoqi@0 | 1007 | // Return zero-based position in component list; -1 if not in list. |
aoqi@0 | 1008 | int InstructForm::operand_position(const char *name, int usedef) { |
aoqi@0 | 1009 | return unique_opnds_idx(_components.operand_position(name, usedef, this)); |
aoqi@0 | 1010 | } |
aoqi@0 | 1011 | |
aoqi@0 | 1012 | int InstructForm::operand_position_format(const char *name) { |
aoqi@0 | 1013 | return unique_opnds_idx(_components.operand_position_format(name, this)); |
aoqi@0 | 1014 | } |
aoqi@0 | 1015 | |
aoqi@0 | 1016 | // Return zero-based position in component list; -1 if not in list. |
aoqi@0 | 1017 | int InstructForm::label_position() { |
aoqi@0 | 1018 | return unique_opnds_idx(_components.label_position()); |
aoqi@0 | 1019 | } |
aoqi@0 | 1020 | |
aoqi@0 | 1021 | int InstructForm::method_position() { |
aoqi@0 | 1022 | return unique_opnds_idx(_components.method_position()); |
aoqi@0 | 1023 | } |
aoqi@0 | 1024 | |
aoqi@0 | 1025 | // Return number of relocation entries needed for this instruction. |
aoqi@0 | 1026 | uint InstructForm::reloc(FormDict &globals) { |
aoqi@0 | 1027 | uint reloc_entries = 0; |
aoqi@0 | 1028 | // Check for "Call" nodes |
aoqi@0 | 1029 | if ( is_ideal_call() ) ++reloc_entries; |
aoqi@0 | 1030 | if ( is_ideal_return() ) ++reloc_entries; |
aoqi@0 | 1031 | if ( is_ideal_safepoint() ) ++reloc_entries; |
aoqi@0 | 1032 | |
aoqi@0 | 1033 | |
aoqi@0 | 1034 | // Check if operands MAYBE oop pointers, by checking for ConP elements |
aoqi@0 | 1035 | // Proceed through the leaves of the match-tree and check for ConPs |
aoqi@0 | 1036 | if ( _matrule != NULL ) { |
aoqi@0 | 1037 | uint position = 0; |
aoqi@0 | 1038 | const char *result = NULL; |
aoqi@0 | 1039 | const char *name = NULL; |
aoqi@0 | 1040 | const char *opType = NULL; |
aoqi@0 | 1041 | while (_matrule->base_operand(position, globals, result, name, opType)) { |
aoqi@0 | 1042 | if ( strcmp(opType,"ConP") == 0 ) { |
aoqi@0 | 1043 | #ifdef SPARC |
aoqi@0 | 1044 | reloc_entries += 2; // 1 for sethi + 1 for setlo |
aoqi@0 | 1045 | #else |
aoqi@0 | 1046 | ++reloc_entries; |
aoqi@0 | 1047 | #endif |
aoqi@0 | 1048 | } |
aoqi@0 | 1049 | ++position; |
aoqi@0 | 1050 | } |
aoqi@0 | 1051 | } |
aoqi@0 | 1052 | |
aoqi@0 | 1053 | // Above is only a conservative estimate |
aoqi@0 | 1054 | // because it did not check contents of operand classes. |
aoqi@0 | 1055 | // !!!!! !!!!! |
aoqi@0 | 1056 | // Add 1 to reloc info for each operand class in the component list. |
aoqi@0 | 1057 | Component *comp; |
aoqi@0 | 1058 | _components.reset(); |
aoqi@0 | 1059 | while ( (comp = _components.iter()) != NULL ) { |
aoqi@0 | 1060 | const Form *form = globals[comp->_type]; |
aoqi@0 | 1061 | assert( form, "Did not find component's type in global names"); |
aoqi@0 | 1062 | const OpClassForm *opc = form->is_opclass(); |
aoqi@0 | 1063 | const OperandForm *oper = form->is_operand(); |
aoqi@0 | 1064 | if ( opc && (oper == NULL) ) { |
aoqi@0 | 1065 | ++reloc_entries; |
aoqi@0 | 1066 | } else if ( oper ) { |
aoqi@0 | 1067 | // floats and doubles loaded out of method's constant pool require reloc info |
aoqi@0 | 1068 | Form::DataType type = oper->is_base_constant(globals); |
aoqi@0 | 1069 | if ( (type == Form::idealF) || (type == Form::idealD) ) { |
aoqi@0 | 1070 | ++reloc_entries; |
aoqi@0 | 1071 | } |
aoqi@0 | 1072 | } |
aoqi@0 | 1073 | } |
aoqi@0 | 1074 | |
aoqi@0 | 1075 | // Float and Double constants may come from the CodeBuffer table |
aoqi@0 | 1076 | // and require relocatable addresses for access |
aoqi@0 | 1077 | // !!!!! |
aoqi@0 | 1078 | // Check for any component being an immediate float or double. |
aoqi@0 | 1079 | Form::DataType data_type = is_chain_of_constant(globals); |
aoqi@0 | 1080 | if( data_type==idealD || data_type==idealF ) { |
aoqi@0 | 1081 | #ifdef SPARC |
aoqi@0 | 1082 | // sparc required more relocation entries for floating constants |
aoqi@0 | 1083 | // (expires 9/98) |
aoqi@0 | 1084 | reloc_entries += 6; |
aoqi@0 | 1085 | #else |
aoqi@0 | 1086 | reloc_entries++; |
aoqi@0 | 1087 | #endif |
aoqi@0 | 1088 | } |
aoqi@0 | 1089 | |
aoqi@0 | 1090 | return reloc_entries; |
aoqi@0 | 1091 | } |
aoqi@0 | 1092 | |
aoqi@0 | 1093 | // Utility function defined in archDesc.cpp |
aoqi@0 | 1094 | extern bool is_def(int usedef); |
aoqi@0 | 1095 | |
aoqi@0 | 1096 | // Return the result of reducing an instruction |
aoqi@0 | 1097 | const char *InstructForm::reduce_result() { |
aoqi@0 | 1098 | const char* result = "Universe"; // default |
aoqi@0 | 1099 | _components.reset(); |
aoqi@0 | 1100 | Component *comp = _components.iter(); |
aoqi@0 | 1101 | if (comp != NULL && comp->isa(Component::DEF)) { |
aoqi@0 | 1102 | result = comp->_type; |
aoqi@0 | 1103 | // Override this if the rule is a store operation: |
aoqi@0 | 1104 | if (_matrule && _matrule->_rChild && |
aoqi@0 | 1105 | is_store_to_memory(_matrule->_rChild->_opType)) |
aoqi@0 | 1106 | result = "Universe"; |
aoqi@0 | 1107 | } |
aoqi@0 | 1108 | return result; |
aoqi@0 | 1109 | } |
aoqi@0 | 1110 | |
aoqi@0 | 1111 | // Return the name of the operand on the right hand side of the binary match |
aoqi@0 | 1112 | // Return NULL if there is no right hand side |
aoqi@0 | 1113 | const char *InstructForm::reduce_right(FormDict &globals) const { |
aoqi@0 | 1114 | if( _matrule == NULL ) return NULL; |
aoqi@0 | 1115 | return _matrule->reduce_right(globals); |
aoqi@0 | 1116 | } |
aoqi@0 | 1117 | |
aoqi@0 | 1118 | // Similar for left |
aoqi@0 | 1119 | const char *InstructForm::reduce_left(FormDict &globals) const { |
aoqi@0 | 1120 | if( _matrule == NULL ) return NULL; |
aoqi@0 | 1121 | return _matrule->reduce_left(globals); |
aoqi@0 | 1122 | } |
aoqi@0 | 1123 | |
aoqi@0 | 1124 | |
aoqi@0 | 1125 | // Base class for this instruction, MachNode except for calls |
aoqi@0 | 1126 | const char *InstructForm::mach_base_class(FormDict &globals) const { |
aoqi@0 | 1127 | if( is_ideal_call() == Form::JAVA_STATIC ) { |
aoqi@0 | 1128 | return "MachCallStaticJavaNode"; |
aoqi@0 | 1129 | } |
aoqi@0 | 1130 | else if( is_ideal_call() == Form::JAVA_DYNAMIC ) { |
aoqi@0 | 1131 | return "MachCallDynamicJavaNode"; |
aoqi@0 | 1132 | } |
aoqi@0 | 1133 | else if( is_ideal_call() == Form::JAVA_RUNTIME ) { |
aoqi@0 | 1134 | return "MachCallRuntimeNode"; |
aoqi@0 | 1135 | } |
aoqi@0 | 1136 | else if( is_ideal_call() == Form::JAVA_LEAF ) { |
aoqi@0 | 1137 | return "MachCallLeafNode"; |
aoqi@0 | 1138 | } |
aoqi@0 | 1139 | else if (is_ideal_return()) { |
aoqi@0 | 1140 | return "MachReturnNode"; |
aoqi@0 | 1141 | } |
aoqi@0 | 1142 | else if (is_ideal_halt()) { |
aoqi@0 | 1143 | return "MachHaltNode"; |
aoqi@0 | 1144 | } |
aoqi@0 | 1145 | else if (is_ideal_safepoint()) { |
aoqi@0 | 1146 | return "MachSafePointNode"; |
aoqi@0 | 1147 | } |
aoqi@0 | 1148 | else if (is_ideal_if()) { |
aoqi@0 | 1149 | return "MachIfNode"; |
aoqi@0 | 1150 | } |
aoqi@0 | 1151 | else if (is_ideal_goto()) { |
aoqi@0 | 1152 | return "MachGotoNode"; |
aoqi@0 | 1153 | } |
aoqi@0 | 1154 | else if (is_ideal_fastlock()) { |
aoqi@0 | 1155 | return "MachFastLockNode"; |
aoqi@0 | 1156 | } |
aoqi@0 | 1157 | else if (is_ideal_nop()) { |
aoqi@0 | 1158 | return "MachNopNode"; |
aoqi@0 | 1159 | } |
aoqi@0 | 1160 | else if (is_mach_constant()) { |
aoqi@0 | 1161 | return "MachConstantNode"; |
aoqi@0 | 1162 | } |
aoqi@0 | 1163 | else if (captures_bottom_type(globals)) { |
aoqi@0 | 1164 | return "MachTypeNode"; |
aoqi@0 | 1165 | } else { |
aoqi@0 | 1166 | return "MachNode"; |
aoqi@0 | 1167 | } |
aoqi@0 | 1168 | assert( false, "ShouldNotReachHere()"); |
aoqi@0 | 1169 | return NULL; |
aoqi@0 | 1170 | } |
aoqi@0 | 1171 | |
aoqi@0 | 1172 | // Compare the instruction predicates for textual equality |
aoqi@0 | 1173 | bool equivalent_predicates( const InstructForm *instr1, const InstructForm *instr2 ) { |
aoqi@0 | 1174 | const Predicate *pred1 = instr1->_predicate; |
aoqi@0 | 1175 | const Predicate *pred2 = instr2->_predicate; |
aoqi@0 | 1176 | if( pred1 == NULL && pred2 == NULL ) { |
aoqi@0 | 1177 | // no predicates means they are identical |
aoqi@0 | 1178 | return true; |
aoqi@0 | 1179 | } |
aoqi@0 | 1180 | if( pred1 != NULL && pred2 != NULL ) { |
aoqi@0 | 1181 | // compare the predicates |
aoqi@0 | 1182 | if (ADLParser::equivalent_expressions(pred1->_pred, pred2->_pred)) { |
aoqi@0 | 1183 | return true; |
aoqi@0 | 1184 | } |
aoqi@0 | 1185 | } |
aoqi@0 | 1186 | |
aoqi@0 | 1187 | return false; |
aoqi@0 | 1188 | } |
aoqi@0 | 1189 | |
aoqi@0 | 1190 | // Check if this instruction can cisc-spill to 'alternate' |
aoqi@0 | 1191 | bool InstructForm::cisc_spills_to(ArchDesc &AD, InstructForm *instr) { |
aoqi@0 | 1192 | assert( _matrule != NULL && instr->_matrule != NULL, "must have match rules"); |
aoqi@0 | 1193 | // Do not replace if a cisc-version has been found. |
aoqi@0 | 1194 | if( cisc_spill_operand() != Not_cisc_spillable ) return false; |
aoqi@0 | 1195 | |
aoqi@0 | 1196 | int cisc_spill_operand = Maybe_cisc_spillable; |
aoqi@0 | 1197 | char *result = NULL; |
aoqi@0 | 1198 | char *result2 = NULL; |
aoqi@0 | 1199 | const char *op_name = NULL; |
aoqi@0 | 1200 | const char *reg_type = NULL; |
aoqi@0 | 1201 | FormDict &globals = AD.globalNames(); |
aoqi@0 | 1202 | cisc_spill_operand = _matrule->matchrule_cisc_spill_match(globals, AD.get_registers(), instr->_matrule, op_name, reg_type); |
aoqi@0 | 1203 | if( (cisc_spill_operand != Not_cisc_spillable) && (op_name != NULL) && equivalent_predicates(this, instr) ) { |
aoqi@0 | 1204 | cisc_spill_operand = operand_position(op_name, Component::USE); |
aoqi@0 | 1205 | int def_oper = operand_position(op_name, Component::DEF); |
aoqi@0 | 1206 | if( def_oper == NameList::Not_in_list && instr->num_opnds() == num_opnds()) { |
aoqi@0 | 1207 | // Do not support cisc-spilling for destination operands and |
aoqi@0 | 1208 | // make sure they have the same number of operands. |
aoqi@0 | 1209 | _cisc_spill_alternate = instr; |
aoqi@0 | 1210 | instr->set_cisc_alternate(true); |
aoqi@0 | 1211 | if( AD._cisc_spill_debug ) { |
aoqi@0 | 1212 | fprintf(stderr, "Instruction %s cisc-spills-to %s\n", _ident, instr->_ident); |
aoqi@0 | 1213 | fprintf(stderr, " using operand %s %s at index %d\n", reg_type, op_name, cisc_spill_operand); |
aoqi@0 | 1214 | } |
aoqi@0 | 1215 | // Record that a stack-version of the reg_mask is needed |
aoqi@0 | 1216 | // !!!!! |
aoqi@0 | 1217 | OperandForm *oper = (OperandForm*)(globals[reg_type]->is_operand()); |
aoqi@0 | 1218 | assert( oper != NULL, "cisc-spilling non operand"); |
aoqi@0 | 1219 | const char *reg_class_name = oper->constrained_reg_class(); |
aoqi@0 | 1220 | AD.set_stack_or_reg(reg_class_name); |
aoqi@0 | 1221 | const char *reg_mask_name = AD.reg_mask(*oper); |
aoqi@0 | 1222 | set_cisc_reg_mask_name(reg_mask_name); |
aoqi@0 | 1223 | const char *stack_or_reg_mask_name = AD.stack_or_reg_mask(*oper); |
aoqi@0 | 1224 | } else { |
aoqi@0 | 1225 | cisc_spill_operand = Not_cisc_spillable; |
aoqi@0 | 1226 | } |
aoqi@0 | 1227 | } else { |
aoqi@0 | 1228 | cisc_spill_operand = Not_cisc_spillable; |
aoqi@0 | 1229 | } |
aoqi@0 | 1230 | |
aoqi@0 | 1231 | set_cisc_spill_operand(cisc_spill_operand); |
aoqi@0 | 1232 | return (cisc_spill_operand != Not_cisc_spillable); |
aoqi@0 | 1233 | } |
aoqi@0 | 1234 | |
aoqi@0 | 1235 | // Check to see if this instruction can be replaced with the short branch |
aoqi@0 | 1236 | // instruction `short-branch' |
aoqi@0 | 1237 | bool InstructForm::check_branch_variant(ArchDesc &AD, InstructForm *short_branch) { |
aoqi@0 | 1238 | if (_matrule != NULL && |
aoqi@0 | 1239 | this != short_branch && // Don't match myself |
aoqi@0 | 1240 | !is_short_branch() && // Don't match another short branch variant |
aoqi@0 | 1241 | reduce_result() != NULL && |
aoqi@0 | 1242 | strcmp(reduce_result(), short_branch->reduce_result()) == 0 && |
aoqi@0 | 1243 | _matrule->equivalent(AD.globalNames(), short_branch->_matrule)) { |
aoqi@0 | 1244 | // The instructions are equivalent. |
aoqi@0 | 1245 | |
aoqi@0 | 1246 | // Now verify that both instructions have the same parameters and |
aoqi@0 | 1247 | // the same effects. Both branch forms should have the same inputs |
aoqi@0 | 1248 | // and resulting projections to correctly replace a long branch node |
aoqi@0 | 1249 | // with corresponding short branch node during code generation. |
aoqi@0 | 1250 | |
aoqi@0 | 1251 | bool different = false; |
aoqi@0 | 1252 | if (short_branch->_components.count() != _components.count()) { |
aoqi@0 | 1253 | different = true; |
aoqi@0 | 1254 | } else if (_components.count() > 0) { |
aoqi@0 | 1255 | short_branch->_components.reset(); |
aoqi@0 | 1256 | _components.reset(); |
aoqi@0 | 1257 | Component *comp; |
aoqi@0 | 1258 | while ((comp = _components.iter()) != NULL) { |
aoqi@0 | 1259 | Component *short_comp = short_branch->_components.iter(); |
aoqi@0 | 1260 | if (short_comp == NULL || |
aoqi@0 | 1261 | short_comp->_type != comp->_type || |
aoqi@0 | 1262 | short_comp->_usedef != comp->_usedef) { |
aoqi@0 | 1263 | different = true; |
aoqi@0 | 1264 | break; |
aoqi@0 | 1265 | } |
aoqi@0 | 1266 | } |
aoqi@0 | 1267 | if (short_branch->_components.iter() != NULL) |
aoqi@0 | 1268 | different = true; |
aoqi@0 | 1269 | } |
aoqi@0 | 1270 | if (different) { |
aoqi@0 | 1271 | globalAD->syntax_err(short_branch->_linenum, "Instruction %s and its short form %s have different parameters\n", _ident, short_branch->_ident); |
aoqi@0 | 1272 | } |
aoqi@0 | 1273 | if (AD._adl_debug > 1 || AD._short_branch_debug) { |
aoqi@0 | 1274 | fprintf(stderr, "Instruction %s has short form %s\n", _ident, short_branch->_ident); |
aoqi@0 | 1275 | } |
aoqi@0 | 1276 | _short_branch_form = short_branch; |
aoqi@0 | 1277 | return true; |
aoqi@0 | 1278 | } |
aoqi@0 | 1279 | return false; |
aoqi@0 | 1280 | } |
aoqi@0 | 1281 | |
aoqi@0 | 1282 | |
aoqi@0 | 1283 | // --------------------------- FILE *output_routines |
aoqi@0 | 1284 | // |
aoqi@0 | 1285 | // Generate the format call for the replacement variable |
aoqi@0 | 1286 | void InstructForm::rep_var_format(FILE *fp, const char *rep_var) { |
aoqi@0 | 1287 | // Handle special constant table variables. |
aoqi@0 | 1288 | if (strcmp(rep_var, "constanttablebase") == 0) { |
aoqi@0 | 1289 | fprintf(fp, "char reg[128]; ra->dump_register(in(mach_constant_base_node_input()), reg);\n"); |
aoqi@0 | 1290 | fprintf(fp, " st->print(\"%%s\", reg);\n"); |
aoqi@0 | 1291 | return; |
aoqi@0 | 1292 | } |
aoqi@0 | 1293 | if (strcmp(rep_var, "constantoffset") == 0) { |
aoqi@0 | 1294 | fprintf(fp, "st->print(\"#%%d\", constant_offset_unchecked());\n"); |
aoqi@0 | 1295 | return; |
aoqi@0 | 1296 | } |
aoqi@0 | 1297 | if (strcmp(rep_var, "constantaddress") == 0) { |
aoqi@0 | 1298 | fprintf(fp, "st->print(\"constant table base + #%%d\", constant_offset_unchecked());\n"); |
aoqi@0 | 1299 | return; |
aoqi@0 | 1300 | } |
aoqi@0 | 1301 | |
aoqi@0 | 1302 | // Find replacement variable's type |
aoqi@0 | 1303 | const Form *form = _localNames[rep_var]; |
aoqi@0 | 1304 | if (form == NULL) { |
aoqi@0 | 1305 | globalAD->syntax_err(_linenum, "Unknown replacement variable %s in format statement of %s.", |
aoqi@0 | 1306 | rep_var, _ident); |
aoqi@0 | 1307 | return; |
aoqi@0 | 1308 | } |
aoqi@0 | 1309 | OpClassForm *opc = form->is_opclass(); |
aoqi@0 | 1310 | assert( opc, "replacement variable was not found in local names"); |
aoqi@0 | 1311 | // Lookup the index position of the replacement variable |
aoqi@0 | 1312 | int idx = operand_position_format(rep_var); |
aoqi@0 | 1313 | if ( idx == -1 ) { |
aoqi@0 | 1314 | globalAD->syntax_err(_linenum, "Could not find replacement variable %s in format statement of %s.\n", |
aoqi@0 | 1315 | rep_var, _ident); |
aoqi@0 | 1316 | assert(strcmp(opc->_ident, "label") == 0, "Unimplemented"); |
aoqi@0 | 1317 | return; |
aoqi@0 | 1318 | } |
aoqi@0 | 1319 | |
aoqi@0 | 1320 | if (is_noninput_operand(idx)) { |
aoqi@0 | 1321 | // This component isn't in the input array. Print out the static |
aoqi@0 | 1322 | // name of the register. |
aoqi@0 | 1323 | OperandForm* oper = form->is_operand(); |
aoqi@0 | 1324 | if (oper != NULL && oper->is_bound_register()) { |
aoqi@0 | 1325 | const RegDef* first = oper->get_RegClass()->find_first_elem(); |
aoqi@0 | 1326 | fprintf(fp, " st->print_raw(\"%s\");\n", first->_regname); |
aoqi@0 | 1327 | } else { |
aoqi@0 | 1328 | globalAD->syntax_err(_linenum, "In %s can't find format for %s %s", _ident, opc->_ident, rep_var); |
aoqi@0 | 1329 | } |
aoqi@0 | 1330 | } else { |
aoqi@0 | 1331 | // Output the format call for this operand |
aoqi@0 | 1332 | fprintf(fp,"opnd_array(%d)->",idx); |
aoqi@0 | 1333 | if (idx == 0) |
aoqi@0 | 1334 | fprintf(fp,"int_format(ra, this, st); // %s\n", rep_var); |
aoqi@0 | 1335 | else |
aoqi@0 | 1336 | fprintf(fp,"ext_format(ra, this,idx%d, st); // %s\n", idx, rep_var ); |
aoqi@0 | 1337 | } |
aoqi@0 | 1338 | } |
aoqi@0 | 1339 | |
aoqi@0 | 1340 | // Seach through operands to determine parameters unique positions. |
aoqi@0 | 1341 | void InstructForm::set_unique_opnds() { |
aoqi@0 | 1342 | uint* uniq_idx = NULL; |
aoqi@0 | 1343 | uint nopnds = num_opnds(); |
aoqi@0 | 1344 | uint num_uniq = nopnds; |
aoqi@0 | 1345 | uint i; |
aoqi@0 | 1346 | _uniq_idx_length = 0; |
aoqi@0 | 1347 | if (nopnds > 0) { |
aoqi@0 | 1348 | // Allocate index array. Worst case we're mapping from each |
aoqi@0 | 1349 | // component back to an index and any DEF always goes at 0 so the |
aoqi@0 | 1350 | // length of the array has to be the number of components + 1. |
aoqi@0 | 1351 | _uniq_idx_length = _components.count() + 1; |
aoqi@0 | 1352 | uniq_idx = (uint*) malloc(sizeof(uint) * _uniq_idx_length); |
aoqi@0 | 1353 | for (i = 0; i < _uniq_idx_length; i++) { |
aoqi@0 | 1354 | uniq_idx[i] = i; |
aoqi@0 | 1355 | } |
aoqi@0 | 1356 | } |
aoqi@0 | 1357 | // Do it only if there is a match rule and no expand rule. With an |
aoqi@0 | 1358 | // expand rule it is done by creating new mach node in Expand() |
aoqi@0 | 1359 | // method. |
aoqi@0 | 1360 | if (nopnds > 0 && _matrule != NULL && _exprule == NULL) { |
aoqi@0 | 1361 | const char *name; |
aoqi@0 | 1362 | uint count; |
aoqi@0 | 1363 | bool has_dupl_use = false; |
aoqi@0 | 1364 | |
aoqi@0 | 1365 | _parameters.reset(); |
aoqi@0 | 1366 | while ((name = _parameters.iter()) != NULL) { |
aoqi@0 | 1367 | count = 0; |
aoqi@0 | 1368 | uint position = 0; |
aoqi@0 | 1369 | uint uniq_position = 0; |
aoqi@0 | 1370 | _components.reset(); |
aoqi@0 | 1371 | Component *comp = NULL; |
aoqi@0 | 1372 | if (sets_result()) { |
aoqi@0 | 1373 | comp = _components.iter(); |
aoqi@0 | 1374 | position++; |
aoqi@0 | 1375 | } |
aoqi@0 | 1376 | // The next code is copied from the method operand_position(). |
aoqi@0 | 1377 | for (; (comp = _components.iter()) != NULL; ++position) { |
aoqi@0 | 1378 | // When the first component is not a DEF, |
aoqi@0 | 1379 | // leave space for the result operand! |
aoqi@0 | 1380 | if (position==0 && (!comp->isa(Component::DEF))) { |
aoqi@0 | 1381 | ++position; |
aoqi@0 | 1382 | } |
aoqi@0 | 1383 | if (strcmp(name, comp->_name) == 0) { |
aoqi@0 | 1384 | if (++count > 1) { |
aoqi@0 | 1385 | assert(position < _uniq_idx_length, "out of bounds"); |
aoqi@0 | 1386 | uniq_idx[position] = uniq_position; |
aoqi@0 | 1387 | has_dupl_use = true; |
aoqi@0 | 1388 | } else { |
aoqi@0 | 1389 | uniq_position = position; |
aoqi@0 | 1390 | } |
aoqi@0 | 1391 | } |
aoqi@0 | 1392 | if (comp->isa(Component::DEF) && comp->isa(Component::USE)) { |
aoqi@0 | 1393 | ++position; |
aoqi@0 | 1394 | if (position != 1) |
aoqi@0 | 1395 | --position; // only use two slots for the 1st USE_DEF |
aoqi@0 | 1396 | } |
aoqi@0 | 1397 | } |
aoqi@0 | 1398 | } |
aoqi@0 | 1399 | if (has_dupl_use) { |
aoqi@0 | 1400 | for (i = 1; i < nopnds; i++) { |
aoqi@0 | 1401 | if (i != uniq_idx[i]) { |
aoqi@0 | 1402 | break; |
aoqi@0 | 1403 | } |
aoqi@0 | 1404 | } |
aoqi@0 | 1405 | uint j = i; |
aoqi@0 | 1406 | for (; i < nopnds; i++) { |
aoqi@0 | 1407 | if (i == uniq_idx[i]) { |
aoqi@0 | 1408 | uniq_idx[i] = j++; |
aoqi@0 | 1409 | } |
aoqi@0 | 1410 | } |
aoqi@0 | 1411 | num_uniq = j; |
aoqi@0 | 1412 | } |
aoqi@0 | 1413 | } |
aoqi@0 | 1414 | _uniq_idx = uniq_idx; |
aoqi@0 | 1415 | _num_uniq = num_uniq; |
aoqi@0 | 1416 | } |
aoqi@0 | 1417 | |
aoqi@0 | 1418 | // Generate index values needed for determining the operand position |
aoqi@0 | 1419 | void InstructForm::index_temps(FILE *fp, FormDict &globals, const char *prefix, const char *receiver) { |
aoqi@0 | 1420 | uint idx = 0; // position of operand in match rule |
aoqi@0 | 1421 | int cur_num_opnds = num_opnds(); |
aoqi@0 | 1422 | |
aoqi@0 | 1423 | // Compute the index into vector of operand pointers: |
aoqi@0 | 1424 | // idx0=0 is used to indicate that info comes from this same node, not from input edge. |
aoqi@0 | 1425 | // idx1 starts at oper_input_base() |
aoqi@0 | 1426 | if ( cur_num_opnds >= 1 ) { |
aoqi@0 | 1427 | fprintf(fp," // Start at oper_input_base() and count operands\n"); |
aoqi@0 | 1428 | fprintf(fp," unsigned %sidx0 = %d;\n", prefix, oper_input_base(globals)); |
aoqi@0 | 1429 | fprintf(fp," unsigned %sidx1 = %d;", prefix, oper_input_base(globals)); |
aoqi@0 | 1430 | fprintf(fp," \t// %s\n", unique_opnd_ident(1)); |
aoqi@0 | 1431 | |
aoqi@0 | 1432 | // Generate starting points for other unique operands if they exist |
aoqi@0 | 1433 | for ( idx = 2; idx < num_unique_opnds(); ++idx ) { |
aoqi@0 | 1434 | if( *receiver == 0 ) { |
aoqi@0 | 1435 | fprintf(fp," unsigned %sidx%d = %sidx%d + opnd_array(%d)->num_edges();", |
aoqi@0 | 1436 | prefix, idx, prefix, idx-1, idx-1 ); |
aoqi@0 | 1437 | } else { |
aoqi@0 | 1438 | fprintf(fp," unsigned %sidx%d = %sidx%d + %s_opnds[%d]->num_edges();", |
aoqi@0 | 1439 | prefix, idx, prefix, idx-1, receiver, idx-1 ); |
aoqi@0 | 1440 | } |
aoqi@0 | 1441 | fprintf(fp," \t// %s\n", unique_opnd_ident(idx)); |
aoqi@0 | 1442 | } |
aoqi@0 | 1443 | } |
aoqi@0 | 1444 | if( *receiver != 0 ) { |
aoqi@0 | 1445 | // This value is used by generate_peepreplace when copying a node. |
aoqi@0 | 1446 | // Don't emit it in other cases since it can hide bugs with the |
aoqi@0 | 1447 | // use invalid idx's. |
aoqi@0 | 1448 | fprintf(fp," unsigned %sidx%d = %sreq(); \n", prefix, idx, receiver); |
aoqi@0 | 1449 | } |
aoqi@0 | 1450 | |
aoqi@0 | 1451 | } |
aoqi@0 | 1452 | |
aoqi@0 | 1453 | // --------------------------- |
aoqi@0 | 1454 | bool InstructForm::verify() { |
aoqi@0 | 1455 | // !!!!! !!!!! |
aoqi@0 | 1456 | // Check that a "label" operand occurs last in the operand list, if present |
aoqi@0 | 1457 | return true; |
aoqi@0 | 1458 | } |
aoqi@0 | 1459 | |
aoqi@0 | 1460 | void InstructForm::dump() { |
aoqi@0 | 1461 | output(stderr); |
aoqi@0 | 1462 | } |
aoqi@0 | 1463 | |
aoqi@0 | 1464 | void InstructForm::output(FILE *fp) { |
aoqi@0 | 1465 | fprintf(fp,"\nInstruction: %s\n", (_ident?_ident:"")); |
aoqi@0 | 1466 | if (_matrule) _matrule->output(fp); |
aoqi@0 | 1467 | if (_insencode) _insencode->output(fp); |
aoqi@0 | 1468 | if (_constant) _constant->output(fp); |
aoqi@0 | 1469 | if (_opcode) _opcode->output(fp); |
aoqi@0 | 1470 | if (_attribs) _attribs->output(fp); |
aoqi@0 | 1471 | if (_predicate) _predicate->output(fp); |
aoqi@0 | 1472 | if (_effects.Size()) { |
aoqi@0 | 1473 | fprintf(fp,"Effects\n"); |
aoqi@0 | 1474 | _effects.dump(); |
aoqi@0 | 1475 | } |
aoqi@0 | 1476 | if (_exprule) _exprule->output(fp); |
aoqi@0 | 1477 | if (_rewrule) _rewrule->output(fp); |
aoqi@0 | 1478 | if (_format) _format->output(fp); |
aoqi@0 | 1479 | if (_peephole) _peephole->output(fp); |
aoqi@0 | 1480 | } |
aoqi@0 | 1481 | |
aoqi@0 | 1482 | void MachNodeForm::dump() { |
aoqi@0 | 1483 | output(stderr); |
aoqi@0 | 1484 | } |
aoqi@0 | 1485 | |
aoqi@0 | 1486 | void MachNodeForm::output(FILE *fp) { |
aoqi@0 | 1487 | fprintf(fp,"\nMachNode: %s\n", (_ident?_ident:"")); |
aoqi@0 | 1488 | } |
aoqi@0 | 1489 | |
aoqi@0 | 1490 | //------------------------------build_predicate-------------------------------- |
aoqi@0 | 1491 | // Build instruction predicates. If the user uses the same operand name |
aoqi@0 | 1492 | // twice, we need to check that the operands are pointer-eequivalent in |
aoqi@0 | 1493 | // the DFA during the labeling process. |
aoqi@0 | 1494 | Predicate *InstructForm::build_predicate() { |
aoqi@0 | 1495 | char buf[1024], *s=buf; |
aoqi@0 | 1496 | Dict names(cmpstr,hashstr,Form::arena); // Map Names to counts |
aoqi@0 | 1497 | |
aoqi@0 | 1498 | MatchNode *mnode = |
aoqi@0 | 1499 | strcmp(_matrule->_opType, "Set") ? _matrule : _matrule->_rChild; |
aoqi@0 | 1500 | mnode->count_instr_names(names); |
aoqi@0 | 1501 | |
aoqi@0 | 1502 | uint first = 1; |
aoqi@0 | 1503 | // Start with the predicate supplied in the .ad file. |
aoqi@0 | 1504 | if( _predicate ) { |
aoqi@0 | 1505 | if( first ) first=0; |
aoqi@0 | 1506 | strcpy(s,"("); s += strlen(s); |
aoqi@0 | 1507 | strcpy(s,_predicate->_pred); |
aoqi@0 | 1508 | s += strlen(s); |
aoqi@0 | 1509 | strcpy(s,")"); s += strlen(s); |
aoqi@0 | 1510 | } |
aoqi@0 | 1511 | for( DictI i(&names); i.test(); ++i ) { |
aoqi@0 | 1512 | uintptr_t cnt = (uintptr_t)i._value; |
aoqi@0 | 1513 | if( cnt > 1 ) { // Need a predicate at all? |
aoqi@0 | 1514 | assert( cnt == 2, "Unimplemented" ); |
aoqi@0 | 1515 | // Handle many pairs |
aoqi@0 | 1516 | if( first ) first=0; |
aoqi@0 | 1517 | else { // All tests must pass, so use '&&' |
aoqi@0 | 1518 | strcpy(s," && "); |
aoqi@0 | 1519 | s += strlen(s); |
aoqi@0 | 1520 | } |
aoqi@0 | 1521 | // Add predicate to working buffer |
aoqi@0 | 1522 | sprintf(s,"/*%s*/(",(char*)i._key); |
aoqi@0 | 1523 | s += strlen(s); |
aoqi@0 | 1524 | mnode->build_instr_pred(s,(char*)i._key,0); |
aoqi@0 | 1525 | s += strlen(s); |
aoqi@0 | 1526 | strcpy(s," == "); s += strlen(s); |
aoqi@0 | 1527 | mnode->build_instr_pred(s,(char*)i._key,1); |
aoqi@0 | 1528 | s += strlen(s); |
aoqi@0 | 1529 | strcpy(s,")"); s += strlen(s); |
aoqi@0 | 1530 | } |
aoqi@0 | 1531 | } |
aoqi@0 | 1532 | if( s == buf ) s = NULL; |
aoqi@0 | 1533 | else { |
aoqi@0 | 1534 | assert( strlen(buf) < sizeof(buf), "String buffer overflow" ); |
aoqi@0 | 1535 | s = strdup(buf); |
aoqi@0 | 1536 | } |
aoqi@0 | 1537 | return new Predicate(s); |
aoqi@0 | 1538 | } |
aoqi@0 | 1539 | |
aoqi@0 | 1540 | //------------------------------EncodeForm------------------------------------- |
aoqi@0 | 1541 | // Constructor |
aoqi@0 | 1542 | EncodeForm::EncodeForm() |
aoqi@0 | 1543 | : _encClass(cmpstr,hashstr, Form::arena) { |
aoqi@0 | 1544 | } |
aoqi@0 | 1545 | EncodeForm::~EncodeForm() { |
aoqi@0 | 1546 | } |
aoqi@0 | 1547 | |
aoqi@0 | 1548 | // record a new register class |
aoqi@0 | 1549 | EncClass *EncodeForm::add_EncClass(const char *className) { |
aoqi@0 | 1550 | EncClass *encClass = new EncClass(className); |
aoqi@0 | 1551 | _eclasses.addName(className); |
aoqi@0 | 1552 | _encClass.Insert(className,encClass); |
aoqi@0 | 1553 | return encClass; |
aoqi@0 | 1554 | } |
aoqi@0 | 1555 | |
aoqi@0 | 1556 | // Lookup the function body for an encoding class |
aoqi@0 | 1557 | EncClass *EncodeForm::encClass(const char *className) { |
aoqi@0 | 1558 | assert( className != NULL, "Must provide a defined encoding name"); |
aoqi@0 | 1559 | |
aoqi@0 | 1560 | EncClass *encClass = (EncClass*)_encClass[className]; |
aoqi@0 | 1561 | return encClass; |
aoqi@0 | 1562 | } |
aoqi@0 | 1563 | |
aoqi@0 | 1564 | // Lookup the function body for an encoding class |
aoqi@0 | 1565 | const char *EncodeForm::encClassBody(const char *className) { |
aoqi@0 | 1566 | if( className == NULL ) return NULL; |
aoqi@0 | 1567 | |
aoqi@0 | 1568 | EncClass *encClass = (EncClass*)_encClass[className]; |
aoqi@0 | 1569 | assert( encClass != NULL, "Encode Class is missing."); |
aoqi@0 | 1570 | encClass->_code.reset(); |
aoqi@0 | 1571 | const char *code = (const char*)encClass->_code.iter(); |
aoqi@0 | 1572 | assert( code != NULL, "Found an empty encode class body."); |
aoqi@0 | 1573 | |
aoqi@0 | 1574 | return code; |
aoqi@0 | 1575 | } |
aoqi@0 | 1576 | |
aoqi@0 | 1577 | // Lookup the function body for an encoding class |
aoqi@0 | 1578 | const char *EncodeForm::encClassPrototype(const char *className) { |
aoqi@0 | 1579 | assert( className != NULL, "Encode class name must be non NULL."); |
aoqi@0 | 1580 | |
aoqi@0 | 1581 | return className; |
aoqi@0 | 1582 | } |
aoqi@0 | 1583 | |
aoqi@0 | 1584 | void EncodeForm::dump() { // Debug printer |
aoqi@0 | 1585 | output(stderr); |
aoqi@0 | 1586 | } |
aoqi@0 | 1587 | |
aoqi@0 | 1588 | void EncodeForm::output(FILE *fp) { // Write info to output files |
aoqi@0 | 1589 | const char *name; |
aoqi@0 | 1590 | fprintf(fp,"\n"); |
aoqi@0 | 1591 | fprintf(fp,"-------------------- Dump EncodeForm --------------------\n"); |
aoqi@0 | 1592 | for (_eclasses.reset(); (name = _eclasses.iter()) != NULL;) { |
aoqi@0 | 1593 | ((EncClass*)_encClass[name])->output(fp); |
aoqi@0 | 1594 | } |
aoqi@0 | 1595 | fprintf(fp,"-------------------- end EncodeForm --------------------\n"); |
aoqi@0 | 1596 | } |
aoqi@0 | 1597 | //------------------------------EncClass--------------------------------------- |
aoqi@0 | 1598 | EncClass::EncClass(const char *name) |
aoqi@0 | 1599 | : _localNames(cmpstr,hashstr, Form::arena), _name(name) { |
aoqi@0 | 1600 | } |
aoqi@0 | 1601 | EncClass::~EncClass() { |
aoqi@0 | 1602 | } |
aoqi@0 | 1603 | |
aoqi@0 | 1604 | // Add a parameter <type,name> pair |
aoqi@0 | 1605 | void EncClass::add_parameter(const char *parameter_type, const char *parameter_name) { |
aoqi@0 | 1606 | _parameter_type.addName( parameter_type ); |
aoqi@0 | 1607 | _parameter_name.addName( parameter_name ); |
aoqi@0 | 1608 | } |
aoqi@0 | 1609 | |
aoqi@0 | 1610 | // Verify operand types in parameter list |
aoqi@0 | 1611 | bool EncClass::check_parameter_types(FormDict &globals) { |
aoqi@0 | 1612 | // !!!!! |
aoqi@0 | 1613 | return false; |
aoqi@0 | 1614 | } |
aoqi@0 | 1615 | |
aoqi@0 | 1616 | // Add the decomposed "code" sections of an encoding's code-block |
aoqi@0 | 1617 | void EncClass::add_code(const char *code) { |
aoqi@0 | 1618 | _code.addName(code); |
aoqi@0 | 1619 | } |
aoqi@0 | 1620 | |
aoqi@0 | 1621 | // Add the decomposed "replacement variables" of an encoding's code-block |
aoqi@0 | 1622 | void EncClass::add_rep_var(char *replacement_var) { |
aoqi@0 | 1623 | _code.addName(NameList::_signal); |
aoqi@0 | 1624 | _rep_vars.addName(replacement_var); |
aoqi@0 | 1625 | } |
aoqi@0 | 1626 | |
aoqi@0 | 1627 | // Lookup the function body for an encoding class |
aoqi@0 | 1628 | int EncClass::rep_var_index(const char *rep_var) { |
aoqi@0 | 1629 | uint position = 0; |
aoqi@0 | 1630 | const char *name = NULL; |
aoqi@0 | 1631 | |
aoqi@0 | 1632 | _parameter_name.reset(); |
aoqi@0 | 1633 | while ( (name = _parameter_name.iter()) != NULL ) { |
aoqi@0 | 1634 | if ( strcmp(rep_var,name) == 0 ) return position; |
aoqi@0 | 1635 | ++position; |
aoqi@0 | 1636 | } |
aoqi@0 | 1637 | |
aoqi@0 | 1638 | return -1; |
aoqi@0 | 1639 | } |
aoqi@0 | 1640 | |
aoqi@0 | 1641 | // Check after parsing |
aoqi@0 | 1642 | bool EncClass::verify() { |
aoqi@0 | 1643 | // 1!!!! |
aoqi@0 | 1644 | // Check that each replacement variable, '$name' in architecture description |
aoqi@0 | 1645 | // is actually a local variable for this encode class, or a reserved name |
aoqi@0 | 1646 | // "primary, secondary, tertiary" |
aoqi@0 | 1647 | return true; |
aoqi@0 | 1648 | } |
aoqi@0 | 1649 | |
aoqi@0 | 1650 | void EncClass::dump() { |
aoqi@0 | 1651 | output(stderr); |
aoqi@0 | 1652 | } |
aoqi@0 | 1653 | |
aoqi@0 | 1654 | // Write info to output files |
aoqi@0 | 1655 | void EncClass::output(FILE *fp) { |
aoqi@0 | 1656 | fprintf(fp,"EncClass: %s", (_name ? _name : "")); |
aoqi@0 | 1657 | |
aoqi@0 | 1658 | // Output the parameter list |
aoqi@0 | 1659 | _parameter_type.reset(); |
aoqi@0 | 1660 | _parameter_name.reset(); |
aoqi@0 | 1661 | const char *type = _parameter_type.iter(); |
aoqi@0 | 1662 | const char *name = _parameter_name.iter(); |
aoqi@0 | 1663 | fprintf(fp, " ( "); |
aoqi@0 | 1664 | for ( ; (type != NULL) && (name != NULL); |
aoqi@0 | 1665 | (type = _parameter_type.iter()), (name = _parameter_name.iter()) ) { |
aoqi@0 | 1666 | fprintf(fp, " %s %s,", type, name); |
aoqi@0 | 1667 | } |
aoqi@0 | 1668 | fprintf(fp, " ) "); |
aoqi@0 | 1669 | |
aoqi@0 | 1670 | // Output the code block |
aoqi@0 | 1671 | _code.reset(); |
aoqi@0 | 1672 | _rep_vars.reset(); |
aoqi@0 | 1673 | const char *code; |
aoqi@0 | 1674 | while ( (code = _code.iter()) != NULL ) { |
aoqi@0 | 1675 | if ( _code.is_signal(code) ) { |
aoqi@0 | 1676 | // A replacement variable |
aoqi@0 | 1677 | const char *rep_var = _rep_vars.iter(); |
aoqi@0 | 1678 | fprintf(fp,"($%s)", rep_var); |
aoqi@0 | 1679 | } else { |
aoqi@0 | 1680 | // A section of code |
aoqi@0 | 1681 | fprintf(fp,"%s", code); |
aoqi@0 | 1682 | } |
aoqi@0 | 1683 | } |
aoqi@0 | 1684 | |
aoqi@0 | 1685 | } |
aoqi@0 | 1686 | |
aoqi@0 | 1687 | //------------------------------Opcode----------------------------------------- |
aoqi@0 | 1688 | Opcode::Opcode(char *primary, char *secondary, char *tertiary) |
aoqi@0 | 1689 | : _primary(primary), _secondary(secondary), _tertiary(tertiary) { |
aoqi@0 | 1690 | } |
aoqi@0 | 1691 | |
aoqi@0 | 1692 | Opcode::~Opcode() { |
aoqi@0 | 1693 | } |
aoqi@0 | 1694 | |
aoqi@0 | 1695 | Opcode::opcode_type Opcode::as_opcode_type(const char *param) { |
aoqi@0 | 1696 | if( strcmp(param,"primary") == 0 ) { |
aoqi@0 | 1697 | return Opcode::PRIMARY; |
aoqi@0 | 1698 | } |
aoqi@0 | 1699 | else if( strcmp(param,"secondary") == 0 ) { |
aoqi@0 | 1700 | return Opcode::SECONDARY; |
aoqi@0 | 1701 | } |
aoqi@0 | 1702 | else if( strcmp(param,"tertiary") == 0 ) { |
aoqi@0 | 1703 | return Opcode::TERTIARY; |
aoqi@0 | 1704 | } |
aoqi@0 | 1705 | return Opcode::NOT_AN_OPCODE; |
aoqi@0 | 1706 | } |
aoqi@0 | 1707 | |
aoqi@0 | 1708 | bool Opcode::print_opcode(FILE *fp, Opcode::opcode_type desired_opcode) { |
aoqi@0 | 1709 | // Default values previously provided by MachNode::primary()... |
aoqi@0 | 1710 | const char *description = NULL; |
aoqi@0 | 1711 | const char *value = NULL; |
aoqi@0 | 1712 | // Check if user provided any opcode definitions |
aoqi@0 | 1713 | if( this != NULL ) { |
aoqi@0 | 1714 | // Update 'value' if user provided a definition in the instruction |
aoqi@0 | 1715 | switch (desired_opcode) { |
aoqi@0 | 1716 | case PRIMARY: |
aoqi@0 | 1717 | description = "primary()"; |
aoqi@0 | 1718 | if( _primary != NULL) { value = _primary; } |
aoqi@0 | 1719 | break; |
aoqi@0 | 1720 | case SECONDARY: |
aoqi@0 | 1721 | description = "secondary()"; |
aoqi@0 | 1722 | if( _secondary != NULL ) { value = _secondary; } |
aoqi@0 | 1723 | break; |
aoqi@0 | 1724 | case TERTIARY: |
aoqi@0 | 1725 | description = "tertiary()"; |
aoqi@0 | 1726 | if( _tertiary != NULL ) { value = _tertiary; } |
aoqi@0 | 1727 | break; |
aoqi@0 | 1728 | default: |
aoqi@0 | 1729 | assert( false, "ShouldNotReachHere();"); |
aoqi@0 | 1730 | break; |
aoqi@0 | 1731 | } |
aoqi@0 | 1732 | } |
aoqi@0 | 1733 | if (value != NULL) { |
aoqi@0 | 1734 | fprintf(fp, "(%s /*%s*/)", value, description); |
aoqi@0 | 1735 | } |
aoqi@0 | 1736 | return value != NULL; |
aoqi@0 | 1737 | } |
aoqi@0 | 1738 | |
aoqi@0 | 1739 | void Opcode::dump() { |
aoqi@0 | 1740 | output(stderr); |
aoqi@0 | 1741 | } |
aoqi@0 | 1742 | |
aoqi@0 | 1743 | // Write info to output files |
aoqi@0 | 1744 | void Opcode::output(FILE *fp) { |
aoqi@0 | 1745 | if (_primary != NULL) fprintf(fp,"Primary opcode: %s\n", _primary); |
aoqi@0 | 1746 | if (_secondary != NULL) fprintf(fp,"Secondary opcode: %s\n", _secondary); |
aoqi@0 | 1747 | if (_tertiary != NULL) fprintf(fp,"Tertiary opcode: %s\n", _tertiary); |
aoqi@0 | 1748 | } |
aoqi@0 | 1749 | |
aoqi@0 | 1750 | //------------------------------InsEncode-------------------------------------- |
aoqi@0 | 1751 | InsEncode::InsEncode() { |
aoqi@0 | 1752 | } |
aoqi@0 | 1753 | InsEncode::~InsEncode() { |
aoqi@0 | 1754 | } |
aoqi@0 | 1755 | |
aoqi@0 | 1756 | // Add "encode class name" and its parameters |
aoqi@0 | 1757 | NameAndList *InsEncode::add_encode(char *encoding) { |
aoqi@0 | 1758 | assert( encoding != NULL, "Must provide name for encoding"); |
aoqi@0 | 1759 | |
aoqi@0 | 1760 | // add_parameter(NameList::_signal); |
aoqi@0 | 1761 | NameAndList *encode = new NameAndList(encoding); |
aoqi@0 | 1762 | _encoding.addName((char*)encode); |
aoqi@0 | 1763 | |
aoqi@0 | 1764 | return encode; |
aoqi@0 | 1765 | } |
aoqi@0 | 1766 | |
aoqi@0 | 1767 | // Access the list of encodings |
aoqi@0 | 1768 | void InsEncode::reset() { |
aoqi@0 | 1769 | _encoding.reset(); |
aoqi@0 | 1770 | // _parameter.reset(); |
aoqi@0 | 1771 | } |
aoqi@0 | 1772 | const char* InsEncode::encode_class_iter() { |
aoqi@0 | 1773 | NameAndList *encode_class = (NameAndList*)_encoding.iter(); |
aoqi@0 | 1774 | return ( encode_class != NULL ? encode_class->name() : NULL ); |
aoqi@0 | 1775 | } |
aoqi@0 | 1776 | // Obtain parameter name from zero based index |
aoqi@0 | 1777 | const char *InsEncode::rep_var_name(InstructForm &inst, uint param_no) { |
aoqi@0 | 1778 | NameAndList *params = (NameAndList*)_encoding.current(); |
aoqi@0 | 1779 | assert( params != NULL, "Internal Error"); |
aoqi@0 | 1780 | const char *param = (*params)[param_no]; |
aoqi@0 | 1781 | |
aoqi@0 | 1782 | // Remove '$' if parser placed it there. |
aoqi@0 | 1783 | return ( param != NULL && *param == '$') ? (param+1) : param; |
aoqi@0 | 1784 | } |
aoqi@0 | 1785 | |
aoqi@0 | 1786 | void InsEncode::dump() { |
aoqi@0 | 1787 | output(stderr); |
aoqi@0 | 1788 | } |
aoqi@0 | 1789 | |
aoqi@0 | 1790 | // Write info to output files |
aoqi@0 | 1791 | void InsEncode::output(FILE *fp) { |
aoqi@0 | 1792 | NameAndList *encoding = NULL; |
aoqi@0 | 1793 | const char *parameter = NULL; |
aoqi@0 | 1794 | |
aoqi@0 | 1795 | fprintf(fp,"InsEncode: "); |
aoqi@0 | 1796 | _encoding.reset(); |
aoqi@0 | 1797 | |
aoqi@0 | 1798 | while ( (encoding = (NameAndList*)_encoding.iter()) != 0 ) { |
aoqi@0 | 1799 | // Output the encoding being used |
aoqi@0 | 1800 | fprintf(fp,"%s(", encoding->name() ); |
aoqi@0 | 1801 | |
aoqi@0 | 1802 | // Output its parameter list, if any |
aoqi@0 | 1803 | bool first_param = true; |
aoqi@0 | 1804 | encoding->reset(); |
aoqi@0 | 1805 | while ( (parameter = encoding->iter()) != 0 ) { |
aoqi@0 | 1806 | // Output the ',' between parameters |
aoqi@0 | 1807 | if ( ! first_param ) fprintf(fp,", "); |
aoqi@0 | 1808 | first_param = false; |
aoqi@0 | 1809 | // Output the parameter |
aoqi@0 | 1810 | fprintf(fp,"%s", parameter); |
aoqi@0 | 1811 | } // done with parameters |
aoqi@0 | 1812 | fprintf(fp,") "); |
aoqi@0 | 1813 | } // done with encodings |
aoqi@0 | 1814 | |
aoqi@0 | 1815 | fprintf(fp,"\n"); |
aoqi@0 | 1816 | } |
aoqi@0 | 1817 | |
aoqi@0 | 1818 | //------------------------------Effect----------------------------------------- |
aoqi@0 | 1819 | static int effect_lookup(const char *name) { |
aoqi@0 | 1820 | if(!strcmp(name, "USE")) return Component::USE; |
aoqi@0 | 1821 | if(!strcmp(name, "DEF")) return Component::DEF; |
aoqi@0 | 1822 | if(!strcmp(name, "USE_DEF")) return Component::USE_DEF; |
aoqi@0 | 1823 | if(!strcmp(name, "KILL")) return Component::KILL; |
aoqi@0 | 1824 | if(!strcmp(name, "USE_KILL")) return Component::USE_KILL; |
aoqi@0 | 1825 | if(!strcmp(name, "TEMP")) return Component::TEMP; |
aoqi@0 | 1826 | if(!strcmp(name, "INVALID")) return Component::INVALID; |
aoqi@0 | 1827 | if(!strcmp(name, "CALL")) return Component::CALL; |
aoqi@0 | 1828 | assert( false,"Invalid effect name specified\n"); |
aoqi@0 | 1829 | return Component::INVALID; |
aoqi@0 | 1830 | } |
aoqi@0 | 1831 | |
aoqi@0 | 1832 | const char *Component::getUsedefName() { |
aoqi@0 | 1833 | switch (_usedef) { |
aoqi@0 | 1834 | case Component::INVALID: return "INVALID"; break; |
aoqi@0 | 1835 | case Component::USE: return "USE"; break; |
aoqi@0 | 1836 | case Component::USE_DEF: return "USE_DEF"; break; |
aoqi@0 | 1837 | case Component::USE_KILL: return "USE_KILL"; break; |
aoqi@0 | 1838 | case Component::KILL: return "KILL"; break; |
aoqi@0 | 1839 | case Component::TEMP: return "TEMP"; break; |
aoqi@0 | 1840 | case Component::DEF: return "DEF"; break; |
aoqi@0 | 1841 | case Component::CALL: return "CALL"; break; |
aoqi@0 | 1842 | default: assert(false, "unknown effect"); |
aoqi@0 | 1843 | } |
aoqi@0 | 1844 | return "Undefined Use/Def info"; |
aoqi@0 | 1845 | } |
aoqi@0 | 1846 | |
aoqi@0 | 1847 | Effect::Effect(const char *name) : _name(name), _use_def(effect_lookup(name)) { |
aoqi@0 | 1848 | _ftype = Form::EFF; |
aoqi@0 | 1849 | } |
aoqi@0 | 1850 | |
aoqi@0 | 1851 | Effect::~Effect() { |
aoqi@0 | 1852 | } |
aoqi@0 | 1853 | |
aoqi@0 | 1854 | // Dynamic type check |
aoqi@0 | 1855 | Effect *Effect::is_effect() const { |
aoqi@0 | 1856 | return (Effect*)this; |
aoqi@0 | 1857 | } |
aoqi@0 | 1858 | |
aoqi@0 | 1859 | |
aoqi@0 | 1860 | // True if this component is equal to the parameter. |
aoqi@0 | 1861 | bool Effect::is(int use_def_kill_enum) const { |
aoqi@0 | 1862 | return (_use_def == use_def_kill_enum ? true : false); |
aoqi@0 | 1863 | } |
aoqi@0 | 1864 | // True if this component is used/def'd/kill'd as the parameter suggests. |
aoqi@0 | 1865 | bool Effect::isa(int use_def_kill_enum) const { |
aoqi@0 | 1866 | return (_use_def & use_def_kill_enum) == use_def_kill_enum; |
aoqi@0 | 1867 | } |
aoqi@0 | 1868 | |
aoqi@0 | 1869 | void Effect::dump() { |
aoqi@0 | 1870 | output(stderr); |
aoqi@0 | 1871 | } |
aoqi@0 | 1872 | |
aoqi@0 | 1873 | void Effect::output(FILE *fp) { // Write info to output files |
aoqi@0 | 1874 | fprintf(fp,"Effect: %s\n", (_name?_name:"")); |
aoqi@0 | 1875 | } |
aoqi@0 | 1876 | |
aoqi@0 | 1877 | //------------------------------ExpandRule------------------------------------- |
aoqi@0 | 1878 | ExpandRule::ExpandRule() : _expand_instrs(), |
aoqi@0 | 1879 | _newopconst(cmpstr, hashstr, Form::arena) { |
aoqi@0 | 1880 | _ftype = Form::EXP; |
aoqi@0 | 1881 | } |
aoqi@0 | 1882 | |
aoqi@0 | 1883 | ExpandRule::~ExpandRule() { // Destructor |
aoqi@0 | 1884 | } |
aoqi@0 | 1885 | |
aoqi@0 | 1886 | void ExpandRule::add_instruction(NameAndList *instruction_name_and_operand_list) { |
aoqi@0 | 1887 | _expand_instrs.addName((char*)instruction_name_and_operand_list); |
aoqi@0 | 1888 | } |
aoqi@0 | 1889 | |
aoqi@0 | 1890 | void ExpandRule::reset_instructions() { |
aoqi@0 | 1891 | _expand_instrs.reset(); |
aoqi@0 | 1892 | } |
aoqi@0 | 1893 | |
aoqi@0 | 1894 | NameAndList* ExpandRule::iter_instructions() { |
aoqi@0 | 1895 | return (NameAndList*)_expand_instrs.iter(); |
aoqi@0 | 1896 | } |
aoqi@0 | 1897 | |
aoqi@0 | 1898 | |
aoqi@0 | 1899 | void ExpandRule::dump() { |
aoqi@0 | 1900 | output(stderr); |
aoqi@0 | 1901 | } |
aoqi@0 | 1902 | |
aoqi@0 | 1903 | void ExpandRule::output(FILE *fp) { // Write info to output files |
aoqi@0 | 1904 | NameAndList *expand_instr = NULL; |
aoqi@0 | 1905 | const char *opid = NULL; |
aoqi@0 | 1906 | |
aoqi@0 | 1907 | fprintf(fp,"\nExpand Rule:\n"); |
aoqi@0 | 1908 | |
aoqi@0 | 1909 | // Iterate over the instructions 'node' expands into |
aoqi@0 | 1910 | for(reset_instructions(); (expand_instr = iter_instructions()) != NULL; ) { |
aoqi@0 | 1911 | fprintf(fp,"%s(", expand_instr->name()); |
aoqi@0 | 1912 | |
aoqi@0 | 1913 | // iterate over the operand list |
aoqi@0 | 1914 | for( expand_instr->reset(); (opid = expand_instr->iter()) != NULL; ) { |
aoqi@0 | 1915 | fprintf(fp,"%s ", opid); |
aoqi@0 | 1916 | } |
aoqi@0 | 1917 | fprintf(fp,");\n"); |
aoqi@0 | 1918 | } |
aoqi@0 | 1919 | } |
aoqi@0 | 1920 | |
aoqi@0 | 1921 | //------------------------------RewriteRule------------------------------------ |
aoqi@0 | 1922 | RewriteRule::RewriteRule(char* params, char* block) |
aoqi@0 | 1923 | : _tempParams(params), _tempBlock(block) { }; // Constructor |
aoqi@0 | 1924 | RewriteRule::~RewriteRule() { // Destructor |
aoqi@0 | 1925 | } |
aoqi@0 | 1926 | |
aoqi@0 | 1927 | void RewriteRule::dump() { |
aoqi@0 | 1928 | output(stderr); |
aoqi@0 | 1929 | } |
aoqi@0 | 1930 | |
aoqi@0 | 1931 | void RewriteRule::output(FILE *fp) { // Write info to output files |
aoqi@0 | 1932 | fprintf(fp,"\nRewrite Rule:\n%s\n%s\n", |
aoqi@0 | 1933 | (_tempParams?_tempParams:""), |
aoqi@0 | 1934 | (_tempBlock?_tempBlock:"")); |
aoqi@0 | 1935 | } |
aoqi@0 | 1936 | |
aoqi@0 | 1937 | |
aoqi@0 | 1938 | //==============================MachNodes====================================== |
aoqi@0 | 1939 | //------------------------------MachNodeForm----------------------------------- |
aoqi@0 | 1940 | MachNodeForm::MachNodeForm(char *id) |
aoqi@0 | 1941 | : _ident(id) { |
aoqi@0 | 1942 | } |
aoqi@0 | 1943 | |
aoqi@0 | 1944 | MachNodeForm::~MachNodeForm() { |
aoqi@0 | 1945 | } |
aoqi@0 | 1946 | |
aoqi@0 | 1947 | MachNodeForm *MachNodeForm::is_machnode() const { |
aoqi@0 | 1948 | return (MachNodeForm*)this; |
aoqi@0 | 1949 | } |
aoqi@0 | 1950 | |
aoqi@0 | 1951 | //==============================Operand Classes================================ |
aoqi@0 | 1952 | //------------------------------OpClassForm------------------------------------ |
aoqi@0 | 1953 | OpClassForm::OpClassForm(const char* id) : _ident(id) { |
aoqi@0 | 1954 | _ftype = Form::OPCLASS; |
aoqi@0 | 1955 | } |
aoqi@0 | 1956 | |
aoqi@0 | 1957 | OpClassForm::~OpClassForm() { |
aoqi@0 | 1958 | } |
aoqi@0 | 1959 | |
aoqi@0 | 1960 | bool OpClassForm::ideal_only() const { return 0; } |
aoqi@0 | 1961 | |
aoqi@0 | 1962 | OpClassForm *OpClassForm::is_opclass() const { |
aoqi@0 | 1963 | return (OpClassForm*)this; |
aoqi@0 | 1964 | } |
aoqi@0 | 1965 | |
aoqi@0 | 1966 | Form::InterfaceType OpClassForm::interface_type(FormDict &globals) const { |
aoqi@0 | 1967 | if( _oplst.count() == 0 ) return Form::no_interface; |
aoqi@0 | 1968 | |
aoqi@0 | 1969 | // Check that my operands have the same interface type |
aoqi@0 | 1970 | Form::InterfaceType interface; |
aoqi@0 | 1971 | bool first = true; |
aoqi@0 | 1972 | NameList &op_list = (NameList &)_oplst; |
aoqi@0 | 1973 | op_list.reset(); |
aoqi@0 | 1974 | const char *op_name; |
aoqi@0 | 1975 | while( (op_name = op_list.iter()) != NULL ) { |
aoqi@0 | 1976 | const Form *form = globals[op_name]; |
aoqi@0 | 1977 | OperandForm *operand = form->is_operand(); |
aoqi@0 | 1978 | assert( operand, "Entry in operand class that is not an operand"); |
aoqi@0 | 1979 | if( first ) { |
aoqi@0 | 1980 | first = false; |
aoqi@0 | 1981 | interface = operand->interface_type(globals); |
aoqi@0 | 1982 | } else { |
aoqi@0 | 1983 | interface = (interface == operand->interface_type(globals) ? interface : Form::no_interface); |
aoqi@0 | 1984 | } |
aoqi@0 | 1985 | } |
aoqi@0 | 1986 | return interface; |
aoqi@0 | 1987 | } |
aoqi@0 | 1988 | |
aoqi@0 | 1989 | bool OpClassForm::stack_slots_only(FormDict &globals) const { |
aoqi@0 | 1990 | if( _oplst.count() == 0 ) return false; // how? |
aoqi@0 | 1991 | |
aoqi@0 | 1992 | NameList &op_list = (NameList &)_oplst; |
aoqi@0 | 1993 | op_list.reset(); |
aoqi@0 | 1994 | const char *op_name; |
aoqi@0 | 1995 | while( (op_name = op_list.iter()) != NULL ) { |
aoqi@0 | 1996 | const Form *form = globals[op_name]; |
aoqi@0 | 1997 | OperandForm *operand = form->is_operand(); |
aoqi@0 | 1998 | assert( operand, "Entry in operand class that is not an operand"); |
aoqi@0 | 1999 | if( !operand->stack_slots_only(globals) ) return false; |
aoqi@0 | 2000 | } |
aoqi@0 | 2001 | return true; |
aoqi@0 | 2002 | } |
aoqi@0 | 2003 | |
aoqi@0 | 2004 | |
aoqi@0 | 2005 | void OpClassForm::dump() { |
aoqi@0 | 2006 | output(stderr); |
aoqi@0 | 2007 | } |
aoqi@0 | 2008 | |
aoqi@0 | 2009 | void OpClassForm::output(FILE *fp) { |
aoqi@0 | 2010 | const char *name; |
aoqi@0 | 2011 | fprintf(fp,"\nOperand Class: %s\n", (_ident?_ident:"")); |
aoqi@0 | 2012 | fprintf(fp,"\nCount = %d\n", _oplst.count()); |
aoqi@0 | 2013 | for(_oplst.reset(); (name = _oplst.iter()) != NULL;) { |
aoqi@0 | 2014 | fprintf(fp,"%s, ",name); |
aoqi@0 | 2015 | } |
aoqi@0 | 2016 | fprintf(fp,"\n"); |
aoqi@0 | 2017 | } |
aoqi@0 | 2018 | |
aoqi@0 | 2019 | |
aoqi@0 | 2020 | //==============================Operands======================================= |
aoqi@0 | 2021 | //------------------------------OperandForm------------------------------------ |
aoqi@0 | 2022 | OperandForm::OperandForm(const char* id) |
aoqi@0 | 2023 | : OpClassForm(id), _ideal_only(false), |
aoqi@0 | 2024 | _localNames(cmpstr, hashstr, Form::arena) { |
aoqi@0 | 2025 | _ftype = Form::OPER; |
aoqi@0 | 2026 | |
aoqi@0 | 2027 | _matrule = NULL; |
aoqi@0 | 2028 | _interface = NULL; |
aoqi@0 | 2029 | _attribs = NULL; |
aoqi@0 | 2030 | _predicate = NULL; |
aoqi@0 | 2031 | _constraint= NULL; |
aoqi@0 | 2032 | _construct = NULL; |
aoqi@0 | 2033 | _format = NULL; |
aoqi@0 | 2034 | } |
aoqi@0 | 2035 | OperandForm::OperandForm(const char* id, bool ideal_only) |
aoqi@0 | 2036 | : OpClassForm(id), _ideal_only(ideal_only), |
aoqi@0 | 2037 | _localNames(cmpstr, hashstr, Form::arena) { |
aoqi@0 | 2038 | _ftype = Form::OPER; |
aoqi@0 | 2039 | |
aoqi@0 | 2040 | _matrule = NULL; |
aoqi@0 | 2041 | _interface = NULL; |
aoqi@0 | 2042 | _attribs = NULL; |
aoqi@0 | 2043 | _predicate = NULL; |
aoqi@0 | 2044 | _constraint= NULL; |
aoqi@0 | 2045 | _construct = NULL; |
aoqi@0 | 2046 | _format = NULL; |
aoqi@0 | 2047 | } |
aoqi@0 | 2048 | OperandForm::~OperandForm() { |
aoqi@0 | 2049 | } |
aoqi@0 | 2050 | |
aoqi@0 | 2051 | |
aoqi@0 | 2052 | OperandForm *OperandForm::is_operand() const { |
aoqi@0 | 2053 | return (OperandForm*)this; |
aoqi@0 | 2054 | } |
aoqi@0 | 2055 | |
aoqi@0 | 2056 | bool OperandForm::ideal_only() const { |
aoqi@0 | 2057 | return _ideal_only; |
aoqi@0 | 2058 | } |
aoqi@0 | 2059 | |
aoqi@0 | 2060 | Form::InterfaceType OperandForm::interface_type(FormDict &globals) const { |
aoqi@0 | 2061 | if( _interface == NULL ) return Form::no_interface; |
aoqi@0 | 2062 | |
aoqi@0 | 2063 | return _interface->interface_type(globals); |
aoqi@0 | 2064 | } |
aoqi@0 | 2065 | |
aoqi@0 | 2066 | |
aoqi@0 | 2067 | bool OperandForm::stack_slots_only(FormDict &globals) const { |
aoqi@0 | 2068 | if( _constraint == NULL ) return false; |
aoqi@0 | 2069 | return _constraint->stack_slots_only(); |
aoqi@0 | 2070 | } |
aoqi@0 | 2071 | |
aoqi@0 | 2072 | |
aoqi@0 | 2073 | // Access op_cost attribute or return NULL. |
aoqi@0 | 2074 | const char* OperandForm::cost() { |
aoqi@0 | 2075 | for (Attribute* cur = _attribs; cur != NULL; cur = (Attribute*)cur->_next) { |
aoqi@0 | 2076 | if( strcmp(cur->_ident,AttributeForm::_op_cost) == 0 ) { |
aoqi@0 | 2077 | return cur->_val; |
aoqi@0 | 2078 | } |
aoqi@0 | 2079 | } |
aoqi@0 | 2080 | return NULL; |
aoqi@0 | 2081 | } |
aoqi@0 | 2082 | |
aoqi@0 | 2083 | // Return the number of leaves below this complex operand |
aoqi@0 | 2084 | uint OperandForm::num_leaves() const { |
aoqi@0 | 2085 | if ( ! _matrule) return 0; |
aoqi@0 | 2086 | |
aoqi@0 | 2087 | int num_leaves = _matrule->_numleaves; |
aoqi@0 | 2088 | return num_leaves; |
aoqi@0 | 2089 | } |
aoqi@0 | 2090 | |
aoqi@0 | 2091 | // Return the number of constants contained within this complex operand |
aoqi@0 | 2092 | uint OperandForm::num_consts(FormDict &globals) const { |
aoqi@0 | 2093 | if ( ! _matrule) return 0; |
aoqi@0 | 2094 | |
aoqi@0 | 2095 | // This is a recursive invocation on all operands in the matchrule |
aoqi@0 | 2096 | return _matrule->num_consts(globals); |
aoqi@0 | 2097 | } |
aoqi@0 | 2098 | |
aoqi@0 | 2099 | // Return the number of constants in match rule with specified type |
aoqi@0 | 2100 | uint OperandForm::num_consts(FormDict &globals, Form::DataType type) const { |
aoqi@0 | 2101 | if ( ! _matrule) return 0; |
aoqi@0 | 2102 | |
aoqi@0 | 2103 | // This is a recursive invocation on all operands in the matchrule |
aoqi@0 | 2104 | return _matrule->num_consts(globals, type); |
aoqi@0 | 2105 | } |
aoqi@0 | 2106 | |
aoqi@0 | 2107 | // Return the number of pointer constants contained within this complex operand |
aoqi@0 | 2108 | uint OperandForm::num_const_ptrs(FormDict &globals) const { |
aoqi@0 | 2109 | if ( ! _matrule) return 0; |
aoqi@0 | 2110 | |
aoqi@0 | 2111 | // This is a recursive invocation on all operands in the matchrule |
aoqi@0 | 2112 | return _matrule->num_const_ptrs(globals); |
aoqi@0 | 2113 | } |
aoqi@0 | 2114 | |
aoqi@0 | 2115 | uint OperandForm::num_edges(FormDict &globals) const { |
aoqi@0 | 2116 | uint edges = 0; |
aoqi@0 | 2117 | uint leaves = num_leaves(); |
aoqi@0 | 2118 | uint consts = num_consts(globals); |
aoqi@0 | 2119 | |
aoqi@0 | 2120 | // If we are matching a constant directly, there are no leaves. |
aoqi@0 | 2121 | edges = ( leaves > consts ) ? leaves - consts : 0; |
aoqi@0 | 2122 | |
aoqi@0 | 2123 | // !!!!! |
aoqi@0 | 2124 | // Special case operands that do not have a corresponding ideal node. |
aoqi@0 | 2125 | if( (edges == 0) && (consts == 0) ) { |
aoqi@0 | 2126 | if( constrained_reg_class() != NULL ) { |
aoqi@0 | 2127 | edges = 1; |
aoqi@0 | 2128 | } else { |
aoqi@0 | 2129 | if( _matrule |
aoqi@0 | 2130 | && (_matrule->_lChild == NULL) && (_matrule->_rChild == NULL) ) { |
aoqi@0 | 2131 | const Form *form = globals[_matrule->_opType]; |
aoqi@0 | 2132 | OperandForm *oper = form ? form->is_operand() : NULL; |
aoqi@0 | 2133 | if( oper ) { |
aoqi@0 | 2134 | return oper->num_edges(globals); |
aoqi@0 | 2135 | } |
aoqi@0 | 2136 | } |
aoqi@0 | 2137 | } |
aoqi@0 | 2138 | } |
aoqi@0 | 2139 | |
aoqi@0 | 2140 | return edges; |
aoqi@0 | 2141 | } |
aoqi@0 | 2142 | |
aoqi@0 | 2143 | |
aoqi@0 | 2144 | // Check if this operand is usable for cisc-spilling |
aoqi@0 | 2145 | bool OperandForm::is_cisc_reg(FormDict &globals) const { |
aoqi@0 | 2146 | const char *ideal = ideal_type(globals); |
aoqi@0 | 2147 | bool is_cisc_reg = (ideal && (ideal_to_Reg_type(ideal) != none)); |
aoqi@0 | 2148 | return is_cisc_reg; |
aoqi@0 | 2149 | } |
aoqi@0 | 2150 | |
aoqi@0 | 2151 | bool OpClassForm::is_cisc_mem(FormDict &globals) const { |
aoqi@0 | 2152 | Form::InterfaceType my_interface = interface_type(globals); |
aoqi@0 | 2153 | return (my_interface == memory_interface); |
aoqi@0 | 2154 | } |
aoqi@0 | 2155 | |
aoqi@0 | 2156 | |
aoqi@0 | 2157 | // node matches ideal 'Bool' |
aoqi@0 | 2158 | bool OperandForm::is_ideal_bool() const { |
aoqi@0 | 2159 | if( _matrule == NULL ) return false; |
aoqi@0 | 2160 | |
aoqi@0 | 2161 | return _matrule->is_ideal_bool(); |
aoqi@0 | 2162 | } |
aoqi@0 | 2163 | |
aoqi@0 | 2164 | // Require user's name for an sRegX to be stackSlotX |
aoqi@0 | 2165 | Form::DataType OperandForm::is_user_name_for_sReg() const { |
aoqi@0 | 2166 | DataType data_type = none; |
aoqi@0 | 2167 | if( _ident != NULL ) { |
aoqi@0 | 2168 | if( strcmp(_ident,"stackSlotI") == 0 ) data_type = Form::idealI; |
aoqi@0 | 2169 | else if( strcmp(_ident,"stackSlotP") == 0 ) data_type = Form::idealP; |
aoqi@0 | 2170 | else if( strcmp(_ident,"stackSlotD") == 0 ) data_type = Form::idealD; |
aoqi@0 | 2171 | else if( strcmp(_ident,"stackSlotF") == 0 ) data_type = Form::idealF; |
aoqi@0 | 2172 | else if( strcmp(_ident,"stackSlotL") == 0 ) data_type = Form::idealL; |
aoqi@0 | 2173 | } |
aoqi@0 | 2174 | assert((data_type == none) || (_matrule == NULL), "No match-rule for stackSlotX"); |
aoqi@0 | 2175 | |
aoqi@0 | 2176 | return data_type; |
aoqi@0 | 2177 | } |
aoqi@0 | 2178 | |
aoqi@0 | 2179 | |
aoqi@0 | 2180 | // Return ideal type, if there is a single ideal type for this operand |
aoqi@0 | 2181 | const char *OperandForm::ideal_type(FormDict &globals, RegisterForm *registers) const { |
aoqi@0 | 2182 | const char *type = NULL; |
aoqi@0 | 2183 | if (ideal_only()) type = _ident; |
aoqi@0 | 2184 | else if( _matrule == NULL ) { |
aoqi@0 | 2185 | // Check for condition code register |
aoqi@0 | 2186 | const char *rc_name = constrained_reg_class(); |
aoqi@0 | 2187 | // !!!!! |
aoqi@0 | 2188 | if (rc_name == NULL) return NULL; |
aoqi@0 | 2189 | // !!!!! !!!!! |
aoqi@0 | 2190 | // Check constraints on result's register class |
aoqi@0 | 2191 | if( registers ) { |
aoqi@0 | 2192 | RegClass *reg_class = registers->getRegClass(rc_name); |
aoqi@0 | 2193 | assert( reg_class != NULL, "Register class is not defined"); |
aoqi@0 | 2194 | |
aoqi@0 | 2195 | // Check for ideal type of entries in register class, all are the same type |
aoqi@0 | 2196 | reg_class->reset(); |
aoqi@0 | 2197 | RegDef *reg_def = reg_class->RegDef_iter(); |
aoqi@0 | 2198 | assert( reg_def != NULL, "No entries in register class"); |
aoqi@0 | 2199 | assert( reg_def->_idealtype != NULL, "Did not define ideal type for register"); |
aoqi@0 | 2200 | // Return substring that names the register's ideal type |
aoqi@0 | 2201 | type = reg_def->_idealtype + 3; |
aoqi@0 | 2202 | assert( *(reg_def->_idealtype + 0) == 'O', "Expect Op_ prefix"); |
aoqi@0 | 2203 | assert( *(reg_def->_idealtype + 1) == 'p', "Expect Op_ prefix"); |
aoqi@0 | 2204 | assert( *(reg_def->_idealtype + 2) == '_', "Expect Op_ prefix"); |
aoqi@0 | 2205 | } |
aoqi@0 | 2206 | } |
aoqi@0 | 2207 | else if( _matrule->_lChild == NULL && _matrule->_rChild == NULL ) { |
aoqi@0 | 2208 | // This operand matches a single type, at the top level. |
aoqi@0 | 2209 | // Check for ideal type |
aoqi@0 | 2210 | type = _matrule->_opType; |
aoqi@0 | 2211 | if( strcmp(type,"Bool") == 0 ) |
aoqi@0 | 2212 | return "Bool"; |
aoqi@0 | 2213 | // transitive lookup |
aoqi@0 | 2214 | const Form *frm = globals[type]; |
aoqi@0 | 2215 | OperandForm *op = frm->is_operand(); |
aoqi@0 | 2216 | type = op->ideal_type(globals, registers); |
aoqi@0 | 2217 | } |
aoqi@0 | 2218 | return type; |
aoqi@0 | 2219 | } |
aoqi@0 | 2220 | |
aoqi@0 | 2221 | |
aoqi@0 | 2222 | // If there is a single ideal type for this interface field, return it. |
aoqi@0 | 2223 | const char *OperandForm::interface_ideal_type(FormDict &globals, |
aoqi@0 | 2224 | const char *field) const { |
aoqi@0 | 2225 | const char *ideal_type = NULL; |
aoqi@0 | 2226 | const char *value = NULL; |
aoqi@0 | 2227 | |
aoqi@0 | 2228 | // Check if "field" is valid for this operand's interface |
aoqi@0 | 2229 | if ( ! is_interface_field(field, value) ) return ideal_type; |
aoqi@0 | 2230 | |
aoqi@0 | 2231 | // !!!!! !!!!! !!!!! |
aoqi@0 | 2232 | // If a valid field has a constant value, identify "ConI" or "ConP" or ... |
aoqi@0 | 2233 | |
aoqi@0 | 2234 | // Else, lookup type of field's replacement variable |
aoqi@0 | 2235 | |
aoqi@0 | 2236 | return ideal_type; |
aoqi@0 | 2237 | } |
aoqi@0 | 2238 | |
aoqi@0 | 2239 | |
aoqi@0 | 2240 | RegClass* OperandForm::get_RegClass() const { |
aoqi@0 | 2241 | if (_interface && !_interface->is_RegInterface()) return NULL; |
aoqi@0 | 2242 | return globalAD->get_registers()->getRegClass(constrained_reg_class()); |
aoqi@0 | 2243 | } |
aoqi@0 | 2244 | |
aoqi@0 | 2245 | |
aoqi@0 | 2246 | bool OperandForm::is_bound_register() const { |
aoqi@0 | 2247 | RegClass* reg_class = get_RegClass(); |
aoqi@0 | 2248 | if (reg_class == NULL) { |
aoqi@0 | 2249 | return false; |
aoqi@0 | 2250 | } |
aoqi@0 | 2251 | |
aoqi@0 | 2252 | const char* name = ideal_type(globalAD->globalNames()); |
aoqi@0 | 2253 | if (name == NULL) { |
aoqi@0 | 2254 | return false; |
aoqi@0 | 2255 | } |
aoqi@0 | 2256 | |
aoqi@0 | 2257 | uint size = 0; |
aoqi@0 | 2258 | if (strcmp(name, "RegFlags") == 0) size = 1; |
aoqi@0 | 2259 | if (strcmp(name, "RegI") == 0) size = 1; |
aoqi@0 | 2260 | if (strcmp(name, "RegF") == 0) size = 1; |
aoqi@0 | 2261 | if (strcmp(name, "RegD") == 0) size = 2; |
aoqi@0 | 2262 | if (strcmp(name, "RegL") == 0) size = 2; |
aoqi@0 | 2263 | if (strcmp(name, "RegN") == 0) size = 1; |
aoqi@0 | 2264 | if (strcmp(name, "RegP") == 0) size = globalAD->get_preproc_def("_LP64") ? 2 : 1; |
aoqi@0 | 2265 | if (size == 0) { |
aoqi@0 | 2266 | return false; |
aoqi@0 | 2267 | } |
aoqi@0 | 2268 | return size == reg_class->size(); |
aoqi@0 | 2269 | } |
aoqi@0 | 2270 | |
aoqi@0 | 2271 | |
aoqi@0 | 2272 | // Check if this is a valid field for this operand, |
aoqi@0 | 2273 | // Return 'true' if valid, and set the value to the string the user provided. |
aoqi@0 | 2274 | bool OperandForm::is_interface_field(const char *field, |
aoqi@0 | 2275 | const char * &value) const { |
aoqi@0 | 2276 | return false; |
aoqi@0 | 2277 | } |
aoqi@0 | 2278 | |
aoqi@0 | 2279 | |
aoqi@0 | 2280 | // Return register class name if a constraint specifies the register class. |
aoqi@0 | 2281 | const char *OperandForm::constrained_reg_class() const { |
aoqi@0 | 2282 | const char *reg_class = NULL; |
aoqi@0 | 2283 | if ( _constraint ) { |
aoqi@0 | 2284 | // !!!!! |
aoqi@0 | 2285 | Constraint *constraint = _constraint; |
aoqi@0 | 2286 | if ( strcmp(_constraint->_func,"ALLOC_IN_RC") == 0 ) { |
aoqi@0 | 2287 | reg_class = _constraint->_arg; |
aoqi@0 | 2288 | } |
aoqi@0 | 2289 | } |
aoqi@0 | 2290 | |
aoqi@0 | 2291 | return reg_class; |
aoqi@0 | 2292 | } |
aoqi@0 | 2293 | |
aoqi@0 | 2294 | |
aoqi@0 | 2295 | // Return the register class associated with 'leaf'. |
aoqi@0 | 2296 | const char *OperandForm::in_reg_class(uint leaf, FormDict &globals) { |
aoqi@0 | 2297 | const char *reg_class = NULL; // "RegMask::Empty"; |
aoqi@0 | 2298 | |
aoqi@0 | 2299 | if((_matrule == NULL) || (_matrule->is_chain_rule(globals))) { |
aoqi@0 | 2300 | reg_class = constrained_reg_class(); |
aoqi@0 | 2301 | return reg_class; |
aoqi@0 | 2302 | } |
aoqi@0 | 2303 | const char *result = NULL; |
aoqi@0 | 2304 | const char *name = NULL; |
aoqi@0 | 2305 | const char *type = NULL; |
aoqi@0 | 2306 | // iterate through all base operands |
aoqi@0 | 2307 | // until we reach the register that corresponds to "leaf" |
aoqi@0 | 2308 | // This function is not looking for an ideal type. It needs the first |
aoqi@0 | 2309 | // level user type associated with the leaf. |
aoqi@0 | 2310 | for(uint idx = 0;_matrule->base_operand(idx,globals,result,name,type);++idx) { |
aoqi@0 | 2311 | const Form *form = (_localNames[name] ? _localNames[name] : globals[result]); |
aoqi@0 | 2312 | OperandForm *oper = form ? form->is_operand() : NULL; |
aoqi@0 | 2313 | if( oper ) { |
aoqi@0 | 2314 | reg_class = oper->constrained_reg_class(); |
aoqi@0 | 2315 | if( reg_class ) { |
aoqi@0 | 2316 | reg_class = reg_class; |
aoqi@0 | 2317 | } else { |
aoqi@0 | 2318 | // ShouldNotReachHere(); |
aoqi@0 | 2319 | } |
aoqi@0 | 2320 | } else { |
aoqi@0 | 2321 | // ShouldNotReachHere(); |
aoqi@0 | 2322 | } |
aoqi@0 | 2323 | |
aoqi@0 | 2324 | // Increment our target leaf position if current leaf is not a candidate. |
aoqi@0 | 2325 | if( reg_class == NULL) ++leaf; |
aoqi@0 | 2326 | // Exit the loop with the value of reg_class when at the correct index |
aoqi@0 | 2327 | if( idx == leaf ) break; |
aoqi@0 | 2328 | // May iterate through all base operands if reg_class for 'leaf' is NULL |
aoqi@0 | 2329 | } |
aoqi@0 | 2330 | return reg_class; |
aoqi@0 | 2331 | } |
aoqi@0 | 2332 | |
aoqi@0 | 2333 | |
aoqi@0 | 2334 | // Recursive call to construct list of top-level operands. |
aoqi@0 | 2335 | // Implementation does not modify state of internal structures |
aoqi@0 | 2336 | void OperandForm::build_components() { |
aoqi@0 | 2337 | if (_matrule) _matrule->append_components(_localNames, _components); |
aoqi@0 | 2338 | |
aoqi@0 | 2339 | // Add parameters that "do not appear in match rule". |
aoqi@0 | 2340 | const char *name; |
aoqi@0 | 2341 | for (_parameters.reset(); (name = _parameters.iter()) != NULL;) { |
aoqi@0 | 2342 | OperandForm *opForm = (OperandForm*)_localNames[name]; |
aoqi@0 | 2343 | |
aoqi@0 | 2344 | if ( _components.operand_position(name) == -1 ) { |
aoqi@0 | 2345 | _components.insert(name, opForm->_ident, Component::INVALID, false); |
aoqi@0 | 2346 | } |
aoqi@0 | 2347 | } |
aoqi@0 | 2348 | |
aoqi@0 | 2349 | return; |
aoqi@0 | 2350 | } |
aoqi@0 | 2351 | |
aoqi@0 | 2352 | int OperandForm::operand_position(const char *name, int usedef) { |
aoqi@0 | 2353 | return _components.operand_position(name, usedef, this); |
aoqi@0 | 2354 | } |
aoqi@0 | 2355 | |
aoqi@0 | 2356 | |
aoqi@0 | 2357 | // Return zero-based position in component list, only counting constants; |
aoqi@0 | 2358 | // Return -1 if not in list. |
aoqi@0 | 2359 | int OperandForm::constant_position(FormDict &globals, const Component *last) { |
aoqi@0 | 2360 | // Iterate through components and count constants preceding 'constant' |
aoqi@0 | 2361 | int position = 0; |
aoqi@0 | 2362 | Component *comp; |
aoqi@0 | 2363 | _components.reset(); |
aoqi@0 | 2364 | while( (comp = _components.iter()) != NULL && (comp != last) ) { |
aoqi@0 | 2365 | // Special case for operands that take a single user-defined operand |
aoqi@0 | 2366 | // Skip the initial definition in the component list. |
aoqi@0 | 2367 | if( strcmp(comp->_name,this->_ident) == 0 ) continue; |
aoqi@0 | 2368 | |
aoqi@0 | 2369 | const char *type = comp->_type; |
aoqi@0 | 2370 | // Lookup operand form for replacement variable's type |
aoqi@0 | 2371 | const Form *form = globals[type]; |
aoqi@0 | 2372 | assert( form != NULL, "Component's type not found"); |
aoqi@0 | 2373 | OperandForm *oper = form ? form->is_operand() : NULL; |
aoqi@0 | 2374 | if( oper ) { |
aoqi@0 | 2375 | if( oper->_matrule->is_base_constant(globals) != Form::none ) { |
aoqi@0 | 2376 | ++position; |
aoqi@0 | 2377 | } |
aoqi@0 | 2378 | } |
aoqi@0 | 2379 | } |
aoqi@0 | 2380 | |
aoqi@0 | 2381 | // Check for being passed a component that was not in the list |
aoqi@0 | 2382 | if( comp != last ) position = -1; |
aoqi@0 | 2383 | |
aoqi@0 | 2384 | return position; |
aoqi@0 | 2385 | } |
aoqi@0 | 2386 | // Provide position of constant by "name" |
aoqi@0 | 2387 | int OperandForm::constant_position(FormDict &globals, const char *name) { |
aoqi@0 | 2388 | const Component *comp = _components.search(name); |
aoqi@0 | 2389 | int idx = constant_position( globals, comp ); |
aoqi@0 | 2390 | |
aoqi@0 | 2391 | return idx; |
aoqi@0 | 2392 | } |
aoqi@0 | 2393 | |
aoqi@0 | 2394 | |
aoqi@0 | 2395 | // Return zero-based position in component list, only counting constants; |
aoqi@0 | 2396 | // Return -1 if not in list. |
aoqi@0 | 2397 | int OperandForm::register_position(FormDict &globals, const char *reg_name) { |
aoqi@0 | 2398 | // Iterate through components and count registers preceding 'last' |
aoqi@0 | 2399 | uint position = 0; |
aoqi@0 | 2400 | Component *comp; |
aoqi@0 | 2401 | _components.reset(); |
aoqi@0 | 2402 | while( (comp = _components.iter()) != NULL |
aoqi@0 | 2403 | && (strcmp(comp->_name,reg_name) != 0) ) { |
aoqi@0 | 2404 | // Special case for operands that take a single user-defined operand |
aoqi@0 | 2405 | // Skip the initial definition in the component list. |
aoqi@0 | 2406 | if( strcmp(comp->_name,this->_ident) == 0 ) continue; |
aoqi@0 | 2407 | |
aoqi@0 | 2408 | const char *type = comp->_type; |
aoqi@0 | 2409 | // Lookup operand form for component's type |
aoqi@0 | 2410 | const Form *form = globals[type]; |
aoqi@0 | 2411 | assert( form != NULL, "Component's type not found"); |
aoqi@0 | 2412 | OperandForm *oper = form ? form->is_operand() : NULL; |
aoqi@0 | 2413 | if( oper ) { |
aoqi@0 | 2414 | if( oper->_matrule->is_base_register(globals) ) { |
aoqi@0 | 2415 | ++position; |
aoqi@0 | 2416 | } |
aoqi@0 | 2417 | } |
aoqi@0 | 2418 | } |
aoqi@0 | 2419 | |
aoqi@0 | 2420 | return position; |
aoqi@0 | 2421 | } |
aoqi@0 | 2422 | |
aoqi@0 | 2423 | |
aoqi@0 | 2424 | const char *OperandForm::reduce_result() const { |
aoqi@0 | 2425 | return _ident; |
aoqi@0 | 2426 | } |
aoqi@0 | 2427 | // Return the name of the operand on the right hand side of the binary match |
aoqi@0 | 2428 | // Return NULL if there is no right hand side |
aoqi@0 | 2429 | const char *OperandForm::reduce_right(FormDict &globals) const { |
aoqi@0 | 2430 | return ( _matrule ? _matrule->reduce_right(globals) : NULL ); |
aoqi@0 | 2431 | } |
aoqi@0 | 2432 | |
aoqi@0 | 2433 | // Similar for left |
aoqi@0 | 2434 | const char *OperandForm::reduce_left(FormDict &globals) const { |
aoqi@0 | 2435 | return ( _matrule ? _matrule->reduce_left(globals) : NULL ); |
aoqi@0 | 2436 | } |
aoqi@0 | 2437 | |
aoqi@0 | 2438 | |
aoqi@0 | 2439 | // --------------------------- FILE *output_routines |
aoqi@0 | 2440 | // |
aoqi@0 | 2441 | // Output code for disp_is_oop, if true. |
aoqi@0 | 2442 | void OperandForm::disp_is_oop(FILE *fp, FormDict &globals) { |
aoqi@0 | 2443 | // Check it is a memory interface with a non-user-constant disp field |
aoqi@0 | 2444 | if ( this->_interface == NULL ) return; |
aoqi@0 | 2445 | MemInterface *mem_interface = this->_interface->is_MemInterface(); |
aoqi@0 | 2446 | if ( mem_interface == NULL ) return; |
aoqi@0 | 2447 | const char *disp = mem_interface->_disp; |
aoqi@0 | 2448 | if ( *disp != '$' ) return; |
aoqi@0 | 2449 | |
aoqi@0 | 2450 | // Lookup replacement variable in operand's component list |
aoqi@0 | 2451 | const char *rep_var = disp + 1; |
aoqi@0 | 2452 | const Component *comp = this->_components.search(rep_var); |
aoqi@0 | 2453 | assert( comp != NULL, "Replacement variable not found in components"); |
aoqi@0 | 2454 | // Lookup operand form for replacement variable's type |
aoqi@0 | 2455 | const char *type = comp->_type; |
aoqi@0 | 2456 | Form *form = (Form*)globals[type]; |
aoqi@0 | 2457 | assert( form != NULL, "Replacement variable's type not found"); |
aoqi@0 | 2458 | OperandForm *op = form->is_operand(); |
aoqi@0 | 2459 | assert( op, "Memory Interface 'disp' can only emit an operand form"); |
aoqi@0 | 2460 | // Check if this is a ConP, which may require relocation |
aoqi@0 | 2461 | if ( op->is_base_constant(globals) == Form::idealP ) { |
aoqi@0 | 2462 | // Find the constant's index: _c0, _c1, _c2, ... , _cN |
aoqi@0 | 2463 | uint idx = op->constant_position( globals, rep_var); |
aoqi@0 | 2464 | fprintf(fp," virtual relocInfo::relocType disp_reloc() const {"); |
aoqi@0 | 2465 | fprintf(fp, " return _c%d->reloc();", idx); |
aoqi@0 | 2466 | fprintf(fp, " }\n"); |
aoqi@0 | 2467 | } |
aoqi@0 | 2468 | } |
aoqi@0 | 2469 | |
aoqi@0 | 2470 | // Generate code for internal and external format methods |
aoqi@0 | 2471 | // |
aoqi@0 | 2472 | // internal access to reg# node->_idx |
aoqi@0 | 2473 | // access to subsumed constant _c0, _c1, |
aoqi@0 | 2474 | void OperandForm::int_format(FILE *fp, FormDict &globals, uint index) { |
aoqi@0 | 2475 | Form::DataType dtype; |
aoqi@0 | 2476 | if (_matrule && (_matrule->is_base_register(globals) || |
aoqi@0 | 2477 | strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) { |
aoqi@0 | 2478 | // !!!!! !!!!! |
aoqi@0 | 2479 | fprintf(fp," { char reg_str[128];\n"); |
aoqi@0 | 2480 | fprintf(fp," ra->dump_register(node,reg_str);\n"); |
aoqi@0 | 2481 | fprintf(fp," st->print(\"%cs\",reg_str);\n",'%'); |
aoqi@0 | 2482 | fprintf(fp," }\n"); |
aoqi@0 | 2483 | } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) { |
aoqi@0 | 2484 | format_constant( fp, index, dtype ); |
aoqi@0 | 2485 | } else if (ideal_to_sReg_type(_ident) != Form::none) { |
aoqi@0 | 2486 | // Special format for Stack Slot Register |
aoqi@0 | 2487 | fprintf(fp," { char reg_str[128];\n"); |
aoqi@0 | 2488 | fprintf(fp," ra->dump_register(node,reg_str);\n"); |
aoqi@0 | 2489 | fprintf(fp," st->print(\"%cs\",reg_str);\n",'%'); |
aoqi@0 | 2490 | fprintf(fp," }\n"); |
aoqi@0 | 2491 | } else { |
aoqi@0 | 2492 | fprintf(fp," st->print(\"No format defined for %s\n\");\n", _ident); |
aoqi@0 | 2493 | fflush(fp); |
aoqi@0 | 2494 | fprintf(stderr,"No format defined for %s\n", _ident); |
aoqi@0 | 2495 | dump(); |
aoqi@0 | 2496 | assert( false,"Internal error:\n output_internal_operand() attempting to output other than a Register or Constant"); |
aoqi@0 | 2497 | } |
aoqi@0 | 2498 | } |
aoqi@0 | 2499 | |
aoqi@0 | 2500 | // Similar to "int_format" but for cases where data is external to operand |
aoqi@0 | 2501 | // external access to reg# node->in(idx)->_idx, |
aoqi@0 | 2502 | void OperandForm::ext_format(FILE *fp, FormDict &globals, uint index) { |
aoqi@0 | 2503 | Form::DataType dtype; |
aoqi@0 | 2504 | if (_matrule && (_matrule->is_base_register(globals) || |
aoqi@0 | 2505 | strcmp(ideal_type(globalAD->globalNames()), "RegFlags") == 0)) { |
aoqi@0 | 2506 | fprintf(fp," { char reg_str[128];\n"); |
aoqi@0 | 2507 | fprintf(fp," ra->dump_register(node->in(idx"); |
aoqi@0 | 2508 | if ( index != 0 ) fprintf(fp, "+%d",index); |
aoqi@0 | 2509 | fprintf(fp, "),reg_str);\n"); |
aoqi@0 | 2510 | fprintf(fp," st->print(\"%cs\",reg_str);\n",'%'); |
aoqi@0 | 2511 | fprintf(fp," }\n"); |
aoqi@0 | 2512 | } else if (_matrule && (dtype = _matrule->is_base_constant(globals)) != Form::none) { |
aoqi@0 | 2513 | format_constant( fp, index, dtype ); |
aoqi@0 | 2514 | } else if (ideal_to_sReg_type(_ident) != Form::none) { |
aoqi@0 | 2515 | // Special format for Stack Slot Register |
aoqi@0 | 2516 | fprintf(fp," { char reg_str[128];\n"); |
aoqi@0 | 2517 | fprintf(fp," ra->dump_register(node->in(idx"); |
aoqi@0 | 2518 | if ( index != 0 ) fprintf(fp, "+%d",index); |
aoqi@0 | 2519 | fprintf(fp, "),reg_str);\n"); |
aoqi@0 | 2520 | fprintf(fp," st->print(\"%cs\",reg_str);\n",'%'); |
aoqi@0 | 2521 | fprintf(fp," }\n"); |
aoqi@0 | 2522 | } else { |
aoqi@0 | 2523 | fprintf(fp," st->print(\"No format defined for %s\n\");\n", _ident); |
aoqi@0 | 2524 | assert( false,"Internal error:\n output_external_operand() attempting to output other than a Register or Constant"); |
aoqi@0 | 2525 | } |
aoqi@0 | 2526 | } |
aoqi@0 | 2527 | |
aoqi@0 | 2528 | void OperandForm::format_constant(FILE *fp, uint const_index, uint const_type) { |
aoqi@0 | 2529 | switch(const_type) { |
aoqi@0 | 2530 | case Form::idealI: fprintf(fp," st->print(\"#%%d\", _c%d);\n", const_index); break; |
aoqi@0 | 2531 | case Form::idealP: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break; |
aoqi@0 | 2532 | case Form::idealNKlass: |
aoqi@0 | 2533 | case Form::idealN: fprintf(fp," if (_c%d) _c%d->dump_on(st);\n", const_index, const_index); break; |
aoqi@0 | 2534 | case Form::idealL: fprintf(fp," st->print(\"#\" INT64_FORMAT, (int64_t)_c%d);\n", const_index); break; |
aoqi@0 | 2535 | case Form::idealF: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break; |
aoqi@0 | 2536 | case Form::idealD: fprintf(fp," st->print(\"#%%f\", _c%d);\n", const_index); break; |
aoqi@0 | 2537 | default: |
aoqi@0 | 2538 | assert( false, "ShouldNotReachHere()"); |
aoqi@0 | 2539 | } |
aoqi@0 | 2540 | } |
aoqi@0 | 2541 | |
aoqi@0 | 2542 | // Return the operand form corresponding to the given index, else NULL. |
aoqi@0 | 2543 | OperandForm *OperandForm::constant_operand(FormDict &globals, |
aoqi@0 | 2544 | uint index) { |
aoqi@0 | 2545 | // !!!!! |
aoqi@0 | 2546 | // Check behavior on complex operands |
aoqi@0 | 2547 | uint n_consts = num_consts(globals); |
aoqi@0 | 2548 | if( n_consts > 0 ) { |
aoqi@0 | 2549 | uint i = 0; |
aoqi@0 | 2550 | const char *type; |
aoqi@0 | 2551 | Component *comp; |
aoqi@0 | 2552 | _components.reset(); |
aoqi@0 | 2553 | if ((comp = _components.iter()) == NULL) { |
aoqi@0 | 2554 | assert(n_consts == 1, "Bad component list detected.\n"); |
aoqi@0 | 2555 | // Current operand is THE operand |
aoqi@0 | 2556 | if ( index == 0 ) { |
aoqi@0 | 2557 | return this; |
aoqi@0 | 2558 | } |
aoqi@0 | 2559 | } // end if NULL |
aoqi@0 | 2560 | else { |
aoqi@0 | 2561 | // Skip the first component, it can not be a DEF of a constant |
aoqi@0 | 2562 | do { |
aoqi@0 | 2563 | type = comp->base_type(globals); |
aoqi@0 | 2564 | // Check that "type" is a 'ConI', 'ConP', ... |
aoqi@0 | 2565 | if ( ideal_to_const_type(type) != Form::none ) { |
aoqi@0 | 2566 | // When at correct component, get corresponding Operand |
aoqi@0 | 2567 | if ( index == 0 ) { |
aoqi@0 | 2568 | return globals[comp->_type]->is_operand(); |
aoqi@0 | 2569 | } |
aoqi@0 | 2570 | // Decrement number of constants to go |
aoqi@0 | 2571 | --index; |
aoqi@0 | 2572 | } |
aoqi@0 | 2573 | } while((comp = _components.iter()) != NULL); |
aoqi@0 | 2574 | } |
aoqi@0 | 2575 | } |
aoqi@0 | 2576 | |
aoqi@0 | 2577 | // Did not find a constant for this index. |
aoqi@0 | 2578 | return NULL; |
aoqi@0 | 2579 | } |
aoqi@0 | 2580 | |
aoqi@0 | 2581 | // If this operand has a single ideal type, return its type |
aoqi@0 | 2582 | Form::DataType OperandForm::simple_type(FormDict &globals) const { |
aoqi@0 | 2583 | const char *type_name = ideal_type(globals); |
aoqi@0 | 2584 | Form::DataType type = type_name ? ideal_to_const_type( type_name ) |
aoqi@0 | 2585 | : Form::none; |
aoqi@0 | 2586 | return type; |
aoqi@0 | 2587 | } |
aoqi@0 | 2588 | |
aoqi@0 | 2589 | Form::DataType OperandForm::is_base_constant(FormDict &globals) const { |
aoqi@0 | 2590 | if ( _matrule == NULL ) return Form::none; |
aoqi@0 | 2591 | |
aoqi@0 | 2592 | return _matrule->is_base_constant(globals); |
aoqi@0 | 2593 | } |
aoqi@0 | 2594 | |
aoqi@0 | 2595 | // "true" if this operand is a simple type that is swallowed |
aoqi@0 | 2596 | bool OperandForm::swallowed(FormDict &globals) const { |
aoqi@0 | 2597 | Form::DataType type = simple_type(globals); |
aoqi@0 | 2598 | if( type != Form::none ) { |
aoqi@0 | 2599 | return true; |
aoqi@0 | 2600 | } |
aoqi@0 | 2601 | |
aoqi@0 | 2602 | return false; |
aoqi@0 | 2603 | } |
aoqi@0 | 2604 | |
aoqi@0 | 2605 | // Output code to access the value of the index'th constant |
aoqi@0 | 2606 | void OperandForm::access_constant(FILE *fp, FormDict &globals, |
aoqi@0 | 2607 | uint const_index) { |
aoqi@0 | 2608 | OperandForm *oper = constant_operand(globals, const_index); |
aoqi@0 | 2609 | assert( oper, "Index exceeds number of constants in operand"); |
aoqi@0 | 2610 | Form::DataType dtype = oper->is_base_constant(globals); |
aoqi@0 | 2611 | |
aoqi@0 | 2612 | switch(dtype) { |
aoqi@0 | 2613 | case idealI: fprintf(fp,"_c%d", const_index); break; |
aoqi@0 | 2614 | case idealP: fprintf(fp,"_c%d->get_con()",const_index); break; |
aoqi@0 | 2615 | case idealL: fprintf(fp,"_c%d", const_index); break; |
aoqi@0 | 2616 | case idealF: fprintf(fp,"_c%d", const_index); break; |
aoqi@0 | 2617 | case idealD: fprintf(fp,"_c%d", const_index); break; |
aoqi@0 | 2618 | default: |
aoqi@0 | 2619 | assert( false, "ShouldNotReachHere()"); |
aoqi@0 | 2620 | } |
aoqi@0 | 2621 | } |
aoqi@0 | 2622 | |
aoqi@0 | 2623 | |
aoqi@0 | 2624 | void OperandForm::dump() { |
aoqi@0 | 2625 | output(stderr); |
aoqi@0 | 2626 | } |
aoqi@0 | 2627 | |
aoqi@0 | 2628 | void OperandForm::output(FILE *fp) { |
aoqi@0 | 2629 | fprintf(fp,"\nOperand: %s\n", (_ident?_ident:"")); |
aoqi@0 | 2630 | if (_matrule) _matrule->dump(); |
aoqi@0 | 2631 | if (_interface) _interface->dump(); |
aoqi@0 | 2632 | if (_attribs) _attribs->dump(); |
aoqi@0 | 2633 | if (_predicate) _predicate->dump(); |
aoqi@0 | 2634 | if (_constraint) _constraint->dump(); |
aoqi@0 | 2635 | if (_construct) _construct->dump(); |
aoqi@0 | 2636 | if (_format) _format->dump(); |
aoqi@0 | 2637 | } |
aoqi@0 | 2638 | |
aoqi@0 | 2639 | //------------------------------Constraint------------------------------------- |
aoqi@0 | 2640 | Constraint::Constraint(const char *func, const char *arg) |
aoqi@0 | 2641 | : _func(func), _arg(arg) { |
aoqi@0 | 2642 | } |
aoqi@0 | 2643 | Constraint::~Constraint() { /* not owner of char* */ |
aoqi@0 | 2644 | } |
aoqi@0 | 2645 | |
aoqi@0 | 2646 | bool Constraint::stack_slots_only() const { |
aoqi@0 | 2647 | return strcmp(_func, "ALLOC_IN_RC") == 0 |
aoqi@0 | 2648 | && strcmp(_arg, "stack_slots") == 0; |
aoqi@0 | 2649 | } |
aoqi@0 | 2650 | |
aoqi@0 | 2651 | void Constraint::dump() { |
aoqi@0 | 2652 | output(stderr); |
aoqi@0 | 2653 | } |
aoqi@0 | 2654 | |
aoqi@0 | 2655 | void Constraint::output(FILE *fp) { // Write info to output files |
aoqi@0 | 2656 | assert((_func != NULL && _arg != NULL),"missing constraint function or arg"); |
aoqi@0 | 2657 | fprintf(fp,"Constraint: %s ( %s )\n", _func, _arg); |
aoqi@0 | 2658 | } |
aoqi@0 | 2659 | |
aoqi@0 | 2660 | //------------------------------Predicate-------------------------------------- |
aoqi@0 | 2661 | Predicate::Predicate(char *pr) |
aoqi@0 | 2662 | : _pred(pr) { |
aoqi@0 | 2663 | } |
aoqi@0 | 2664 | Predicate::~Predicate() { |
aoqi@0 | 2665 | } |
aoqi@0 | 2666 | |
aoqi@0 | 2667 | void Predicate::dump() { |
aoqi@0 | 2668 | output(stderr); |
aoqi@0 | 2669 | } |
aoqi@0 | 2670 | |
aoqi@0 | 2671 | void Predicate::output(FILE *fp) { |
aoqi@0 | 2672 | fprintf(fp,"Predicate"); // Write to output files |
aoqi@0 | 2673 | } |
aoqi@0 | 2674 | //------------------------------Interface-------------------------------------- |
aoqi@0 | 2675 | Interface::Interface(const char *name) : _name(name) { |
aoqi@0 | 2676 | } |
aoqi@0 | 2677 | Interface::~Interface() { |
aoqi@0 | 2678 | } |
aoqi@0 | 2679 | |
aoqi@0 | 2680 | Form::InterfaceType Interface::interface_type(FormDict &globals) const { |
aoqi@0 | 2681 | Interface *thsi = (Interface*)this; |
aoqi@0 | 2682 | if ( thsi->is_RegInterface() ) return Form::register_interface; |
aoqi@0 | 2683 | if ( thsi->is_MemInterface() ) return Form::memory_interface; |
aoqi@0 | 2684 | if ( thsi->is_ConstInterface() ) return Form::constant_interface; |
aoqi@0 | 2685 | if ( thsi->is_CondInterface() ) return Form::conditional_interface; |
aoqi@0 | 2686 | |
aoqi@0 | 2687 | return Form::no_interface; |
aoqi@0 | 2688 | } |
aoqi@0 | 2689 | |
aoqi@0 | 2690 | RegInterface *Interface::is_RegInterface() { |
aoqi@0 | 2691 | if ( strcmp(_name,"REG_INTER") != 0 ) |
aoqi@0 | 2692 | return NULL; |
aoqi@0 | 2693 | return (RegInterface*)this; |
aoqi@0 | 2694 | } |
aoqi@0 | 2695 | MemInterface *Interface::is_MemInterface() { |
aoqi@0 | 2696 | if ( strcmp(_name,"MEMORY_INTER") != 0 ) return NULL; |
aoqi@0 | 2697 | return (MemInterface*)this; |
aoqi@0 | 2698 | } |
aoqi@0 | 2699 | ConstInterface *Interface::is_ConstInterface() { |
aoqi@0 | 2700 | if ( strcmp(_name,"CONST_INTER") != 0 ) return NULL; |
aoqi@0 | 2701 | return (ConstInterface*)this; |
aoqi@0 | 2702 | } |
aoqi@0 | 2703 | CondInterface *Interface::is_CondInterface() { |
aoqi@0 | 2704 | if ( strcmp(_name,"COND_INTER") != 0 ) return NULL; |
aoqi@0 | 2705 | return (CondInterface*)this; |
aoqi@0 | 2706 | } |
aoqi@0 | 2707 | |
aoqi@0 | 2708 | |
aoqi@0 | 2709 | void Interface::dump() { |
aoqi@0 | 2710 | output(stderr); |
aoqi@0 | 2711 | } |
aoqi@0 | 2712 | |
aoqi@0 | 2713 | // Write info to output files |
aoqi@0 | 2714 | void Interface::output(FILE *fp) { |
aoqi@0 | 2715 | fprintf(fp,"Interface: %s\n", (_name ? _name : "") ); |
aoqi@0 | 2716 | } |
aoqi@0 | 2717 | |
aoqi@0 | 2718 | //------------------------------RegInterface----------------------------------- |
aoqi@0 | 2719 | RegInterface::RegInterface() : Interface("REG_INTER") { |
aoqi@0 | 2720 | } |
aoqi@0 | 2721 | RegInterface::~RegInterface() { |
aoqi@0 | 2722 | } |
aoqi@0 | 2723 | |
aoqi@0 | 2724 | void RegInterface::dump() { |
aoqi@0 | 2725 | output(stderr); |
aoqi@0 | 2726 | } |
aoqi@0 | 2727 | |
aoqi@0 | 2728 | // Write info to output files |
aoqi@0 | 2729 | void RegInterface::output(FILE *fp) { |
aoqi@0 | 2730 | Interface::output(fp); |
aoqi@0 | 2731 | } |
aoqi@0 | 2732 | |
aoqi@0 | 2733 | //------------------------------ConstInterface--------------------------------- |
aoqi@0 | 2734 | ConstInterface::ConstInterface() : Interface("CONST_INTER") { |
aoqi@0 | 2735 | } |
aoqi@0 | 2736 | ConstInterface::~ConstInterface() { |
aoqi@0 | 2737 | } |
aoqi@0 | 2738 | |
aoqi@0 | 2739 | void ConstInterface::dump() { |
aoqi@0 | 2740 | output(stderr); |
aoqi@0 | 2741 | } |
aoqi@0 | 2742 | |
aoqi@0 | 2743 | // Write info to output files |
aoqi@0 | 2744 | void ConstInterface::output(FILE *fp) { |
aoqi@0 | 2745 | Interface::output(fp); |
aoqi@0 | 2746 | } |
aoqi@0 | 2747 | |
aoqi@0 | 2748 | //------------------------------MemInterface----------------------------------- |
aoqi@0 | 2749 | MemInterface::MemInterface(char *base, char *index, char *scale, char *disp) |
aoqi@0 | 2750 | : Interface("MEMORY_INTER"), _base(base), _index(index), _scale(scale), _disp(disp) { |
aoqi@0 | 2751 | } |
aoqi@0 | 2752 | MemInterface::~MemInterface() { |
aoqi@0 | 2753 | // not owner of any character arrays |
aoqi@0 | 2754 | } |
aoqi@0 | 2755 | |
aoqi@0 | 2756 | void MemInterface::dump() { |
aoqi@0 | 2757 | output(stderr); |
aoqi@0 | 2758 | } |
aoqi@0 | 2759 | |
aoqi@0 | 2760 | // Write info to output files |
aoqi@0 | 2761 | void MemInterface::output(FILE *fp) { |
aoqi@0 | 2762 | Interface::output(fp); |
aoqi@0 | 2763 | if ( _base != NULL ) fprintf(fp," base == %s\n", _base); |
aoqi@0 | 2764 | if ( _index != NULL ) fprintf(fp," index == %s\n", _index); |
aoqi@0 | 2765 | if ( _scale != NULL ) fprintf(fp," scale == %s\n", _scale); |
aoqi@0 | 2766 | if ( _disp != NULL ) fprintf(fp," disp == %s\n", _disp); |
aoqi@0 | 2767 | // fprintf(fp,"\n"); |
aoqi@0 | 2768 | } |
aoqi@0 | 2769 | |
aoqi@0 | 2770 | //------------------------------CondInterface---------------------------------- |
aoqi@0 | 2771 | CondInterface::CondInterface(const char* equal, const char* equal_format, |
aoqi@0 | 2772 | const char* not_equal, const char* not_equal_format, |
aoqi@0 | 2773 | const char* less, const char* less_format, |
aoqi@0 | 2774 | const char* greater_equal, const char* greater_equal_format, |
aoqi@0 | 2775 | const char* less_equal, const char* less_equal_format, |
aoqi@0 | 2776 | const char* greater, const char* greater_format, |
aoqi@0 | 2777 | const char* overflow, const char* overflow_format, |
aoqi@0 | 2778 | const char* no_overflow, const char* no_overflow_format) |
aoqi@0 | 2779 | : Interface("COND_INTER"), |
aoqi@0 | 2780 | _equal(equal), _equal_format(equal_format), |
aoqi@0 | 2781 | _not_equal(not_equal), _not_equal_format(not_equal_format), |
aoqi@0 | 2782 | _less(less), _less_format(less_format), |
aoqi@0 | 2783 | _greater_equal(greater_equal), _greater_equal_format(greater_equal_format), |
aoqi@0 | 2784 | _less_equal(less_equal), _less_equal_format(less_equal_format), |
aoqi@0 | 2785 | _greater(greater), _greater_format(greater_format), |
aoqi@0 | 2786 | _overflow(overflow), _overflow_format(overflow_format), |
aoqi@0 | 2787 | _no_overflow(no_overflow), _no_overflow_format(no_overflow_format) { |
aoqi@0 | 2788 | } |
aoqi@0 | 2789 | CondInterface::~CondInterface() { |
aoqi@0 | 2790 | // not owner of any character arrays |
aoqi@0 | 2791 | } |
aoqi@0 | 2792 | |
aoqi@0 | 2793 | void CondInterface::dump() { |
aoqi@0 | 2794 | output(stderr); |
aoqi@0 | 2795 | } |
aoqi@0 | 2796 | |
aoqi@0 | 2797 | // Write info to output files |
aoqi@0 | 2798 | void CondInterface::output(FILE *fp) { |
aoqi@0 | 2799 | Interface::output(fp); |
aoqi@0 | 2800 | if ( _equal != NULL ) fprintf(fp," equal == %s\n", _equal); |
aoqi@0 | 2801 | if ( _not_equal != NULL ) fprintf(fp," not_equal == %s\n", _not_equal); |
aoqi@0 | 2802 | if ( _less != NULL ) fprintf(fp," less == %s\n", _less); |
aoqi@0 | 2803 | if ( _greater_equal != NULL ) fprintf(fp," greater_equal == %s\n", _greater_equal); |
aoqi@0 | 2804 | if ( _less_equal != NULL ) fprintf(fp," less_equal == %s\n", _less_equal); |
aoqi@0 | 2805 | if ( _greater != NULL ) fprintf(fp," greater == %s\n", _greater); |
aoqi@0 | 2806 | if ( _overflow != NULL ) fprintf(fp," overflow == %s\n", _overflow); |
aoqi@0 | 2807 | if ( _no_overflow != NULL ) fprintf(fp," no_overflow == %s\n", _no_overflow); |
aoqi@0 | 2808 | // fprintf(fp,"\n"); |
aoqi@0 | 2809 | } |
aoqi@0 | 2810 | |
aoqi@0 | 2811 | //------------------------------ConstructRule---------------------------------- |
aoqi@0 | 2812 | ConstructRule::ConstructRule(char *cnstr) |
aoqi@0 | 2813 | : _construct(cnstr) { |
aoqi@0 | 2814 | } |
aoqi@0 | 2815 | ConstructRule::~ConstructRule() { |
aoqi@0 | 2816 | } |
aoqi@0 | 2817 | |
aoqi@0 | 2818 | void ConstructRule::dump() { |
aoqi@0 | 2819 | output(stderr); |
aoqi@0 | 2820 | } |
aoqi@0 | 2821 | |
aoqi@0 | 2822 | void ConstructRule::output(FILE *fp) { |
aoqi@0 | 2823 | fprintf(fp,"\nConstruct Rule\n"); // Write to output files |
aoqi@0 | 2824 | } |
aoqi@0 | 2825 | |
aoqi@0 | 2826 | |
aoqi@0 | 2827 | //==============================Shared Forms=================================== |
aoqi@0 | 2828 | //------------------------------AttributeForm---------------------------------- |
aoqi@0 | 2829 | int AttributeForm::_insId = 0; // start counter at 0 |
aoqi@0 | 2830 | int AttributeForm::_opId = 0; // start counter at 0 |
aoqi@0 | 2831 | const char* AttributeForm::_ins_cost = "ins_cost"; // required name |
aoqi@0 | 2832 | const char* AttributeForm::_op_cost = "op_cost"; // required name |
aoqi@0 | 2833 | |
aoqi@0 | 2834 | AttributeForm::AttributeForm(char *attr, int type, char *attrdef) |
aoqi@0 | 2835 | : Form(Form::ATTR), _attrname(attr), _atype(type), _attrdef(attrdef) { |
aoqi@0 | 2836 | if (type==OP_ATTR) { |
aoqi@0 | 2837 | id = ++_opId; |
aoqi@0 | 2838 | } |
aoqi@0 | 2839 | else if (type==INS_ATTR) { |
aoqi@0 | 2840 | id = ++_insId; |
aoqi@0 | 2841 | } |
aoqi@0 | 2842 | else assert( false,""); |
aoqi@0 | 2843 | } |
aoqi@0 | 2844 | AttributeForm::~AttributeForm() { |
aoqi@0 | 2845 | } |
aoqi@0 | 2846 | |
aoqi@0 | 2847 | // Dynamic type check |
aoqi@0 | 2848 | AttributeForm *AttributeForm::is_attribute() const { |
aoqi@0 | 2849 | return (AttributeForm*)this; |
aoqi@0 | 2850 | } |
aoqi@0 | 2851 | |
aoqi@0 | 2852 | |
aoqi@0 | 2853 | // inlined // int AttributeForm::type() { return id;} |
aoqi@0 | 2854 | |
aoqi@0 | 2855 | void AttributeForm::dump() { |
aoqi@0 | 2856 | output(stderr); |
aoqi@0 | 2857 | } |
aoqi@0 | 2858 | |
aoqi@0 | 2859 | void AttributeForm::output(FILE *fp) { |
aoqi@0 | 2860 | if( _attrname && _attrdef ) { |
aoqi@0 | 2861 | fprintf(fp,"\n// AttributeForm \nstatic const int %s = %s;\n", |
aoqi@0 | 2862 | _attrname, _attrdef); |
aoqi@0 | 2863 | } |
aoqi@0 | 2864 | else { |
aoqi@0 | 2865 | fprintf(fp,"\n// AttributeForm missing name %s or definition %s\n", |
aoqi@0 | 2866 | (_attrname?_attrname:""), (_attrdef?_attrdef:"") ); |
aoqi@0 | 2867 | } |
aoqi@0 | 2868 | } |
aoqi@0 | 2869 | |
aoqi@0 | 2870 | //------------------------------Component-------------------------------------- |
aoqi@0 | 2871 | Component::Component(const char *name, const char *type, int usedef) |
aoqi@0 | 2872 | : _name(name), _type(type), _usedef(usedef) { |
aoqi@0 | 2873 | _ftype = Form::COMP; |
aoqi@0 | 2874 | } |
aoqi@0 | 2875 | Component::~Component() { |
aoqi@0 | 2876 | } |
aoqi@0 | 2877 | |
aoqi@0 | 2878 | // True if this component is equal to the parameter. |
aoqi@0 | 2879 | bool Component::is(int use_def_kill_enum) const { |
aoqi@0 | 2880 | return (_usedef == use_def_kill_enum ? true : false); |
aoqi@0 | 2881 | } |
aoqi@0 | 2882 | // True if this component is used/def'd/kill'd as the parameter suggests. |
aoqi@0 | 2883 | bool Component::isa(int use_def_kill_enum) const { |
aoqi@0 | 2884 | return (_usedef & use_def_kill_enum) == use_def_kill_enum; |
aoqi@0 | 2885 | } |
aoqi@0 | 2886 | |
aoqi@0 | 2887 | // Extend this component with additional use/def/kill behavior |
aoqi@0 | 2888 | int Component::promote_use_def_info(int new_use_def) { |
aoqi@0 | 2889 | _usedef |= new_use_def; |
aoqi@0 | 2890 | |
aoqi@0 | 2891 | return _usedef; |
aoqi@0 | 2892 | } |
aoqi@0 | 2893 | |
aoqi@0 | 2894 | // Check the base type of this component, if it has one |
aoqi@0 | 2895 | const char *Component::base_type(FormDict &globals) { |
aoqi@0 | 2896 | const Form *frm = globals[_type]; |
aoqi@0 | 2897 | if (frm == NULL) return NULL; |
aoqi@0 | 2898 | OperandForm *op = frm->is_operand(); |
aoqi@0 | 2899 | if (op == NULL) return NULL; |
aoqi@0 | 2900 | if (op->ideal_only()) return op->_ident; |
aoqi@0 | 2901 | return (char *)op->ideal_type(globals); |
aoqi@0 | 2902 | } |
aoqi@0 | 2903 | |
aoqi@0 | 2904 | void Component::dump() { |
aoqi@0 | 2905 | output(stderr); |
aoqi@0 | 2906 | } |
aoqi@0 | 2907 | |
aoqi@0 | 2908 | void Component::output(FILE *fp) { |
aoqi@0 | 2909 | fprintf(fp,"Component:"); // Write to output files |
aoqi@0 | 2910 | fprintf(fp, " name = %s", _name); |
aoqi@0 | 2911 | fprintf(fp, ", type = %s", _type); |
aoqi@0 | 2912 | assert(_usedef != 0, "unknown effect"); |
aoqi@0 | 2913 | fprintf(fp, ", use/def = %s\n", getUsedefName()); |
aoqi@0 | 2914 | } |
aoqi@0 | 2915 | |
aoqi@0 | 2916 | |
aoqi@0 | 2917 | //------------------------------ComponentList--------------------------------- |
aoqi@0 | 2918 | ComponentList::ComponentList() : NameList(), _matchcnt(0) { |
aoqi@0 | 2919 | } |
aoqi@0 | 2920 | ComponentList::~ComponentList() { |
aoqi@0 | 2921 | // // This list may not own its elements if copied via assignment |
aoqi@0 | 2922 | // Component *component; |
aoqi@0 | 2923 | // for (reset(); (component = iter()) != NULL;) { |
aoqi@0 | 2924 | // delete component; |
aoqi@0 | 2925 | // } |
aoqi@0 | 2926 | } |
aoqi@0 | 2927 | |
aoqi@0 | 2928 | void ComponentList::insert(Component *component, bool mflag) { |
aoqi@0 | 2929 | NameList::addName((char *)component); |
aoqi@0 | 2930 | if(mflag) _matchcnt++; |
aoqi@0 | 2931 | } |
aoqi@0 | 2932 | void ComponentList::insert(const char *name, const char *opType, int usedef, |
aoqi@0 | 2933 | bool mflag) { |
aoqi@0 | 2934 | Component * component = new Component(name, opType, usedef); |
aoqi@0 | 2935 | insert(component, mflag); |
aoqi@0 | 2936 | } |
aoqi@0 | 2937 | Component *ComponentList::current() { return (Component*)NameList::current(); } |
aoqi@0 | 2938 | Component *ComponentList::iter() { return (Component*)NameList::iter(); } |
aoqi@0 | 2939 | Component *ComponentList::match_iter() { |
aoqi@0 | 2940 | if(_iter < _matchcnt) return (Component*)NameList::iter(); |
aoqi@0 | 2941 | return NULL; |
aoqi@0 | 2942 | } |
aoqi@0 | 2943 | Component *ComponentList::post_match_iter() { |
aoqi@0 | 2944 | Component *comp = iter(); |
aoqi@0 | 2945 | // At end of list? |
aoqi@0 | 2946 | if ( comp == NULL ) { |
aoqi@0 | 2947 | return comp; |
aoqi@0 | 2948 | } |
aoqi@0 | 2949 | // In post-match components? |
aoqi@0 | 2950 | if (_iter > match_count()-1) { |
aoqi@0 | 2951 | return comp; |
aoqi@0 | 2952 | } |
aoqi@0 | 2953 | |
aoqi@0 | 2954 | return post_match_iter(); |
aoqi@0 | 2955 | } |
aoqi@0 | 2956 | |
aoqi@0 | 2957 | void ComponentList::reset() { NameList::reset(); } |
aoqi@0 | 2958 | int ComponentList::count() { return NameList::count(); } |
aoqi@0 | 2959 | |
aoqi@0 | 2960 | Component *ComponentList::operator[](int position) { |
aoqi@0 | 2961 | // Shortcut complete iteration if there are not enough entries |
aoqi@0 | 2962 | if (position >= count()) return NULL; |
aoqi@0 | 2963 | |
aoqi@0 | 2964 | int index = 0; |
aoqi@0 | 2965 | Component *component = NULL; |
aoqi@0 | 2966 | for (reset(); (component = iter()) != NULL;) { |
aoqi@0 | 2967 | if (index == position) { |
aoqi@0 | 2968 | return component; |
aoqi@0 | 2969 | } |
aoqi@0 | 2970 | ++index; |
aoqi@0 | 2971 | } |
aoqi@0 | 2972 | |
aoqi@0 | 2973 | return NULL; |
aoqi@0 | 2974 | } |
aoqi@0 | 2975 | |
aoqi@0 | 2976 | const Component *ComponentList::search(const char *name) { |
aoqi@0 | 2977 | PreserveIter pi(this); |
aoqi@0 | 2978 | reset(); |
aoqi@0 | 2979 | for( Component *comp = NULL; ((comp = iter()) != NULL); ) { |
aoqi@0 | 2980 | if( strcmp(comp->_name,name) == 0 ) return comp; |
aoqi@0 | 2981 | } |
aoqi@0 | 2982 | |
aoqi@0 | 2983 | return NULL; |
aoqi@0 | 2984 | } |
aoqi@0 | 2985 | |
aoqi@0 | 2986 | // Return number of USEs + number of DEFs |
aoqi@0 | 2987 | // When there are no components, or the first component is a USE, |
aoqi@0 | 2988 | // then we add '1' to hold a space for the 'result' operand. |
aoqi@0 | 2989 | int ComponentList::num_operands() { |
aoqi@0 | 2990 | PreserveIter pi(this); |
aoqi@0 | 2991 | uint count = 1; // result operand |
aoqi@0 | 2992 | uint position = 0; |
aoqi@0 | 2993 | |
aoqi@0 | 2994 | Component *component = NULL; |
aoqi@0 | 2995 | for( reset(); (component = iter()) != NULL; ++position ) { |
aoqi@0 | 2996 | if( component->isa(Component::USE) || |
aoqi@0 | 2997 | ( position == 0 && (! component->isa(Component::DEF))) ) { |
aoqi@0 | 2998 | ++count; |
aoqi@0 | 2999 | } |
aoqi@0 | 3000 | } |
aoqi@0 | 3001 | |
aoqi@0 | 3002 | return count; |
aoqi@0 | 3003 | } |
aoqi@0 | 3004 | |
aoqi@0 | 3005 | // Return zero-based position of operand 'name' in list; -1 if not in list. |
aoqi@0 | 3006 | // if parameter 'usedef' is ::USE, it will match USE, USE_DEF, ... |
aoqi@0 | 3007 | int ComponentList::operand_position(const char *name, int usedef, Form *fm) { |
aoqi@0 | 3008 | PreserveIter pi(this); |
aoqi@0 | 3009 | int position = 0; |
aoqi@0 | 3010 | int num_opnds = num_operands(); |
aoqi@0 | 3011 | Component *component; |
aoqi@0 | 3012 | Component* preceding_non_use = NULL; |
aoqi@0 | 3013 | Component* first_def = NULL; |
aoqi@0 | 3014 | for (reset(); (component = iter()) != NULL; ++position) { |
aoqi@0 | 3015 | // When the first component is not a DEF, |
aoqi@0 | 3016 | // leave space for the result operand! |
aoqi@0 | 3017 | if ( position==0 && (! component->isa(Component::DEF)) ) { |
aoqi@0 | 3018 | ++position; |
aoqi@0 | 3019 | ++num_opnds; |
aoqi@0 | 3020 | } |
aoqi@0 | 3021 | if (strcmp(name, component->_name)==0 && (component->isa(usedef))) { |
aoqi@0 | 3022 | // When the first entry in the component list is a DEF and a USE |
aoqi@0 | 3023 | // Treat them as being separate, a DEF first, then a USE |
aoqi@0 | 3024 | if( position==0 |
aoqi@0 | 3025 | && usedef==Component::USE && component->isa(Component::DEF) ) { |
aoqi@0 | 3026 | assert(position+1 < num_opnds, "advertised index in bounds"); |
aoqi@0 | 3027 | return position+1; |
aoqi@0 | 3028 | } else { |
aoqi@0 | 3029 | if( preceding_non_use && strcmp(component->_name, preceding_non_use->_name) ) { |
aoqi@0 | 3030 | fprintf(stderr, "the name '%s(%s)' should not precede the name '%s(%s)'", |
aoqi@0 | 3031 | preceding_non_use->_name, preceding_non_use->getUsedefName(), |
aoqi@0 | 3032 | name, component->getUsedefName()); |
aoqi@0 | 3033 | if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident); |
aoqi@0 | 3034 | if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident); |
aoqi@0 | 3035 | fprintf(stderr, "\n"); |
aoqi@0 | 3036 | } |
aoqi@0 | 3037 | if( position >= num_opnds ) { |
aoqi@0 | 3038 | fprintf(stderr, "the name '%s' is too late in its name list", name); |
aoqi@0 | 3039 | if (fm && fm->is_instruction()) fprintf(stderr, "in form '%s'", fm->is_instruction()->_ident); |
aoqi@0 | 3040 | if (fm && fm->is_operand()) fprintf(stderr, "in form '%s'", fm->is_operand()->_ident); |
aoqi@0 | 3041 | fprintf(stderr, "\n"); |
aoqi@0 | 3042 | } |
aoqi@0 | 3043 | assert(position < num_opnds, "advertised index in bounds"); |
aoqi@0 | 3044 | return position; |
aoqi@0 | 3045 | } |
aoqi@0 | 3046 | } |
aoqi@0 | 3047 | if( component->isa(Component::DEF) |
aoqi@0 | 3048 | && component->isa(Component::USE) ) { |
aoqi@0 | 3049 | ++position; |
aoqi@0 | 3050 | if( position != 1 ) --position; // only use two slots for the 1st USE_DEF |
aoqi@0 | 3051 | } |
aoqi@0 | 3052 | if( component->isa(Component::DEF) && !first_def ) { |
aoqi@0 | 3053 | first_def = component; |
aoqi@0 | 3054 | } |
aoqi@0 | 3055 | if( !component->isa(Component::USE) && component != first_def ) { |
aoqi@0 | 3056 | preceding_non_use = component; |
aoqi@0 | 3057 | } else if( preceding_non_use && !strcmp(component->_name, preceding_non_use->_name) ) { |
aoqi@0 | 3058 | preceding_non_use = NULL; |
aoqi@0 | 3059 | } |
aoqi@0 | 3060 | } |
aoqi@0 | 3061 | return Not_in_list; |
aoqi@0 | 3062 | } |
aoqi@0 | 3063 | |
aoqi@0 | 3064 | // Find position for this name, regardless of use/def information |
aoqi@0 | 3065 | int ComponentList::operand_position(const char *name) { |
aoqi@0 | 3066 | PreserveIter pi(this); |
aoqi@0 | 3067 | int position = 0; |
aoqi@0 | 3068 | Component *component; |
aoqi@0 | 3069 | for (reset(); (component = iter()) != NULL; ++position) { |
aoqi@0 | 3070 | // When the first component is not a DEF, |
aoqi@0 | 3071 | // leave space for the result operand! |
aoqi@0 | 3072 | if ( position==0 && (! component->isa(Component::DEF)) ) { |
aoqi@0 | 3073 | ++position; |
aoqi@0 | 3074 | } |
aoqi@0 | 3075 | if (strcmp(name, component->_name)==0) { |
aoqi@0 | 3076 | return position; |
aoqi@0 | 3077 | } |
aoqi@0 | 3078 | if( component->isa(Component::DEF) |
aoqi@0 | 3079 | && component->isa(Component::USE) ) { |
aoqi@0 | 3080 | ++position; |
aoqi@0 | 3081 | if( position != 1 ) --position; // only use two slots for the 1st USE_DEF |
aoqi@0 | 3082 | } |
aoqi@0 | 3083 | } |
aoqi@0 | 3084 | return Not_in_list; |
aoqi@0 | 3085 | } |
aoqi@0 | 3086 | |
aoqi@0 | 3087 | int ComponentList::operand_position_format(const char *name, Form *fm) { |
aoqi@0 | 3088 | PreserveIter pi(this); |
aoqi@0 | 3089 | int first_position = operand_position(name); |
aoqi@0 | 3090 | int use_position = operand_position(name, Component::USE, fm); |
aoqi@0 | 3091 | |
aoqi@0 | 3092 | return ((first_position < use_position) ? use_position : first_position); |
aoqi@0 | 3093 | } |
aoqi@0 | 3094 | |
aoqi@0 | 3095 | int ComponentList::label_position() { |
aoqi@0 | 3096 | PreserveIter pi(this); |
aoqi@0 | 3097 | int position = 0; |
aoqi@0 | 3098 | reset(); |
aoqi@0 | 3099 | for( Component *comp; (comp = iter()) != NULL; ++position) { |
aoqi@0 | 3100 | // When the first component is not a DEF, |
aoqi@0 | 3101 | // leave space for the result operand! |
aoqi@0 | 3102 | if ( position==0 && (! comp->isa(Component::DEF)) ) { |
aoqi@0 | 3103 | ++position; |
aoqi@0 | 3104 | } |
aoqi@0 | 3105 | if (strcmp(comp->_type, "label")==0) { |
aoqi@0 | 3106 | return position; |
aoqi@0 | 3107 | } |
aoqi@0 | 3108 | if( comp->isa(Component::DEF) |
aoqi@0 | 3109 | && comp->isa(Component::USE) ) { |
aoqi@0 | 3110 | ++position; |
aoqi@0 | 3111 | if( position != 1 ) --position; // only use two slots for the 1st USE_DEF |
aoqi@0 | 3112 | } |
aoqi@0 | 3113 | } |
aoqi@0 | 3114 | |
aoqi@0 | 3115 | return -1; |
aoqi@0 | 3116 | } |
aoqi@0 | 3117 | |
aoqi@0 | 3118 | int ComponentList::method_position() { |
aoqi@0 | 3119 | PreserveIter pi(this); |
aoqi@0 | 3120 | int position = 0; |
aoqi@0 | 3121 | reset(); |
aoqi@0 | 3122 | for( Component *comp; (comp = iter()) != NULL; ++position) { |
aoqi@0 | 3123 | // When the first component is not a DEF, |
aoqi@0 | 3124 | // leave space for the result operand! |
aoqi@0 | 3125 | if ( position==0 && (! comp->isa(Component::DEF)) ) { |
aoqi@0 | 3126 | ++position; |
aoqi@0 | 3127 | } |
aoqi@0 | 3128 | if (strcmp(comp->_type, "method")==0) { |
aoqi@0 | 3129 | return position; |
aoqi@0 | 3130 | } |
aoqi@0 | 3131 | if( comp->isa(Component::DEF) |
aoqi@0 | 3132 | && comp->isa(Component::USE) ) { |
aoqi@0 | 3133 | ++position; |
aoqi@0 | 3134 | if( position != 1 ) --position; // only use two slots for the 1st USE_DEF |
aoqi@0 | 3135 | } |
aoqi@0 | 3136 | } |
aoqi@0 | 3137 | |
aoqi@0 | 3138 | return -1; |
aoqi@0 | 3139 | } |
aoqi@0 | 3140 | |
aoqi@0 | 3141 | void ComponentList::dump() { output(stderr); } |
aoqi@0 | 3142 | |
aoqi@0 | 3143 | void ComponentList::output(FILE *fp) { |
aoqi@0 | 3144 | PreserveIter pi(this); |
aoqi@0 | 3145 | fprintf(fp, "\n"); |
aoqi@0 | 3146 | Component *component; |
aoqi@0 | 3147 | for (reset(); (component = iter()) != NULL;) { |
aoqi@0 | 3148 | component->output(fp); |
aoqi@0 | 3149 | } |
aoqi@0 | 3150 | fprintf(fp, "\n"); |
aoqi@0 | 3151 | } |
aoqi@0 | 3152 | |
aoqi@0 | 3153 | //------------------------------MatchNode-------------------------------------- |
aoqi@0 | 3154 | MatchNode::MatchNode(ArchDesc &ad, const char *result, const char *mexpr, |
aoqi@0 | 3155 | const char *opType, MatchNode *lChild, MatchNode *rChild) |
aoqi@0 | 3156 | : _AD(ad), _result(result), _name(mexpr), _opType(opType), |
aoqi@0 | 3157 | _lChild(lChild), _rChild(rChild), _internalop(0), _numleaves(0), |
aoqi@0 | 3158 | _commutative_id(0) { |
aoqi@0 | 3159 | _numleaves = (lChild ? lChild->_numleaves : 0) |
aoqi@0 | 3160 | + (rChild ? rChild->_numleaves : 0); |
aoqi@0 | 3161 | } |
aoqi@0 | 3162 | |
aoqi@0 | 3163 | MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode) |
aoqi@0 | 3164 | : _AD(ad), _result(mnode._result), _name(mnode._name), |
aoqi@0 | 3165 | _opType(mnode._opType), _lChild(mnode._lChild), _rChild(mnode._rChild), |
aoqi@0 | 3166 | _internalop(0), _numleaves(mnode._numleaves), |
aoqi@0 | 3167 | _commutative_id(mnode._commutative_id) { |
aoqi@0 | 3168 | } |
aoqi@0 | 3169 | |
aoqi@0 | 3170 | MatchNode::MatchNode(ArchDesc &ad, MatchNode& mnode, int clone) |
aoqi@0 | 3171 | : _AD(ad), _result(mnode._result), _name(mnode._name), |
aoqi@0 | 3172 | _opType(mnode._opType), |
aoqi@0 | 3173 | _internalop(0), _numleaves(mnode._numleaves), |
aoqi@0 | 3174 | _commutative_id(mnode._commutative_id) { |
aoqi@0 | 3175 | if (mnode._lChild) { |
aoqi@0 | 3176 | _lChild = new MatchNode(ad, *mnode._lChild, clone); |
aoqi@0 | 3177 | } else { |
aoqi@0 | 3178 | _lChild = NULL; |
aoqi@0 | 3179 | } |
aoqi@0 | 3180 | if (mnode._rChild) { |
aoqi@0 | 3181 | _rChild = new MatchNode(ad, *mnode._rChild, clone); |
aoqi@0 | 3182 | } else { |
aoqi@0 | 3183 | _rChild = NULL; |
aoqi@0 | 3184 | } |
aoqi@0 | 3185 | } |
aoqi@0 | 3186 | |
aoqi@0 | 3187 | MatchNode::~MatchNode() { |
aoqi@0 | 3188 | // // This node may not own its children if copied via assignment |
aoqi@0 | 3189 | // if( _lChild ) delete _lChild; |
aoqi@0 | 3190 | // if( _rChild ) delete _rChild; |
aoqi@0 | 3191 | } |
aoqi@0 | 3192 | |
aoqi@0 | 3193 | bool MatchNode::find_type(const char *type, int &position) const { |
aoqi@0 | 3194 | if ( (_lChild != NULL) && (_lChild->find_type(type, position)) ) return true; |
aoqi@0 | 3195 | if ( (_rChild != NULL) && (_rChild->find_type(type, position)) ) return true; |
aoqi@0 | 3196 | |
aoqi@0 | 3197 | if (strcmp(type,_opType)==0) { |
aoqi@0 | 3198 | return true; |
aoqi@0 | 3199 | } else { |
aoqi@0 | 3200 | ++position; |
aoqi@0 | 3201 | } |
aoqi@0 | 3202 | return false; |
aoqi@0 | 3203 | } |
aoqi@0 | 3204 | |
aoqi@0 | 3205 | // Recursive call collecting info on top-level operands, not transitive. |
aoqi@0 | 3206 | // Implementation does not modify state of internal structures. |
aoqi@0 | 3207 | void MatchNode::append_components(FormDict& locals, ComponentList& components, |
aoqi@0 | 3208 | bool def_flag) const { |
aoqi@0 | 3209 | int usedef = def_flag ? Component::DEF : Component::USE; |
aoqi@0 | 3210 | FormDict &globals = _AD.globalNames(); |
aoqi@0 | 3211 | |
aoqi@0 | 3212 | assert (_name != NULL, "MatchNode::build_components encountered empty node\n"); |
aoqi@0 | 3213 | // Base case |
aoqi@0 | 3214 | if (_lChild==NULL && _rChild==NULL) { |
aoqi@0 | 3215 | // If _opType is not an operation, do not build a component for it ##### |
aoqi@0 | 3216 | const Form *f = globals[_opType]; |
aoqi@0 | 3217 | if( f != NULL ) { |
aoqi@0 | 3218 | // Add non-ideals that are operands, operand-classes, |
aoqi@0 | 3219 | if( ! f->ideal_only() |
aoqi@0 | 3220 | && (f->is_opclass() || f->is_operand()) ) { |
aoqi@0 | 3221 | components.insert(_name, _opType, usedef, true); |
aoqi@0 | 3222 | } |
aoqi@0 | 3223 | } |
aoqi@0 | 3224 | return; |
aoqi@0 | 3225 | } |
aoqi@0 | 3226 | // Promote results of "Set" to DEF |
aoqi@0 | 3227 | bool tmpdef_flag = (!strcmp(_opType, "Set")) ? true : false; |
aoqi@0 | 3228 | if (_lChild) _lChild->append_components(locals, components, tmpdef_flag); |
aoqi@0 | 3229 | tmpdef_flag = false; // only applies to component immediately following 'Set' |
aoqi@0 | 3230 | if (_rChild) _rChild->append_components(locals, components, tmpdef_flag); |
aoqi@0 | 3231 | } |
aoqi@0 | 3232 | |
aoqi@0 | 3233 | // Find the n'th base-operand in the match node, |
aoqi@0 | 3234 | // recursively investigates match rules of user-defined operands. |
aoqi@0 | 3235 | // |
aoqi@0 | 3236 | // Implementation does not modify state of internal structures since they |
aoqi@0 | 3237 | // can be shared. |
aoqi@0 | 3238 | bool MatchNode::base_operand(uint &position, FormDict &globals, |
aoqi@0 | 3239 | const char * &result, const char * &name, |
aoqi@0 | 3240 | const char * &opType) const { |
aoqi@0 | 3241 | assert (_name != NULL, "MatchNode::base_operand encountered empty node\n"); |
aoqi@0 | 3242 | // Base case |
aoqi@0 | 3243 | if (_lChild==NULL && _rChild==NULL) { |
aoqi@0 | 3244 | // Check for special case: "Universe", "label" |
aoqi@0 | 3245 | if (strcmp(_opType,"Universe") == 0 || strcmp(_opType,"label")==0 ) { |
aoqi@0 | 3246 | if (position == 0) { |
aoqi@0 | 3247 | result = _result; |
aoqi@0 | 3248 | name = _name; |
aoqi@0 | 3249 | opType = _opType; |
aoqi@0 | 3250 | return 1; |
aoqi@0 | 3251 | } else { |
aoqi@0 | 3252 | -- position; |
aoqi@0 | 3253 | return 0; |
aoqi@0 | 3254 | } |
aoqi@0 | 3255 | } |
aoqi@0 | 3256 | |
aoqi@0 | 3257 | const Form *form = globals[_opType]; |
aoqi@0 | 3258 | MatchNode *matchNode = NULL; |
aoqi@0 | 3259 | // Check for user-defined type |
aoqi@0 | 3260 | if (form) { |
aoqi@0 | 3261 | // User operand or instruction? |
aoqi@0 | 3262 | OperandForm *opForm = form->is_operand(); |
aoqi@0 | 3263 | InstructForm *inForm = form->is_instruction(); |
aoqi@0 | 3264 | if ( opForm ) { |
aoqi@0 | 3265 | matchNode = (MatchNode*)opForm->_matrule; |
aoqi@0 | 3266 | } else if ( inForm ) { |
aoqi@0 | 3267 | matchNode = (MatchNode*)inForm->_matrule; |
aoqi@0 | 3268 | } |
aoqi@0 | 3269 | } |
aoqi@0 | 3270 | // if this is user-defined, recurse on match rule |
aoqi@0 | 3271 | // User-defined operand and instruction forms have a match-rule. |
aoqi@0 | 3272 | if (matchNode) { |
aoqi@0 | 3273 | return (matchNode->base_operand(position,globals,result,name,opType)); |
aoqi@0 | 3274 | } else { |
aoqi@0 | 3275 | // Either not a form, or a system-defined form (no match rule). |
aoqi@0 | 3276 | if (position==0) { |
aoqi@0 | 3277 | result = _result; |
aoqi@0 | 3278 | name = _name; |
aoqi@0 | 3279 | opType = _opType; |
aoqi@0 | 3280 | return 1; |
aoqi@0 | 3281 | } else { |
aoqi@0 | 3282 | --position; |
aoqi@0 | 3283 | return 0; |
aoqi@0 | 3284 | } |
aoqi@0 | 3285 | } |
aoqi@0 | 3286 | |
aoqi@0 | 3287 | } else { |
aoqi@0 | 3288 | // Examine the left child and right child as well |
aoqi@0 | 3289 | if (_lChild) { |
aoqi@0 | 3290 | if (_lChild->base_operand(position, globals, result, name, opType)) |
aoqi@0 | 3291 | return 1; |
aoqi@0 | 3292 | } |
aoqi@0 | 3293 | |
aoqi@0 | 3294 | if (_rChild) { |
aoqi@0 | 3295 | if (_rChild->base_operand(position, globals, result, name, opType)) |
aoqi@0 | 3296 | return 1; |
aoqi@0 | 3297 | } |
aoqi@0 | 3298 | } |
aoqi@0 | 3299 | |
aoqi@0 | 3300 | return 0; |
aoqi@0 | 3301 | } |
aoqi@0 | 3302 | |
aoqi@0 | 3303 | // Recursive call on all operands' match rules in my match rule. |
aoqi@0 | 3304 | uint MatchNode::num_consts(FormDict &globals) const { |
aoqi@0 | 3305 | uint index = 0; |
aoqi@0 | 3306 | uint num_consts = 0; |
aoqi@0 | 3307 | const char *result; |
aoqi@0 | 3308 | const char *name; |
aoqi@0 | 3309 | const char *opType; |
aoqi@0 | 3310 | |
aoqi@0 | 3311 | for (uint position = index; |
aoqi@0 | 3312 | base_operand(position,globals,result,name,opType); position = index) { |
aoqi@0 | 3313 | ++index; |
aoqi@0 | 3314 | if( ideal_to_const_type(opType) ) num_consts++; |
aoqi@0 | 3315 | } |
aoqi@0 | 3316 | |
aoqi@0 | 3317 | return num_consts; |
aoqi@0 | 3318 | } |
aoqi@0 | 3319 | |
aoqi@0 | 3320 | // Recursive call on all operands' match rules in my match rule. |
aoqi@0 | 3321 | // Constants in match rule subtree with specified type |
aoqi@0 | 3322 | uint MatchNode::num_consts(FormDict &globals, Form::DataType type) const { |
aoqi@0 | 3323 | uint index = 0; |
aoqi@0 | 3324 | uint num_consts = 0; |
aoqi@0 | 3325 | const char *result; |
aoqi@0 | 3326 | const char *name; |
aoqi@0 | 3327 | const char *opType; |
aoqi@0 | 3328 | |
aoqi@0 | 3329 | for (uint position = index; |
aoqi@0 | 3330 | base_operand(position,globals,result,name,opType); position = index) { |
aoqi@0 | 3331 | ++index; |
aoqi@0 | 3332 | if( ideal_to_const_type(opType) == type ) num_consts++; |
aoqi@0 | 3333 | } |
aoqi@0 | 3334 | |
aoqi@0 | 3335 | return num_consts; |
aoqi@0 | 3336 | } |
aoqi@0 | 3337 | |
aoqi@0 | 3338 | // Recursive call on all operands' match rules in my match rule. |
aoqi@0 | 3339 | uint MatchNode::num_const_ptrs(FormDict &globals) const { |
aoqi@0 | 3340 | return num_consts( globals, Form::idealP ); |
aoqi@0 | 3341 | } |
aoqi@0 | 3342 | |
aoqi@0 | 3343 | bool MatchNode::sets_result() const { |
aoqi@0 | 3344 | return ( (strcmp(_name,"Set") == 0) ? true : false ); |
aoqi@0 | 3345 | } |
aoqi@0 | 3346 | |
aoqi@0 | 3347 | const char *MatchNode::reduce_right(FormDict &globals) const { |
aoqi@0 | 3348 | // If there is no right reduction, return NULL. |
aoqi@0 | 3349 | const char *rightStr = NULL; |
aoqi@0 | 3350 | |
aoqi@0 | 3351 | // If we are a "Set", start from the right child. |
aoqi@0 | 3352 | const MatchNode *const mnode = sets_result() ? |
aoqi@0 | 3353 | (const MatchNode *)this->_rChild : |
aoqi@0 | 3354 | (const MatchNode *)this; |
aoqi@0 | 3355 | |
aoqi@0 | 3356 | // If our right child exists, it is the right reduction |
aoqi@0 | 3357 | if ( mnode->_rChild ) { |
aoqi@0 | 3358 | rightStr = mnode->_rChild->_internalop ? mnode->_rChild->_internalop |
aoqi@0 | 3359 | : mnode->_rChild->_opType; |
aoqi@0 | 3360 | } |
aoqi@0 | 3361 | // Else, May be simple chain rule: (Set dst operand_form), rightStr=NULL; |
aoqi@0 | 3362 | return rightStr; |
aoqi@0 | 3363 | } |
aoqi@0 | 3364 | |
aoqi@0 | 3365 | const char *MatchNode::reduce_left(FormDict &globals) const { |
aoqi@0 | 3366 | // If there is no left reduction, return NULL. |
aoqi@0 | 3367 | const char *leftStr = NULL; |
aoqi@0 | 3368 | |
aoqi@0 | 3369 | // If we are a "Set", start from the right child. |
aoqi@0 | 3370 | const MatchNode *const mnode = sets_result() ? |
aoqi@0 | 3371 | (const MatchNode *)this->_rChild : |
aoqi@0 | 3372 | (const MatchNode *)this; |
aoqi@0 | 3373 | |
aoqi@0 | 3374 | // If our left child exists, it is the left reduction |
aoqi@0 | 3375 | if ( mnode->_lChild ) { |
aoqi@0 | 3376 | leftStr = mnode->_lChild->_internalop ? mnode->_lChild->_internalop |
aoqi@0 | 3377 | : mnode->_lChild->_opType; |
aoqi@0 | 3378 | } else { |
aoqi@0 | 3379 | // May be simple chain rule: (Set dst operand_form_source) |
aoqi@0 | 3380 | if ( sets_result() ) { |
aoqi@0 | 3381 | OperandForm *oper = globals[mnode->_opType]->is_operand(); |
aoqi@0 | 3382 | if( oper ) { |
aoqi@0 | 3383 | leftStr = mnode->_opType; |
aoqi@0 | 3384 | } |
aoqi@0 | 3385 | } |
aoqi@0 | 3386 | } |
aoqi@0 | 3387 | return leftStr; |
aoqi@0 | 3388 | } |
aoqi@0 | 3389 | |
aoqi@0 | 3390 | //------------------------------count_instr_names------------------------------ |
aoqi@0 | 3391 | // Count occurrences of operands names in the leaves of the instruction |
aoqi@0 | 3392 | // match rule. |
aoqi@0 | 3393 | void MatchNode::count_instr_names( Dict &names ) { |
aoqi@0 | 3394 | if( !this ) return; |
aoqi@0 | 3395 | if( _lChild ) _lChild->count_instr_names(names); |
aoqi@0 | 3396 | if( _rChild ) _rChild->count_instr_names(names); |
aoqi@0 | 3397 | if( !_lChild && !_rChild ) { |
aoqi@0 | 3398 | uintptr_t cnt = (uintptr_t)names[_name]; |
aoqi@0 | 3399 | cnt++; // One more name found |
aoqi@0 | 3400 | names.Insert(_name,(void*)cnt); |
aoqi@0 | 3401 | } |
aoqi@0 | 3402 | } |
aoqi@0 | 3403 | |
aoqi@0 | 3404 | //------------------------------build_instr_pred------------------------------- |
aoqi@0 | 3405 | // Build a path to 'name' in buf. Actually only build if cnt is zero, so we |
aoqi@0 | 3406 | // can skip some leading instances of 'name'. |
aoqi@0 | 3407 | int MatchNode::build_instr_pred( char *buf, const char *name, int cnt ) { |
aoqi@0 | 3408 | if( _lChild ) { |
aoqi@0 | 3409 | if( !cnt ) strcpy( buf, "_kids[0]->" ); |
aoqi@0 | 3410 | cnt = _lChild->build_instr_pred( buf+strlen(buf), name, cnt ); |
aoqi@0 | 3411 | if( cnt < 0 ) return cnt; // Found it, all done |
aoqi@0 | 3412 | } |
aoqi@0 | 3413 | if( _rChild ) { |
aoqi@0 | 3414 | if( !cnt ) strcpy( buf, "_kids[1]->" ); |
aoqi@0 | 3415 | cnt = _rChild->build_instr_pred( buf+strlen(buf), name, cnt ); |
aoqi@0 | 3416 | if( cnt < 0 ) return cnt; // Found it, all done |
aoqi@0 | 3417 | } |
aoqi@0 | 3418 | if( !_lChild && !_rChild ) { // Found a leaf |
aoqi@0 | 3419 | // Wrong name? Give up... |
aoqi@0 | 3420 | if( strcmp(name,_name) ) return cnt; |
aoqi@0 | 3421 | if( !cnt ) strcpy(buf,"_leaf"); |
aoqi@0 | 3422 | return cnt-1; |
aoqi@0 | 3423 | } |
aoqi@0 | 3424 | return cnt; |
aoqi@0 | 3425 | } |
aoqi@0 | 3426 | |
aoqi@0 | 3427 | |
aoqi@0 | 3428 | //------------------------------build_internalop------------------------------- |
aoqi@0 | 3429 | // Build string representation of subtree |
aoqi@0 | 3430 | void MatchNode::build_internalop( ) { |
aoqi@0 | 3431 | char *iop, *subtree; |
aoqi@0 | 3432 | const char *lstr, *rstr; |
aoqi@0 | 3433 | // Build string representation of subtree |
aoqi@0 | 3434 | // Operation lchildType rchildType |
aoqi@0 | 3435 | int len = (int)strlen(_opType) + 4; |
aoqi@0 | 3436 | lstr = (_lChild) ? ((_lChild->_internalop) ? |
aoqi@0 | 3437 | _lChild->_internalop : _lChild->_opType) : ""; |
aoqi@0 | 3438 | rstr = (_rChild) ? ((_rChild->_internalop) ? |
aoqi@0 | 3439 | _rChild->_internalop : _rChild->_opType) : ""; |
aoqi@0 | 3440 | len += (int)strlen(lstr) + (int)strlen(rstr); |
aoqi@0 | 3441 | subtree = (char *)malloc(len); |
aoqi@0 | 3442 | sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr); |
aoqi@0 | 3443 | // Hash the subtree string in _internalOps; if a name exists, use it |
aoqi@0 | 3444 | iop = (char *)_AD._internalOps[subtree]; |
aoqi@0 | 3445 | // Else create a unique name, and add it to the hash table |
aoqi@0 | 3446 | if (iop == NULL) { |
aoqi@0 | 3447 | iop = subtree; |
aoqi@0 | 3448 | _AD._internalOps.Insert(subtree, iop); |
aoqi@0 | 3449 | _AD._internalOpNames.addName(iop); |
aoqi@0 | 3450 | _AD._internalMatch.Insert(iop, this); |
aoqi@0 | 3451 | } |
aoqi@0 | 3452 | // Add the internal operand name to the MatchNode |
aoqi@0 | 3453 | _internalop = iop; |
aoqi@0 | 3454 | _result = iop; |
aoqi@0 | 3455 | } |
aoqi@0 | 3456 | |
aoqi@0 | 3457 | |
aoqi@0 | 3458 | void MatchNode::dump() { |
aoqi@0 | 3459 | output(stderr); |
aoqi@0 | 3460 | } |
aoqi@0 | 3461 | |
aoqi@0 | 3462 | void MatchNode::output(FILE *fp) { |
aoqi@0 | 3463 | if (_lChild==0 && _rChild==0) { |
aoqi@0 | 3464 | fprintf(fp," %s",_name); // operand |
aoqi@0 | 3465 | } |
aoqi@0 | 3466 | else { |
aoqi@0 | 3467 | fprintf(fp," (%s ",_name); // " (opcodeName " |
aoqi@0 | 3468 | if(_lChild) _lChild->output(fp); // left operand |
aoqi@0 | 3469 | if(_rChild) _rChild->output(fp); // right operand |
aoqi@0 | 3470 | fprintf(fp,")"); // ")" |
aoqi@0 | 3471 | } |
aoqi@0 | 3472 | } |
aoqi@0 | 3473 | |
aoqi@0 | 3474 | int MatchNode::needs_ideal_memory_edge(FormDict &globals) const { |
aoqi@0 | 3475 | static const char *needs_ideal_memory_list[] = { |
aoqi@0 | 3476 | "StoreI","StoreL","StoreP","StoreN","StoreNKlass","StoreD","StoreF" , |
aoqi@0 | 3477 | "StoreB","StoreC","Store" ,"StoreFP", |
aoqi@0 | 3478 | "LoadI", "LoadL", "LoadP" ,"LoadN", "LoadD" ,"LoadF" , |
aoqi@0 | 3479 | "LoadB" , "LoadUB", "LoadUS" ,"LoadS" ,"Load" , |
aoqi@0 | 3480 | "StoreVector", "LoadVector", |
aoqi@0 | 3481 | "LoadRange", "LoadKlass", "LoadNKlass", "LoadL_unaligned", "LoadD_unaligned", |
aoqi@0 | 3482 | "LoadPLocked", |
aoqi@0 | 3483 | "StorePConditional", "StoreIConditional", "StoreLConditional", |
aoqi@0 | 3484 | "CompareAndSwapI", "CompareAndSwapL", "CompareAndSwapP", "CompareAndSwapN", |
aoqi@0 | 3485 | "StoreCM", |
aoqi@0 | 3486 | "ClearArray", |
aoqi@0 | 3487 | "GetAndAddI", "GetAndSetI", "GetAndSetP", |
aoqi@0 | 3488 | "GetAndAddL", "GetAndSetL", "GetAndSetN", |
aoqi@0 | 3489 | }; |
aoqi@0 | 3490 | int cnt = sizeof(needs_ideal_memory_list)/sizeof(char*); |
aoqi@0 | 3491 | if( strcmp(_opType,"PrefetchRead")==0 || |
aoqi@0 | 3492 | strcmp(_opType,"PrefetchWrite")==0 || |
aoqi@0 | 3493 | strcmp(_opType,"PrefetchAllocation")==0 ) |
aoqi@0 | 3494 | return 1; |
aoqi@0 | 3495 | if( _lChild ) { |
aoqi@0 | 3496 | const char *opType = _lChild->_opType; |
aoqi@0 | 3497 | for( int i=0; i<cnt; i++ ) |
aoqi@0 | 3498 | if( strcmp(opType,needs_ideal_memory_list[i]) == 0 ) |
aoqi@0 | 3499 | return 1; |
aoqi@0 | 3500 | if( _lChild->needs_ideal_memory_edge(globals) ) |
aoqi@0 | 3501 | return 1; |
aoqi@0 | 3502 | } |
aoqi@0 | 3503 | if( _rChild ) { |
aoqi@0 | 3504 | const char *opType = _rChild->_opType; |
aoqi@0 | 3505 | for( int i=0; i<cnt; i++ ) |
aoqi@0 | 3506 | if( strcmp(opType,needs_ideal_memory_list[i]) == 0 ) |
aoqi@0 | 3507 | return 1; |
aoqi@0 | 3508 | if( _rChild->needs_ideal_memory_edge(globals) ) |
aoqi@0 | 3509 | return 1; |
aoqi@0 | 3510 | } |
aoqi@0 | 3511 | |
aoqi@0 | 3512 | return 0; |
aoqi@0 | 3513 | } |
aoqi@0 | 3514 | |
aoqi@0 | 3515 | // TRUE if defines a derived oop, and so needs a base oop edge present |
aoqi@0 | 3516 | // post-matching. |
aoqi@0 | 3517 | int MatchNode::needs_base_oop_edge() const { |
aoqi@0 | 3518 | if( !strcmp(_opType,"AddP") ) return 1; |
aoqi@0 | 3519 | if( strcmp(_opType,"Set") ) return 0; |
aoqi@0 | 3520 | return !strcmp(_rChild->_opType,"AddP"); |
aoqi@0 | 3521 | } |
aoqi@0 | 3522 | |
aoqi@0 | 3523 | int InstructForm::needs_base_oop_edge(FormDict &globals) const { |
aoqi@0 | 3524 | if( is_simple_chain_rule(globals) ) { |
aoqi@0 | 3525 | const char *src = _matrule->_rChild->_opType; |
aoqi@0 | 3526 | OperandForm *src_op = globals[src]->is_operand(); |
aoqi@0 | 3527 | assert( src_op, "Not operand class of chain rule" ); |
aoqi@0 | 3528 | return src_op->_matrule ? src_op->_matrule->needs_base_oop_edge() : 0; |
aoqi@0 | 3529 | } // Else check instruction |
aoqi@0 | 3530 | |
aoqi@0 | 3531 | return _matrule ? _matrule->needs_base_oop_edge() : 0; |
aoqi@0 | 3532 | } |
aoqi@0 | 3533 | |
aoqi@0 | 3534 | |
aoqi@0 | 3535 | //-------------------------cisc spilling methods------------------------------- |
aoqi@0 | 3536 | // helper routines and methods for detecting cisc-spilling instructions |
aoqi@0 | 3537 | //-------------------------cisc_spill_merge------------------------------------ |
aoqi@0 | 3538 | int MatchNode::cisc_spill_merge(int left_spillable, int right_spillable) { |
aoqi@0 | 3539 | int cisc_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3540 | |
aoqi@0 | 3541 | // Combine results of left and right checks |
aoqi@0 | 3542 | if( (left_spillable == Maybe_cisc_spillable) && (right_spillable == Maybe_cisc_spillable) ) { |
aoqi@0 | 3543 | // neither side is spillable, nor prevents cisc spilling |
aoqi@0 | 3544 | cisc_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3545 | } |
aoqi@0 | 3546 | else if( (left_spillable == Maybe_cisc_spillable) && (right_spillable > Maybe_cisc_spillable) ) { |
aoqi@0 | 3547 | // right side is spillable |
aoqi@0 | 3548 | cisc_spillable = right_spillable; |
aoqi@0 | 3549 | } |
aoqi@0 | 3550 | else if( (right_spillable == Maybe_cisc_spillable) && (left_spillable > Maybe_cisc_spillable) ) { |
aoqi@0 | 3551 | // left side is spillable |
aoqi@0 | 3552 | cisc_spillable = left_spillable; |
aoqi@0 | 3553 | } |
aoqi@0 | 3554 | else if( (left_spillable == Not_cisc_spillable) || (right_spillable == Not_cisc_spillable) ) { |
aoqi@0 | 3555 | // left or right prevents cisc spilling this instruction |
aoqi@0 | 3556 | cisc_spillable = Not_cisc_spillable; |
aoqi@0 | 3557 | } |
aoqi@0 | 3558 | else { |
aoqi@0 | 3559 | // Only allow one to spill |
aoqi@0 | 3560 | cisc_spillable = Not_cisc_spillable; |
aoqi@0 | 3561 | } |
aoqi@0 | 3562 | |
aoqi@0 | 3563 | return cisc_spillable; |
aoqi@0 | 3564 | } |
aoqi@0 | 3565 | |
aoqi@0 | 3566 | //-------------------------root_ops_match-------------------------------------- |
aoqi@0 | 3567 | bool static root_ops_match(FormDict &globals, const char *op1, const char *op2) { |
aoqi@0 | 3568 | // Base Case: check that the current operands/operations match |
aoqi@0 | 3569 | assert( op1, "Must have op's name"); |
aoqi@0 | 3570 | assert( op2, "Must have op's name"); |
aoqi@0 | 3571 | const Form *form1 = globals[op1]; |
aoqi@0 | 3572 | const Form *form2 = globals[op2]; |
aoqi@0 | 3573 | |
aoqi@0 | 3574 | return (form1 == form2); |
aoqi@0 | 3575 | } |
aoqi@0 | 3576 | |
aoqi@0 | 3577 | //-------------------------cisc_spill_match_node------------------------------- |
aoqi@0 | 3578 | // Recursively check two MatchRules for legal conversion via cisc-spilling |
aoqi@0 | 3579 | int MatchNode::cisc_spill_match(FormDict& globals, RegisterForm* registers, MatchNode* mRule2, const char* &operand, const char* ®_type) { |
aoqi@0 | 3580 | int cisc_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3581 | int left_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3582 | int right_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3583 | |
aoqi@0 | 3584 | // Check that each has same number of operands at this level |
aoqi@0 | 3585 | if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) |
aoqi@0 | 3586 | return Not_cisc_spillable; |
aoqi@0 | 3587 | |
aoqi@0 | 3588 | // Base Case: check that the current operands/operations match |
aoqi@0 | 3589 | // or are CISC spillable |
aoqi@0 | 3590 | assert( _opType, "Must have _opType"); |
aoqi@0 | 3591 | assert( mRule2->_opType, "Must have _opType"); |
aoqi@0 | 3592 | const Form *form = globals[_opType]; |
aoqi@0 | 3593 | const Form *form2 = globals[mRule2->_opType]; |
aoqi@0 | 3594 | if( form == form2 ) { |
aoqi@0 | 3595 | cisc_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3596 | } else { |
aoqi@0 | 3597 | const InstructForm *form2_inst = form2 ? form2->is_instruction() : NULL; |
aoqi@0 | 3598 | const char *name_left = mRule2->_lChild ? mRule2->_lChild->_opType : NULL; |
aoqi@0 | 3599 | const char *name_right = mRule2->_rChild ? mRule2->_rChild->_opType : NULL; |
aoqi@0 | 3600 | DataType data_type = Form::none; |
aoqi@0 | 3601 | if (form->is_operand()) { |
aoqi@0 | 3602 | // Make sure the loadX matches the type of the reg |
aoqi@0 | 3603 | data_type = form->ideal_to_Reg_type(form->is_operand()->ideal_type(globals)); |
aoqi@0 | 3604 | } |
aoqi@0 | 3605 | // Detect reg vs (loadX memory) |
aoqi@0 | 3606 | if( form->is_cisc_reg(globals) |
aoqi@0 | 3607 | && form2_inst |
aoqi@0 | 3608 | && data_type != Form::none |
aoqi@0 | 3609 | && (is_load_from_memory(mRule2->_opType) == data_type) // reg vs. (load memory) |
aoqi@0 | 3610 | && (name_left != NULL) // NOT (load) |
aoqi@0 | 3611 | && (name_right == NULL) ) { // NOT (load memory foo) |
aoqi@0 | 3612 | const Form *form2_left = name_left ? globals[name_left] : NULL; |
aoqi@0 | 3613 | if( form2_left && form2_left->is_cisc_mem(globals) ) { |
aoqi@0 | 3614 | cisc_spillable = Is_cisc_spillable; |
aoqi@0 | 3615 | operand = _name; |
aoqi@0 | 3616 | reg_type = _result; |
aoqi@0 | 3617 | return Is_cisc_spillable; |
aoqi@0 | 3618 | } else { |
aoqi@0 | 3619 | cisc_spillable = Not_cisc_spillable; |
aoqi@0 | 3620 | } |
aoqi@0 | 3621 | } |
aoqi@0 | 3622 | // Detect reg vs memory |
aoqi@0 | 3623 | else if( form->is_cisc_reg(globals) && form2->is_cisc_mem(globals) ) { |
aoqi@0 | 3624 | cisc_spillable = Is_cisc_spillable; |
aoqi@0 | 3625 | operand = _name; |
aoqi@0 | 3626 | reg_type = _result; |
aoqi@0 | 3627 | return Is_cisc_spillable; |
aoqi@0 | 3628 | } else { |
aoqi@0 | 3629 | cisc_spillable = Not_cisc_spillable; |
aoqi@0 | 3630 | } |
aoqi@0 | 3631 | } |
aoqi@0 | 3632 | |
aoqi@0 | 3633 | // If cisc is still possible, check rest of tree |
aoqi@0 | 3634 | if( cisc_spillable == Maybe_cisc_spillable ) { |
aoqi@0 | 3635 | // Check that each has same number of operands at this level |
aoqi@0 | 3636 | if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable; |
aoqi@0 | 3637 | |
aoqi@0 | 3638 | // Check left operands |
aoqi@0 | 3639 | if( (_lChild == NULL) && (mRule2->_lChild == NULL) ) { |
aoqi@0 | 3640 | left_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3641 | } else { |
aoqi@0 | 3642 | left_spillable = _lChild->cisc_spill_match(globals, registers, mRule2->_lChild, operand, reg_type); |
aoqi@0 | 3643 | } |
aoqi@0 | 3644 | |
aoqi@0 | 3645 | // Check right operands |
aoqi@0 | 3646 | if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) { |
aoqi@0 | 3647 | right_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3648 | } else { |
aoqi@0 | 3649 | right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type); |
aoqi@0 | 3650 | } |
aoqi@0 | 3651 | |
aoqi@0 | 3652 | // Combine results of left and right checks |
aoqi@0 | 3653 | cisc_spillable = cisc_spill_merge(left_spillable, right_spillable); |
aoqi@0 | 3654 | } |
aoqi@0 | 3655 | |
aoqi@0 | 3656 | return cisc_spillable; |
aoqi@0 | 3657 | } |
aoqi@0 | 3658 | |
aoqi@0 | 3659 | //---------------------------cisc_spill_match_rule------------------------------ |
aoqi@0 | 3660 | // Recursively check two MatchRules for legal conversion via cisc-spilling |
aoqi@0 | 3661 | // This method handles the root of Match tree, |
aoqi@0 | 3662 | // general recursive checks done in MatchNode |
aoqi@0 | 3663 | int MatchRule::matchrule_cisc_spill_match(FormDict& globals, RegisterForm* registers, |
aoqi@0 | 3664 | MatchRule* mRule2, const char* &operand, |
aoqi@0 | 3665 | const char* ®_type) { |
aoqi@0 | 3666 | int cisc_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3667 | int left_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3668 | int right_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3669 | |
aoqi@0 | 3670 | // Check that each sets a result |
aoqi@0 | 3671 | if( !(sets_result() && mRule2->sets_result()) ) return Not_cisc_spillable; |
aoqi@0 | 3672 | // Check that each has same number of operands at this level |
aoqi@0 | 3673 | if( (_lChild && !(mRule2->_lChild)) || (_rChild && !(mRule2->_rChild)) ) return Not_cisc_spillable; |
aoqi@0 | 3674 | |
aoqi@0 | 3675 | // Check left operands: at root, must be target of 'Set' |
aoqi@0 | 3676 | if( (_lChild == NULL) || (mRule2->_lChild == NULL) ) { |
aoqi@0 | 3677 | left_spillable = Not_cisc_spillable; |
aoqi@0 | 3678 | } else { |
aoqi@0 | 3679 | // Do not support cisc-spilling instruction's target location |
aoqi@0 | 3680 | if( root_ops_match(globals, _lChild->_opType, mRule2->_lChild->_opType) ) { |
aoqi@0 | 3681 | left_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3682 | } else { |
aoqi@0 | 3683 | left_spillable = Not_cisc_spillable; |
aoqi@0 | 3684 | } |
aoqi@0 | 3685 | } |
aoqi@0 | 3686 | |
aoqi@0 | 3687 | // Check right operands: recursive walk to identify reg->mem operand |
aoqi@0 | 3688 | if( (_rChild == NULL) && (mRule2->_rChild == NULL) ) { |
aoqi@0 | 3689 | right_spillable = Maybe_cisc_spillable; |
aoqi@0 | 3690 | } else { |
aoqi@0 | 3691 | right_spillable = _rChild->cisc_spill_match(globals, registers, mRule2->_rChild, operand, reg_type); |
aoqi@0 | 3692 | } |
aoqi@0 | 3693 | |
aoqi@0 | 3694 | // Combine results of left and right checks |
aoqi@0 | 3695 | cisc_spillable = cisc_spill_merge(left_spillable, right_spillable); |
aoqi@0 | 3696 | |
aoqi@0 | 3697 | return cisc_spillable; |
aoqi@0 | 3698 | } |
aoqi@0 | 3699 | |
aoqi@0 | 3700 | //----------------------------- equivalent ------------------------------------ |
aoqi@0 | 3701 | // Recursively check to see if two match rules are equivalent. |
aoqi@0 | 3702 | // This rule handles the root. |
aoqi@0 | 3703 | bool MatchRule::equivalent(FormDict &globals, MatchNode *mRule2) { |
aoqi@0 | 3704 | // Check that each sets a result |
aoqi@0 | 3705 | if (sets_result() != mRule2->sets_result()) { |
aoqi@0 | 3706 | return false; |
aoqi@0 | 3707 | } |
aoqi@0 | 3708 | |
aoqi@0 | 3709 | // Check that the current operands/operations match |
aoqi@0 | 3710 | assert( _opType, "Must have _opType"); |
aoqi@0 | 3711 | assert( mRule2->_opType, "Must have _opType"); |
aoqi@0 | 3712 | const Form *form = globals[_opType]; |
aoqi@0 | 3713 | const Form *form2 = globals[mRule2->_opType]; |
aoqi@0 | 3714 | if( form != form2 ) { |
aoqi@0 | 3715 | return false; |
aoqi@0 | 3716 | } |
aoqi@0 | 3717 | |
aoqi@0 | 3718 | if (_lChild ) { |
aoqi@0 | 3719 | if( !_lChild->equivalent(globals, mRule2->_lChild) ) |
aoqi@0 | 3720 | return false; |
aoqi@0 | 3721 | } else if (mRule2->_lChild) { |
aoqi@0 | 3722 | return false; // I have NULL left child, mRule2 has non-NULL left child. |
aoqi@0 | 3723 | } |
aoqi@0 | 3724 | |
aoqi@0 | 3725 | if (_rChild ) { |
aoqi@0 | 3726 | if( !_rChild->equivalent(globals, mRule2->_rChild) ) |
aoqi@0 | 3727 | return false; |
aoqi@0 | 3728 | } else if (mRule2->_rChild) { |
aoqi@0 | 3729 | return false; // I have NULL right child, mRule2 has non-NULL right child. |
aoqi@0 | 3730 | } |
aoqi@0 | 3731 | |
aoqi@0 | 3732 | // We've made it through the gauntlet. |
aoqi@0 | 3733 | return true; |
aoqi@0 | 3734 | } |
aoqi@0 | 3735 | |
aoqi@0 | 3736 | //----------------------------- equivalent ------------------------------------ |
aoqi@0 | 3737 | // Recursively check to see if two match rules are equivalent. |
aoqi@0 | 3738 | // This rule handles the operands. |
aoqi@0 | 3739 | bool MatchNode::equivalent(FormDict &globals, MatchNode *mNode2) { |
aoqi@0 | 3740 | if( !mNode2 ) |
aoqi@0 | 3741 | return false; |
aoqi@0 | 3742 | |
aoqi@0 | 3743 | // Check that the current operands/operations match |
aoqi@0 | 3744 | assert( _opType, "Must have _opType"); |
aoqi@0 | 3745 | assert( mNode2->_opType, "Must have _opType"); |
aoqi@0 | 3746 | const Form *form = globals[_opType]; |
aoqi@0 | 3747 | const Form *form2 = globals[mNode2->_opType]; |
aoqi@0 | 3748 | if( form != form2 ) { |
aoqi@0 | 3749 | return false; |
aoqi@0 | 3750 | } |
aoqi@0 | 3751 | |
aoqi@0 | 3752 | // Check that their children also match |
aoqi@0 | 3753 | if (_lChild ) { |
aoqi@0 | 3754 | if( !_lChild->equivalent(globals, mNode2->_lChild) ) |
aoqi@0 | 3755 | return false; |
aoqi@0 | 3756 | } else if (mNode2->_lChild) { |
aoqi@0 | 3757 | return false; // I have NULL left child, mNode2 has non-NULL left child. |
aoqi@0 | 3758 | } |
aoqi@0 | 3759 | |
aoqi@0 | 3760 | if (_rChild ) { |
aoqi@0 | 3761 | if( !_rChild->equivalent(globals, mNode2->_rChild) ) |
aoqi@0 | 3762 | return false; |
aoqi@0 | 3763 | } else if (mNode2->_rChild) { |
aoqi@0 | 3764 | return false; // I have NULL right child, mNode2 has non-NULL right child. |
aoqi@0 | 3765 | } |
aoqi@0 | 3766 | |
aoqi@0 | 3767 | // We've made it through the gauntlet. |
aoqi@0 | 3768 | return true; |
aoqi@0 | 3769 | } |
aoqi@0 | 3770 | |
aoqi@0 | 3771 | //-------------------------- has_commutative_op ------------------------------- |
aoqi@0 | 3772 | // Recursively check for commutative operations with subtree operands |
aoqi@0 | 3773 | // which could be swapped. |
aoqi@0 | 3774 | void MatchNode::count_commutative_op(int& count) { |
aoqi@0 | 3775 | static const char *commut_op_list[] = { |
aoqi@0 | 3776 | "AddI","AddL","AddF","AddD", |
aoqi@0 | 3777 | "AndI","AndL", |
aoqi@0 | 3778 | "MaxI","MinI", |
aoqi@0 | 3779 | "MulI","MulL","MulF","MulD", |
aoqi@0 | 3780 | "OrI" ,"OrL" , |
aoqi@0 | 3781 | "XorI","XorL" |
aoqi@0 | 3782 | }; |
aoqi@0 | 3783 | int cnt = sizeof(commut_op_list)/sizeof(char*); |
aoqi@0 | 3784 | |
aoqi@0 | 3785 | if( _lChild && _rChild && (_lChild->_lChild || _rChild->_lChild) ) { |
aoqi@0 | 3786 | // Don't swap if right operand is an immediate constant. |
aoqi@0 | 3787 | bool is_const = false; |
aoqi@0 | 3788 | if( _rChild->_lChild == NULL && _rChild->_rChild == NULL ) { |
aoqi@0 | 3789 | FormDict &globals = _AD.globalNames(); |
aoqi@0 | 3790 | const Form *form = globals[_rChild->_opType]; |
aoqi@0 | 3791 | if ( form ) { |
aoqi@0 | 3792 | OperandForm *oper = form->is_operand(); |
aoqi@0 | 3793 | if( oper && oper->interface_type(globals) == Form::constant_interface ) |
aoqi@0 | 3794 | is_const = true; |
aoqi@0 | 3795 | } |
aoqi@0 | 3796 | } |
aoqi@0 | 3797 | if( !is_const ) { |
aoqi@0 | 3798 | for( int i=0; i<cnt; i++ ) { |
aoqi@0 | 3799 | if( strcmp(_opType, commut_op_list[i]) == 0 ) { |
aoqi@0 | 3800 | count++; |
aoqi@0 | 3801 | _commutative_id = count; // id should be > 0 |
aoqi@0 | 3802 | break; |
aoqi@0 | 3803 | } |
aoqi@0 | 3804 | } |
aoqi@0 | 3805 | } |
aoqi@0 | 3806 | } |
aoqi@0 | 3807 | if( _lChild ) |
aoqi@0 | 3808 | _lChild->count_commutative_op(count); |
aoqi@0 | 3809 | if( _rChild ) |
aoqi@0 | 3810 | _rChild->count_commutative_op(count); |
aoqi@0 | 3811 | } |
aoqi@0 | 3812 | |
aoqi@0 | 3813 | //-------------------------- swap_commutative_op ------------------------------ |
aoqi@0 | 3814 | // Recursively swap specified commutative operation with subtree operands. |
aoqi@0 | 3815 | void MatchNode::swap_commutative_op(bool atroot, int id) { |
aoqi@0 | 3816 | if( _commutative_id == id ) { // id should be > 0 |
aoqi@0 | 3817 | assert(_lChild && _rChild && (_lChild->_lChild || _rChild->_lChild ), |
aoqi@0 | 3818 | "not swappable operation"); |
aoqi@0 | 3819 | MatchNode* tmp = _lChild; |
aoqi@0 | 3820 | _lChild = _rChild; |
aoqi@0 | 3821 | _rChild = tmp; |
aoqi@0 | 3822 | // Don't exit here since we need to build internalop. |
aoqi@0 | 3823 | } |
aoqi@0 | 3824 | |
aoqi@0 | 3825 | bool is_set = ( strcmp(_opType, "Set") == 0 ); |
aoqi@0 | 3826 | if( _lChild ) |
aoqi@0 | 3827 | _lChild->swap_commutative_op(is_set, id); |
aoqi@0 | 3828 | if( _rChild ) |
aoqi@0 | 3829 | _rChild->swap_commutative_op(is_set, id); |
aoqi@0 | 3830 | |
aoqi@0 | 3831 | // If not the root, reduce this subtree to an internal operand |
aoqi@0 | 3832 | if( !atroot && (_lChild || _rChild) ) { |
aoqi@0 | 3833 | build_internalop(); |
aoqi@0 | 3834 | } |
aoqi@0 | 3835 | } |
aoqi@0 | 3836 | |
aoqi@0 | 3837 | //-------------------------- swap_commutative_op ------------------------------ |
aoqi@0 | 3838 | // Recursively swap specified commutative operation with subtree operands. |
aoqi@0 | 3839 | void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count, int& match_rules_cnt) { |
aoqi@0 | 3840 | assert(match_rules_cnt < 100," too many match rule clones"); |
aoqi@0 | 3841 | // Clone |
aoqi@0 | 3842 | MatchRule* clone = new MatchRule(_AD, this); |
aoqi@0 | 3843 | // Swap operands of commutative operation |
aoqi@0 | 3844 | ((MatchNode*)clone)->swap_commutative_op(true, count); |
aoqi@0 | 3845 | char* buf = (char*) malloc(strlen(instr_ident) + 4); |
aoqi@0 | 3846 | sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++); |
aoqi@0 | 3847 | clone->_result = buf; |
aoqi@0 | 3848 | |
aoqi@0 | 3849 | clone->_next = this->_next; |
aoqi@0 | 3850 | this-> _next = clone; |
aoqi@0 | 3851 | if( (--count) > 0 ) { |
aoqi@0 | 3852 | this-> matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt); |
aoqi@0 | 3853 | clone->matchrule_swap_commutative_op(instr_ident, count, match_rules_cnt); |
aoqi@0 | 3854 | } |
aoqi@0 | 3855 | } |
aoqi@0 | 3856 | |
aoqi@0 | 3857 | //------------------------------MatchRule-------------------------------------- |
aoqi@0 | 3858 | MatchRule::MatchRule(ArchDesc &ad) |
aoqi@0 | 3859 | : MatchNode(ad), _depth(0), _construct(NULL), _numchilds(0) { |
aoqi@0 | 3860 | _next = NULL; |
aoqi@0 | 3861 | } |
aoqi@0 | 3862 | |
aoqi@0 | 3863 | MatchRule::MatchRule(ArchDesc &ad, MatchRule* mRule) |
aoqi@0 | 3864 | : MatchNode(ad, *mRule, 0), _depth(mRule->_depth), |
aoqi@0 | 3865 | _construct(mRule->_construct), _numchilds(mRule->_numchilds) { |
aoqi@0 | 3866 | _next = NULL; |
aoqi@0 | 3867 | } |
aoqi@0 | 3868 | |
aoqi@0 | 3869 | MatchRule::MatchRule(ArchDesc &ad, MatchNode* mroot, int depth, char *cnstr, |
aoqi@0 | 3870 | int numleaves) |
aoqi@0 | 3871 | : MatchNode(ad,*mroot), _depth(depth), _construct(cnstr), |
aoqi@0 | 3872 | _numchilds(0) { |
aoqi@0 | 3873 | _next = NULL; |
aoqi@0 | 3874 | mroot->_lChild = NULL; |
aoqi@0 | 3875 | mroot->_rChild = NULL; |
aoqi@0 | 3876 | delete mroot; |
aoqi@0 | 3877 | _numleaves = numleaves; |
aoqi@0 | 3878 | _numchilds = (_lChild ? 1 : 0) + (_rChild ? 1 : 0); |
aoqi@0 | 3879 | } |
aoqi@0 | 3880 | MatchRule::~MatchRule() { |
aoqi@0 | 3881 | } |
aoqi@0 | 3882 | |
aoqi@0 | 3883 | // Recursive call collecting info on top-level operands, not transitive. |
aoqi@0 | 3884 | // Implementation does not modify state of internal structures. |
aoqi@0 | 3885 | void MatchRule::append_components(FormDict& locals, ComponentList& components, bool def_flag) const { |
aoqi@0 | 3886 | assert (_name != NULL, "MatchNode::build_components encountered empty node\n"); |
aoqi@0 | 3887 | |
aoqi@0 | 3888 | MatchNode::append_components(locals, components, |
aoqi@0 | 3889 | false /* not necessarily a def */); |
aoqi@0 | 3890 | } |
aoqi@0 | 3891 | |
aoqi@0 | 3892 | // Recursive call on all operands' match rules in my match rule. |
aoqi@0 | 3893 | // Implementation does not modify state of internal structures since they |
aoqi@0 | 3894 | // can be shared. |
aoqi@0 | 3895 | // The MatchNode that is called first treats its |
aoqi@0 | 3896 | bool MatchRule::base_operand(uint &position0, FormDict &globals, |
aoqi@0 | 3897 | const char *&result, const char * &name, |
aoqi@0 | 3898 | const char * &opType)const{ |
aoqi@0 | 3899 | uint position = position0; |
aoqi@0 | 3900 | |
aoqi@0 | 3901 | return (MatchNode::base_operand( position, globals, result, name, opType)); |
aoqi@0 | 3902 | } |
aoqi@0 | 3903 | |
aoqi@0 | 3904 | |
aoqi@0 | 3905 | bool MatchRule::is_base_register(FormDict &globals) const { |
aoqi@0 | 3906 | uint position = 1; |
aoqi@0 | 3907 | const char *result = NULL; |
aoqi@0 | 3908 | const char *name = NULL; |
aoqi@0 | 3909 | const char *opType = NULL; |
aoqi@0 | 3910 | if (!base_operand(position, globals, result, name, opType)) { |
aoqi@0 | 3911 | position = 0; |
aoqi@0 | 3912 | if( base_operand(position, globals, result, name, opType) && |
aoqi@0 | 3913 | (strcmp(opType,"RegI")==0 || |
aoqi@0 | 3914 | strcmp(opType,"RegP")==0 || |
aoqi@0 | 3915 | strcmp(opType,"RegN")==0 || |
aoqi@0 | 3916 | strcmp(opType,"RegL")==0 || |
aoqi@0 | 3917 | strcmp(opType,"RegF")==0 || |
aoqi@0 | 3918 | strcmp(opType,"RegD")==0 || |
aoqi@0 | 3919 | strcmp(opType,"VecS")==0 || |
aoqi@0 | 3920 | strcmp(opType,"VecD")==0 || |
aoqi@0 | 3921 | strcmp(opType,"VecX")==0 || |
aoqi@0 | 3922 | strcmp(opType,"VecY")==0 || |
aoqi@0 | 3923 | strcmp(opType,"Reg" )==0) ) { |
aoqi@0 | 3924 | return 1; |
aoqi@0 | 3925 | } |
aoqi@0 | 3926 | } |
aoqi@0 | 3927 | return 0; |
aoqi@0 | 3928 | } |
aoqi@0 | 3929 | |
aoqi@0 | 3930 | Form::DataType MatchRule::is_base_constant(FormDict &globals) const { |
aoqi@0 | 3931 | uint position = 1; |
aoqi@0 | 3932 | const char *result = NULL; |
aoqi@0 | 3933 | const char *name = NULL; |
aoqi@0 | 3934 | const char *opType = NULL; |
aoqi@0 | 3935 | if (!base_operand(position, globals, result, name, opType)) { |
aoqi@0 | 3936 | position = 0; |
aoqi@0 | 3937 | if (base_operand(position, globals, result, name, opType)) { |
aoqi@0 | 3938 | return ideal_to_const_type(opType); |
aoqi@0 | 3939 | } |
aoqi@0 | 3940 | } |
aoqi@0 | 3941 | return Form::none; |
aoqi@0 | 3942 | } |
aoqi@0 | 3943 | |
aoqi@0 | 3944 | bool MatchRule::is_chain_rule(FormDict &globals) const { |
aoqi@0 | 3945 | |
aoqi@0 | 3946 | // Check for chain rule, and do not generate a match list for it |
aoqi@0 | 3947 | if ((_lChild == NULL) && (_rChild == NULL) ) { |
aoqi@0 | 3948 | const Form *form = globals[_opType]; |
aoqi@0 | 3949 | // If this is ideal, then it is a base match, not a chain rule. |
aoqi@0 | 3950 | if ( form && form->is_operand() && (!form->ideal_only())) { |
aoqi@0 | 3951 | return true; |
aoqi@0 | 3952 | } |
aoqi@0 | 3953 | } |
aoqi@0 | 3954 | // Check for "Set" form of chain rule, and do not generate a match list |
aoqi@0 | 3955 | if (_rChild) { |
aoqi@0 | 3956 | const char *rch = _rChild->_opType; |
aoqi@0 | 3957 | const Form *form = globals[rch]; |
aoqi@0 | 3958 | if ((!strcmp(_opType,"Set") && |
aoqi@0 | 3959 | ((form) && form->is_operand()))) { |
aoqi@0 | 3960 | return true; |
aoqi@0 | 3961 | } |
aoqi@0 | 3962 | } |
aoqi@0 | 3963 | return false; |
aoqi@0 | 3964 | } |
aoqi@0 | 3965 | |
aoqi@0 | 3966 | int MatchRule::is_ideal_copy() const { |
aoqi@0 | 3967 | if( _rChild ) { |
aoqi@0 | 3968 | const char *opType = _rChild->_opType; |
aoqi@0 | 3969 | #if 1 |
aoqi@0 | 3970 | if( strcmp(opType,"CastIP")==0 ) |
aoqi@0 | 3971 | return 1; |
aoqi@0 | 3972 | #else |
aoqi@0 | 3973 | if( strcmp(opType,"CastII")==0 ) |
aoqi@0 | 3974 | return 1; |
aoqi@0 | 3975 | // Do not treat *CastPP this way, because it |
aoqi@0 | 3976 | // may transfer a raw pointer to an oop. |
aoqi@0 | 3977 | // If the register allocator were to coalesce this |
aoqi@0 | 3978 | // into a single LRG, the GC maps would be incorrect. |
aoqi@0 | 3979 | //if( strcmp(opType,"CastPP")==0 ) |
aoqi@0 | 3980 | // return 1; |
aoqi@0 | 3981 | //if( strcmp(opType,"CheckCastPP")==0 ) |
aoqi@0 | 3982 | // return 1; |
aoqi@0 | 3983 | // |
aoqi@0 | 3984 | // Do not treat CastX2P or CastP2X this way, because |
aoqi@0 | 3985 | // raw pointers and int types are treated differently |
aoqi@0 | 3986 | // when saving local & stack info for safepoints in |
aoqi@0 | 3987 | // Output(). |
aoqi@0 | 3988 | //if( strcmp(opType,"CastX2P")==0 ) |
aoqi@0 | 3989 | // return 1; |
aoqi@0 | 3990 | //if( strcmp(opType,"CastP2X")==0 ) |
aoqi@0 | 3991 | // return 1; |
aoqi@0 | 3992 | #endif |
aoqi@0 | 3993 | } |
aoqi@0 | 3994 | if( is_chain_rule(_AD.globalNames()) && |
aoqi@0 | 3995 | _lChild && strncmp(_lChild->_opType,"stackSlot",9)==0 ) |
aoqi@0 | 3996 | return 1; |
aoqi@0 | 3997 | return 0; |
aoqi@0 | 3998 | } |
aoqi@0 | 3999 | |
aoqi@0 | 4000 | |
aoqi@0 | 4001 | int MatchRule::is_expensive() const { |
aoqi@0 | 4002 | if( _rChild ) { |
aoqi@0 | 4003 | const char *opType = _rChild->_opType; |
aoqi@0 | 4004 | if( strcmp(opType,"AtanD")==0 || |
aoqi@0 | 4005 | strcmp(opType,"CosD")==0 || |
aoqi@0 | 4006 | strcmp(opType,"DivD")==0 || |
aoqi@0 | 4007 | strcmp(opType,"DivF")==0 || |
aoqi@0 | 4008 | strcmp(opType,"DivI")==0 || |
aoqi@0 | 4009 | strcmp(opType,"ExpD")==0 || |
aoqi@0 | 4010 | strcmp(opType,"LogD")==0 || |
aoqi@0 | 4011 | strcmp(opType,"Log10D")==0 || |
aoqi@0 | 4012 | strcmp(opType,"ModD")==0 || |
aoqi@0 | 4013 | strcmp(opType,"ModF")==0 || |
aoqi@0 | 4014 | strcmp(opType,"ModI")==0 || |
aoqi@0 | 4015 | strcmp(opType,"PowD")==0 || |
aoqi@0 | 4016 | strcmp(opType,"SinD")==0 || |
aoqi@0 | 4017 | strcmp(opType,"SqrtD")==0 || |
aoqi@0 | 4018 | strcmp(opType,"TanD")==0 || |
aoqi@0 | 4019 | strcmp(opType,"ConvD2F")==0 || |
aoqi@0 | 4020 | strcmp(opType,"ConvD2I")==0 || |
aoqi@0 | 4021 | strcmp(opType,"ConvD2L")==0 || |
aoqi@0 | 4022 | strcmp(opType,"ConvF2D")==0 || |
aoqi@0 | 4023 | strcmp(opType,"ConvF2I")==0 || |
aoqi@0 | 4024 | strcmp(opType,"ConvF2L")==0 || |
aoqi@0 | 4025 | strcmp(opType,"ConvI2D")==0 || |
aoqi@0 | 4026 | strcmp(opType,"ConvI2F")==0 || |
aoqi@0 | 4027 | strcmp(opType,"ConvI2L")==0 || |
aoqi@0 | 4028 | strcmp(opType,"ConvL2D")==0 || |
aoqi@0 | 4029 | strcmp(opType,"ConvL2F")==0 || |
aoqi@0 | 4030 | strcmp(opType,"ConvL2I")==0 || |
aoqi@0 | 4031 | strcmp(opType,"DecodeN")==0 || |
aoqi@0 | 4032 | strcmp(opType,"EncodeP")==0 || |
aoqi@0 | 4033 | strcmp(opType,"EncodePKlass")==0 || |
aoqi@0 | 4034 | strcmp(opType,"DecodeNKlass")==0 || |
aoqi@0 | 4035 | strcmp(opType,"RoundDouble")==0 || |
aoqi@0 | 4036 | strcmp(opType,"RoundFloat")==0 || |
aoqi@0 | 4037 | strcmp(opType,"ReverseBytesI")==0 || |
aoqi@0 | 4038 | strcmp(opType,"ReverseBytesL")==0 || |
aoqi@0 | 4039 | strcmp(opType,"ReverseBytesUS")==0 || |
aoqi@0 | 4040 | strcmp(opType,"ReverseBytesS")==0 || |
aoqi@0 | 4041 | strcmp(opType,"ReplicateB")==0 || |
aoqi@0 | 4042 | strcmp(opType,"ReplicateS")==0 || |
aoqi@0 | 4043 | strcmp(opType,"ReplicateI")==0 || |
aoqi@0 | 4044 | strcmp(opType,"ReplicateL")==0 || |
aoqi@0 | 4045 | strcmp(opType,"ReplicateF")==0 || |
aoqi@0 | 4046 | strcmp(opType,"ReplicateD")==0 || |
aoqi@0 | 4047 | 0 /* 0 to line up columns nicely */ ) |
aoqi@0 | 4048 | return 1; |
aoqi@0 | 4049 | } |
aoqi@0 | 4050 | return 0; |
aoqi@0 | 4051 | } |
aoqi@0 | 4052 | |
aoqi@0 | 4053 | bool MatchRule::is_ideal_if() const { |
aoqi@0 | 4054 | if( !_opType ) return false; |
aoqi@0 | 4055 | return |
aoqi@0 | 4056 | !strcmp(_opType,"If" ) || |
aoqi@0 | 4057 | !strcmp(_opType,"CountedLoopEnd"); |
aoqi@0 | 4058 | } |
aoqi@0 | 4059 | |
aoqi@0 | 4060 | bool MatchRule::is_ideal_fastlock() const { |
aoqi@0 | 4061 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4062 | return (strcmp(_rChild->_opType,"FastLock") == 0); |
aoqi@0 | 4063 | } |
aoqi@0 | 4064 | return false; |
aoqi@0 | 4065 | } |
aoqi@0 | 4066 | |
aoqi@0 | 4067 | bool MatchRule::is_ideal_membar() const { |
aoqi@0 | 4068 | if( !_opType ) return false; |
aoqi@0 | 4069 | return |
aoqi@0 | 4070 | !strcmp(_opType,"MemBarAcquire") || |
aoqi@0 | 4071 | !strcmp(_opType,"MemBarRelease") || |
aoqi@0 | 4072 | !strcmp(_opType,"MemBarAcquireLock") || |
aoqi@0 | 4073 | !strcmp(_opType,"MemBarReleaseLock") || |
aoqi@0 | 4074 | !strcmp(_opType,"LoadFence" ) || |
aoqi@0 | 4075 | !strcmp(_opType,"StoreFence") || |
aoqi@0 | 4076 | !strcmp(_opType,"MemBarVolatile") || |
aoqi@0 | 4077 | !strcmp(_opType,"MemBarCPUOrder") || |
aoqi@0 | 4078 | !strcmp(_opType,"MemBarStoreStore"); |
aoqi@0 | 4079 | } |
aoqi@0 | 4080 | |
aoqi@0 | 4081 | bool MatchRule::is_ideal_loadPC() const { |
aoqi@0 | 4082 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4083 | return (strcmp(_rChild->_opType,"LoadPC") == 0); |
aoqi@0 | 4084 | } |
aoqi@0 | 4085 | return false; |
aoqi@0 | 4086 | } |
aoqi@0 | 4087 | |
aoqi@0 | 4088 | bool MatchRule::is_ideal_box() const { |
aoqi@0 | 4089 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4090 | return (strcmp(_rChild->_opType,"Box") == 0); |
aoqi@0 | 4091 | } |
aoqi@0 | 4092 | return false; |
aoqi@0 | 4093 | } |
aoqi@0 | 4094 | |
aoqi@0 | 4095 | bool MatchRule::is_ideal_goto() const { |
aoqi@0 | 4096 | bool ideal_goto = false; |
aoqi@0 | 4097 | |
aoqi@0 | 4098 | if( _opType && (strcmp(_opType,"Goto") == 0) ) { |
aoqi@0 | 4099 | ideal_goto = true; |
aoqi@0 | 4100 | } |
aoqi@0 | 4101 | return ideal_goto; |
aoqi@0 | 4102 | } |
aoqi@0 | 4103 | |
aoqi@0 | 4104 | bool MatchRule::is_ideal_jump() const { |
aoqi@0 | 4105 | if( _opType ) { |
aoqi@0 | 4106 | if( !strcmp(_opType,"Jump") ) |
aoqi@0 | 4107 | return true; |
aoqi@0 | 4108 | } |
aoqi@0 | 4109 | return false; |
aoqi@0 | 4110 | } |
aoqi@0 | 4111 | |
aoqi@0 | 4112 | bool MatchRule::is_ideal_bool() const { |
aoqi@0 | 4113 | if( _opType ) { |
aoqi@0 | 4114 | if( !strcmp(_opType,"Bool") ) |
aoqi@0 | 4115 | return true; |
aoqi@0 | 4116 | } |
aoqi@0 | 4117 | return false; |
aoqi@0 | 4118 | } |
aoqi@0 | 4119 | |
aoqi@0 | 4120 | |
aoqi@0 | 4121 | Form::DataType MatchRule::is_ideal_load() const { |
aoqi@0 | 4122 | Form::DataType ideal_load = Form::none; |
aoqi@0 | 4123 | |
aoqi@0 | 4124 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4125 | const char *opType = _rChild->_opType; |
aoqi@0 | 4126 | ideal_load = is_load_from_memory(opType); |
aoqi@0 | 4127 | } |
aoqi@0 | 4128 | |
aoqi@0 | 4129 | return ideal_load; |
aoqi@0 | 4130 | } |
aoqi@0 | 4131 | |
aoqi@0 | 4132 | bool MatchRule::is_vector() const { |
aoqi@0 | 4133 | static const char *vector_list[] = { |
aoqi@0 | 4134 | "AddVB","AddVS","AddVI","AddVL","AddVF","AddVD", |
aoqi@0 | 4135 | "SubVB","SubVS","SubVI","SubVL","SubVF","SubVD", |
aoqi@0 | 4136 | "MulVS","MulVI","MulVF","MulVD", |
aoqi@0 | 4137 | "DivVF","DivVD", |
aoqi@0 | 4138 | "AndV" ,"XorV" ,"OrV", |
aoqi@0 | 4139 | "LShiftCntV","RShiftCntV", |
aoqi@0 | 4140 | "LShiftVB","LShiftVS","LShiftVI","LShiftVL", |
aoqi@0 | 4141 | "RShiftVB","RShiftVS","RShiftVI","RShiftVL", |
aoqi@0 | 4142 | "URShiftVB","URShiftVS","URShiftVI","URShiftVL", |
aoqi@0 | 4143 | "ReplicateB","ReplicateS","ReplicateI","ReplicateL","ReplicateF","ReplicateD", |
aoqi@0 | 4144 | "LoadVector","StoreVector", |
aoqi@0 | 4145 | // Next are not supported currently. |
aoqi@0 | 4146 | "PackB","PackS","PackI","PackL","PackF","PackD","Pack2L","Pack2D", |
aoqi@0 | 4147 | "ExtractB","ExtractUB","ExtractC","ExtractS","ExtractI","ExtractL","ExtractF","ExtractD" |
aoqi@0 | 4148 | }; |
aoqi@0 | 4149 | int cnt = sizeof(vector_list)/sizeof(char*); |
aoqi@0 | 4150 | if (_rChild) { |
aoqi@0 | 4151 | const char *opType = _rChild->_opType; |
aoqi@0 | 4152 | for (int i=0; i<cnt; i++) |
aoqi@0 | 4153 | if (strcmp(opType,vector_list[i]) == 0) |
aoqi@0 | 4154 | return true; |
aoqi@0 | 4155 | } |
aoqi@0 | 4156 | return false; |
aoqi@0 | 4157 | } |
aoqi@0 | 4158 | |
aoqi@0 | 4159 | |
aoqi@0 | 4160 | bool MatchRule::skip_antidep_check() const { |
aoqi@0 | 4161 | // Some loads operate on what is effectively immutable memory so we |
aoqi@0 | 4162 | // should skip the anti dep computations. For some of these nodes |
aoqi@0 | 4163 | // the rewritable field keeps the anti dep logic from triggering but |
aoqi@0 | 4164 | // for certain kinds of LoadKlass it does not since they are |
aoqi@0 | 4165 | // actually reading memory which could be rewritten by the runtime, |
aoqi@0 | 4166 | // though never by generated code. This disables it uniformly for |
aoqi@0 | 4167 | // the nodes that behave like this: LoadKlass, LoadNKlass and |
aoqi@0 | 4168 | // LoadRange. |
aoqi@0 | 4169 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4170 | const char *opType = _rChild->_opType; |
aoqi@0 | 4171 | if (strcmp("LoadKlass", opType) == 0 || |
aoqi@0 | 4172 | strcmp("LoadNKlass", opType) == 0 || |
aoqi@0 | 4173 | strcmp("LoadRange", opType) == 0) { |
aoqi@0 | 4174 | return true; |
aoqi@0 | 4175 | } |
aoqi@0 | 4176 | } |
aoqi@0 | 4177 | |
aoqi@0 | 4178 | return false; |
aoqi@0 | 4179 | } |
aoqi@0 | 4180 | |
aoqi@0 | 4181 | |
aoqi@0 | 4182 | Form::DataType MatchRule::is_ideal_store() const { |
aoqi@0 | 4183 | Form::DataType ideal_store = Form::none; |
aoqi@0 | 4184 | |
aoqi@0 | 4185 | if ( _opType && (strcmp(_opType,"Set") == 0) && _rChild ) { |
aoqi@0 | 4186 | const char *opType = _rChild->_opType; |
aoqi@0 | 4187 | ideal_store = is_store_to_memory(opType); |
aoqi@0 | 4188 | } |
aoqi@0 | 4189 | |
aoqi@0 | 4190 | return ideal_store; |
aoqi@0 | 4191 | } |
aoqi@0 | 4192 | |
aoqi@0 | 4193 | |
aoqi@0 | 4194 | void MatchRule::dump() { |
aoqi@0 | 4195 | output(stderr); |
aoqi@0 | 4196 | } |
aoqi@0 | 4197 | |
aoqi@0 | 4198 | // Write just one line. |
aoqi@0 | 4199 | void MatchRule::output_short(FILE *fp) { |
aoqi@0 | 4200 | fprintf(fp,"MatchRule: ( %s",_name); |
aoqi@0 | 4201 | if (_lChild) _lChild->output(fp); |
aoqi@0 | 4202 | if (_rChild) _rChild->output(fp); |
aoqi@0 | 4203 | fprintf(fp," )"); |
aoqi@0 | 4204 | } |
aoqi@0 | 4205 | |
aoqi@0 | 4206 | void MatchRule::output(FILE *fp) { |
aoqi@0 | 4207 | output_short(fp); |
aoqi@0 | 4208 | fprintf(fp,"\n nesting depth = %d\n", _depth); |
aoqi@0 | 4209 | if (_result) fprintf(fp," Result Type = %s", _result); |
aoqi@0 | 4210 | fprintf(fp,"\n"); |
aoqi@0 | 4211 | } |
aoqi@0 | 4212 | |
aoqi@0 | 4213 | //------------------------------Attribute-------------------------------------- |
aoqi@0 | 4214 | Attribute::Attribute(char *id, char* val, int type) |
aoqi@0 | 4215 | : _ident(id), _val(val), _atype(type) { |
aoqi@0 | 4216 | } |
aoqi@0 | 4217 | Attribute::~Attribute() { |
aoqi@0 | 4218 | } |
aoqi@0 | 4219 | |
aoqi@0 | 4220 | int Attribute::int_val(ArchDesc &ad) { |
aoqi@0 | 4221 | // Make sure it is an integer constant: |
aoqi@0 | 4222 | int result = 0; |
aoqi@0 | 4223 | if (!_val || !ADLParser::is_int_token(_val, result)) { |
aoqi@0 | 4224 | ad.syntax_err(0, "Attribute %s must have an integer value: %s", |
aoqi@0 | 4225 | _ident, _val ? _val : ""); |
aoqi@0 | 4226 | } |
aoqi@0 | 4227 | return result; |
aoqi@0 | 4228 | } |
aoqi@0 | 4229 | |
aoqi@0 | 4230 | void Attribute::dump() { |
aoqi@0 | 4231 | output(stderr); |
aoqi@0 | 4232 | } // Debug printer |
aoqi@0 | 4233 | |
aoqi@0 | 4234 | // Write to output files |
aoqi@0 | 4235 | void Attribute::output(FILE *fp) { |
aoqi@0 | 4236 | fprintf(fp,"Attribute: %s %s\n", (_ident?_ident:""), (_val?_val:"")); |
aoqi@0 | 4237 | } |
aoqi@0 | 4238 | |
aoqi@0 | 4239 | //------------------------------FormatRule---------------------------------- |
aoqi@0 | 4240 | FormatRule::FormatRule(char *temp) |
aoqi@0 | 4241 | : _temp(temp) { |
aoqi@0 | 4242 | } |
aoqi@0 | 4243 | FormatRule::~FormatRule() { |
aoqi@0 | 4244 | } |
aoqi@0 | 4245 | |
aoqi@0 | 4246 | void FormatRule::dump() { |
aoqi@0 | 4247 | output(stderr); |
aoqi@0 | 4248 | } |
aoqi@0 | 4249 | |
aoqi@0 | 4250 | // Write to output files |
aoqi@0 | 4251 | void FormatRule::output(FILE *fp) { |
aoqi@0 | 4252 | fprintf(fp,"\nFormat Rule: \n%s", (_temp?_temp:"")); |
aoqi@0 | 4253 | fprintf(fp,"\n"); |
aoqi@0 | 4254 | } |