jdk

Форк
0
/
archDesc.cpp 
1307 строк · 42.5 Кб
1
//
2
// Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
//
5
// This code is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU General Public License version 2 only, as
7
// published by the Free Software Foundation.
8
//
9
// This code is distributed in the hope that it will be useful, but WITHOUT
10
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// version 2 for more details (a copy is included in the LICENSE file that
13
// accompanied this code).
14
//
15
// You should have received a copy of the GNU General Public License version
16
// 2 along with this work; if not, write to the Free Software Foundation,
17
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
//
19
// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
// or visit www.oracle.com if you need additional information or have any
21
// questions.
22
//
23
//
24

25

26
// archDesc.cpp - Internal format for architecture definition
27
#include <unordered_set>
28
#include "adlc.hpp"
29

30
static FILE *errfile = stderr;
31

32
//--------------------------- utility functions -----------------------------
33
inline char toUpper(char lower) {
34
  return (('a' <= lower && lower <= 'z') ? ((char) (lower + ('A'-'a'))) : lower);
35
}
36
char *toUpper(const char *str) {
37
  char *upper  = new char[strlen(str)+1];
38
  char *result = upper;
39
  const char *end    = str + strlen(str);
40
  for (; str < end; ++str, ++upper) {
41
    *upper = toUpper(*str);
42
  }
43
  *upper = '\0';
44
  return result;
45
}
46

47
//---------------------------ChainList Methods-------------------------------
48
ChainList::ChainList() {
49
}
50

51
void ChainList::insert(const char *name, const char *cost, const char *rule) {
52
  _name.addName(name);
53
  _cost.addName(cost);
54
  _rule.addName(rule);
55
}
56

57
bool ChainList::search(const char *name) {
58
  return _name.search(name);
59
}
60

61
void ChainList::reset() {
62
  _name.reset();
63
  _cost.reset();
64
  _rule.reset();
65
}
66

67
bool ChainList::iter(const char * &name, const char * &cost, const char * &rule) {
68
  bool        notDone = false;
69
  const char *n       = _name.iter();
70
  const char *c       = _cost.iter();
71
  const char *r       = _rule.iter();
72

73
  if (n && c && r) {
74
    notDone = true;
75
    name = n;
76
    cost = c;
77
    rule = r;
78
  }
79

80
  return notDone;
81
}
82

83
void ChainList::dump() {
84
  output(stderr);
85
}
86

87
void ChainList::output(FILE *fp) {
88
  fprintf(fp, "\nChain Rules: output resets iterator\n");
89
  const char   *cost  = nullptr;
90
  const char   *name  = nullptr;
91
  const char   *rule  = nullptr;
92
  bool   chains_exist = false;
93
  for(reset(); (iter(name,cost,rule)) == true; ) {
94
    fprintf(fp, "Chain to <%s> at cost #%s using %s_rule\n",name, cost ? cost : "0", rule);
95
    //  // Check for transitive chain rules
96
    //  Form *form = (Form *)_globalNames[rule];
97
    //  if (form->is_instruction()) {
98
    //    // chain_rule(fp, indent, name, cost, rule);
99
    //    chain_rule(fp, indent, name, cost, rule);
100
    //  }
101
  }
102
  reset();
103
  if( ! chains_exist ) {
104
    fprintf(fp, "No entries in this ChainList\n");
105
  }
106
}
107

108

109
//---------------------------MatchList Methods-------------------------------
110
bool MatchList::search(const char *opc, const char *res, const char *lch,
111
                       const char *rch, Predicate *pr) {
112
  bool tmp = false;
113
  if ((res == _resultStr) || (res && _resultStr && !strcmp(res, _resultStr))) {
114
    if ((lch == _lchild) || (lch && _lchild && !strcmp(lch, _lchild))) {
115
      if ((rch == _rchild) || (rch && _rchild && !strcmp(rch, _rchild))) {
116
        char * predStr = get_pred();
117
        char * prStr = pr?pr->_pred:nullptr;
118
        if (ADLParser::equivalent_expressions(prStr, predStr)) {
119
          return true;
120
        }
121
      }
122
    }
123
  }
124
  if (_next) {
125
    tmp = _next->search(opc, res, lch, rch, pr);
126
  }
127
  return tmp;
128
}
129

130

131
void MatchList::dump() {
132
  output(stderr);
133
}
134

135
void MatchList::output(FILE *fp) {
136
  fprintf(fp, "\nMatchList output is Unimplemented();\n");
137
}
138

139

140
//---------------------------ArchDesc Constructor and Destructor-------------
141

142
ArchDesc::ArchDesc()
143
  : _globalNames(cmpstr,hashstr, Form::arena),
144
    _globalDefs(cmpstr,hashstr, Form::arena),
145
    _preproc_table(cmpstr,hashstr, Form::arena),
146
    _idealIndex(cmpstr,hashstr, Form::arena),
147
    _internalOps(cmpstr,hashstr, Form::arena),
148
    _internalMatch(cmpstr,hashstr, Form::arena),
149
    _chainRules(cmpstr,hashstr, Form::arena),
150
    _cisc_spill_operand(nullptr),
151
    _needs_deep_clone_jvms(false) {
152

153
      // Initialize the opcode to MatchList table with nulls
154
      for( int i=0; i<_last_opcode; ++i ) {
155
        _mlistab[i] = nullptr;
156
      }
157

158
      // Set-up the global tables
159
      initKeywords(_globalNames);    // Initialize the Name Table with keywords
160

161
      // Prime user-defined types with predefined types: Set, RegI, RegF, ...
162
      initBaseOpTypes();
163

164
      // Initialize flags & counters
165
      _TotalLines        = 0;
166
      _no_output         = 0;
167
      _quiet_mode        = 0;
168
      _disable_warnings  = 0;
169
      _dfa_debug         = 0;
170
      _dfa_small         = 0;
171
      _adl_debug         = 0;
172
      _adlocation_debug  = 0;
173
      _internalOpCounter = 0;
174
      _cisc_spill_debug  = false;
175
      _short_branch_debug = false;
176

177
      // Initialize match rule flags
178
      for (int i = 0; i < _last_opcode; i++) {
179
        _has_match_rule[i] = false;
180
      }
181

182
      // Error/Warning Counts
183
      _syntax_errs       = 0;
184
      _semantic_errs     = 0;
185
      _warnings          = 0;
186
      _internal_errs     = 0;
187

188
      // Initialize I/O Files
189
      _ADL_file._name = nullptr; _ADL_file._fp = nullptr;
190
      // Machine dependent output files
191
      _DFA_file._name    = nullptr;  _DFA_file._fp = nullptr;
192
      _HPP_file._name    = nullptr;  _HPP_file._fp = nullptr;
193
      _CPP_file._name    = nullptr;  _CPP_file._fp = nullptr;
194
      _bug_file._name    = "bugs.out";      _bug_file._fp = nullptr;
195

196
      // Initialize Register & Pipeline Form Pointers
197
      _register = nullptr;
198
      _encode = nullptr;
199
      _pipeline = nullptr;
200
      _frame = nullptr;
201
}
202

