src/hotspot/share/adlc/forms.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 2150
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2150
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: 2150
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    25
#ifndef SHARE_ADLC_FORMS_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    26
#define SHARE_ADLC_FORMS_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// FORMS.HPP - ADL Parser Generic and Utility Forms Classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#define TRUE 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#define FALSE 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// DEFINITIONS OF LEGAL ATTRIBUTE TYPES
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#define INS_ATTR 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#define OP_ATTR  1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// DEFINITIONS OF LEGAL CONSTRAINT TYPES
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Class List
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class Form;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class InstructForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class MachNodeForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class OperandForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class OpClassForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class AttributeForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class RegisterForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class PipelineForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
class SourceForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class EncodeForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
class Component;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
class Constraint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
class Predicate;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
class MatchRule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
class Attribute;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
class Effect;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
class ExpandRule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
class RewriteRule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
class ConstructRule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
class FormatRule;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
class Peephole;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
class EncClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
class Interface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
class RegInterface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
class ConstInterface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
class MemInterface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
class CondInterface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
class Opcode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
class InsEncode;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
class RegDef;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
class RegClass;
30202
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 18699
diff changeset
    71
class CodeSnippetRegClass;
6f5c48bd9b82 8075798: Allow ADLC register class to depend on runtime conditions also for cisc-spillable classes
zmajo
parents: 18699
diff changeset
    72
