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