203
ArchDesc::~ArchDesc() {
204
  // Clean-up and quit
205

206
}
207

208
//---------------------------ArchDesc methods: Public ----------------------
209
// Store forms according to type
210
void ArchDesc::addForm(PreHeaderForm *ptr) { _pre_header.addForm(ptr); };
211
void ArchDesc::addForm(HeaderForm    *ptr) { _header.addForm(ptr); };
212
void ArchDesc::addForm(SourceForm    *ptr) { _source.addForm(ptr); };
213
void ArchDesc::addForm(EncodeForm    *ptr) { _encode = ptr; };
214
void ArchDesc::addForm(InstructForm  *ptr) { _instructions.addForm(ptr); };
215
void ArchDesc::addForm(MachNodeForm  *ptr) { _machnodes.addForm(ptr); };
216
void ArchDesc::addForm(OperandForm   *ptr) { _operands.addForm(ptr); };
217
void ArchDesc::addForm(OpClassForm   *ptr) { _opclass.addForm(ptr); };
218
void ArchDesc::addForm(AttributeForm *ptr) { _attributes.addForm(ptr); };
219
void ArchDesc::addForm(RegisterForm  *ptr) { _register = ptr; };
220
void ArchDesc::addForm(FrameForm     *ptr) { _frame = ptr; };
221
void ArchDesc::addForm(PipelineForm  *ptr) { _pipeline = ptr; };
222

223
// Build MatchList array and construct MatchLists
224
void ArchDesc::generateMatchLists() {
225
  // Call inspection routines to populate array
226
  inspectOperands();
227
  inspectInstructions();
228
}
229

230
// Build MatchList structures for operands
231
void ArchDesc::inspectOperands() {
232

233
  // Iterate through all operands
234
  _operands.reset();
235
  OperandForm *op;
236
  for( ; (op = (OperandForm*)_operands.iter()) != nullptr;) {
237
    // Construct list of top-level operands (components)
238
    op->build_components();
239

240
    // Ensure that match field is defined.
241
    if ( op->_matrule == nullptr )  continue;
242

243
    // Type check match rules
244
    check_optype(op->_matrule);
245

246
    // Construct chain rules
247
    build_chain_rule(op);
248

249
    MatchRule *mrule = op->_matrule;
250
    Predicate *pred  = op->_predicate;
251

252
    // Grab the machine type of the operand
253
    const char  *rootOp    = op->_ident;
254
    mrule->_machType  = rootOp;
255

256
    // Check for special cases
257
    if (strcmp(rootOp,"Universe")==0) continue;
258
    if (strcmp(rootOp,"label")==0) continue;
259
    // !!!!! !!!!!
260
    assert( strcmp(rootOp,"sReg") != 0, "Disable untyped 'sReg'");
261
    if (strcmp(rootOp,"sRegI")==0) continue;
262
    if (strcmp(rootOp,"sRegP")==0) continue;
263
    if (strcmp(rootOp,"sRegF")==0) continue;
264
    if (strcmp(rootOp,"sRegD")==0) continue;
265
    if (strcmp(rootOp,"sRegL")==0) continue;
266

267
    // Cost for this match
268
    const char *costStr     = op->cost();
269
    const char *defaultCost =
270
      ((AttributeForm*)_globalNames[AttributeForm::_op_cost])->_attrdef;
271
    const char *cost        =  costStr? costStr : defaultCost;
272

273
    // Find result type for match.
274
    const char *result      = op->reduce_result();
275

276
    // Construct a MatchList for this entry.
277
    // Iterate over the list to enumerate all match cases for operands with multiple match rules.
278
    for (; mrule != nullptr; mrule = mrule->_next) {
279
      mrule->_machType = rootOp;
280
      buildMatchList(mrule, result, rootOp, pred, cost);
281
    }
282
  }
283
}
284

285
// Build MatchList structures for instructions
286
void ArchDesc::inspectInstructions() {
287

288
  // Iterate through all instructions
289
  _instructions.reset();
290
  InstructForm *instr;
291
  for( ; (instr = (InstructForm*)_instructions.iter()) != nullptr; ) {
292
    // Construct list of top-level operands (components)
293
    instr->build_components();
294

295
    // Ensure that match field is defined.
296
    if ( instr->_matrule == nullptr )  continue;
297

298
    MatchRule &mrule = *instr->_matrule;
299
    Predicate *pred  =  instr->build_predicate();
300

301
    // Grab the machine type of the operand
302
    const char  *rootOp    = instr->_ident;
303
    mrule._machType  = rootOp;
304

305
    // Cost for this match
306
    const char *costStr = instr->cost();
307
    const char *defaultCost =
308
      ((AttributeForm*)_globalNames[AttributeForm::_ins_cost])->_attrdef;
309
    const char *cost    =  costStr? costStr : defaultCost;
310

311
    // Find result type for match
312
    const char *result  = instr->reduce_result();
313

314
    if (( instr->is_ideal_branch() && instr->label_position() == -1) ||
315
        (!instr->is_ideal_branch() && instr->label_position() != -1)) {
316
      syntax_err(instr->_linenum, "%s: Only branches to a label are supported\n", rootOp);
317
    }
318

319
    Attribute *attr = instr->_attribs;
320
    while (attr != nullptr) {
321
      if (strcmp(attr->_ident,"ins_short_branch") == 0 &&
322
          attr->int_val(*this) != 0) {
323
        if (!instr->is_ideal_branch() || instr->label_position() == -1) {
324
          syntax_err(instr->_linenum, "%s: Only short branch to a label is supported\n", rootOp);
325
        }
326
        instr->set_short_branch(true);
327
      } else if (strcmp(attr->_ident,"ins_alignment") == 0 &&
328
          attr->int_val(*this) != 0) {
329
        instr->set_alignment(attr->int_val(*this));
330
      }
331
      attr = (Attribute *)attr->_next;
332
    }
333

334
    if (!instr->is_short_branch()) {
335
      buildMatchList(instr->_matrule, result, mrule._machType, pred, cost);
336
    }
337
  }
338
}
339

340
static int setsResult(MatchRule &mrule) {
341
  if (strcmp(mrule._name,"Set") == 0) return 1;
342
  return 0;
343
}
344

