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