annotate src/share/vm/adlc/archDesc.cpp @ 5763:55fb97c4c58d

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