345
const char *ArchDesc::getMatchListIndex(MatchRule &mrule) {
346
  if (setsResult(mrule)) {
347
    // right child
348
    return mrule._rChild->_opType;
349
  } else {
350
    // first entry
351
    return mrule._opType;
352
  }
353
}
354

355

356
//------------------------------result of reduction----------------------------
357

358

359
//------------------------------left reduction---------------------------------
360
// Return the left reduction associated with an internal name
361
const char *ArchDesc::reduceLeft(char         *internalName) {
362
  const char *left  = nullptr;
363
  MatchNode *mnode = (MatchNode*)_internalMatch[internalName];
364
  if (mnode->_lChild) {
365
    mnode = mnode->_lChild;
366
    left = mnode->_internalop ? mnode->_internalop : mnode->_opType;
367
  }
368
  return left;
369
}
370

371

372
//------------------------------right reduction--------------------------------
373
const char *ArchDesc::reduceRight(char  *internalName) {
374
  const char *right  = nullptr;
375
  MatchNode *mnode = (MatchNode*)_internalMatch[internalName];
376
  if (mnode->_rChild) {
377
    mnode = mnode->_rChild;
378
    right = mnode->_internalop ? mnode->_internalop : mnode->_opType;
379
  }
380
  return right;
381
}
382

383

384
//------------------------------check_optype-----------------------------------
385
void ArchDesc::check_optype(MatchRule *mrule) {
386
  MatchRule *rule = mrule;
387

388
  //   !!!!!
389
  //   // Cycle through the list of match rules
390
  //   while(mrule) {
391
  //     // Check for a filled in type field
392
  //     if (mrule->_opType == nullptr) {
393
  //     const Form  *form    = operands[_result];
394
  //     OpClassForm *opcForm = form ? form->is_opclass() : nullptr;
395
  //     assert(opcForm != nullptr, "Match Rule contains invalid operand name.");
396
  //     }
397
  //     char *opType = opcForm->_ident;
398
  //   }
399
}
400

401
//------------------------------add_chain_rule_entry--------------------------
402
void ArchDesc::add_chain_rule_entry(const char *src, const char *cost,
403
                                    const char *result) {
404
  // Look-up the operation in chain rule table
405
  ChainList *lst = (ChainList *)_chainRules[src];
406
  if (lst == nullptr) {
407
    lst = new ChainList();
408
    _chainRules.Insert(src, lst);
409
  }
410
  if (!lst->search(result)) {
411
    if (cost == nullptr) {
412
      cost = ((AttributeForm*)_globalNames[AttributeForm::_op_cost])->_attrdef;
413
    }
414
    lst->insert(result, cost, result);
415
  }
416
}
417

418
//------------------------------build_chain_rule-------------------------------
419
void ArchDesc::build_chain_rule(OperandForm *oper) {
420
  MatchRule     *rule;
421

422
  // Check for chain rules here
423
  // If this is only a chain rule
424
  if ((oper->_matrule) && (oper->_matrule->_lChild == nullptr) &&
425
      (oper->_matrule->_rChild == nullptr)) {
426

427
    {
428
      const Form *form = _globalNames[oper->_matrule->_opType];
429
      if ((form) && form->is_operand() &&
430
          (form->ideal_only() == false)) {
431
        add_chain_rule_entry(oper->_matrule->_opType, oper->cost(), oper->_ident);
432
      }
433
    }
434
    // Check for additional chain rules
435
    if (oper->_matrule->_next) {
436
      rule = oper->_matrule;
437
      do {
438
        rule = rule->_next;
439
        // Any extra match rules after the first must be chain rules
440
        const Form *form = _globalNames[rule->_opType];
441
        if ((form) && form->is_operand() &&
442
            (form->ideal_only() == false)) {
443
          add_chain_rule_entry(rule->_opType, oper->cost(), oper->_ident);
444
        }
445
      } while(rule->_next != nullptr);
446
    }
447
  }
448
  else if ((oper->_matrule) && (oper->_matrule->_next)) {
449
    // Regardless of whether the first matchrule is a chain rule, check the list
450
    rule = oper->_matrule;
451
    do {
452
      rule = rule->_next;
453
      // Any extra match rules after the first must be chain rules
454
      const Form *form = _globalNames[rule->_opType];
455
      if ((form) && form->is_operand() &&
456
          (form->ideal_only() == false)) {
457
        assert( oper->cost(), "This case expects null cost, not default cost");
458
        add_chain_rule_entry(rule->_opType, oper->cost(), oper->_ident);
459
      }
460
    } while(rule->_next != nullptr);
461
  }
462

463
}
464

465
//------------------------------buildMatchList---------------------------------
466
// operands and instructions provide the result
467
void ArchDesc::buildMatchList(MatchRule *mrule, const char *resultStr,
468
                              const char *rootOp, Predicate *pred,
469
                              const char *cost) {
470
  const char *leftstr, *rightstr;
471
  MatchNode  *mnode;
472

473
  leftstr = rightstr = nullptr;
474
  // Check for chain rule, and do not generate a match list for it
475
  if ( mrule->is_chain_rule(_globalNames) ) {
476
    return;
477
  }
478

479
  // Identify index position among ideal operands
480
  intptr_t    index     = _last_opcode;
481
  const char  *indexStr  = getMatchListIndex(*mrule);
482
  index  = (intptr_t)_idealIndex[indexStr];
483
  if (index == 0) {
484
    fprintf(stderr, "Ideal node missing: %s\n", indexStr);
485
    assert(index != 0, "Failed lookup of ideal node\n");
486
  }
487

488
  // Check that this will be placed appropriately in the DFA
489
  if (index >= _last_opcode) {
490
    fprintf(stderr, "Invalid match rule %s <-- ( %s )\n",
491
            resultStr ? resultStr : " ",
492
            rootOp    ? rootOp    : " ");
493
    assert(index < _last_opcode, "Matching item not in ideal graph\n");
494
    return;
495
  }
496

497

498
  // Walk the MatchRule, generating MatchList entries for each level
499
  // of the rule (each nesting of parentheses)
500
  // Check for "Set"
501
  if (!strcmp(mrule->_opType, "Set")) {
502
    mnode = mrule->_rChild;
503
    buildMList(mnode, rootOp, resultStr, pred, cost);
504
    return;
505
  }
506
  // Build MatchLists for children
507
  // Check each child for an internal operand name, and use that name
508
  // for the parent's matchlist entry if it exists
509
  mnode = mrule->_lChild;
510
  if (mnode) {
511
    buildMList(mnode, nullptr, nullptr, nullptr, nullptr);
512
    leftstr = mnode->_internalop ? mnode->_internalop : mnode->_opType;
513
  }
514
  mnode = mrule->_rChild;
515
  if (mnode) {
516
    buildMList(mnode, nullptr, nullptr, nullptr, nullptr);
517
    rightstr = mnode->_internalop ? mnode->_internalop : mnode->_opType;
518
  }
519
  // Search for an identical matchlist entry already on the list
520
  if ((_mlistab[index] == nullptr) ||
521
      (_mlistab[index] &&
522
       !_mlistab[index]->search(rootOp, resultStr, leftstr, rightstr, pred))) {
523
    // Place this match rule at front of list
524
    MatchList *mList =
525
      new MatchList(_mlistab[index], pred, cost,
526
                    rootOp, resultStr, leftstr, rightstr);
527
    _mlistab[index] = mList;
528
  }
529
}
530

