src/share/vm/adlc/archDesc.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial