1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/adlc/forms.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,597 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_ADLC_FORMS_HPP 1.29 +#define SHARE_VM_ADLC_FORMS_HPP 1.30 + 1.31 +// FORMS.HPP - ADL Parser Generic and Utility Forms Classes 1.32 + 1.33 +#define TRUE 1 1.34 +#define FALSE 0 1.35 + 1.36 +// DEFINITIONS OF LEGAL ATTRIBUTE TYPES 1.37 +#define INS_ATTR 0 1.38 +#define OP_ATTR 1 1.39 + 1.40 +// DEFINITIONS OF LEGAL CONSTRAINT TYPES 1.41 + 1.42 +// Class List 1.43 +class Form; 1.44 +class InstructForm; 1.45 +class MachNodeForm; 1.46 +class OperandForm; 1.47 +class OpClassForm; 1.48 +class AttributeForm; 1.49 +class RegisterForm; 1.50 +class PipelineForm; 1.51 +class SourceForm; 1.52 +class EncodeForm; 1.53 +class Component; 1.54 +class Constraint; 1.55 +class Predicate; 1.56 +class MatchRule; 1.57 +class Attribute; 1.58 +class Effect; 1.59 +class ExpandRule; 1.60 +class RewriteRule; 1.61 +class ConstructRule; 1.62 +class FormatRule; 1.63 +class Peephole; 1.64 +class EncClass; 1.65 +class Interface; 1.66 +class RegInterface; 1.67 +class ConstInterface; 1.68 +class MemInterface; 1.69 +class CondInterface; 1.70 +class Opcode; 1.71 +class InsEncode; 1.72 +class RegDef; 1.73 +class RegClass; 1.74 +class AllocClass; 1.75 +class ResourceForm; 1.76 +class PipeClassForm; 1.77 +class PeepMatch; 1.78 +class PeepConstraint; 1.79 +class PeepReplace; 1.80 +class MatchList; 1.81 + 1.82 +class ArchDesc; 1.83 + 1.84 +//------------------------------FormDict--------------------------------------- 1.85 +// Dictionary containing Forms, and objects derived from forms 1.86 +class FormDict { 1.87 +private: 1.88 + Dict _form; // map names, char*, to their Form* or NULL 1.89 + 1.90 + // Disable public use of constructor, copy-ctor, operator =, operator == 1.91 + FormDict( ); 1.92 + FormDict &operator =( const FormDict & ); 1.93 + // == compares two dictionaries; they must have the same keys (their keys 1.94 + // must match using CmpKey) and they must have the same values (pointer 1.95 + // comparison). If so 1 is returned, if not 0 is returned. 1.96 + bool operator ==(const FormDict &d) const; // Compare dictionaries for equal 1.97 + 1.98 +public: 1.99 + // cmp is a key comparision routine. hash is a routine to hash a key. 1.100 + // FormDict( CmpKey cmp, Hash hash ); 1.101 + FormDict( CmpKey cmp, Hash hash, Arena *arena ); 1.102 + FormDict( const FormDict & fd ); // Deep-copy guts 1.103 + ~FormDict(); 1.104 + 1.105 + // Return # of key-value pairs in dict 1.106 + int Size(void) const; 1.107 + 1.108 + // Insert inserts the given key-value pair into the dictionary. The prior 1.109 + // value of the key is returned; NULL if the key was not previously defined. 1.110 + const Form *Insert(const char *name, Form *form); // A new key-value 1.111 + 1.112 + // Find finds the value of a given key; or NULL if not found. 1.113 + // The dictionary is NOT changed. 1.114 + const Form *operator [](const char *name) const; // Do a lookup 1.115 + 1.116 + void dump(); 1.117 +}; 1.118 + 1.119 +// ***** Master Class for ADL Parser Forms ***** 1.120 +//------------------------------Form------------------------------------------- 1.121 +class Form { 1.122 +public: 1.123 + static Arena *arena; // arena used by forms 1.124 +private: 1.125 + static Arena *generate_arena(); // allocate arena used by forms 1.126 + 1.127 +protected: 1.128 + int _ftype; // Indicator for derived class type 1.129 + 1.130 +public: 1.131 + // Public Data 1.132 + Form *_next; // Next pointer for form lists 1.133 + int _linenum; // Line number for debugging 1.134 + 1.135 + // Dynamic type check for common forms. 1.136 + virtual OpClassForm *is_opclass() const; 1.137 + virtual OperandForm *is_operand() const; 1.138 + virtual InstructForm *is_instruction() const; 1.139 + virtual MachNodeForm *is_machnode() const; 1.140 + virtual AttributeForm *is_attribute() const; 1.141 + virtual Effect *is_effect() const; 1.142 + virtual ResourceForm *is_resource() const; 1.143 + virtual PipeClassForm *is_pipeclass() const; 1.144 + 1.145 + // Check if this form is an operand usable for cisc-spilling 1.146 + virtual bool is_cisc_reg(FormDict &globals) const { return false; } 1.147 + virtual bool is_cisc_mem(FormDict &globals) const { return false; } 1.148 + 1.149 + // Public Methods 1.150 + Form(int formType=0, int line=0) 1.151 + : _next(NULL), _linenum(line), _ftype(formType) { }; 1.152 + virtual ~Form() {}; 1.153 + 1.154 + virtual bool ideal_only() const { 1.155 + assert(0,"Check of ideal status on non-instruction/operand form.\n"); 1.156 + return FALSE; 1.157 + } 1.158 + 1.159 + // Check constraints after parsing 1.160 + virtual bool verify() { return true; } 1.161 + 1.162 + virtual void dump() { output(stderr); } // Debug printer 1.163 + // Write info to output files 1.164 + virtual void output(FILE *fp) { fprintf(fp,"Form Output"); } 1.165 + 1.166 +public: 1.167 + // ADLC types, match the last character on ideal operands and instructions 1.168 + enum DataType { 1.169 + none = 0, // Not a simple type 1.170 + idealI = 1, // Integer type 1.171 + idealP = 2, // Pointer types, oop(s) 1.172 + idealL = 3, // Long type 1.173 + idealF = 4, // Float type 1.174 + idealD = 5, // Double type 1.175 + idealB = 6, // Byte type 1.176 + idealC = 7, // Char type 1.177 + idealS = 8, // String type 1.178 + idealN = 9, // Narrow oop types 1.179 + idealNKlass = 10, // Narrow klass types 1.180 + idealV = 11 // Vector type 1.181 + }; 1.182 + // Convert ideal name to a DataType, return DataType::none if not a 'ConX' 1.183 + Form::DataType ideal_to_const_type(const char *ideal_type_name) const; 1.184 + // Convert ideal name to a DataType, return DataType::none if not a 'sRegX 1.185 + Form::DataType ideal_to_sReg_type(const char *name) const; 1.186 + // Convert ideal name to a DataType, return DataType::none if not a 'RegX 1.187 + Form::DataType ideal_to_Reg_type(const char *name) const; 1.188 + 1.189 + // Convert ideal name to a DataType, return DataType::none if not a 'LoadX 1.190 + Form::DataType is_load_from_memory(const char *opType) const; 1.191 + // Convert ideal name to a DataType, return DataType::none if not a 'StoreX 1.192 + Form::DataType is_store_to_memory(const char *opType) const; 1.193 + 1.194 + // ADLC call types, matched with ideal world 1.195 + enum CallType { 1.196 + invalid_type = 0, // invalid call type 1.197 + JAVA_STATIC = 1, // monomorphic entry 1.198 + JAVA_DYNAMIC = 2, // possibly megamorphic, inline cache call 1.199 + JAVA_COMPILED = 3, // callee will be compiled java 1.200 + JAVA_INTERP = 4, // callee will be executed by interpreter 1.201 + JAVA_NATIVE = 5, // native entrypoint 1.202 + JAVA_RUNTIME = 6, // runtime entrypoint 1.203 + JAVA_LEAF = 7 // calling leaf 1.204 + }; 1.205 + 1.206 + // Interface types for operands and operand classes 1.207 + enum InterfaceType { 1.208 + no_interface = 0, // unknown or inconsistent interface type 1.209 + constant_interface = 1, // interface to constants 1.210 + register_interface = 2, // interface to registers 1.211 + memory_interface = 3, // interface to memory 1.212 + conditional_interface = 4 // interface for condition codes 1.213 + }; 1.214 + virtual Form::InterfaceType interface_type(FormDict &globals) const; 1.215 + 1.216 + enum CiscSpillInfo { 1.217 + Not_cisc_spillable = AdlcVMDeps::Not_cisc_spillable, 1.218 + Maybe_cisc_spillable = 0, 1.219 + Is_cisc_spillable = 1 1.220 + // ... 1.221 + }; 1.222 + 1.223 + // LEGAL FORM TYPES 1.224 + enum { 1.225 + INS, 1.226 + OPER, 1.227 + OPCLASS, 1.228 + SRC, 1.229 + ADEF, 1.230 + REG, 1.231 + PIPE, 1.232 + CNST, 1.233 + PRED, 1.234 + ATTR, 1.235 + MAT, 1.236 + ENC, 1.237 + FOR, 1.238 + EXP, 1.239 + REW, 1.240 + EFF, 1.241 + RDEF, 1.242 + RCL, 1.243 + ACL, 1.244 + RES, 1.245 + PCL, 1.246 + PDEF, 1.247 + REGL, 1.248 + RESL, 1.249 + STAL, 1.250 + COMP, 1.251 + PEEP, 1.252 + RESO 1.253 + }; 1.254 + 1.255 +}; 1.256 + 1.257 +//------------------------------FormList--------------------------------------- 1.258 +class FormList { 1.259 +private: 1.260 + Form *_root; 1.261 + Form *_tail; 1.262 + Form *_cur; 1.263 + int _justReset; // Set immediately after reset 1.264 + Form *_cur2; // Nested iterator 1.265 + int _justReset2; 1.266 + 1.267 +public: 1.268 + void addForm(Form * entry) { 1.269 + if (_tail==NULL) { _root = _tail = _cur = entry;} 1.270 + else { _tail->_next = entry; _tail = entry;} 1.271 + }; 1.272 + Form * current() { return _cur; }; 1.273 + Form * iter() { if (_justReset) _justReset = 0; 1.274 + else if (_cur) _cur = _cur->_next; 1.275 + return _cur;}; 1.276 + void reset() { if (_root) {_cur = _root; _justReset = 1;} }; 1.277 + 1.278 + // Second iterator, state is internal 1.279 + Form * current2(){ return _cur2; }; 1.280 + Form * iter2() { if (_justReset2) _justReset2 = 0; 1.281 + else if (_cur2) _cur2 = _cur2->_next; 1.282 + return _cur2;}; 1.283 + void reset2() { if (_root) {_cur2 = _root; _justReset2 = 1;} }; 1.284 + 1.285 + int count() { 1.286 + int count = 0; reset(); 1.287 + for( Form *cur; (cur = iter()) != NULL; ) { ++count; }; 1.288 + return count; 1.289 + } 1.290 + 1.291 + void dump() { 1.292 + reset(); 1.293 + Form *cur; 1.294 + for(; (cur = iter()) != NULL; ) { 1.295 + cur->dump(); 1.296 + }; 1.297 + } 1.298 + 1.299 + bool verify() { 1.300 + bool verified = true; 1.301 + 1.302 + reset(); 1.303 + Form *cur; 1.304 + for(; (cur = iter()) != NULL; ) { 1.305 + if ( ! cur->verify() ) verified = false; 1.306 + }; 1.307 + 1.308 + return verified; 1.309 + } 1.310 + 1.311 + void output(FILE* fp) { 1.312 + reset(); 1.313 + Form *cur; 1.314 + for( ; (cur = iter()) != NULL; ) { 1.315 + cur->output(fp); 1.316 + }; 1.317 + } 1.318 + 1.319 + FormList() { _justReset = 1; _justReset2 = 1; _root = NULL; _tail = NULL; _cur = NULL; _cur2 = NULL;}; 1.320 + ~FormList(); 1.321 +}; 1.322 + 1.323 +//------------------------------NameList--------------------------------------- 1.324 +// Extendable list of pointers, <char *> 1.325 +class NameList { 1.326 + friend class PreserveIter; 1.327 + 1.328 +private: 1.329 + int _cur; // Insert next entry here; count of entries 1.330 + int _max; // Number of spaces allocated 1.331 + const char **_names; // Array of names 1.332 + 1.333 +protected: 1.334 + int _iter; // position during iteration 1.335 + bool _justReset; // Set immediately after reset 1.336 + 1.337 + 1.338 +public: 1.339 + static const char *_signal; // reserved user-defined string 1.340 + static const char *_signal2; // reserved user-defined string 1.341 + static const char *_signal3; // reserved user-defined string 1.342 + enum { Not_in_list = -1 }; 1.343 + 1.344 + void addName(const char *name); 1.345 + void add_signal(); 1.346 + void clear(); // Remove all entries 1.347 + 1.348 + int count() const; 1.349 + 1.350 + void reset(); // Reset iteration 1.351 + const char *iter(); // after reset(), first element : else next 1.352 + const char *current(); // return current element in iteration. 1.353 + const char *peek(int skip = 1); // returns element + skip in iteration if there is one 1.354 + 1.355 + bool current_is_signal(); // Return 'true' if current entry is signal 1.356 + bool is_signal(const char *entry); // Return true if entry is a signal 1.357 + 1.358 + bool search(const char *); // Search for a name in the list 1.359 + int index(const char *); // Return index of name in list 1.360 + const char *name (intptr_t index);// Return name at index in list 1.361 + 1.362 + void dump(); // output to stderr 1.363 + void output(FILE *fp); // Output list of names to 'fp' 1.364 + 1.365 + NameList(); 1.366 + ~NameList(); 1.367 +}; 1.368 + 1.369 + 1.370 +// Convenience class to preserve iteration state since iterators are 1.371 +// internal instead of being external. 1.372 +class PreserveIter { 1.373 + private: 1.374 + NameList* _list; 1.375 + int _iter; 1.376 + bool _justReset; 1.377 + 1.378 + public: 1.379 + PreserveIter(NameList* nl) { 1.380 + _list = nl; 1.381 + _iter = _list->_iter; 1.382 + _justReset = _list->_justReset; 1.383 + } 1.384 + ~PreserveIter() { 1.385 + _list->_iter = _iter; 1.386 + _list->_justReset = _justReset; 1.387 + } 1.388 + 1.389 +}; 1.390 + 1.391 + 1.392 +//------------------------------NameAndList------------------------------------ 1.393 +// Storage for a name and an associated list of names 1.394 +class NameAndList { 1.395 +private: 1.396 + const char *_name; 1.397 + NameList _list; 1.398 + 1.399 +public: 1.400 + NameAndList(char *name); 1.401 + ~NameAndList(); 1.402 + 1.403 + // Add to entries in list 1.404 + void add_entry(const char *entry); 1.405 + 1.406 + // Access the name and its associated list. 1.407 + const char *name() const; 1.408 + void reset(); 1.409 + const char *iter(); 1.410 + 1.411 + int count() { return _list.count(); } 1.412 + 1.413 + // Return the "index" entry in the list, zero-based 1.414 + const char *operator[](int index); 1.415 + 1.416 + 1.417 + void dump(); // output to stderr 1.418 + void output(FILE *fp); // Output list of names to 'fp' 1.419 +}; 1.420 + 1.421 +//------------------------------ComponentList--------------------------------- 1.422 +// Component lists always have match rule operands first, followed by parameter 1.423 +// operands which do not appear in the match list (in order of declaration). 1.424 +class ComponentList : private NameList { 1.425 +private: 1.426 + int _matchcnt; // Count of match rule operands 1.427 + 1.428 +public: 1.429 + 1.430 + // This is a batch program. (And I have a destructor bug!) 1.431 + void operator delete( void *ptr ) {} 1.432 + 1.433 + void insert(Component *component, bool mflag); 1.434 + void insert(const char *name, const char *opType, int usedef, bool mflag); 1.435 + 1.436 + int count(); 1.437 + int match_count() { return _matchcnt; } // Get count of match rule opers 1.438 + 1.439 + Component *iter(); // after reset(), first element : else next 1.440 + Component *match_iter(); // after reset(), first element : else next 1.441 + Component *post_match_iter(); // after reset(), first element : else next 1.442 + void reset(); // Reset iteration 1.443 + Component *current(); // return current element in iteration. 1.444 + 1.445 + // Return element at "position", else NULL 1.446 + Component *operator[](int position); 1.447 + Component *at(int position) { return (*this)[position]; } 1.448 + 1.449 + // Return first component having this name. 1.450 + const Component *search(const char *name); 1.451 + 1.452 + // Return number of USEs + number of DEFs 1.453 + int num_operands(); 1.454 + // Return zero-based position in list; -1 if not in list. 1.455 + int operand_position(const char *name, int usedef, Form *fm); 1.456 + // Find position for this name, regardless of use/def information 1.457 + int operand_position(const char *name); 1.458 + // Find position for this name when looked up for output via "format" 1.459 + int operand_position_format(const char *name, Form *fm); 1.460 + // Find position for the Label when looked up for output via "format" 1.461 + int label_position(); 1.462 + // Find position for the Method when looked up for output via "format" 1.463 + int method_position(); 1.464 + 1.465 + void dump(); // output to stderr 1.466 + void output(FILE *fp); // Output list of names to 'fp' 1.467 + 1.468 + ComponentList(); 1.469 + ~ComponentList(); 1.470 +}; 1.471 + 1.472 +//------------------------------SourceForm------------------------------------- 1.473 +class SourceForm : public Form { 1.474 +private: 1.475 + 1.476 +public: 1.477 + // Public Data 1.478 + char *_code; // Buffer for storing code text 1.479 + 1.480 + // Public Methods 1.481 + SourceForm(char* code); 1.482 + ~SourceForm(); 1.483 + 1.484 + virtual const char* classname() { return "SourceForm"; } 1.485 + 1.486 + void dump(); // Debug printer 1.487 + void output(FILE *fp); // Write output files 1.488 +}; 1.489 + 1.490 +class HeaderForm : public SourceForm { 1.491 +public: 1.492 + HeaderForm(char* code) : SourceForm(code) { } 1.493 + 1.494 + virtual const char* classname() { return "HeaderForm"; } 1.495 +}; 1.496 + 1.497 +class PreHeaderForm : public SourceForm { 1.498 +public: 1.499 + PreHeaderForm(char* code) : SourceForm(code) { } 1.500 + 1.501 + virtual const char* classname() { return "PreHeaderForm"; } 1.502 +}; 1.503 + 1.504 + 1.505 + 1.506 + 1.507 +//------------------------------Expr------------------------------------------ 1.508 +#define STRING_BUFFER_LENGTH 2048 1.509 +// class Expr represents integer expressions containing constants and addition 1.510 +// Value must be in range zero through maximum positive integer. 32bits. 1.511 +// Expected use: instruction and operand costs 1.512 +class Expr { 1.513 +public: 1.514 + enum { 1.515 + Zero = 0, 1.516 + Max = 0x7fffffff 1.517 + }; 1.518 + const char *_external_name; // if !NULL, then print this instead of _expr 1.519 + const char *_expr; 1.520 + int _min_value; 1.521 + int _max_value; 1.522 + 1.523 + Expr(); 1.524 + Expr(const char *cost); 1.525 + Expr(const char *name, const char *expression, int min_value, int max_value); 1.526 + Expr *clone() const; 1.527 + 1.528 + bool is_unknown() const { return (this == Expr::get_unknown()); } 1.529 + bool is_zero() const { return (_min_value == Expr::Zero && _max_value == Expr::Zero); } 1.530 + bool less_than_or_equal(const Expr *c) const { return (_max_value <= c->_min_value); } 1.531 + 1.532 + void add(const Expr *c); 1.533 + void add(const char *c); 1.534 + void add(const char *c, ArchDesc &AD); // check if 'c' is defined in <arch>.ad 1.535 + void set_external_name(const char *name) { _external_name = name; } 1.536 + 1.537 + const char *as_string() const { return (_external_name != NULL ? _external_name : _expr); } 1.538 + void print() const; 1.539 + void print_define(FILE *fp) const; 1.540 + void print_assert(FILE *fp) const; 1.541 + 1.542 + static Expr *get_unknown(); // Returns pointer to shared unknown cost instance 1.543 + 1.544 + static char *buffer() { return &external_buffer[0]; } 1.545 + static bool init_buffers(); // Fill buffers with 0 1.546 + static bool check_buffers(); // if buffer use may have overflowed, assert 1.547 + 1.548 +private: 1.549 + static Expr *_unknown_expr; 1.550 + static char string_buffer[STRING_BUFFER_LENGTH]; 1.551 + static char external_buffer[STRING_BUFFER_LENGTH]; 1.552 + static bool _init_buffers; 1.553 + const char *compute_expr(const Expr *c1, const Expr *c2); // cost as string after adding 'c1' and 'c2' 1.554 + int compute_min (const Expr *c1, const Expr *c2); // minimum after adding 'c1' and 'c2' 1.555 + int compute_max (const Expr *c1, const Expr *c2); // maximum after adding 'c1' and 'c2' 1.556 + const char *compute_external(const Expr *c1, const Expr *c2); // external name after adding 'c1' and 'c2' 1.557 +}; 1.558 + 1.559 +//------------------------------ExprDict--------------------------------------- 1.560 +// Dictionary containing Exprs 1.561 +class ExprDict { 1.562 +private: 1.563 + Dict _expr; // map names, char*, to their Expr* or NULL 1.564 + NameList _defines; // record the order of definitions entered with define call 1.565 + 1.566 + // Disable public use of constructor, copy-ctor, operator =, operator == 1.567 + ExprDict( ); 1.568 + ExprDict( const ExprDict & ); // Deep-copy guts 1.569 + ExprDict &operator =( const ExprDict & ); 1.570 + // == compares two dictionaries; they must have the same keys (their keys 1.571 + // must match using CmpKey) and they must have the same values (pointer 1.572 + // comparison). If so 1 is returned, if not 0 is returned. 1.573 + bool operator ==(const ExprDict &d) const; // Compare dictionaries for equal 1.574 + 1.575 +public: 1.576 + // cmp is a key comparision routine. hash is a routine to hash a key. 1.577 + ExprDict( CmpKey cmp, Hash hash, Arena *arena ); 1.578 + ~ExprDict(); 1.579 + 1.580 + // Return # of key-value pairs in dict 1.581 + int Size(void) const; 1.582 + 1.583 + // define inserts the given key-value pair into the dictionary, 1.584 + // and records the name in order for later output, ... 1.585 + const Expr *define(const char *name, Expr *expr); 1.586 + 1.587 + // Insert inserts the given key-value pair into the dictionary. The prior 1.588 + // value of the key is returned; NULL if the key was not previously defined. 1.589 + const Expr *Insert(const char *name, Expr *expr); // A new key-value 1.590 + 1.591 + // Find finds the value of a given key; or NULL if not found. 1.592 + // The dictionary is NOT changed. 1.593 + const Expr *operator [](const char *name) const; // Do a lookup 1.594 + 1.595 + void print_defines(FILE *fp); 1.596 + void print_asserts(FILE *fp); 1.597 + void dump(); 1.598 +}; 1.599 + 1.600 +#endif // SHARE_VM_ADLC_FORMS_HPP