531
// Recursive call for construction of match lists
532
void ArchDesc::buildMList(MatchNode *node, const char *rootOp,
533
                          const char *resultOp, Predicate *pred,
534
                          const char *cost) {
535
  const char *leftstr, *rightstr;
536
  const char *resultop;
537
  const char *opcode;
538
  MatchNode  *mnode;
539
  Form       *form;
540

541
  leftstr = rightstr = nullptr;
542
  // Do not process leaves of the Match Tree if they are not ideal
543
  if ((node) && (node->_lChild == nullptr) && (node->_rChild == nullptr) &&
544
      ((form = (Form *)_globalNames[node->_opType]) != nullptr) &&
545
      (!form->ideal_only())) {
546
    return;
547
  }
548

549
  // Identify index position among ideal operands
550
  intptr_t index = _last_opcode;
551
  const char *indexStr = node ? node->_opType : (char *) " ";
552
  index = (intptr_t)_idealIndex[indexStr];
553
  if (index == 0) {
554
    fprintf(stderr, "error: operand \"%s\" not found\n", indexStr);
555
    assert(0, "fatal error");
556
  }
557

558
  if (node == nullptr) {
559
    fprintf(stderr, "error: node is null\n");
560
    assert(0, "fatal error");
561
  }
562
  // Build MatchLists for children
563
  // Check each child for an internal operand name, and use that name
564
  // for the parent's matchlist entry if it exists
565
  mnode = node->_lChild;
566
  if (mnode) {
567
    buildMList(mnode, nullptr, nullptr, nullptr, nullptr);
568
    leftstr = mnode->_internalop ? mnode->_internalop : mnode->_opType;
569
  }
570
  mnode = node->_rChild;
571
  if (mnode) {
572
    buildMList(mnode, nullptr, nullptr, nullptr, nullptr);
573
    rightstr = mnode->_internalop ? mnode->_internalop : mnode->_opType;
574
  }
575
  // Grab the string for the opcode of this list entry
576
  if (rootOp == nullptr) {
577
    opcode = (node->_internalop) ? node->_internalop : node->_opType;
578
  } else {
579
    opcode = rootOp;
580
  }
581
  // Grab the string for the result of this list entry
582
  if (resultOp == nullptr) {
583
    resultop = (node->_internalop) ? node->_internalop : node->_opType;
584
  }
585
  else resultop = resultOp;
586
  // Search for an identical matchlist entry already on the list
587
  if ((_mlistab[index] == nullptr) || (_mlistab[index] &&
588
                                    !_mlistab[index]->search(opcode, resultop, leftstr, rightstr, pred))) {
589
    // Place this match rule at front of list
590
    MatchList *mList =
591
      new MatchList(_mlistab[index],pred,cost,
592
                    opcode, resultop, leftstr, rightstr);
593
    _mlistab[index] = mList;
594
  }
595
}
596

597
// Count number of OperandForms defined
598
int  ArchDesc::operandFormCount() {
599
  // Only interested in ones with non-null match rule
600
  int  count = 0; _operands.reset();
601
  OperandForm *cur;
602
  for( ; (cur = (OperandForm*)_operands.iter()) != nullptr; ) {
603
    if (cur->_matrule != nullptr) ++count;
604
  };
605
  return count;
606
}
607

608
// Count number of OpClassForms defined
609
int  ArchDesc::opclassFormCount() {
610
  // Only interested in ones with non-null match rule
611
  int  count = 0; _operands.reset();
612
  OpClassForm *cur;
613
  for( ; (cur = (OpClassForm*)_opclass.iter()) != nullptr; ) {
614
    ++count;
615
  };
616
  return count;
617
}
618

619
// Count number of InstructForms defined
620
int  ArchDesc::instructFormCount() {
621
  // Only interested in ones with non-null match rule
622
  int  count = 0; _instructions.reset();
623
  InstructForm *cur;
624
  for( ; (cur = (InstructForm*)_instructions.iter()) != nullptr; ) {
625
    if (cur->_matrule != nullptr) ++count;
626
  };
627
  return count;
628
}
629

630

631
//------------------------------get_preproc_def--------------------------------
632
// Return the textual binding for a given CPP flag name.
633
// Return null if there is no binding, or it has been #undef-ed.
634
char* ArchDesc::get_preproc_def(const char* flag) {
635
  // In case of syntax errors, flag may take the value null.
636
  SourceForm* deff = nullptr;
637
  if (flag != nullptr)
638
    deff = (SourceForm*) _preproc_table[flag];
639
  return (deff == nullptr) ? nullptr : deff->_code;
640
}
641

642

643
//------------------------------set_preproc_def--------------------------------
644
// Change or create a textual binding for a given CPP flag name.
645
// Giving null means the flag name is to be #undef-ed.
646
// In any case, _preproc_list collects all names either #defined or #undef-ed.
647
void ArchDesc::set_preproc_def(const char* flag, const char* def) {
648
  SourceForm* deff = (SourceForm*) _preproc_table[flag];
649
  if (deff == nullptr) {
650
    deff = new SourceForm(nullptr);
651
    _preproc_table.Insert(flag, deff);
652
    _preproc_list.addName(flag);   // this supports iteration
653
  }
654
  deff->_code = (char*) def;
655
}
656

657

658
bool ArchDesc::verify() {
659

660
  if (_register)
661
    assert( _register->verify(), "Register declarations failed verification");
662
  if (!_quiet_mode)
663
    fprintf(stderr,"\n");
664
  // fprintf(stderr,"---------------------------- Verify Operands ---------------\n");
665
  // _operands.verify();
666
  // fprintf(stderr,"\n");
667
  // fprintf(stderr,"---------------------------- Verify Operand Classes --------\n");
668
  // _opclass.verify();
669
  // fprintf(stderr,"\n");
670
  // fprintf(stderr,"---------------------------- Verify Attributes  ------------\n");
671
  // _attributes.verify();
672
  // fprintf(stderr,"\n");
673
  if (!_quiet_mode)
674
    fprintf(stderr,"---------------------------- Verify Instructions ----------------------------\n");
675
  _instructions.verify();
676
  if (!_quiet_mode)
677
    fprintf(stderr,"\n");
678
  // if ( _encode ) {
679
  //   fprintf(stderr,"---------------------------- Verify Encodings --------------\n");
680
  //   _encode->verify();
681
  // }
682

683
  //if (_pipeline) _pipeline->verify();
684

685
  return true;
686
}
687

