Wed, 27 Jul 2011 17:28:36 -0700
7069452: Cleanup NodeFlags
Summary: Remove flags which duplicate information in Node::NodeClasses.
Reviewed-by: never
duke@435 | 1 | // |
stefank@2314 | 2 | // Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | // |
duke@435 | 5 | // This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | // under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | // published by the Free Software Foundation. |
duke@435 | 8 | // |
duke@435 | 9 | // This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | // version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | // accompanied this code). |
duke@435 | 14 | // |
duke@435 | 15 | // You should have received a copy of the GNU General Public License version |
duke@435 | 16 | // 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | // |
trims@1907 | 19 | // Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | // or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | // questions. |
duke@435 | 22 | // |
duke@435 | 23 | // |
duke@435 | 24 | |
duke@435 | 25 | |
duke@435 | 26 | // archDesc.cpp - Internal format for architecture definition |
duke@435 | 27 | #include "adlc.hpp" |
duke@435 | 28 | |
duke@435 | 29 | static FILE *errfile = stderr; |
duke@435 | 30 | |
duke@435 | 31 | //--------------------------- utility functions ----------------------------- |
duke@435 | 32 | inline char toUpper(char lower) { |
duke@435 | 33 | return (('a' <= lower && lower <= 'z') ? (lower + ('A'-'a')) : lower); |
duke@435 | 34 | } |
duke@435 | 35 | char *toUpper(const char *str) { |
duke@435 | 36 | char *upper = new char[strlen(str)+1]; |
duke@435 | 37 | char *result = upper; |
duke@435 | 38 | const char *end = str + strlen(str); |
duke@435 | 39 | for (; str < end; ++str, ++upper) { |
duke@435 | 40 | *upper = toUpper(*str); |
duke@435 | 41 | } |
duke@435 | 42 | *upper = '\0'; |
duke@435 | 43 | return result; |
duke@435 | 44 | } |
duke@435 | 45 | |
duke@435 | 46 | // Utilities to characterize effect statements |
duke@435 | 47 | static bool is_def(int usedef) { |
duke@435 | 48 | switch(usedef) { |
duke@435 | 49 | case Component::DEF: |
duke@435 | 50 | case Component::USE_DEF: return true; break; |
duke@435 | 51 | } |
duke@435 | 52 | return false; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | static bool is_use(int usedef) { |
duke@435 | 56 | switch(usedef) { |
duke@435 | 57 | case Component::USE: |
duke@435 | 58 | case Component::USE_DEF: |
duke@435 | 59 | case Component::USE_KILL: return true; break; |
duke@435 | 60 | } |
duke@435 | 61 | return false; |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | static bool is_kill(int usedef) { |
duke@435 | 65 | switch(usedef) { |
duke@435 | 66 | case Component::KILL: |
duke@435 | 67 | case Component::USE_KILL: return true; break; |
duke@435 | 68 | } |
duke@435 | 69 | return false; |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | //---------------------------ChainList Methods------------------------------- |
duke@435 | 73 | ChainList::ChainList() { |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | void ChainList::insert(const char *name, const char *cost, const char *rule) { |
duke@435 | 77 | _name.addName(name); |
duke@435 | 78 | _cost.addName(cost); |
duke@435 | 79 | _rule.addName(rule); |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | bool ChainList::search(const char *name) { |
duke@435 | 83 | return _name.search(name); |
duke@435 | 84 | } |
duke@435 | 85 | |
duke@435 | 86 | void ChainList::reset() { |
duke@435 | 87 | _name.reset(); |
duke@435 | 88 | _cost.reset(); |
duke@435 | 89 | _rule.reset(); |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | bool ChainList::iter(const char * &name, const char * &cost, const char * &rule) { |
duke@435 | 93 | bool notDone = false; |
duke@435 | 94 | const char *n = _name.iter(); |
duke@435 | 95 | const char *c = _cost.iter(); |
duke@435 | 96 | const char *r = _rule.iter(); |
duke@435 | 97 | |
duke@435 | 98 | if (n && c && r) { |
duke@435 | 99 | notDone = true; |
duke@435 | 100 | name = n; |
duke@435 | 101 | cost = c; |
duke@435 | 102 | rule = r; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | return notDone; |
duke@435 | 106 | } |
duke@435 | 107 | |
duke@435 | 108 | void ChainList::dump() { |
duke@435 | 109 | output(stderr); |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | void ChainList::output(FILE *fp) { |
duke@435 | 113 | fprintf(fp, "\nChain Rules: output resets iterator\n"); |
duke@435 | 114 | const char *cost = NULL; |
duke@435 | 115 | const char *name = NULL; |
duke@435 | 116 | const char *rule = NULL; |
duke@435 | 117 | bool chains_exist = false; |
duke@435 | 118 | for(reset(); (iter(name,cost,rule)) == true; ) { |
duke@435 | 119 | fprintf(fp, "Chain to <%s> at cost #%s using %s_rule\n",name, cost ? cost : "0", rule); |
duke@435 | 120 | // // Check for transitive chain rules |
duke@435 | 121 | // Form *form = (Form *)_globalNames[rule]; |
duke@435 | 122 | // if (form->is_instruction()) { |
duke@435 | 123 | // // chain_rule(fp, indent, name, cost, rule); |
duke@435 | 124 | // chain_rule(fp, indent, name, cost, rule); |
duke@435 | 125 | // } |
duke@435 | 126 | } |
duke@435 | 127 | reset(); |
duke@435 | 128 | if( ! chains_exist ) { |
duke@435 | 129 | fprintf(fp, "No entries in this ChainList\n"); |
duke@435 | 130 | } |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | |
duke@435 | 134 | //---------------------------MatchList Methods------------------------------- |
duke@435 | 135 | bool MatchList::search(const char *opc, const char *res, const char *lch, |
duke@435 | 136 | const char *rch, Predicate *pr) { |
duke@435 | 137 | bool tmp = false; |
duke@435 | 138 | if ((res == _resultStr) || (res && _resultStr && !strcmp(res, _resultStr))) { |
duke@435 | 139 | if ((lch == _lchild) || (lch && _lchild && !strcmp(lch, _lchild))) { |
duke@435 | 140 | if ((rch == _rchild) || (rch && _rchild && !strcmp(rch, _rchild))) { |
duke@435 | 141 | char * predStr = get_pred(); |
duke@435 | 142 | char * prStr = pr?pr->_pred:NULL; |
jrose@910 | 143 | if (ADLParser::equivalent_expressions(prStr, predStr)) { |
duke@435 | 144 | return true; |
duke@435 | 145 | } |
duke@435 | 146 | } |
duke@435 | 147 | } |
duke@435 | 148 | } |
duke@435 | 149 | if (_next) { |
duke@435 | 150 | tmp = _next->search(opc, res, lch, rch, pr); |
duke@435 | 151 | } |
duke@435 | 152 | return tmp; |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | |
duke@435 | 156 | void MatchList::dump() { |
duke@435 | 157 | output(stderr); |
duke@435 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | void MatchList::output(FILE *fp) { |
duke@435 | 161 | fprintf(fp, "\nMatchList output is Unimplemented();\n"); |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | |
duke@435 | 165 | //---------------------------ArchDesc Constructor and Destructor------------- |
duke@435 | 166 | |
duke@435 | 167 | ArchDesc::ArchDesc() |
duke@435 | 168 | : _globalNames(cmpstr,hashstr, Form::arena), |
duke@435 | 169 | _globalDefs(cmpstr,hashstr, Form::arena), |
duke@435 | 170 | _preproc_table(cmpstr,hashstr, Form::arena), |
duke@435 | 171 | _idealIndex(cmpstr,hashstr, Form::arena), |
duke@435 | 172 | _internalOps(cmpstr,hashstr, Form::arena), |
duke@435 | 173 | _internalMatch(cmpstr,hashstr, Form::arena), |
duke@435 | 174 | _chainRules(cmpstr,hashstr, Form::arena), |
duke@435 | 175 | _cisc_spill_operand(NULL) { |
duke@435 | 176 | |
duke@435 | 177 | // Initialize the opcode to MatchList table with NULLs |
duke@435 | 178 | for( int i=0; i<_last_opcode; ++i ) { |
duke@435 | 179 | _mlistab[i] = NULL; |
duke@435 | 180 | } |
duke@435 | 181 | |
duke@435 | 182 | // Set-up the global tables |
duke@435 | 183 | initKeywords(_globalNames); // Initialize the Name Table with keywords |
duke@435 | 184 | |
duke@435 | 185 | // Prime user-defined types with predefined types: Set, RegI, RegF, ... |
duke@435 | 186 | initBaseOpTypes(); |
duke@435 | 187 | |
duke@435 | 188 | // Initialize flags & counters |
duke@435 | 189 | _TotalLines = 0; |
duke@435 | 190 | _no_output = 0; |
duke@435 | 191 | _quiet_mode = 0; |
duke@435 | 192 | _disable_warnings = 0; |
duke@435 | 193 | _dfa_debug = 0; |
duke@435 | 194 | _dfa_small = 0; |
duke@435 | 195 | _adl_debug = 0; |
duke@435 | 196 | _adlocation_debug = 0; |
duke@435 | 197 | _internalOpCounter = 0; |
duke@435 | 198 | _cisc_spill_debug = false; |
duke@435 | 199 | _short_branch_debug = false; |
duke@435 | 200 | |
duke@435 | 201 | // Initialize match rule flags |
duke@435 | 202 | for (int i = 0; i < _last_opcode; i++) { |
duke@435 | 203 | _has_match_rule[i] = false; |
duke@435 | 204 | } |
duke@435 | 205 | |
duke@435 | 206 | // Error/Warning Counts |
duke@435 | 207 | _syntax_errs = 0; |
duke@435 | 208 | _semantic_errs = 0; |
duke@435 | 209 | _warnings = 0; |
duke@435 | 210 | _internal_errs = 0; |
duke@435 | 211 | |
duke@435 | 212 | // Initialize I/O Files |
duke@435 | 213 | _ADL_file._name = NULL; _ADL_file._fp = NULL; |
duke@435 | 214 | // Machine dependent output files |
kvn@868 | 215 | _DFA_file._name = NULL; _DFA_file._fp = NULL; |
kvn@868 | 216 | _HPP_file._name = NULL; _HPP_file._fp = NULL; |
kvn@868 | 217 | _CPP_file._name = NULL; _CPP_file._fp = NULL; |
duke@435 | 218 | _bug_file._name = "bugs.out"; _bug_file._fp = NULL; |
duke@435 | 219 | |
duke@435 | 220 | // Initialize Register & Pipeline Form Pointers |
duke@435 | 221 | _register = NULL; |
duke@435 | 222 | _encode = NULL; |
duke@435 | 223 | _pipeline = NULL; |
duke@435 | 224 | } |
duke@435 | 225 | |
duke@435 | 226 | ArchDesc::~ArchDesc() { |
duke@435 | 227 | // Clean-up and quit |
duke@435 | 228 | |
duke@435 | 229 | } |
duke@435 | 230 | |
duke@435 | 231 | //---------------------------ArchDesc methods: Public ---------------------- |
duke@435 | 232 | // Store forms according to type |
duke@435 | 233 | void ArchDesc::addForm(PreHeaderForm *ptr) { _pre_header.addForm(ptr); }; |
duke@435 | 234 | void ArchDesc::addForm(HeaderForm *ptr) { _header.addForm(ptr); }; |
duke@435 | 235 | void ArchDesc::addForm(SourceForm *ptr) { _source.addForm(ptr); }; |
duke@435 | 236 | void ArchDesc::addForm(EncodeForm *ptr) { _encode = ptr; }; |
duke@435 | 237 | void ArchDesc::addForm(InstructForm *ptr) { _instructions.addForm(ptr); }; |
duke@435 | 238 | void ArchDesc::addForm(MachNodeForm *ptr) { _machnodes.addForm(ptr); }; |
duke@435 | 239 | void ArchDesc::addForm(OperandForm *ptr) { _operands.addForm(ptr); }; |
duke@435 | 240 | void ArchDesc::addForm(OpClassForm *ptr) { _opclass.addForm(ptr); }; |
duke@435 | 241 | void ArchDesc::addForm(AttributeForm *ptr) { _attributes.addForm(ptr); }; |
duke@435 | 242 | void ArchDesc::addForm(RegisterForm *ptr) { _register = ptr; }; |
duke@435 | 243 | void ArchDesc::addForm(FrameForm *ptr) { _frame = ptr; }; |
duke@435 | 244 | void ArchDesc::addForm(PipelineForm *ptr) { _pipeline = ptr; }; |
duke@435 | 245 | |
duke@435 | 246 | // Build MatchList array and construct MatchLists |
duke@435 | 247 | void ArchDesc::generateMatchLists() { |
duke@435 | 248 | // Call inspection routines to populate array |
duke@435 | 249 | inspectOperands(); |
duke@435 | 250 | inspectInstructions(); |
duke@435 | 251 | } |
duke@435 | 252 | |
duke@435 | 253 | // Build MatchList structures for operands |
duke@435 | 254 | void ArchDesc::inspectOperands() { |
duke@435 | 255 | |
duke@435 | 256 | // Iterate through all operands |
duke@435 | 257 | _operands.reset(); |
duke@435 | 258 | OperandForm *op; |
duke@435 | 259 | for( ; (op = (OperandForm*)_operands.iter()) != NULL;) { |
duke@435 | 260 | // Construct list of top-level operands (components) |
duke@435 | 261 | op->build_components(); |
duke@435 | 262 | |
duke@435 | 263 | // Ensure that match field is defined. |
duke@435 | 264 | if ( op->_matrule == NULL ) continue; |
duke@435 | 265 | |
duke@435 | 266 | // Type check match rules |
duke@435 | 267 | check_optype(op->_matrule); |
duke@435 | 268 | |
duke@435 | 269 | // Construct chain rules |
duke@435 | 270 | build_chain_rule(op); |
duke@435 | 271 | |
duke@435 | 272 | MatchRule &mrule = *op->_matrule; |
duke@435 | 273 | Predicate *pred = op->_predicate; |
duke@435 | 274 | |
duke@435 | 275 | // Grab the machine type of the operand |
duke@435 | 276 | const char *rootOp = op->_ident; |
duke@435 | 277 | mrule._machType = rootOp; |
duke@435 | 278 | |
duke@435 | 279 | // Check for special cases |
duke@435 | 280 | if (strcmp(rootOp,"Universe")==0) continue; |
duke@435 | 281 | if (strcmp(rootOp,"label")==0) continue; |
duke@435 | 282 | // !!!!! !!!!! |
duke@435 | 283 | assert( strcmp(rootOp,"sReg") != 0, "Disable untyped 'sReg'"); |
duke@435 | 284 | if (strcmp(rootOp,"sRegI")==0) continue; |
duke@435 | 285 | if (strcmp(rootOp,"sRegP")==0) continue; |
duke@435 | 286 | if (strcmp(rootOp,"sRegF")==0) continue; |
duke@435 | 287 | if (strcmp(rootOp,"sRegD")==0) continue; |
duke@435 | 288 | if (strcmp(rootOp,"sRegL")==0) continue; |
duke@435 | 289 | |
duke@435 | 290 | // Cost for this match |
duke@435 | 291 | const char *costStr = op->cost(); |
duke@435 | 292 | const char *defaultCost = |
duke@435 | 293 | ((AttributeForm*)_globalNames[AttributeForm::_op_cost])->_attrdef; |
duke@435 | 294 | const char *cost = costStr? costStr : defaultCost; |
duke@435 | 295 | |
duke@435 | 296 | // Find result type for match. |
duke@435 | 297 | const char *result = op->reduce_result(); |
duke@435 | 298 | bool has_root = false; |
duke@435 | 299 | |
duke@435 | 300 | // Construct a MatchList for this entry |
duke@435 | 301 | buildMatchList(op->_matrule, result, rootOp, pred, cost); |
duke@435 | 302 | } |
duke@435 | 303 | } |
duke@435 | 304 | |
duke@435 | 305 | // Build MatchList structures for instructions |
duke@435 | 306 | void ArchDesc::inspectInstructions() { |
duke@435 | 307 | |
duke@435 | 308 | // Iterate through all instructions |
duke@435 | 309 | _instructions.reset(); |
duke@435 | 310 | InstructForm *instr; |
duke@435 | 311 | for( ; (instr = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 312 | // Construct list of top-level operands (components) |
duke@435 | 313 | instr->build_components(); |
duke@435 | 314 | |
duke@435 | 315 | // Ensure that match field is defined. |
duke@435 | 316 | if ( instr->_matrule == NULL ) continue; |
duke@435 | 317 | |
duke@435 | 318 | MatchRule &mrule = *instr->_matrule; |
duke@435 | 319 | Predicate *pred = instr->build_predicate(); |
duke@435 | 320 | |
duke@435 | 321 | // Grab the machine type of the operand |
duke@435 | 322 | const char *rootOp = instr->_ident; |
duke@435 | 323 | mrule._machType = rootOp; |
duke@435 | 324 | |
duke@435 | 325 | // Cost for this match |
duke@435 | 326 | const char *costStr = instr->cost(); |
duke@435 | 327 | const char *defaultCost = |
duke@435 | 328 | ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef; |
duke@435 | 329 | const char *cost = costStr? costStr : defaultCost; |
duke@435 | 330 | |
duke@435 | 331 | // Find result type for match |
duke@435 | 332 | const char *result = instr->reduce_result(); |
duke@435 | 333 | |
duke@435 | 334 | Attribute *attr = instr->_attribs; |
duke@435 | 335 | while (attr != NULL) { |
duke@435 | 336 | if (strcmp(attr->_ident,"ins_short_branch") == 0 && |
duke@435 | 337 | attr->int_val(*this) != 0) { |
kvn@3040 | 338 | if (!instr->is_ideal_branch() || instr->label_position() == -1) { |
kvn@3040 | 339 | syntax_err(instr->_linenum, "%s: Only short branch to a label is supported\n", rootOp); |
kvn@3040 | 340 | } |
duke@435 | 341 | instr->set_short_branch(true); |
duke@435 | 342 | } else if (strcmp(attr->_ident,"ins_alignment") == 0 && |
duke@435 | 343 | attr->int_val(*this) != 0) { |
duke@435 | 344 | instr->set_alignment(attr->int_val(*this)); |
duke@435 | 345 | } |
duke@435 | 346 | attr = (Attribute *)attr->_next; |
duke@435 | 347 | } |
duke@435 | 348 | |
duke@435 | 349 | if (!instr->is_short_branch()) { |
duke@435 | 350 | buildMatchList(instr->_matrule, result, mrule._machType, pred, cost); |
duke@435 | 351 | } |
duke@435 | 352 | } |
duke@435 | 353 | } |
duke@435 | 354 | |
duke@435 | 355 | static int setsResult(MatchRule &mrule) { |
duke@435 | 356 | if (strcmp(mrule._name,"Set") == 0) return 1; |
duke@435 | 357 | return 0; |
duke@435 | 358 | } |
duke@435 | 359 | |
duke@435 | 360 | const char *ArchDesc::getMatchListIndex(MatchRule &mrule) { |
duke@435 | 361 | if (setsResult(mrule)) { |
duke@435 | 362 | // right child |
duke@435 | 363 | return mrule._rChild->_opType; |
duke@435 | 364 | } else { |
duke@435 | 365 | // first entry |
duke@435 | 366 | return mrule._opType; |
duke@435 | 367 | } |
duke@435 | 368 | } |
duke@435 | 369 | |
duke@435 | 370 | |
duke@435 | 371 | //------------------------------result of reduction---------------------------- |
duke@435 | 372 | |
duke@435 | 373 | |
duke@435 | 374 | //------------------------------left reduction--------------------------------- |
duke@435 | 375 | // Return the left reduction associated with an internal name |
duke@435 | 376 | const char *ArchDesc::reduceLeft(char *internalName) { |
duke@435 | 377 | const char *left = NULL; |
duke@435 | 378 | MatchNode *mnode = (MatchNode*)_internalMatch[internalName]; |
duke@435 | 379 | if (mnode->_lChild) { |
duke@435 | 380 | mnode = mnode->_lChild; |
duke@435 | 381 | left = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 382 | } |
duke@435 | 383 | return left; |
duke@435 | 384 | } |
duke@435 | 385 | |
duke@435 | 386 | |
duke@435 | 387 | //------------------------------right reduction-------------------------------- |
duke@435 | 388 | const char *ArchDesc::reduceRight(char *internalName) { |
duke@435 | 389 | const char *right = NULL; |
duke@435 | 390 | MatchNode *mnode = (MatchNode*)_internalMatch[internalName]; |
duke@435 | 391 | if (mnode->_rChild) { |
duke@435 | 392 | mnode = mnode->_rChild; |
duke@435 | 393 | right = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 394 | } |
duke@435 | 395 | return right; |
duke@435 | 396 | } |
duke@435 | 397 | |
duke@435 | 398 | |
duke@435 | 399 | //------------------------------check_optype----------------------------------- |
duke@435 | 400 | void ArchDesc::check_optype(MatchRule *mrule) { |
duke@435 | 401 | MatchRule *rule = mrule; |
duke@435 | 402 | |
duke@435 | 403 | // !!!!! |
duke@435 | 404 | // // Cycle through the list of match rules |
duke@435 | 405 | // while(mrule) { |
duke@435 | 406 | // // Check for a filled in type field |
duke@435 | 407 | // if (mrule->_opType == NULL) { |
duke@435 | 408 | // const Form *form = operands[_result]; |
duke@435 | 409 | // OpClassForm *opcForm = form ? form->is_opclass() : NULL; |
duke@435 | 410 | // assert(opcForm != NULL, "Match Rule contains invalid operand name."); |
duke@435 | 411 | // } |
duke@435 | 412 | // char *opType = opcForm->_ident; |
duke@435 | 413 | // } |
duke@435 | 414 | } |
duke@435 | 415 | |
duke@435 | 416 | //------------------------------add_chain_rule_entry-------------------------- |
duke@435 | 417 | void ArchDesc::add_chain_rule_entry(const char *src, const char *cost, |
duke@435 | 418 | const char *result) { |
duke@435 | 419 | // Look-up the operation in chain rule table |
duke@435 | 420 | ChainList *lst = (ChainList *)_chainRules[src]; |
duke@435 | 421 | if (lst == NULL) { |
duke@435 | 422 | lst = new ChainList(); |
duke@435 | 423 | _chainRules.Insert(src, lst); |
duke@435 | 424 | } |
duke@435 | 425 | if (!lst->search(result)) { |
duke@435 | 426 | if (cost == NULL) { |
duke@435 | 427 | cost = ((AttributeForm*)_globalNames[AttributeForm::_op_cost])->_attrdef; |
duke@435 | 428 | } |
duke@435 | 429 | lst->insert(result, cost, result); |
duke@435 | 430 | } |
duke@435 | 431 | } |
duke@435 | 432 | |
duke@435 | 433 | //------------------------------build_chain_rule------------------------------- |
duke@435 | 434 | void ArchDesc::build_chain_rule(OperandForm *oper) { |
duke@435 | 435 | MatchRule *rule; |
duke@435 | 436 | |
duke@435 | 437 | // Check for chain rules here |
duke@435 | 438 | // If this is only a chain rule |
duke@435 | 439 | if ((oper->_matrule) && (oper->_matrule->_lChild == NULL) && |
duke@435 | 440 | (oper->_matrule->_rChild == NULL)) { |
duke@435 | 441 | |
twisti@1038 | 442 | { |
twisti@1038 | 443 | const Form *form = _globalNames[oper->_matrule->_opType]; |
twisti@1038 | 444 | if ((form) && form->is_operand() && |
twisti@1038 | 445 | (form->ideal_only() == false)) { |
twisti@1038 | 446 | add_chain_rule_entry(oper->_matrule->_opType, oper->cost(), oper->_ident); |
twisti@1038 | 447 | } |
duke@435 | 448 | } |
duke@435 | 449 | // Check for additional chain rules |
duke@435 | 450 | if (oper->_matrule->_next) { |
duke@435 | 451 | rule = oper->_matrule; |
duke@435 | 452 | do { |
duke@435 | 453 | rule = rule->_next; |
duke@435 | 454 | // Any extra match rules after the first must be chain rules |
duke@435 | 455 | const Form *form = _globalNames[rule->_opType]; |
duke@435 | 456 | if ((form) && form->is_operand() && |
duke@435 | 457 | (form->ideal_only() == false)) { |
duke@435 | 458 | add_chain_rule_entry(rule->_opType, oper->cost(), oper->_ident); |
duke@435 | 459 | } |
duke@435 | 460 | } while(rule->_next != NULL); |
duke@435 | 461 | } |
duke@435 | 462 | } |
duke@435 | 463 | else if ((oper->_matrule) && (oper->_matrule->_next)) { |
duke@435 | 464 | // Regardles of whether the first matchrule is a chain rule, check the list |
duke@435 | 465 | rule = oper->_matrule; |
duke@435 | 466 | do { |
duke@435 | 467 | rule = rule->_next; |
duke@435 | 468 | // Any extra match rules after the first must be chain rules |
duke@435 | 469 | const Form *form = _globalNames[rule->_opType]; |
duke@435 | 470 | if ((form) && form->is_operand() && |
duke@435 | 471 | (form->ideal_only() == false)) { |
duke@435 | 472 | assert( oper->cost(), "This case expects NULL cost, not default cost"); |
duke@435 | 473 | add_chain_rule_entry(rule->_opType, oper->cost(), oper->_ident); |
duke@435 | 474 | } |
duke@435 | 475 | } while(rule->_next != NULL); |
duke@435 | 476 | } |
duke@435 | 477 | |
duke@435 | 478 | } |
duke@435 | 479 | |
duke@435 | 480 | //------------------------------buildMatchList--------------------------------- |
duke@435 | 481 | // operands and instructions provide the result |
duke@435 | 482 | void ArchDesc::buildMatchList(MatchRule *mrule, const char *resultStr, |
duke@435 | 483 | const char *rootOp, Predicate *pred, |
duke@435 | 484 | const char *cost) { |
duke@435 | 485 | const char *leftstr, *rightstr; |
duke@435 | 486 | MatchNode *mnode; |
duke@435 | 487 | |
duke@435 | 488 | leftstr = rightstr = NULL; |
duke@435 | 489 | // Check for chain rule, and do not generate a match list for it |
duke@435 | 490 | if ( mrule->is_chain_rule(_globalNames) ) { |
duke@435 | 491 | return; |
duke@435 | 492 | } |
duke@435 | 493 | |
duke@435 | 494 | // Identify index position among ideal operands |
duke@435 | 495 | intptr_t index = _last_opcode; |
duke@435 | 496 | const char *indexStr = getMatchListIndex(*mrule); |
duke@435 | 497 | index = (intptr_t)_idealIndex[indexStr]; |
duke@435 | 498 | if (index == 0) { |
duke@435 | 499 | fprintf(stderr, "Ideal node missing: %s\n", indexStr); |
duke@435 | 500 | assert(index != 0, "Failed lookup of ideal node\n"); |
duke@435 | 501 | } |
duke@435 | 502 | |
duke@435 | 503 | // Check that this will be placed appropriately in the DFA |
duke@435 | 504 | if (index >= _last_opcode) { |
duke@435 | 505 | fprintf(stderr, "Invalid match rule %s <-- ( %s )\n", |
duke@435 | 506 | resultStr ? resultStr : " ", |
duke@435 | 507 | rootOp ? rootOp : " "); |
duke@435 | 508 | assert(index < _last_opcode, "Matching item not in ideal graph\n"); |
duke@435 | 509 | return; |
duke@435 | 510 | } |
duke@435 | 511 | |
duke@435 | 512 | |
duke@435 | 513 | // Walk the MatchRule, generating MatchList entries for each level |
duke@435 | 514 | // of the rule (each nesting of parentheses) |
duke@435 | 515 | // Check for "Set" |
duke@435 | 516 | if (!strcmp(mrule->_opType, "Set")) { |
duke@435 | 517 | mnode = mrule->_rChild; |
duke@435 | 518 | buildMList(mnode, rootOp, resultStr, pred, cost); |
duke@435 | 519 | return; |
duke@435 | 520 | } |
duke@435 | 521 | // Build MatchLists for children |
duke@435 | 522 | // Check each child for an internal operand name, and use that name |
duke@435 | 523 | // for the parent's matchlist entry if it exists |
duke@435 | 524 | mnode = mrule->_lChild; |
duke@435 | 525 | if (mnode) { |
duke@435 | 526 | buildMList(mnode, NULL, NULL, NULL, NULL); |
duke@435 | 527 | leftstr = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 528 | } |
duke@435 | 529 | mnode = mrule->_rChild; |
duke@435 | 530 | if (mnode) { |
duke@435 | 531 | buildMList(mnode, NULL, NULL, NULL, NULL); |
duke@435 | 532 | rightstr = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 533 | } |
duke@435 | 534 | // Search for an identical matchlist entry already on the list |
duke@435 | 535 | if ((_mlistab[index] == NULL) || |
duke@435 | 536 | (_mlistab[index] && |
duke@435 | 537 | !_mlistab[index]->search(rootOp, resultStr, leftstr, rightstr, pred))) { |
duke@435 | 538 | // Place this match rule at front of list |
duke@435 | 539 | MatchList *mList = |
duke@435 | 540 | new MatchList(_mlistab[index], pred, cost, |
duke@435 | 541 | rootOp, resultStr, leftstr, rightstr); |
duke@435 | 542 | _mlistab[index] = mList; |
duke@435 | 543 | } |
duke@435 | 544 | } |
duke@435 | 545 | |
duke@435 | 546 | // Recursive call for construction of match lists |
duke@435 | 547 | void ArchDesc::buildMList(MatchNode *node, const char *rootOp, |
duke@435 | 548 | const char *resultOp, Predicate *pred, |
duke@435 | 549 | const char *cost) { |
duke@435 | 550 | const char *leftstr, *rightstr; |
duke@435 | 551 | const char *resultop; |
duke@435 | 552 | const char *opcode; |
duke@435 | 553 | MatchNode *mnode; |
duke@435 | 554 | Form *form; |
duke@435 | 555 | |
duke@435 | 556 | leftstr = rightstr = NULL; |
duke@435 | 557 | // Do not process leaves of the Match Tree if they are not ideal |
duke@435 | 558 | if ((node) && (node->_lChild == NULL) && (node->_rChild == NULL) && |
duke@435 | 559 | ((form = (Form *)_globalNames[node->_opType]) != NULL) && |
duke@435 | 560 | (!form->ideal_only())) { |
duke@435 | 561 | return; |
duke@435 | 562 | } |
duke@435 | 563 | |
duke@435 | 564 | // Identify index position among ideal operands |
duke@435 | 565 | intptr_t index = _last_opcode; |
duke@435 | 566 | const char *indexStr = node ? node->_opType : (char *) " "; |
duke@435 | 567 | index = (intptr_t)_idealIndex[indexStr]; |
duke@435 | 568 | if (index == 0) { |
duke@435 | 569 | fprintf(stderr, "error: operand \"%s\" not found\n", indexStr); |
duke@435 | 570 | assert(0, "fatal error"); |
duke@435 | 571 | } |
duke@435 | 572 | |
duke@435 | 573 | // Build MatchLists for children |
duke@435 | 574 | // Check each child for an internal operand name, and use that name |
duke@435 | 575 | // for the parent's matchlist entry if it exists |
duke@435 | 576 | mnode = node->_lChild; |
duke@435 | 577 | if (mnode) { |
duke@435 | 578 | buildMList(mnode, NULL, NULL, NULL, NULL); |
duke@435 | 579 | leftstr = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 580 | } |
duke@435 | 581 | mnode = node->_rChild; |
duke@435 | 582 | if (mnode) { |
duke@435 | 583 | buildMList(mnode, NULL, NULL, NULL, NULL); |
duke@435 | 584 | rightstr = mnode->_internalop ? mnode->_internalop : mnode->_opType; |
duke@435 | 585 | } |
duke@435 | 586 | // Grab the string for the opcode of this list entry |
duke@435 | 587 | if (rootOp == NULL) { |
duke@435 | 588 | opcode = (node->_internalop) ? node->_internalop : node->_opType; |
duke@435 | 589 | } else { |
duke@435 | 590 | opcode = rootOp; |
duke@435 | 591 | } |
duke@435 | 592 | // Grab the string for the result of this list entry |
duke@435 | 593 | if (resultOp == NULL) { |
duke@435 | 594 | resultop = (node->_internalop) ? node->_internalop : node->_opType; |
duke@435 | 595 | } |
duke@435 | 596 | else resultop = resultOp; |
duke@435 | 597 | // Search for an identical matchlist entry already on the list |
duke@435 | 598 | if ((_mlistab[index] == NULL) || (_mlistab[index] && |
duke@435 | 599 | !_mlistab[index]->search(opcode, resultop, leftstr, rightstr, pred))) { |
duke@435 | 600 | // Place this match rule at front of list |
duke@435 | 601 | MatchList *mList = |
duke@435 | 602 | new MatchList(_mlistab[index],pred,cost, |
duke@435 | 603 | opcode, resultop, leftstr, rightstr); |
duke@435 | 604 | _mlistab[index] = mList; |
duke@435 | 605 | } |
duke@435 | 606 | } |
duke@435 | 607 | |
duke@435 | 608 | // Count number of OperandForms defined |
duke@435 | 609 | int ArchDesc::operandFormCount() { |
duke@435 | 610 | // Only interested in ones with non-NULL match rule |
duke@435 | 611 | int count = 0; _operands.reset(); |
duke@435 | 612 | OperandForm *cur; |
duke@435 | 613 | for( ; (cur = (OperandForm*)_operands.iter()) != NULL; ) { |
duke@435 | 614 | if (cur->_matrule != NULL) ++count; |
duke@435 | 615 | }; |
duke@435 | 616 | return count; |
duke@435 | 617 | } |
duke@435 | 618 | |
duke@435 | 619 | // Count number of OpClassForms defined |
duke@435 | 620 | int ArchDesc::opclassFormCount() { |
duke@435 | 621 | // Only interested in ones with non-NULL match rule |
duke@435 | 622 | int count = 0; _operands.reset(); |
duke@435 | 623 | OpClassForm *cur; |
duke@435 | 624 | for( ; (cur = (OpClassForm*)_opclass.iter()) != NULL; ) { |
duke@435 | 625 | ++count; |
duke@435 | 626 | }; |
duke@435 | 627 | return count; |
duke@435 | 628 | } |
duke@435 | 629 | |
duke@435 | 630 | // Count number of InstructForms defined |
duke@435 | 631 | int ArchDesc::instructFormCount() { |
duke@435 | 632 | // Only interested in ones with non-NULL match rule |
duke@435 | 633 | int count = 0; _instructions.reset(); |
duke@435 | 634 | InstructForm *cur; |
duke@435 | 635 | for( ; (cur = (InstructForm*)_instructions.iter()) != NULL; ) { |
duke@435 | 636 | if (cur->_matrule != NULL) ++count; |
duke@435 | 637 | }; |
duke@435 | 638 | return count; |
duke@435 | 639 | } |
duke@435 | 640 | |
duke@435 | 641 | |
duke@435 | 642 | //------------------------------get_preproc_def-------------------------------- |
duke@435 | 643 | // Return the textual binding for a given CPP flag name. |
duke@435 | 644 | // Return NULL if there is no binding, or it has been #undef-ed. |
duke@435 | 645 | char* ArchDesc::get_preproc_def(const char* flag) { |
duke@435 | 646 | SourceForm* deff = (SourceForm*) _preproc_table[flag]; |
duke@435 | 647 | return (deff == NULL) ? NULL : deff->_code; |
duke@435 | 648 | } |
duke@435 | 649 | |
duke@435 | 650 | |
duke@435 | 651 | //------------------------------set_preproc_def-------------------------------- |
duke@435 | 652 | // Change or create a textual binding for a given CPP flag name. |
duke@435 | 653 | // Giving NULL means the flag name is to be #undef-ed. |
duke@435 | 654 | // In any case, _preproc_list collects all names either #defined or #undef-ed. |
duke@435 | 655 | void ArchDesc::set_preproc_def(const char* flag, const char* def) { |
duke@435 | 656 | SourceForm* deff = (SourceForm*) _preproc_table[flag]; |
duke@435 | 657 | if (deff == NULL) { |
duke@435 | 658 | deff = new SourceForm(NULL); |
duke@435 | 659 | _preproc_table.Insert(flag, deff); |
duke@435 | 660 | _preproc_list.addName(flag); // this supports iteration |
duke@435 | 661 | } |
duke@435 | 662 | deff->_code = (char*) def; |
duke@435 | 663 | } |
duke@435 | 664 | |
duke@435 | 665 | |
duke@435 | 666 | bool ArchDesc::verify() { |
duke@435 | 667 | |
duke@435 | 668 | if (_register) |
duke@435 | 669 | assert( _register->verify(), "Register declarations failed verification"); |
duke@435 | 670 | if (!_quiet_mode) |
duke@435 | 671 | fprintf(stderr,"\n"); |
duke@435 | 672 | // fprintf(stderr,"---------------------------- Verify Operands ---------------\n"); |
duke@435 | 673 | // _operands.verify(); |
duke@435 | 674 | // fprintf(stderr,"\n"); |
duke@435 | 675 | // fprintf(stderr,"---------------------------- Verify Operand Classes --------\n"); |
duke@435 | 676 | // _opclass.verify(); |
duke@435 | 677 | // fprintf(stderr,"\n"); |
duke@435 | 678 | // fprintf(stderr,"---------------------------- Verify Attributes ------------\n"); |
duke@435 | 679 | // _attributes.verify(); |
duke@435 | 680 | // fprintf(stderr,"\n"); |
duke@435 | 681 | if (!_quiet_mode) |
duke@435 | 682 | fprintf(stderr,"---------------------------- Verify Instructions ----------------------------\n"); |
duke@435 | 683 | _instructions.verify(); |
duke@435 | 684 | if (!_quiet_mode) |
duke@435 | 685 | fprintf(stderr,"\n"); |
duke@435 | 686 | // if ( _encode ) { |
duke@435 | 687 | // fprintf(stderr,"---------------------------- Verify Encodings --------------\n"); |
duke@435 | 688 | // _encode->verify(); |
duke@435 | 689 | // } |
duke@435 | 690 | |
duke@435 | 691 | //if (_pipeline) _pipeline->verify(); |
duke@435 | 692 | |
duke@435 | 693 | return true; |
duke@435 | 694 | } |
duke@435 | 695 | |
duke@435 | 696 | |
duke@435 | 697 | void ArchDesc::dump() { |
duke@435 | 698 | _pre_header.dump(); |
duke@435 | 699 | _header.dump(); |
duke@435 | 700 | _source.dump(); |
duke@435 | 701 | if (_register) _register->dump(); |
duke@435 | 702 | fprintf(stderr,"\n"); |
duke@435 | 703 | fprintf(stderr,"------------------ Dump Operands ---------------------\n"); |
duke@435 | 704 | _operands.dump(); |
duke@435 | 705 | fprintf(stderr,"\n"); |
duke@435 | 706 | fprintf(stderr,"------------------ Dump Operand Classes --------------\n"); |
duke@435 | 707 | _opclass.dump(); |
duke@435 | 708 | fprintf(stderr,"\n"); |
duke@435 | 709 | fprintf(stderr,"------------------ Dump Attributes ------------------\n"); |
duke@435 | 710 | _attributes.dump(); |
duke@435 | 711 | fprintf(stderr,"\n"); |
duke@435 | 712 | fprintf(stderr,"------------------ Dump Instructions -----------------\n"); |
duke@435 | 713 | _instructions.dump(); |
duke@435 | 714 | if ( _encode ) { |
duke@435 | 715 | fprintf(stderr,"------------------ Dump Encodings --------------------\n"); |
duke@435 | 716 | _encode->dump(); |
duke@435 | 717 | } |
duke@435 | 718 | if (_pipeline) _pipeline->dump(); |
duke@435 | 719 | } |
duke@435 | 720 | |
duke@435 | 721 | |
duke@435 | 722 | //------------------------------init_keywords---------------------------------- |
duke@435 | 723 | // Load the kewords into the global name table |
duke@435 | 724 | void ArchDesc::initKeywords(FormDict& names) { |
duke@435 | 725 | // Insert keyword strings into Global Name Table. Keywords have a NULL value |
duke@435 | 726 | // field for quick easy identification when checking identifiers. |
duke@435 | 727 | names.Insert("instruct", NULL); |
duke@435 | 728 | names.Insert("operand", NULL); |
duke@435 | 729 | names.Insert("attribute", NULL); |
duke@435 | 730 | names.Insert("source", NULL); |
duke@435 | 731 | names.Insert("register", NULL); |
duke@435 | 732 | names.Insert("pipeline", NULL); |
duke@435 | 733 | names.Insert("constraint", NULL); |
duke@435 | 734 | names.Insert("predicate", NULL); |
duke@435 | 735 | names.Insert("encode", NULL); |
duke@435 | 736 | names.Insert("enc_class", NULL); |
duke@435 | 737 | names.Insert("interface", NULL); |
duke@435 | 738 | names.Insert("opcode", NULL); |
duke@435 | 739 | names.Insert("ins_encode", NULL); |
duke@435 | 740 | names.Insert("match", NULL); |
duke@435 | 741 | names.Insert("effect", NULL); |
duke@435 | 742 | names.Insert("expand", NULL); |
duke@435 | 743 | names.Insert("rewrite", NULL); |
duke@435 | 744 | names.Insert("reg_def", NULL); |
duke@435 | 745 | names.Insert("reg_class", NULL); |
duke@435 | 746 | names.Insert("alloc_class", NULL); |
duke@435 | 747 | names.Insert("resource", NULL); |
duke@435 | 748 | names.Insert("pipe_class", NULL); |
duke@435 | 749 | names.Insert("pipe_desc", NULL); |
duke@435 | 750 | } |
duke@435 | 751 | |
duke@435 | 752 | |
duke@435 | 753 | //------------------------------internal_err---------------------------------- |
duke@435 | 754 | // Issue a parser error message, and skip to the end of the current line |
duke@435 | 755 | void ArchDesc::internal_err(const char *fmt, ...) { |
duke@435 | 756 | va_list args; |
duke@435 | 757 | |
duke@435 | 758 | va_start(args, fmt); |
duke@435 | 759 | _internal_errs += emit_msg(0, INTERNAL_ERR, 0, fmt, args); |
duke@435 | 760 | va_end(args); |
duke@435 | 761 | |
duke@435 | 762 | _no_output = 1; |
duke@435 | 763 | } |
duke@435 | 764 | |
duke@435 | 765 | //------------------------------syntax_err---------------------------------- |
duke@435 | 766 | // Issue a parser error message, and skip to the end of the current line |
duke@435 | 767 | void ArchDesc::syntax_err(int lineno, const char *fmt, ...) { |
duke@435 | 768 | va_list args; |
duke@435 | 769 | |
duke@435 | 770 | va_start(args, fmt); |
duke@435 | 771 | _internal_errs += emit_msg(0, SYNERR, lineno, fmt, args); |
duke@435 | 772 | va_end(args); |
duke@435 | 773 | |
duke@435 | 774 | _no_output = 1; |
duke@435 | 775 | } |
duke@435 | 776 | |
duke@435 | 777 | //------------------------------emit_msg--------------------------------------- |
duke@435 | 778 | // Emit a user message, typically a warning or error |
duke@435 | 779 | int ArchDesc::emit_msg(int quiet, int flag, int line, const char *fmt, |
duke@435 | 780 | va_list args) { |
duke@435 | 781 | static int last_lineno = -1; |
duke@435 | 782 | int i; |
duke@435 | 783 | const char *pref; |
duke@435 | 784 | |
duke@435 | 785 | switch(flag) { |
duke@435 | 786 | case 0: pref = "Warning: "; break; |
duke@435 | 787 | case 1: pref = "Syntax Error: "; break; |
duke@435 | 788 | case 2: pref = "Semantic Error: "; break; |
duke@435 | 789 | case 3: pref = "Internal Error: "; break; |
duke@435 | 790 | default: assert(0, ""); break; |
duke@435 | 791 | } |
duke@435 | 792 | |
duke@435 | 793 | if (line == last_lineno) return 0; |
duke@435 | 794 | last_lineno = line; |
duke@435 | 795 | |
duke@435 | 796 | if (!quiet) { /* no output if in quiet mode */ |
duke@435 | 797 | i = fprintf(errfile, "%s(%d) ", _ADL_file._name, line); |
duke@435 | 798 | while (i++ <= 15) fputc(' ', errfile); |
duke@435 | 799 | fprintf(errfile, "%-8s:", pref); |
duke@435 | 800 | vfprintf(errfile, fmt, args); |
duke@435 | 801 | fprintf(errfile, "\n"); } |
duke@435 | 802 | return 1; |
duke@435 | 803 | } |
duke@435 | 804 | |
duke@435 | 805 | |
duke@435 | 806 | // --------------------------------------------------------------------------- |
duke@435 | 807 | //--------Utilities to build mappings for machine registers ------------------ |
duke@435 | 808 | // --------------------------------------------------------------------------- |
duke@435 | 809 | |
duke@435 | 810 | // Construct the name of the register mask. |
duke@435 | 811 | static const char *getRegMask(const char *reg_class_name) { |
duke@435 | 812 | if( reg_class_name == NULL ) return "RegMask::Empty"; |
duke@435 | 813 | |
duke@435 | 814 | if (strcmp(reg_class_name,"Universe")==0) { |
duke@435 | 815 | return "RegMask::Empty"; |
duke@435 | 816 | } else if (strcmp(reg_class_name,"stack_slots")==0) { |
duke@435 | 817 | return "(Compile::current()->FIRST_STACK_mask())"; |
duke@435 | 818 | } else { |
duke@435 | 819 | char *rc_name = toUpper(reg_class_name); |
duke@435 | 820 | const char *mask = "_mask"; |
duke@435 | 821 | int length = (int)strlen(rc_name) + (int)strlen(mask) + 3; |
duke@435 | 822 | char *regMask = new char[length]; |
duke@435 | 823 | sprintf(regMask,"%s%s", rc_name, mask); |
duke@435 | 824 | return regMask; |
duke@435 | 825 | } |
duke@435 | 826 | } |
duke@435 | 827 | |
duke@435 | 828 | // Convert a register class name to its register mask. |
duke@435 | 829 | const char *ArchDesc::reg_class_to_reg_mask(const char *rc_name) { |
duke@435 | 830 | const char *reg_mask = "RegMask::Empty"; |
duke@435 | 831 | |
duke@435 | 832 | if( _register ) { |
duke@435 | 833 | RegClass *reg_class = _register->getRegClass(rc_name); |
duke@435 | 834 | if (reg_class == NULL) { |
duke@435 | 835 | syntax_err(0, "Use of an undefined register class %s", rc_name); |
duke@435 | 836 | return reg_mask; |
duke@435 | 837 | } |
duke@435 | 838 | |
duke@435 | 839 | // Construct the name of the register mask. |
duke@435 | 840 | reg_mask = getRegMask(rc_name); |
duke@435 | 841 | } |
duke@435 | 842 | |
duke@435 | 843 | return reg_mask; |
duke@435 | 844 | } |
duke@435 | 845 | |
duke@435 | 846 | |
duke@435 | 847 | // Obtain the name of the RegMask for an OperandForm |
duke@435 | 848 | const char *ArchDesc::reg_mask(OperandForm &opForm) { |
duke@435 | 849 | const char *regMask = "RegMask::Empty"; |
duke@435 | 850 | |
duke@435 | 851 | // Check constraints on result's register class |
duke@435 | 852 | const char *result_class = opForm.constrained_reg_class(); |
duke@435 | 853 | if (!result_class) opForm.dump(); |
duke@435 | 854 | assert( result_class, "Resulting register class was not defined for operand"); |
duke@435 | 855 | regMask = reg_class_to_reg_mask( result_class ); |
duke@435 | 856 | |
duke@435 | 857 | return regMask; |
duke@435 | 858 | } |
duke@435 | 859 | |
duke@435 | 860 | // Obtain the name of the RegMask for an InstructForm |
duke@435 | 861 | const char *ArchDesc::reg_mask(InstructForm &inForm) { |
duke@435 | 862 | const char *result = inForm.reduce_result(); |
duke@435 | 863 | assert( result, |
duke@435 | 864 | "Did not find result operand or RegMask for this instruction"); |
duke@435 | 865 | |
duke@435 | 866 | // Instructions producing 'Universe' use RegMask::Empty |
duke@435 | 867 | if( strcmp(result,"Universe")==0 ) { |
duke@435 | 868 | return "RegMask::Empty"; |
duke@435 | 869 | } |
duke@435 | 870 | |
duke@435 | 871 | // Lookup this result operand and get its register class |
duke@435 | 872 | Form *form = (Form*)_globalNames[result]; |
duke@435 | 873 | assert( form, "Result operand must be defined"); |
duke@435 | 874 | OperandForm *oper = form->is_operand(); |
coleenp@548 | 875 | if (oper == NULL) form->dump(); |
duke@435 | 876 | assert( oper, "Result must be an OperandForm"); |
duke@435 | 877 | return reg_mask( *oper ); |
duke@435 | 878 | } |
duke@435 | 879 | |
duke@435 | 880 | |
duke@435 | 881 | // Obtain the STACK_OR_reg_mask name for an OperandForm |
duke@435 | 882 | char *ArchDesc::stack_or_reg_mask(OperandForm &opForm) { |
duke@435 | 883 | // name of cisc_spillable version |
duke@435 | 884 | const char *reg_mask_name = reg_mask(opForm); |
duke@435 | 885 | assert( reg_mask_name != NULL, "called with incorrect opForm"); |
duke@435 | 886 | |
duke@435 | 887 | const char *stack_or = "STACK_OR_"; |
duke@435 | 888 | int length = (int)strlen(stack_or) + (int)strlen(reg_mask_name) + 1; |
duke@435 | 889 | char *result = new char[length]; |
duke@435 | 890 | sprintf(result,"%s%s", stack_or, reg_mask_name); |
duke@435 | 891 | |
duke@435 | 892 | return result; |
duke@435 | 893 | } |
duke@435 | 894 | |
duke@435 | 895 | // Record that the register class must generate a stack_or_reg_mask |
duke@435 | 896 | void ArchDesc::set_stack_or_reg(const char *reg_class_name) { |
duke@435 | 897 | if( _register ) { |
duke@435 | 898 | RegClass *reg_class = _register->getRegClass(reg_class_name); |
duke@435 | 899 | reg_class->_stack_or_reg = true; |
duke@435 | 900 | } |
duke@435 | 901 | } |
duke@435 | 902 | |
duke@435 | 903 | |
duke@435 | 904 | // Return the type signature for the ideal operation |
duke@435 | 905 | const char *ArchDesc::getIdealType(const char *idealOp) { |
duke@435 | 906 | // Find last character in idealOp, it specifies the type |
duke@435 | 907 | char last_char = 0; |
duke@435 | 908 | const char *ptr = idealOp; |
duke@435 | 909 | for( ; *ptr != '\0'; ++ptr) { |
duke@435 | 910 | last_char = *ptr; |
duke@435 | 911 | } |
duke@435 | 912 | |
duke@435 | 913 | // !!!!! |
duke@435 | 914 | switch( last_char ) { |
duke@435 | 915 | case 'I': return "TypeInt::INT"; |
duke@435 | 916 | case 'P': return "TypePtr::BOTTOM"; |
coleenp@548 | 917 | case 'N': return "TypeNarrowOop::BOTTOM"; |
duke@435 | 918 | case 'F': return "Type::FLOAT"; |
duke@435 | 919 | case 'D': return "Type::DOUBLE"; |
duke@435 | 920 | case 'L': return "TypeLong::LONG"; |
duke@435 | 921 | case 's': return "TypeInt::CC /*flags*/"; |
duke@435 | 922 | default: |
duke@435 | 923 | return NULL; |
duke@435 | 924 | // !!!!! |
duke@435 | 925 | // internal_err("Ideal type %s with unrecognized type\n",idealOp); |
duke@435 | 926 | break; |
duke@435 | 927 | } |
duke@435 | 928 | |
duke@435 | 929 | return NULL; |
duke@435 | 930 | } |
duke@435 | 931 | |
duke@435 | 932 | |
duke@435 | 933 | |
duke@435 | 934 | OperandForm *ArchDesc::constructOperand(const char *ident, |
duke@435 | 935 | bool ideal_only) { |
duke@435 | 936 | OperandForm *opForm = new OperandForm(ident, ideal_only); |
duke@435 | 937 | _globalNames.Insert(ident, opForm); |
duke@435 | 938 | addForm(opForm); |
duke@435 | 939 | |
duke@435 | 940 | return opForm; |
duke@435 | 941 | } |
duke@435 | 942 | |
duke@435 | 943 | |
duke@435 | 944 | // Import predefined base types: Set = 1, RegI, RegP, ... |
duke@435 | 945 | void ArchDesc::initBaseOpTypes() { |
duke@435 | 946 | // Create OperandForm and assign type for each opcode. |
duke@435 | 947 | for (int i = 1; i < _last_machine_leaf; ++i) { |
duke@435 | 948 | char *ident = (char *)NodeClassNames[i]; |
duke@435 | 949 | constructOperand(ident, true); |
duke@435 | 950 | } |
duke@435 | 951 | // Create InstructForm and assign type for each ideal instruction. |
duke@435 | 952 | for ( int j = _last_machine_leaf+1; j < _last_opcode; ++j) { |
duke@435 | 953 | char *ident = (char *)NodeClassNames[j]; |
coleenp@548 | 954 | if(!strcmp(ident, "ConI") || !strcmp(ident, "ConP") || !strcmp(ident, "ConN") || |
duke@435 | 955 | !strcmp(ident, "ConF") || !strcmp(ident, "ConD") || |
duke@435 | 956 | !strcmp(ident, "ConL") || !strcmp(ident, "Con" ) || |
duke@435 | 957 | !strcmp(ident, "Bool") ) { |
duke@435 | 958 | constructOperand(ident, true); |
duke@435 | 959 | } |
duke@435 | 960 | else { |
duke@435 | 961 | InstructForm *insForm = new InstructForm(ident, true); |
duke@435 | 962 | // insForm->_opcode = nextUserOpType(ident); |
duke@435 | 963 | _globalNames.Insert(ident,insForm); |
duke@435 | 964 | addForm(insForm); |
duke@435 | 965 | } |
duke@435 | 966 | } |
duke@435 | 967 | |
duke@435 | 968 | { OperandForm *opForm; |
duke@435 | 969 | // Create operand type "Universe" for return instructions. |
duke@435 | 970 | const char *ident = "Universe"; |
duke@435 | 971 | opForm = constructOperand(ident, false); |
duke@435 | 972 | |
duke@435 | 973 | // Create operand type "label" for branch targets |
duke@435 | 974 | ident = "label"; |
duke@435 | 975 | opForm = constructOperand(ident, false); |
duke@435 | 976 | |
duke@435 | 977 | // !!!!! Update - when adding a new sReg/stackSlot type |
duke@435 | 978 | // Create operand types "sReg[IPFDL]" for stack slot registers |
duke@435 | 979 | opForm = constructOperand("sRegI", false); |
duke@435 | 980 | opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots"); |
duke@435 | 981 | opForm = constructOperand("sRegP", false); |
duke@435 | 982 | opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots"); |
duke@435 | 983 | opForm = constructOperand("sRegF", false); |
duke@435 | 984 | opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots"); |
duke@435 | 985 | opForm = constructOperand("sRegD", false); |
duke@435 | 986 | opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots"); |
duke@435 | 987 | opForm = constructOperand("sRegL", false); |
duke@435 | 988 | opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots"); |
duke@435 | 989 | |
duke@435 | 990 | // Create operand type "method" for call targets |
duke@435 | 991 | ident = "method"; |
duke@435 | 992 | opForm = constructOperand(ident, false); |
duke@435 | 993 | } |
duke@435 | 994 | |
duke@435 | 995 | // Create Effect Forms for each of the legal effects |
duke@435 | 996 | // USE, DEF, USE_DEF, KILL, USE_KILL |
duke@435 | 997 | { |
duke@435 | 998 | const char *ident = "USE"; |
duke@435 | 999 | Effect *eForm = new Effect(ident); |
duke@435 | 1000 | _globalNames.Insert(ident, eForm); |
duke@435 | 1001 | ident = "DEF"; |
duke@435 | 1002 | eForm = new Effect(ident); |
duke@435 | 1003 | _globalNames.Insert(ident, eForm); |
duke@435 | 1004 | ident = "USE_DEF"; |
duke@435 | 1005 | eForm = new Effect(ident); |
duke@435 | 1006 | _globalNames.Insert(ident, eForm); |
duke@435 | 1007 | ident = "KILL"; |
duke@435 | 1008 | eForm = new Effect(ident); |
duke@435 | 1009 | _globalNames.Insert(ident, eForm); |
duke@435 | 1010 | ident = "USE_KILL"; |
duke@435 | 1011 | eForm = new Effect(ident); |
duke@435 | 1012 | _globalNames.Insert(ident, eForm); |
duke@435 | 1013 | ident = "TEMP"; |
duke@435 | 1014 | eForm = new Effect(ident); |
duke@435 | 1015 | _globalNames.Insert(ident, eForm); |
duke@435 | 1016 | } |
duke@435 | 1017 | |
duke@435 | 1018 | // |
duke@435 | 1019 | // Build mapping from ideal names to ideal indices |
duke@435 | 1020 | int idealIndex = 0; |
duke@435 | 1021 | for (idealIndex = 1; idealIndex < _last_machine_leaf; ++idealIndex) { |
duke@435 | 1022 | const char *idealName = NodeClassNames[idealIndex]; |
twisti@1038 | 1023 | _idealIndex.Insert((void*) idealName, (void*) (intptr_t) idealIndex); |
duke@435 | 1024 | } |
duke@435 | 1025 | for ( idealIndex = _last_machine_leaf+1; |
duke@435 | 1026 | idealIndex < _last_opcode; ++idealIndex) { |
duke@435 | 1027 | const char *idealName = NodeClassNames[idealIndex]; |
twisti@1038 | 1028 | _idealIndex.Insert((void*) idealName, (void*) (intptr_t) idealIndex); |
duke@435 | 1029 | } |
duke@435 | 1030 | |
duke@435 | 1031 | } |
duke@435 | 1032 | |
duke@435 | 1033 | |
duke@435 | 1034 | //---------------------------addSUNcopyright------------------------------- |
duke@435 | 1035 | // output SUN copyright info |
duke@435 | 1036 | void ArchDesc::addSunCopyright(char* legal, int size, FILE *fp) { |
andrew@1403 | 1037 | size_t count = fwrite(legal, 1, size, fp); |
andrew@1403 | 1038 | assert(count == (size_t) size, "copyright info truncated"); |
duke@435 | 1039 | fprintf(fp,"\n"); |
duke@435 | 1040 | fprintf(fp,"// Machine Generated File. Do Not Edit!\n"); |
duke@435 | 1041 | fprintf(fp,"\n"); |
duke@435 | 1042 | } |
duke@435 | 1043 | |
duke@435 | 1044 | |
stefank@2314 | 1045 | //---------------------------addIncludeGuardStart-------------------------- |
stefank@2314 | 1046 | // output the start of an include guard. |
stefank@2314 | 1047 | void ArchDesc::addIncludeGuardStart(ADLFILE &adlfile, const char* guardString) { |
duke@435 | 1048 | // Build #include lines |
duke@435 | 1049 | fprintf(adlfile._fp, "\n"); |
stefank@2314 | 1050 | fprintf(adlfile._fp, "#ifndef %s\n", guardString); |
stefank@2314 | 1051 | fprintf(adlfile._fp, "#define %s\n", guardString); |
duke@435 | 1052 | fprintf(adlfile._fp, "\n"); |
duke@435 | 1053 | |
duke@435 | 1054 | } |
duke@435 | 1055 | |
stefank@2314 | 1056 | //---------------------------addIncludeGuardEnd-------------------------- |
stefank@2314 | 1057 | // output the end of an include guard. |
stefank@2314 | 1058 | void ArchDesc::addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString) { |
stefank@2314 | 1059 | // Build #include lines |
stefank@2314 | 1060 | fprintf(adlfile._fp, "\n"); |
stefank@2314 | 1061 | fprintf(adlfile._fp, "#endif // %s\n", guardString); |
stefank@2314 | 1062 | |
stefank@2314 | 1063 | } |
stefank@2314 | 1064 | |
stefank@2314 | 1065 | //---------------------------addInclude-------------------------- |
stefank@2314 | 1066 | // output the #include line for this file. |
stefank@2314 | 1067 | void ArchDesc::addInclude(ADLFILE &adlfile, const char* fileName) { |
stefank@2314 | 1068 | fprintf(adlfile._fp, "#include \"%s\"\n", fileName); |
stefank@2314 | 1069 | |
stefank@2314 | 1070 | } |
stefank@2314 | 1071 | |
stefank@2314 | 1072 | void ArchDesc::addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName) { |
stefank@2314 | 1073 | fprintf(adlfile._fp, "#include \"%s/%s\"\n", includeDir, fileName); |
stefank@2314 | 1074 | |
stefank@2314 | 1075 | } |
duke@435 | 1076 | |
duke@435 | 1077 | //---------------------------addPreprocessorChecks----------------------------- |
duke@435 | 1078 | // Output C preprocessor code to verify the backend compilation environment. |
duke@435 | 1079 | // The idea is to force code produced by "adlc -DHS64" to be compiled by a |
duke@435 | 1080 | // command of the form "CC ... -DHS64 ...", so that any #ifdefs in the source |
duke@435 | 1081 | // blocks select C code that is consistent with adlc's selections of AD code. |
duke@435 | 1082 | void ArchDesc::addPreprocessorChecks(FILE *fp) { |
duke@435 | 1083 | const char* flag; |
duke@435 | 1084 | _preproc_list.reset(); |
duke@435 | 1085 | if (_preproc_list.count() > 0 && !_preproc_list.current_is_signal()) { |
duke@435 | 1086 | fprintf(fp, "// Check consistency of C++ compilation with ADLC options:\n"); |
duke@435 | 1087 | } |
duke@435 | 1088 | for (_preproc_list.reset(); (flag = _preproc_list.iter()) != NULL; ) { |
duke@435 | 1089 | if (_preproc_list.current_is_signal()) break; |
duke@435 | 1090 | char* def = get_preproc_def(flag); |
duke@435 | 1091 | fprintf(fp, "// Check adlc "); |
duke@435 | 1092 | if (def) |
duke@435 | 1093 | fprintf(fp, "-D%s=%s\n", flag, def); |
duke@435 | 1094 | else fprintf(fp, "-U%s\n", flag); |
duke@435 | 1095 | fprintf(fp, "#%s %s\n", |
duke@435 | 1096 | def ? "ifndef" : "ifdef", flag); |
duke@435 | 1097 | fprintf(fp, "# error \"%s %s be defined\"\n", |
duke@435 | 1098 | flag, def ? "must" : "must not"); |
duke@435 | 1099 | fprintf(fp, "#endif // %s\n", flag); |
duke@435 | 1100 | } |
duke@435 | 1101 | } |
duke@435 | 1102 | |
duke@435 | 1103 | |
duke@435 | 1104 | // Convert operand name into enum name |
duke@435 | 1105 | const char *ArchDesc::machOperEnum(const char *opName) { |
duke@435 | 1106 | return ArchDesc::getMachOperEnum(opName); |
duke@435 | 1107 | } |
duke@435 | 1108 | |
duke@435 | 1109 | // Convert operand name into enum name |
duke@435 | 1110 | const char *ArchDesc::getMachOperEnum(const char *opName) { |
duke@435 | 1111 | return (opName ? toUpper(opName) : opName); |
duke@435 | 1112 | } |
duke@435 | 1113 | |
duke@435 | 1114 | //---------------------------buildMustCloneMap----------------------------- |
duke@435 | 1115 | // Flag cases when machine needs cloned values or instructions |
duke@435 | 1116 | void ArchDesc::buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp) { |
duke@435 | 1117 | // Build external declarations for mappings |
duke@435 | 1118 | fprintf(fp_hpp, "// Mapping from machine-independent opcode to boolean\n"); |
duke@435 | 1119 | fprintf(fp_hpp, "// Flag cases where machine needs cloned values or instructions\n"); |
duke@435 | 1120 | fprintf(fp_hpp, "extern const char must_clone[];\n"); |
duke@435 | 1121 | fprintf(fp_hpp, "\n"); |
duke@435 | 1122 | |
duke@435 | 1123 | // Build mapping from ideal names to ideal indices |
duke@435 | 1124 | fprintf(fp_cpp, "\n"); |
duke@435 | 1125 | fprintf(fp_cpp, "// Mapping from machine-independent opcode to boolean\n"); |
duke@435 | 1126 | fprintf(fp_cpp, "const char must_clone[] = {\n"); |
duke@435 | 1127 | for (int idealIndex = 0; idealIndex < _last_opcode; ++idealIndex) { |
duke@435 | 1128 | int must_clone = 0; |
duke@435 | 1129 | const char *idealName = NodeClassNames[idealIndex]; |
duke@435 | 1130 | // Previously selected constants for cloning |
duke@435 | 1131 | // !!!!! |
duke@435 | 1132 | // These are the current machine-dependent clones |
duke@435 | 1133 | if ( strcmp(idealName,"CmpI") == 0 |
duke@435 | 1134 | || strcmp(idealName,"CmpU") == 0 |
duke@435 | 1135 | || strcmp(idealName,"CmpP") == 0 |
coleenp@548 | 1136 | || strcmp(idealName,"CmpN") == 0 |
duke@435 | 1137 | || strcmp(idealName,"CmpL") == 0 |
duke@435 | 1138 | || strcmp(idealName,"CmpD") == 0 |
duke@435 | 1139 | || strcmp(idealName,"CmpF") == 0 |
duke@435 | 1140 | || strcmp(idealName,"FastLock") == 0 |
duke@435 | 1141 | || strcmp(idealName,"FastUnlock") == 0 |
duke@435 | 1142 | || strcmp(idealName,"Bool") == 0 |
duke@435 | 1143 | || strcmp(idealName,"Binary") == 0 ) { |
duke@435 | 1144 | // Removed ConI from the must_clone list. CPUs that cannot use |
duke@435 | 1145 | // large constants as immediates manifest the constant as an |
duke@435 | 1146 | // instruction. The must_clone flag prevents the constant from |
duke@435 | 1147 | // floating up out of loops. |
duke@435 | 1148 | must_clone = 1; |
duke@435 | 1149 | } |
duke@435 | 1150 | fprintf(fp_cpp, " %d%s // %s: %d\n", must_clone, |
duke@435 | 1151 | (idealIndex != (_last_opcode - 1)) ? "," : " // no trailing comma", |
duke@435 | 1152 | idealName, idealIndex); |
duke@435 | 1153 | } |
duke@435 | 1154 | // Finish defining table |
duke@435 | 1155 | fprintf(fp_cpp, "};\n"); |
duke@435 | 1156 | } |