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