688
class MarkUsageFormClosure : public FormClosure {
689
private:
690
  ArchDesc* _ad;
691
  std::unordered_set<Form*> *_visited;
692

693
public:
694
  MarkUsageFormClosure(ArchDesc* ad, std::unordered_set<Form*> *visit_map) {
695
    _ad = ad;
696
    _visited = visit_map;
697
  }
698
  virtual ~MarkUsageFormClosure() = default;
699

700
  virtual void do_form(Form *form) {
701
    if (_visited->find(form) == _visited->end()) {
702
      _visited->insert(form);
703
      form->forms_do(this);
704
    }
705
  }
706

707
  virtual void do_form_by_name(const char* name) {
708
    const Form* form = _ad->globalNames()[name];
709
    if (form) {
710
      do_form(const_cast<Form*>(form));
711
      return;
712
    }
713
    RegisterForm* regs = _ad->get_registers();
714
    if (regs->getRegClass(name)) {
715
      do_form(regs->getRegClass(name));
716
      return;
717
    }
718
  }
719
};
720

721
// check unused operands
722
bool ArchDesc::check_usage() {
723
  if (_disable_warnings) {
724
    return true;
725
  }
726

727
  std::unordered_set<Form*> visited;
728
  MarkUsageFormClosure callback(this, &visited);
729
  _instructions.reset();
730
  // iterate all instruction to mark used form
731
  InstructForm* instr;
732
  for ( ; (instr = (InstructForm*)_instructions.iter()) != nullptr; ) {
733
    callback.do_form(instr);
734
  }
735

736
  // these forms are coded in OperandForm::is_user_name_for_sReg
737
  // it may happen no instruction use these operands, like stackSlotP in aarch64,
738
  // but we can not desclare they are useless.
739
  callback.do_form_by_name("stackSlotI");
740
  callback.do_form_by_name("stackSlotP");
741
  callback.do_form_by_name("stackSlotD");
742
  callback.do_form_by_name("stackSlotF");
743
  callback.do_form_by_name("stackSlotL");
744

745
  // sReg* are initial created by adlc in ArchDesc::initBaseOpTypes()
746
  // In ARM, no definition or usage in adfile, but they are reported as unused
747
  callback.do_form_by_name("sRegI");
748
  callback.do_form_by_name("sRegP");
749
  callback.do_form_by_name("sRegD");
750
  callback.do_form_by_name("sRegF");
751
  callback.do_form_by_name("sRegL");
752

753
  // special generic vector operands only used in Matcher::pd_specialize_generic_vector_operand
754
  // x86_32 combine x86.ad and x86_32.ad, the vec*/legVec* can not be cleaned from IA32
755
#if defined(AARCH64)
756
  callback.do_form_by_name("vecA");
757
  callback.do_form_by_name("vecD");
758
  callback.do_form_by_name("vecX");
759
#elif defined(IA32) || defined(AMD64)
760
  callback.do_form_by_name("vecS");
761
  callback.do_form_by_name("vecD");
762
  callback.do_form_by_name("vecX");
763
  callback.do_form_by_name("vecY");
764
  callback.do_form_by_name("vecZ");
765
  callback.do_form_by_name("legVecS");
766
  callback.do_form_by_name("legVecD");
767
  callback.do_form_by_name("legVecX");
768
  callback.do_form_by_name("legVecY");
769
  callback.do_form_by_name("legVecZ");
770
#endif
771

772
  int cnt = 0;
773
  _operands.reset();
774
  OperandForm* operand;
775
  for ( ; (operand = (OperandForm*)_operands.iter()) != nullptr; ) {
776
    if(visited.find(operand) == visited.end() && !operand->ideal_only()) {
777
      fprintf(stderr, "\nWarning: unused operand (%s)", operand->_ident);
778
      cnt++;
779
    }
780
  }
781
  if (cnt) fprintf(stderr, "\n-------Warning: total %d unused operands\n", cnt);
782

783
  return true;
784
}
785

786
void ArchDesc::dump() {
787
  _pre_header.dump();
788
  _header.dump();
789
  _source.dump();
790
  if (_register) _register->dump();
791
  fprintf(stderr,"\n");
792
  fprintf(stderr,"------------------ Dump Operands ---------------------\n");
793
  _operands.dump();
794
  fprintf(stderr,"\n");
795
  fprintf(stderr,"------------------ Dump Operand Classes --------------\n");
796
  _opclass.dump();
797
  fprintf(stderr,"\n");
798
  fprintf(stderr,"------------------ Dump Attributes  ------------------\n");
799
  _attributes.dump();
800
  fprintf(stderr,"\n");
801
  fprintf(stderr,"------------------ Dump Instructions -----------------\n");
802
  _instructions.dump();
803
  if ( _encode ) {
804
    fprintf(stderr,"------------------ Dump Encodings --------------------\n");
805
    _encode->dump();
806
  }
807
  if (_pipeline) _pipeline->dump();
808
}
809

810

811
//------------------------------init_keywords----------------------------------
812
// Load the keywords into the global name table
813
void ArchDesc::initKeywords(FormDict& names) {
814
  // Insert keyword strings into Global Name Table.  Keywords have a null value
815
  // field for quick easy identification when checking identifiers.
816
  names.Insert("instruct", nullptr);
817
  names.Insert("operand", nullptr);
818
  names.Insert("attribute", nullptr);
819
  names.Insert("source", nullptr);
820
  names.Insert("register", nullptr);
821
  names.Insert("pipeline", nullptr);
822
  names.Insert("constraint", nullptr);
823
  names.Insert("predicate", nullptr);
824
  names.Insert("encode", nullptr);
825
  names.Insert("enc_class", nullptr);
826
  names.Insert("interface", nullptr);
827
  names.Insert("opcode", nullptr);
828
  names.Insert("ins_encode", nullptr);
829
  names.Insert("match", nullptr);
830
  names.Insert("effect", nullptr);
831
  names.Insert("expand", nullptr);
832
  names.Insert("rewrite", nullptr);
833
  names.Insert("reg_def", nullptr);
834
  names.Insert("reg_class", nullptr);
835
  names.Insert("alloc_class", nullptr);
836
  names.Insert("resource", nullptr);
837
  names.Insert("pipe_class", nullptr);
838
  names.Insert("pipe_desc", nullptr);
839
}
840

