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