class ConditionalRegClass;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
class AllocClass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
class ResourceForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
class PipeClassForm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
class PeepMatch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
class PeepConstraint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
class PeepReplace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
class MatchList;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
class ArchDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
//------------------------------FormDict---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// Dictionary containing Forms, and objects derived from forms
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
class FormDict {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  Dict         _form;              // map names, char*, to their Form* or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Disable public use of constructor, copy-ctor, operator =, operator ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  FormDict( );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  FormDict &operator =( const FormDict & );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // == compares two dictionaries; they must have the same keys (their keys
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // must match using CmpKey) and they must have the same values (pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // comparison).  If so 1 is returned, if not 0 is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  bool operator ==(const FormDict &d) const; // Compare dictionaries for equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // cmp is a key comparision routine.  hash is a routine to hash a key.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // FormDict( CmpKey cmp, Hash hash );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  FormDict( CmpKey cmp, Hash hash, Arena *arena );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  FormDict( const FormDict & fd );    // Deep-copy guts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  ~FormDict();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Return # of key-value pairs in dict
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int Size(void) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Insert inserts the given key-value pair into the dictionary.  The prior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // value of the key is returned; NULL if the key was not previously defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  const Form  *Insert(const char *name, Form *form); // A new key-value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Find finds the value of a given key; or NULL if not found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // The dictionary is NOT changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  const Form  *operator [](const char *name) const;  // Do a lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// ***** Master Class for ADL Parser Forms *****
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
//------------------------------Form-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
class Form {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  static Arena  *arena;            // arena used by forms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static Arena  *generate_arena(); // allocate arena used by forms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  int   _ftype;                    // Indicator for derived class type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Public Data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  Form *_next;                     // Next pointer for form lists
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1495
diff changeset
   132
  int   _linenum;                  // Line number for debugging
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Dynamic type check for common forms.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  virtual OpClassForm   *is_opclass()     const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  virtual OperandForm   *is_operand()     const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  virtual InstructForm  *is_instruction() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  virtual MachNodeForm  *is_machnode()    const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  virtual AttributeForm *is_attribute()   const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  virtual Effect        *is_effect()      const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  virtual ResourceForm  *is_resource()    const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  virtual PipeClassForm *is_pipeclass()   const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Check if this form is an operand usable for cisc-spilling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  virtual bool           is_cisc_reg(FormDict &globals) const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  virtual bool           is_cisc_mem(FormDict &globals) const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Public Methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  Form(int formType=0, int line=0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    : _next(NULL), _linenum(line), _ftype(formType) { };
18699
0ef0e63280de 8017578: Hotspot compilation error with latest Studio compiler
drchase
parents: 13971
diff changeset
   151
  virtual ~Form() {};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  virtual bool ideal_only() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    assert(0,"Check of ideal status on non-instruction/operand form.\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    return FALSE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Check constraints after parsing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  virtual bool verify()    { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  virtual void dump()      { output(stderr); }    // Debug printer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Write info to output files
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  virtual void output(FILE *fp)    { fprintf(fp,"Form Output"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // ADLC types, match the last character on ideal operands and instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  enum DataType {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    none        =  0,  // Not a simple type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    idealI      =  1,  // Integer type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    idealP      =  2,  // Pointer types, oop(s)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    idealL      =  3,  // Long    type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    idealF      =  4,  // Float   type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    idealD      =  5,  // Double  type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    idealB      =  6,  // Byte    type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    idealC      =  7,  // Char    type
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   176
    idealS      =  8,  // String  type
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 7397
diff changeset
   177
    idealN      =  9,  // Narrow oop types
13969
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13104
diff changeset
   178
    idealNKlass = 10,  // Narrow klass types
d2a189b83b87 7054512: Compress class pointers after perm gen removal
roland
parents: 13104
diff changeset
   179
    idealV      = 11   // Vector  type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // Convert ideal name to a DataType, return DataType::none if not a 'ConX'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  Form::DataType  ideal_to_const_type(const char *ideal_type_name) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Convert ideal name to a DataType, return DataType::none if not a 'sRegX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  Form::DataType  ideal_to_sReg_type(const char *name) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Convert ideal name to a DataType, return DataType::none if not a 'RegX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  Form::DataType  ideal_to_Reg_type(const char *name) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Convert ideal name to a DataType, return DataType::none if not a 'LoadX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  Form::DataType is_load_from_memory(const char *opType) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // Convert ideal name to a DataType, return DataType::none if not a 'StoreX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  Form::DataType is_store_to_memory(const char *opType)  const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  // ADLC call types, matched with ideal world
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  enum CallType {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    invalid_type  =  0,  // invalid call type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    JAVA_STATIC   =  1,  // monomorphic entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    JAVA_DYNAMIC  =  2,  // possibly megamorphic, inline cache call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    JAVA_COMPILED =  3,  // callee will be compiled java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    JAVA_INTERP   =  4,  // callee will be executed by interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    JAVA_NATIVE   =  5,  // native entrypoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    JAVA_RUNTIME  =  6,  // runtime entrypoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    JAVA_LEAF     =  7   // calling leaf
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // Interface types for operands and operand classes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  enum InterfaceType {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    no_interface          =  0,  // unknown or inconsistent interface type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    constant_interface    =  1,  // interface to constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    register_interface    =  2,  // interface to registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    memory_interface      =  3,  // interface to memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    conditional_interface =  4   // interface for condition codes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  virtual Form::InterfaceType interface_type(FormDict &globals) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  enum CiscSpillInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    Not_cisc_spillable   =  AdlcVMDeps::Not_cisc_spillable,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    Maybe_cisc_spillable =   0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    Is_cisc_spillable    =   1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // LEGAL FORM TYPES
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    INS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    OPER,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    OPCLASS,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    SRC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    ADEF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    REG,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    PIPE,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    CNST,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    PRED,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    ATTR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    MAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    ENC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    FOR,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    EXP,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    REW,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    EFF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    RDEF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    RCL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    ACL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    RES,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    PCL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    PDEF,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    REGL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    RESL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    STAL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    COMP,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    PEEP,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    RESO
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
//------------------------------FormList---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
class FormList {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  Form *_root;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  Form *_tail;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  Form *_cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  int   _justReset;                // Set immediately after reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  Form *_cur2;                     // Nested iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  int   _justReset2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  void addForm(Form * entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    if (_tail==NULL) { _root = _tail = _cur = entry;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    else { _tail->_next = entry; _tail = entry;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  Form * current() { return _cur; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  Form * iter()    { if (_justReset) _justReset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
                     else if (_cur)  _cur = _cur->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
                     return _cur;};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  void   reset()   { if (_root) {_cur = _root; _justReset = 1;} };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  // Second iterator, state is internal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  Form * current2(){ return _cur2; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  Form * iter2()   { if (_justReset2) _justReset2 = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                    else if (_cur2)  _cur2 = _cur2->_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
                    return _cur2;};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  void   reset2()  { if (_root) {_cur2 = _root; _justReset2 = 1;} };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  int  count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    int  count = 0; reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    for( Form *cur; (cur =  iter()) != NULL; ) { ++count; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    return count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  void dump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    Form *cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    for(; (cur =  iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      cur->dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  bool verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    bool verified = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    Form *cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    for(; (cur =  iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      if ( ! cur->verify() ) verified = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    return verified;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  void output(FILE* fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    Form *cur;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    for( ; (cur =  iter()) != NULL; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      cur->output(fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  ~FormList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
//------------------------------NameList---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
// Extendable list of pointers, <char *>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
class NameList {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  friend class PreserveIter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  int                _cur;         // Insert next entry here; count of entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  int                _max;         // Number of spaces allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  const char       **_names;       // Array of names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  int                _iter;        // position during iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  bool               _justReset;   // Set immediately after reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  static const char *_signal;      // reserved user-defined string
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
   339
  static const char *_signal2;      // reserved user-defined string
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 670
diff changeset
   340
  static const char *_signal3;      // reserved user-defined string
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  enum               { Not_in_list = -1 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  void  addName(const char *name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  void  add_signal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  void  clear();                   // Remove all entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  int   count() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  void  reset();                   // Reset iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  const char *iter();              // after reset(), first element : else next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  const char *current();           // return current element in iteration.
2150
0d91d17158cc 6797305: Add LoadUB and LoadUI opcode class
twisti
parents: 2129
diff changeset
   352
  const char *peek(int skip = 1);  // returns element + skip in iteration if there is one
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  bool  current_is_signal();       // Return 'true' if current entry is signal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  bool  is_signal(const char *entry); // Return true if entry is a signal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  bool  search(const char *);      // Search for a name in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  int   index(const char *);       // Return index of name in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  const char *name (intptr_t index);// Return name at index in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  void  dump();                    // output to stderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  void  output(FILE *fp);          // Output list of names to 'fp'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  NameList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  ~NameList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
// Convenience class to preserve iteration state since iterators are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
// internal instead of being external.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
class PreserveIter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  NameList* _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  int _iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  bool _justReset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  PreserveIter(NameList* nl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    _list = nl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    _iter = _list->_iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    _justReset = _list->_justReset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  ~PreserveIter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    _list->_iter = _iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    _list->_justReset = _justReset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
//------------------------------NameAndList------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// Storage for a name and an associated list of names
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
class NameAndList {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  const char *_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  NameList    _list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  NameAndList(char *name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  ~NameAndList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // Add to entries in list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  void        add_entry(const char *entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // Access the name and its associated list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  const char *name() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  void        reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  const char *iter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  int count() { return _list.count(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Return the "index" entry in the list, zero-based
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  const char *operator[](int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  void  dump();                    // output to stderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  void  output(FILE *fp);          // Output list of names to 'fp'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
//------------------------------ComponentList---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
// Component lists always have match rule operands first, followed by parameter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
// operands which do not appear in the match list (in order of declaration).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
class ComponentList : private NameList {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  int   _matchcnt;                 // Count of match rule operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  // This is a batch program.  (And I have a destructor bug!)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  void operator delete( void *ptr ) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  void insert(Component *component, bool mflag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  void insert(const char *name, const char *opType, int usedef, bool mflag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  int  count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  int  match_count() { return _matchcnt; } // Get count of match rule opers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  Component *iter();               // after reset(), first element : else next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  Component *match_iter();         // after reset(), first element : else next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  Component *post_match_iter();    // after reset(), first element : else next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  void       reset();              // Reset iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  Component *current();            // return current element in iteration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // Return element at "position", else NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  Component *operator[](int position);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  Component *at(int position) { return (*this)[position]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  // Return first component having this name.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  const Component *search(const char *name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // Return number of USEs + number of DEFs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  int        num_operands();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // Return zero-based position in list;  -1 if not in list.
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   454
  int        operand_position(const char *name, int usedef, Form *fm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  // Find position for this name, regardless of use/def information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  int        operand_position(const char *name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // Find position for this name when looked up for output via "format"
13971
3c568f3dacca 8000592: Improve adlc usability
kvn
parents: 13969
diff changeset
   458
  int        operand_position_format(const char *name, Form *fm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // Find position for the Label when looked up for output via "format"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  int        label_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // Find position for the Method when looked up for output via "format"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  int        method_position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  void       dump();               // output to stderr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  void       output(FILE *fp);     // Output list of names to 'fp'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  ComponentList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  ~ComponentList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
//------------------------------SourceForm-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
class SourceForm : public Form {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  // Public Data
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  char *_code;                     // Buffer for storing code text
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  // Public Methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  SourceForm(char* code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  ~SourceForm();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  virtual const char* classname() { return "SourceForm"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  void dump();                    // Debug printer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  void output(FILE *fp);          // Write output files
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
class HeaderForm : public SourceForm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  HeaderForm(char* code) : SourceForm(code) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  virtual const char* classname() { return "HeaderForm"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
class PreHeaderForm : public SourceForm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  PreHeaderForm(char* code) : SourceForm(code) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  virtual const char* classname() { return "PreHeaderForm"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
//------------------------------Expr------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
#define STRING_BUFFER_LENGTH  2048
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
// class Expr represents integer expressions containing constants and addition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
// Value must be in range zero through maximum positive integer. 32bits.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
// Expected use: instruction and operand costs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
class Expr {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    Zero     = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    Max      = 0x7fffffff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  const char *_external_name;  // if !NULL, then print this instead of _expr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  const char *_expr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  int         _min_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  int         _max_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  Expr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  Expr(const char *cost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  Expr(const char *name, const char *expression, int min_value, int max_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  Expr *clone() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  bool  is_unknown() const { return (this == Expr::get_unknown()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  bool  is_zero()    const { return (_min_value == Expr::Zero && _max_value == Expr::Zero); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  bool  less_than_or_equal(const Expr *c) const { return (_max_value <= c->_min_value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  void  add(const Expr *c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  void  add(const char *c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  void  add(const char *c, ArchDesc &AD);   // check if 'c' is defined in <arch>.ad
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  void  set_external_name(const char *name) { _external_name = name; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  const char *as_string()  const { return (_external_name != NULL ? _external_name : _expr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  void  print()            const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  void  print_define(FILE *fp) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  void  print_assert(FILE *fp) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  static Expr *get_unknown();   // Returns pointer to shared unknown cost instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  static char *buffer()         { return &external_buffer[0]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  static bool  init_buffers();  // Fill buffers with 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  static bool  check_buffers(); // if buffer use may have overflowed, assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  static Expr *_unknown_expr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  static char string_buffer[STRING_BUFFER_LENGTH];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  static char external_buffer[STRING_BUFFER_LENGTH];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  static bool _init_buffers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  const char *compute_expr(const Expr *c1, const Expr *c2);  // cost as string after adding 'c1' and 'c2'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  int         compute_min (const Expr *c1, const Expr *c2);  // minimum after adding 'c1' and 'c2'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  int         compute_max (const Expr *c1, const Expr *c2);  // maximum after adding 'c1' and 'c2'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  const char *compute_external(const Expr *c1, const Expr *c2);  // external name after adding 'c1' and 'c2'
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
//------------------------------ExprDict---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
// Dictionary containing Exprs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
class ExprDict {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  Dict         _expr;              // map names, char*, to their Expr* or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  NameList     _defines;           // record the order of definitions entered with define call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  // Disable public use of constructor, copy-ctor, operator =, operator ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  ExprDict( );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  ExprDict( const ExprDict & );    // Deep-copy guts
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  ExprDict &operator =( const ExprDict & );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // == compares two dictionaries; they must have the same keys (their keys
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // must match using CmpKey) and they must have the same values (pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // comparison).  If so 1 is returned, if not 0 is returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  // cmp is a key comparision routine.  hash is a routine to hash a key.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  ExprDict( CmpKey cmp, Hash hash, Arena *arena );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  ~ExprDict();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  // Return # of key-value pairs in dict
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  int Size(void) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // define inserts the given key-value pair into the dictionary,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  // and records the name in order for later output, ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  const Expr  *define(const char *name, Expr *expr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  // Insert inserts the given key-value pair into the dictionary.  The prior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  // value of the key is returned; NULL if the key was not previously defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  const Expr  *Insert(const char *name, Expr *expr); // A new key-value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  // Find finds the value of a given key; or NULL if not found.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  // The dictionary is NOT changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  const Expr  *operator [](const char *name) const;  // Do a lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  void print_defines(FILE *fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  void print_asserts(FILE *fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  void dump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   598
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
   599
#endif // SHARE_ADLC_FORMS_HPP