841

842
//------------------------------internal_err----------------------------------
843
// Issue a parser error message, and skip to the end of the current line
844
void ArchDesc::internal_err(const char *fmt, ...) {
845
  va_list args;
846

847
  va_start(args, fmt);
848
  _internal_errs += emit_msg(0, INTERNAL_ERR, 0, fmt, args);
849
  va_end(args);
850

851
  _no_output = 1;
852
}
853

854
//------------------------------syntax_err----------------------------------
855
// Issue a parser error message, and skip to the end of the current line
856
void ArchDesc::syntax_err(int lineno, const char *fmt, ...) {
857
  va_list args;
858

859
  va_start(args, fmt);
860
  _internal_errs += emit_msg(0, SYNERR, lineno, fmt, args);
861
  va_end(args);
862

863
  _no_output = 1;
864
}
865

866
//------------------------------emit_msg---------------------------------------
867
// Emit a user message, typically a warning or error
868
int ArchDesc::emit_msg(int quiet, int flag, int line, const char *fmt,
869
    va_list args) {
870
  static int  last_lineno = -1;
871
  int         i;
872
  const char *pref;
873

874
  switch(flag) {
875
  case 0: pref = "Warning: "; break;
876
  case 1: pref = "Syntax Error: "; break;
877
  case 2: pref = "Semantic Error: "; break;
878
  case 3: pref = "Internal Error: "; break;
879
  default: assert(0, ""); break;
880
  }
881

882
  if (line == last_lineno) return 0;
883
  last_lineno = line;
884

885
  if (!quiet) {                        /* no output if in quiet mode         */
886
    i = fprintf(errfile, "%s(%d) ", _ADL_file._name, line);
887
    while (i++ <= 15)  fputc(' ', errfile);
888
    fprintf(errfile, "%-8s:", pref);
889
    vfprintf(errfile, fmt, args);
890
    fprintf(errfile, "\n");
891
    fflush(errfile);
892
  }
893
  return 1;
894
}
895

896

897
// ---------------------------------------------------------------------------
898
//--------Utilities to build mappings for machine registers ------------------
899
// ---------------------------------------------------------------------------
900

901
// Construct the name of the register mask.
902
static const char *getRegMask(const char *reg_class_name) {
903
  if( reg_class_name == nullptr ) return "RegMask::Empty";
904

905
  if (strcmp(reg_class_name,"Universe")==0) {
906
    return "RegMask::Empty";
907
  } else if (strcmp(reg_class_name,"stack_slots")==0) {
908
    return "(Compile::current()->FIRST_STACK_mask())";
909
  } else if (strcmp(reg_class_name, "dynamic")==0) {
910
    return "*_opnds[0]->in_RegMask(0)";
911
  } else {
912
    char       *rc_name = toUpper(reg_class_name);
913
    const char *mask    = "_mask";
914
    int         length  = (int)strlen(rc_name) + (int)strlen(mask) + 5;
915
    char       *regMask = new char[length];
916
    snprintf_checked(regMask, length, "%s%s()", rc_name, mask);
917
    delete[] rc_name;
918
    return regMask;
919
  }
920
}
921

922
// Convert a register class name to its register mask.
923
const char *ArchDesc::reg_class_to_reg_mask(const char *rc_name) {
924
  const char *reg_mask = "RegMask::Empty";
925

926
  if( _register ) {
927
    RegClass *reg_class  = _register->getRegClass(rc_name);
928
    if (reg_class == nullptr) {
929
      syntax_err(0, "Use of an undefined register class %s", rc_name);
930
      return reg_mask;
931
    }
932

933
    // Construct the name of the register mask.
934
    reg_mask = getRegMask(rc_name);
935
  }
936

937
  return reg_mask;
938
}
939

940

941
// Obtain the name of the RegMask for an OperandForm
942
const char *ArchDesc::reg_mask(OperandForm  &opForm) {
943
  const char *regMask      = "RegMask::Empty";
944

945
  // Check constraints on result's register class
946
  const char *result_class = opForm.constrained_reg_class();
947
  if (result_class == nullptr) {
948
    opForm.dump();
949
    syntax_err(opForm._linenum,
950
               "Use of an undefined result class for operand: %s",
951
               opForm._ident);
952
    abort();
953
  }
954

955
  regMask = reg_class_to_reg_mask( result_class );
956

957
  return regMask;
958
}
959

960
// Obtain the name of the RegMask for an InstructForm
961
const char *ArchDesc::reg_mask(InstructForm &inForm) {
962
  const char *result = inForm.reduce_result();
963

964
  if (result == nullptr) {
965
    syntax_err(inForm._linenum,
966
               "Did not find result operand or RegMask"
967
               " for this instruction: %s",
968
               inForm._ident);
969
    abort();
970
  }
971

972
  // Instructions producing 'Universe' use RegMask::Empty
973
  if (strcmp(result,"Universe") == 0) {
974
    return "RegMask::Empty";
975
  }
976

977
  // Lookup this result operand and get its register class
978
  Form *form = (Form*)_globalNames[result];
979
  if (form == nullptr) {
980
    syntax_err(inForm._linenum,
981
               "Did not find result operand for result: %s", result);
982
    abort();
983
  }
984
  OperandForm *oper = form->is_operand();
985
  if (oper == nullptr) {
986
    syntax_err(inForm._linenum, "Form is not an OperandForm:");
987
    form->dump();
988
    abort();
989
  }
990
  return reg_mask( *oper );
991
}
992

993

994
// Obtain the STACK_OR_reg_mask name for an OperandForm
995
char *ArchDesc::stack_or_reg_mask(OperandForm  &opForm) {
996
  // name of cisc_spillable version
997
  const char *reg_mask_name = reg_mask(opForm);
998

999
  if (reg_mask_name == nullptr) {
1000
     syntax_err(opForm._linenum,
1001
                "Did not find reg_mask for opForm: %s",
1002
                opForm._ident);
1003
     abort();
1004
  }
1005

1006
  const char *stack_or = "STACK_OR_";
1007
  int   length         = (int)strlen(stack_or) + (int)strlen(reg_mask_name) + 1;
1008
  char *result         = new char[length];
1009
  snprintf_checked(result, length, "%s%s", stack_or, reg_mask_name);
1010

1011
  return result;
1012
}
1013

1014
// Record that the register class must generate a stack_or_reg_mask
1015
void ArchDesc::set_stack_or_reg(const char *reg_class_name) {
1016
  if( _register ) {
1017
    RegClass *reg_class  = _register->getRegClass(reg_class_name);
1018
    reg_class->set_stack_version(true);
1019
  }
1020
}
1021

1022

1023
// Return the type signature for the ideal operation
1024
const char *ArchDesc::getIdealType(const char *idealOp) {
1025
  // Find last character in idealOp, it specifies the type
1026
  char  last_char = 0;
1027
  const char *ptr = idealOp;
1028
  for (; *ptr != '\0'; ++ptr) {
1029
    last_char = *ptr;
1030
  }
1031

1032
  // Match Vector types.
1033
  if (strncmp(idealOp, "Vec",3)==0) {
1034
    switch(last_char) {
1035
    case 'A':  return "TypeVect::VECTA";
1036
    case 'S':  return "TypeVect::VECTS";
1037
    case 'D':  return "TypeVect::VECTD";
1038
    case 'X':  return "TypeVect::VECTX";
1039
    case 'Y':  return "TypeVect::VECTY";
1040
    case 'Z':  return "TypeVect::VECTZ";
1041
    default:
1042
      internal_err("Vector type %s with unrecognized type\n",idealOp);
1043
    }
1044
  }
1045

1046
  if (strncmp(idealOp, "RegVectMask", 8) == 0) {
1047
    return "TypeVect::VECTMASK";
1048
  }
1049

1050
  // !!!!!
1051
  switch(last_char) {
1052
  case 'I':    return "TypeInt::INT";
1053
  case 'P':    return "TypePtr::BOTTOM";
1054
  case 'N':    return "TypeNarrowOop::BOTTOM";
1055
  case 'F':    return "Type::FLOAT";
1056
  case 'D':    return "Type::DOUBLE";
1057
  case 'L':    return "TypeLong::LONG";
1058
  case 's':    return "TypeInt::CC /*flags*/";
1059
  default:
1060
    return nullptr;
1061
    // !!!!!
1062
    // internal_err("Ideal type %s with unrecognized type\n",idealOp);
1063
    break;
1064
  }
1065

1066
  return nullptr;
1067
}
1068

1069

1070

1071
OperandForm *ArchDesc::constructOperand(const char *ident,
1072
                                        bool  ideal_only) {
1073
  OperandForm *opForm = new OperandForm(ident, ideal_only);
1074
  _globalNames.Insert(ident, opForm);
1075
  addForm(opForm);
1076

1077
  return opForm;
1078
}
1079

1080

1081
// Import predefined base types: Set = 1, RegI, RegP, ...
1082
void ArchDesc::initBaseOpTypes() {
1083
  // Create OperandForm and assign type for each opcode.
1084
  for (int i = 1; i < _last_machine_leaf; ++i) {
1085
    char *ident = (char *)NodeClassNames[i];
1086
    constructOperand(ident, true);
1087
  }
1088
  // Create InstructForm and assign type for each ideal instruction.
1089
  for (int j = _last_machine_leaf+1; j < _last_opcode; ++j) {
1090
    char *ident = (char *)NodeClassNames[j];
1091
    if (!strcmp(ident, "ConI") || !strcmp(ident, "ConP") ||
1092
        !strcmp(ident, "ConN") || !strcmp(ident, "ConNKlass") ||
1093
        !strcmp(ident, "ConF") || !strcmp(ident, "ConD") ||
1094
        !strcmp(ident, "ConL") || !strcmp(ident, "Con" ) ||
1095
        !strcmp(ident, "Bool")) {
1096
      constructOperand(ident, true);
1097
    } else {
1098
      InstructForm *insForm = new InstructForm(ident, true);
1099
      // insForm->_opcode = nextUserOpType(ident);
1100
      _globalNames.Insert(ident, insForm);
1101
      addForm(insForm);
1102
    }
1103
  }
1104

1105
  { OperandForm *opForm;
1106
  // Create operand type "Universe" for return instructions.
1107
  const char *ident = "Universe";
1108
  opForm = constructOperand(ident, false);
1109

1110
  // Create operand type "label" for branch targets
1111
  ident = "label";
1112
  opForm = constructOperand(ident, false);
1113

1114
  // !!!!! Update - when adding a new sReg/stackSlot type
1115
  // Create operand types "sReg[IPFDL]" for stack slot registers
1116
  opForm = constructOperand("sRegI", false);
1117
  opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots");
1118
  opForm = constructOperand("sRegP", false);
1119
  opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots");
1120
  opForm = constructOperand("sRegF", false);
1121
  opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots");
1122
  opForm = constructOperand("sRegD", false);
1123
  opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots");
1124
  opForm = constructOperand("sRegL", false);
1125
  opForm->_constraint = new Constraint("ALLOC_IN_RC", "stack_slots");
1126

1127
  // Create operand type "method" for call targets
1128
  ident = "method";
1129
  opForm = constructOperand(ident, false);
1130
  }
1131

1132
  // Create Effect Forms for each of the legal effects
1133
  // USE, DEF, USE_DEF, KILL, USE_KILL
1134
  {
1135
    const char *ident = "USE";
1136
    Effect     *eForm = new Effect(ident);
1137
    _globalNames.Insert(ident, eForm);
1138
    ident = "DEF";
1139
    eForm = new Effect(ident);
1140
    _globalNames.Insert(ident, eForm);
1141
    ident = "USE_DEF";
1142
    eForm = new Effect(ident);
1143
    _globalNames.Insert(ident, eForm);
1144
    ident = "KILL";
1145
    eForm = new Effect(ident);
1146
    _globalNames.Insert(ident, eForm);
1147
    ident = "USE_KILL";
1148
    eForm = new Effect(ident);
1149
    _globalNames.Insert(ident, eForm);
1150
    ident = "TEMP";
1151
    eForm = new Effect(ident);
1152
    _globalNames.Insert(ident, eForm);
1153
    ident = "TEMP_DEF";
1154
    eForm = new Effect(ident);
1155
    _globalNames.Insert(ident, eForm);
1156
    ident = "CALL";
1157
    eForm = new Effect(ident);
1158
    _globalNames.Insert(ident, eForm);
1159
  }
1160

1161
  //
1162
  // Build mapping from ideal names to ideal indices
1163
  int idealIndex = 0;
1164
  for (idealIndex = 1; idealIndex < _last_machine_leaf; ++idealIndex) {
1165
    const char *idealName = NodeClassNames[idealIndex];
1166
    _idealIndex.Insert((void*) idealName, (void*) (intptr_t) idealIndex);
1167
  }
1168
  for (idealIndex = _last_machine_leaf+1;
1169
       idealIndex < _last_opcode; ++idealIndex) {
1170
    const char *idealName = NodeClassNames[idealIndex];
1171
    _idealIndex.Insert((void*) idealName, (void*) (intptr_t) idealIndex);
1172
  }
1173

1174
}
1175

1176

1177
//---------------------------addSUNcopyright-------------------------------
1178
// output SUN copyright info
1179
void ArchDesc::addSunCopyright(char* legal, int size, FILE *fp) {
1180
  size_t count = fwrite(legal, 1, size, fp);
1181
  assert(count == (size_t) size, "copyright info truncated");
1182
  fprintf(fp,"\n");
1183
  fprintf(fp,"// Machine Generated File.  Do Not Edit!\n");
1184
  fprintf(fp,"\n");
1185
}
1186

1187

1188
//---------------------------addIncludeGuardStart--------------------------
1189
// output the start of an include guard.
1190
void ArchDesc::addIncludeGuardStart(ADLFILE &adlfile, const char* guardString) {
1191
  // Build #include lines
1192
  fprintf(adlfile._fp, "\n");
1193
  fprintf(adlfile._fp, "#ifndef %s\n", guardString);
1194
  fprintf(adlfile._fp, "#define %s\n", guardString);
1195
  fprintf(adlfile._fp, "\n");
1196

1197
}
1198

1199
//---------------------------addIncludeGuardEnd--------------------------
1200
// output the end of an include guard.
1201
void ArchDesc::addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString) {
1202
  // Build #include lines
1203
  fprintf(adlfile._fp, "\n");
1204
  fprintf(adlfile._fp, "#endif // %s\n", guardString);
1205

1206
}
1207

1208
//---------------------------addInclude--------------------------
1209
// output the #include line for this file.
1210
void ArchDesc::addInclude(ADLFILE &adlfile, const char* fileName) {
1211
  fprintf(adlfile._fp, "#include \"%s\"\n", fileName);
1212

1213
}
1214

1215
void ArchDesc::addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName) {
1216
  fprintf(adlfile._fp, "#include \"%s/%s\"\n", includeDir, fileName);
1217

1218
}
1219

1220
//---------------------------addPreprocessorChecks-----------------------------
1221
// Output C preprocessor code to verify the backend compilation environment.
1222
// The idea is to force code produced by "adlc -DHS64" to be compiled by a
1223
// command of the form "CC ... -DHS64 ...", so that any #ifdefs in the source
1224
// blocks select C code that is consistent with adlc's selections of AD code.
1225
void ArchDesc::addPreprocessorChecks(FILE *fp) {
1226
  const char* flag;
1227
  _preproc_list.reset();
1228
  if (_preproc_list.count() > 0 && !_preproc_list.current_is_signal()) {
1229
    fprintf(fp, "// Check consistency of C++ compilation with ADLC options:\n");
1230
  }
1231
  for (_preproc_list.reset(); (flag = _preproc_list.iter()) != nullptr; ) {
1232
    if (_preproc_list.current_is_signal())  break;
1233
    char* def = get_preproc_def(flag);
1234
    fprintf(fp, "// Check adlc ");
1235
    if (def)
1236
          fprintf(fp, "-D%s=%s\n", flag, def);
1237
    else  fprintf(fp, "-U%s\n", flag);
1238
    fprintf(fp, "#%s %s\n",
1239
            def ? "ifndef" : "ifdef", flag);
1240
    fprintf(fp, "#  error \"%s %s be defined\"\n",
1241
            flag, def ? "must" : "must not");
1242
    fprintf(fp, "#endif // %s\n", flag);
1243
  }
1244
}
1245

1246

1247
// Convert operand name into enum name
1248
const char *ArchDesc::machOperEnum(const char *opName) {
1249
  return ArchDesc::getMachOperEnum(opName);
1250
}
1251

1252
// Convert operand name into enum name
1253
const char *ArchDesc::getMachOperEnum(const char *opName) {
1254
  return (opName ? toUpper(opName) : opName);
1255
}
1256

1257
//---------------------------buildMustCloneMap-----------------------------
1258
// Flag cases when machine needs cloned values or instructions
1259
void ArchDesc::buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp) {
1260
  // Build external declarations for mappings
1261
  fprintf(fp_hpp, "// Mapping from machine-independent opcode to boolean\n");
1262
  fprintf(fp_hpp, "// Flag cases where machine needs cloned values or instructions\n");
1263
  fprintf(fp_hpp, "extern const char must_clone[];\n");
1264
  fprintf(fp_hpp, "\n");
1265

1266
  // Build mapping from ideal names to ideal indices
1267
  fprintf(fp_cpp, "\n");
1268
  fprintf(fp_cpp, "// Mapping from machine-independent opcode to boolean\n");
1269
  fprintf(fp_cpp, "const        char must_clone[] = {\n");
1270
  for (int idealIndex = 0; idealIndex < _last_opcode; ++idealIndex) {
1271
    int         must_clone = 0;
1272
    const char *idealName = NodeClassNames[idealIndex];
1273
    // Previously selected constants for cloning
1274
    // !!!!!
1275
    // These are the current machine-dependent clones
1276
    if ( strcmp(idealName,"CmpI") == 0
1277
         || strcmp(idealName,"CmpU") == 0
1278
         || strcmp(idealName,"CmpP") == 0
1279
         || strcmp(idealName,"CmpN") == 0
1280
         || strcmp(idealName,"CmpL") == 0
1281
         || strcmp(idealName,"CmpUL") == 0
1282
         || strcmp(idealName,"CmpD") == 0
1283
         || strcmp(idealName,"CmpF") == 0
1284
         || strcmp(idealName,"FastLock") == 0
1285
         || strcmp(idealName,"FastUnlock") == 0
1286
         || strcmp(idealName,"OverflowAddI") == 0
1287
         || strcmp(idealName,"OverflowAddL") == 0
1288
         || strcmp(idealName,"OverflowSubI") == 0
1289
         || strcmp(idealName,"OverflowSubL") == 0
1290
         || strcmp(idealName,"OverflowMulI") == 0
1291
         || strcmp(idealName,"OverflowMulL") == 0
1292
         || strcmp(idealName,"Bool") == 0
1293
         || strcmp(idealName,"Binary") == 0
1294
         || strcmp(idealName,"VectorTest") == 0 ) {
1295
      // Removed ConI from the must_clone list.  CPUs that cannot use
1296
      // large constants as immediates manifest the constant as an
1297
      // instruction.  The must_clone flag prevents the constant from
1298
      // floating up out of loops.
1299
      must_clone = 1;
1300
    }
1301
    fprintf(fp_cpp, "  %d%s // %s: %d\n", must_clone,
1302
      (idealIndex != (_last_opcode - 1)) ? "," : " // no trailing comma",
1303
      idealName, idealIndex);
1304
  }
1305
  // Finish defining table
1306
  fprintf(fp_cpp, "};\n");
1307
}
1308

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.