1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/adlc/archDesc.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,413 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, 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_ARCHDESC_HPP 1.29 +#define SHARE_VM_ADLC_ARCHDESC_HPP 1.30 + 1.31 +// Definitions for Error Flags 1.32 +#define WARN 0 1.33 +#define SYNERR 1 1.34 +#define SEMERR 2 1.35 +#define INTERNAL_ERR 3 1.36 + 1.37 +// Minimal declarations for include files 1.38 +class OutputMap; 1.39 +class ProductionState; 1.40 +class Expr; 1.41 + 1.42 +// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES 1.43 +typedef BufferedFile ADLFILE; 1.44 + 1.45 +//---------------------------ChainList----------------------------------------- 1.46 +class ChainList { 1.47 + NameList _name; 1.48 + NameList _cost; 1.49 + NameList _rule; 1.50 + 1.51 +public: 1.52 + void insert(const char *name, const char *cost, const char *rule); 1.53 + bool search(const char *name); 1.54 + 1.55 + void reset(); 1.56 + bool iter(const char * &name, const char * &cost, const char * &rule); 1.57 + 1.58 + void dump(); 1.59 + void output(FILE *fp); 1.60 + 1.61 + ChainList(); 1.62 + ~ChainList(); 1.63 +}; 1.64 + 1.65 +//---------------------------MatchList----------------------------------------- 1.66 +class MatchList { 1.67 +private: 1.68 + MatchList *_next; 1.69 + Predicate *_pred; // Predicate which applies to this match rule 1.70 + const char *_cost; 1.71 + 1.72 +public: 1.73 + const char *_opcode; 1.74 + const char *_resultStr; 1.75 + const char *_lchild; 1.76 + const char *_rchild; 1.77 + 1.78 + MatchList(MatchList *nxt, Predicate *prd): _next(nxt), _pred(prd), _cost(NULL){ 1.79 + _resultStr = _lchild = _rchild = _opcode = NULL; } 1.80 + 1.81 + MatchList(MatchList *nxt, Predicate *prd, const char *cost, 1.82 + const char *opcode, const char *resultStr, const char *lchild, 1.83 + const char *rchild) 1.84 + : _next(nxt), _pred(prd), _cost(cost), _opcode(opcode), 1.85 + _resultStr(resultStr), _lchild(lchild), _rchild(rchild) { } 1.86 + 1.87 + MatchList *get_next(void) { return _next; } 1.88 + char *get_pred(void) { return (_pred?_pred->_pred:NULL); } 1.89 + Predicate *get_pred_obj(void) { return _pred; } 1.90 + const char *get_cost(void) { return _cost == NULL ? "0" :_cost; } 1.91 + bool search(const char *opc, const char *res, const char *lch, 1.92 + const char *rch, Predicate *pr); 1.93 + 1.94 + void dump(); 1.95 + void output(FILE *fp); 1.96 +}; 1.97 + 1.98 +//---------------------------ArchDesc------------------------------------------ 1.99 +class ArchDesc { 1.100 +private: 1.101 + FormDict _globalNames; // Global names 1.102 + Dict _idealIndex; // Map ideal names to index in enumeration 1.103 + ExprDict _globalDefs; // Global definitions, #defines 1.104 + int _internalOpCounter; // Internal Operand Counter 1.105 + 1.106 + FormList _header; // List of Source Code Forms for hpp file 1.107 + FormList _pre_header; // ditto for the very top of the hpp file 1.108 + FormList _source; // List of Source Code Forms for output 1.109 + FormList _instructions; // List of Instruction Forms for output 1.110 + FormList _machnodes; // List of Node Classes (special for pipelining) 1.111 + FormList _operands; // List of Operand Forms for output 1.112 + FormList _opclass; // List of Operand Class Forms for output 1.113 + FormList _attributes; // List of Attribute Forms for parsing 1.114 + RegisterForm *_register; // Only one Register Form allowed 1.115 + FrameForm *_frame; // Describe stack-frame layout 1.116 + EncodeForm *_encode; // Only one Encode Form allowed 1.117 + PipelineForm *_pipeline; // Pipeline Form for output 1.118 + 1.119 + bool _has_match_rule[_last_opcode]; // found AD rule for ideal node in <arch>.ad 1.120 + 1.121 + MatchList *_mlistab[_last_opcode]; // Array of MatchLists 1.122 + 1.123 + // The Architecture Description identifies which user-defined operand can be used 1.124 + // to access [stack_pointer + offset] 1.125 + OperandForm *_cisc_spill_operand; 1.126 + 1.127 + // If a Call node uses $constanttablebase, it gets MachConstantBaseNode 1.128 + // by the matcher and the matcher will modify the jvms. If so, jvm states 1.129 + // always have to be cloned when a node is cloned. Adlc generates 1.130 + // Compile::needs_clone_jvms() accordingly. 1.131 + bool _needs_clone_jvms; 1.132 + 1.133 + // Methods for outputting the DFA 1.134 + void gen_match(FILE *fp, MatchList &mlist, ProductionState &status, Dict &operands_chained_from); 1.135 + void chain_rule(FILE *fp, const char *indent, const char *ideal, 1.136 + const Expr *icost, const char *irule, 1.137 + Dict &operands_chained_from, ProductionState &status); 1.138 + void expand_opclass(FILE *fp, const char *indent, const Expr *cost, 1.139 + const char *result_type, ProductionState &status); 1.140 + Expr *calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status); 1.141 + void prune_matchlist(Dict &minimize, MatchList &mlist); 1.142 + 1.143 + // Helper function that outputs code to generate an instruction in MachNodeGenerator 1.144 + void buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent); 1.145 + 1.146 +public: 1.147 + ArchDesc(); 1.148 + ~ArchDesc(); 1.149 + 1.150 + // Option flags which control miscellaneous behaviors throughout the code 1.151 + int _TotalLines; // Line Counter 1.152 + int _no_output; // Flag to disable output of DFA, etc. 1.153 + int _quiet_mode; // Do not output banner messages, etc. 1.154 + int _disable_warnings; // Do not output warning messages 1.155 + int _dfa_debug; // Debug Flag for generated DFA 1.156 + int _dfa_small; // Debug Flag for generated DFA 1.157 + int _adl_debug; // Debug Flag for ADLC 1.158 + int _adlocation_debug; // Debug Flag to use ad file locations 1.159 + bool _cisc_spill_debug; // Debug Flag to see cisc-spill-instructions 1.160 + bool _short_branch_debug; // Debug Flag to see short branch instructions 1.161 + 1.162 + // Error/Warning Counts 1.163 + int _syntax_errs; // Count of syntax errors 1.164 + int _semantic_errs; // Count of semantic errors 1.165 + int _warnings; // Count warnings 1.166 + int _internal_errs; // Count of internal errors 1.167 + 1.168 + // Accessor for private data. 1.169 + void has_match_rule(int opc, const bool b) { _has_match_rule[opc] = b; } 1.170 + 1.171 + // I/O Files 1.172 + ADLFILE _ADL_file; // Input Architecture Description File 1.173 + // Machine dependent files, built from architecture definition 1.174 + ADLFILE _DFA_file; // File for definition of Matcher::DFA 1.175 + ADLFILE _HPP_file; // File for ArchNode class declarations 1.176 + ADLFILE _CPP_file; // File for ArchNode class defintions 1.177 + ADLFILE _CPP_CLONE_file; // File for MachNode/Oper clone defintions 1.178 + ADLFILE _CPP_EXPAND_file; // File for MachNode expand methods 1.179 + ADLFILE _CPP_FORMAT_file; // File for MachNode/Oper format defintions 1.180 + ADLFILE _CPP_GEN_file; // File for MachNode/Oper generator methods 1.181 + ADLFILE _CPP_MISC_file; // File for miscellaneous MachNode/Oper tables & methods 1.182 + ADLFILE _CPP_PEEPHOLE_file; // File for MachNode peephole methods 1.183 + ADLFILE _CPP_PIPELINE_file; // File for MachNode pipeline defintions 1.184 + ADLFILE _VM_file; // File for constants needed in VM code 1.185 + ADLFILE _bug_file; // DFA debugging file 1.186 + 1.187 + // I/O helper methods 1.188 + int open_file(bool required, ADLFILE & adf, const char *action); 1.189 + void close_file(int delete_out, ADLFILE & adf); 1.190 + int open_files(void); 1.191 + void close_files(int delete_out); 1.192 + 1.193 + Dict _chainRules; // Maps user operand names to ChainRules 1.194 + Dict _internalOps; // Maps match strings to internal operand names 1.195 + NameList _internalOpNames; // List internal operand names 1.196 + Dict _internalMatch; // Map internal name to its MatchNode 1.197 + 1.198 + NameList _preproc_list; // Preprocessor flag names 1.199 + FormDict _preproc_table;// Preprocessor flag bindings 1.200 + char* get_preproc_def(const char* flag); 1.201 + void set_preproc_def(const char* flag, const char* def); 1.202 + 1.203 + FormDict& globalNames() {return _globalNames;} // map global names to forms 1.204 + void initKeywords(FormDict& globals); // Add keywords to global name table 1.205 + 1.206 + ExprDict& globalDefs() {return _globalDefs;} // map global names to expressions 1.207 + 1.208 + OperandForm *constructOperand(const char *ident, bool ideal_only); 1.209 + void initBaseOpTypes(); // Import predefined base types. 1.210 + 1.211 + void addForm(PreHeaderForm *ptr); // Add objects to pre-header list 1.212 + void addForm(HeaderForm *ptr); // Add objects to header list 1.213 + void addForm(SourceForm *ptr); // Add objects to source list 1.214 + void addForm(EncodeForm *ptr); // Add objects to encode list 1.215 + void addForm(InstructForm *ptr); // Add objects to the instruct list 1.216 + void addForm(OperandForm *ptr); // Add objects to the operand list 1.217 + void addForm(OpClassForm *ptr); // Add objects to the opclasss list 1.218 + void addForm(AttributeForm *ptr); // Add objects to the attributes list 1.219 + void addForm(RegisterForm *ptr); // Add objects to the register list 1.220 + void addForm(FrameForm *ptr); // Add objects to the frame list 1.221 + void addForm(PipelineForm *ptr); // Add objects to the pipeline list 1.222 + void addForm(MachNodeForm *ptr); // Add objects to the machnode list 1.223 + 1.224 + int operandFormCount(); // Count number of OperandForms defined 1.225 + int opclassFormCount(); // Count number of OpClassForms defined 1.226 + int instructFormCount(); // Count number of InstructForms defined 1.227 + 1.228 + inline void getForm(EncodeForm **ptr) { *ptr = _encode; } 1.229 + 1.230 + bool verify(); 1.231 + void dump(); 1.232 + 1.233 + // Helper utility that gets MatchList components from inside MatchRule 1.234 + void check_optype(MatchRule *mrule); 1.235 + void build_chain_rule(OperandForm *oper); 1.236 + void add_chain_rule_entry(const char *src, const char *cost, 1.237 + const char *result); 1.238 + const char *getMatchListIndex(MatchRule &mrule); 1.239 + void generateMatchLists(); // Build MatchList array and populate it 1.240 + void inspectOperands(); // Build MatchLists for all operands 1.241 + void inspectOpClasses(); // Build MatchLists for all operands 1.242 + void inspectInstructions(); // Build MatchLists for all operands 1.243 + void buildDFA(FILE *fp); // Driver for constructing the DFA 1.244 + void gen_dfa_state_body(FILE *fp, Dict &minmize, ProductionState &status, Dict &chained, int i); // Driver for constructing the DFA state bodies 1.245 + 1.246 + // Helper utilities to generate reduction maps for internal operands 1.247 + const char *reduceLeft (char *internalName); 1.248 + const char *reduceRight(char *internalName); 1.249 + 1.250 + // Build enumerations, (1) dense operand index, (2) operands and opcodes 1.251 + const char *machOperEnum(const char *opName); // create dense index names using static function 1.252 + static const char *getMachOperEnum(const char *opName);// create dense index name 1.253 + void buildMachOperEnum(FILE *fp_hpp);// dense enumeration for operands 1.254 + void buildMachOpcodesEnum(FILE *fp_hpp);// enumeration for MachOpers & MachNodes 1.255 + 1.256 + // Helper utilities to generate Register Masks 1.257 + RegisterForm *get_registers() { return _register; } 1.258 + const char *reg_mask(OperandForm &opForm); 1.259 + const char *reg_mask(InstructForm &instForm); 1.260 + const char *reg_class_to_reg_mask(const char *reg_class); 1.261 + char *stack_or_reg_mask(OperandForm &opForm); // name of cisc_spillable version 1.262 + // This register class should also generate a stack_or_reg_mask 1.263 + void set_stack_or_reg(const char *reg_class_name); // for cisc-spillable reg classes 1.264 + // Generate an enumeration of register mask names and the RegMask objects. 1.265 + void declare_register_masks(FILE *fp_cpp); 1.266 + void build_register_masks(FILE *fp_cpp); 1.267 + // Generate enumeration of machine register numbers 1.268 + void buildMachRegisterNumbers(FILE *fp_hpp); 1.269 + // Generate enumeration of machine register encodings 1.270 + void buildMachRegisterEncodes(FILE *fp_hpp); 1.271 + // Generate Regsiter Size Array 1.272 + void declareRegSizes(FILE *fp_hpp); 1.273 + // Generate Pipeline Class information 1.274 + void declare_pipe_classes(FILE *fp_hpp); 1.275 + // Generate Pipeline definitions 1.276 + void build_pipeline_enums(FILE *fp_cpp); 1.277 + // Generate Pipeline Class information 1.278 + void build_pipe_classes(FILE *fp_cpp); 1.279 + 1.280 + // Declare and define mappings from rules to result and input types 1.281 + void build_map(OutputMap &map); 1.282 + void buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp); 1.283 + // build flags for signaling that our machine needs this instruction cloned 1.284 + void buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp); 1.285 + 1.286 + // output SUN copyright info 1.287 + void addSunCopyright(char* legal, int size, FILE *fp); 1.288 + // output the start of an include guard. 1.289 + void addIncludeGuardStart(ADLFILE &adlfile, const char* guardString); 1.290 + // output the end of an include guard. 1.291 + void addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString); 1.292 + // output the #include line for this file. 1.293 + void addInclude(ADLFILE &adlfile, const char* fileName); 1.294 + void addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName); 1.295 + // Output C preprocessor code to verify the backend compilation environment. 1.296 + void addPreprocessorChecks(FILE *fp); 1.297 + // Output C source and header (source_hpp) blocks. 1.298 + void addPreHeaderBlocks(FILE *fp_hpp); 1.299 + void addHeaderBlocks(FILE *fp_hpp); 1.300 + void addSourceBlocks(FILE *fp_cpp); 1.301 + void generate_needs_clone_jvms(FILE *fp_cpp); 1.302 + void generate_adlc_verification(FILE *fp_cpp); 1.303 + 1.304 + // output declaration of class State 1.305 + void defineStateClass(FILE *fp); 1.306 + 1.307 + // Generator for MachOper objects given integer type 1.308 + void buildMachOperGenerator(FILE *fp_cpp); 1.309 + // Generator for MachNode objects given integer type 1.310 + void buildMachNodeGenerator(FILE *fp_cpp); 1.311 + 1.312 + // Generator for Expand methods for instructions with expand rules 1.313 + void defineExpand (FILE *fp, InstructForm *node); 1.314 + // Generator for Peephole methods for instructions with peephole rules 1.315 + void definePeephole (FILE *fp, InstructForm *node); 1.316 + // Generator for Size methods for instructions 1.317 + void defineSize (FILE *fp, InstructForm &node); 1.318 + 1.319 +public: 1.320 + // Generator for EvalConstantValue methods for instructions 1.321 + void defineEvalConstant(FILE *fp, InstructForm &node); 1.322 + // Generator for Emit methods for instructions 1.323 + void defineEmit (FILE *fp, InstructForm &node); 1.324 + // Generator for postalloc_expand methods for instructions. 1.325 + void define_postalloc_expand(FILE *fp, InstructForm &node); 1.326 + 1.327 + // Define a MachOper encode method 1.328 + void define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals, 1.329 + const char *name, const char *encoding); 1.330 + 1.331 + // Methods to construct the MachNode class hierarchy 1.332 + // Return the type signature for the ideal operation 1.333 + const char *getIdealType(const char *idealOp); 1.334 + // Declare and define the classes derived from MachOper and MachNode 1.335 + void declareClasses(FILE *fp_hpp); 1.336 + void defineClasses(FILE *fp_cpp); 1.337 + 1.338 + // Emit an ADLC message 1.339 + void internal_err( const char *fmt, ...); 1.340 + void syntax_err ( int lineno, const char *fmt, ...); 1.341 + int emit_msg(int quiet, int flag, int linenum, const char *fmt, 1.342 + va_list args); 1.343 + 1.344 + // Generator for has_match_rule methods 1.345 + void buildInstructMatchCheck(FILE *fp_cpp) const; 1.346 + 1.347 + // Generator for Frame Methods 1.348 + void buildFrameMethods(FILE *fp_cpp); 1.349 + 1.350 + // Generate CISC_spilling oracle and MachNode::cisc_spill() methods 1.351 + void build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp); 1.352 + void identify_cisc_spill_instructions(); 1.353 + void identify_short_branches(); 1.354 + void identify_unique_operands(); 1.355 + void set_cisc_spill_operand(OperandForm *opForm) { _cisc_spill_operand = opForm; } 1.356 + OperandForm *cisc_spill_operand() { return _cisc_spill_operand; } 1.357 + bool can_cisc_spill() { return _cisc_spill_operand != NULL; } 1.358 + 1.359 + 1.360 +protected: 1.361 + // build MatchList from MatchRule 1.362 + void buildMatchList(MatchRule *mrule, const char *resultStr, 1.363 + const char *rootOp, Predicate *pred, const char *cost); 1.364 + 1.365 + void buildMList(MatchNode *node, const char *rootOp, const char *resultOp, 1.366 + Predicate *pred, const char *cost); 1.367 + 1.368 + friend class ADLParser; 1.369 + 1.370 +}; 1.371 + 1.372 + 1.373 +// -------------------------------- maps ------------------------------------ 1.374 + 1.375 +// Base class for generating a mapping from rule number to value. 1.376 +// Used with ArchDesc::build_map() for all maps except "enum MachOperands" 1.377 +// A derived class defines the appropriate output for a specific mapping. 1.378 +class OutputMap { 1.379 +protected: 1.380 + FILE *_hpp; 1.381 + FILE *_cpp; 1.382 + FormDict &_globals; 1.383 + ArchDesc &_AD; 1.384 + const char *_name; 1.385 +public: 1.386 + OutputMap (FILE *decl_file, FILE *def_file, FormDict &globals, ArchDesc &AD, const char *name) 1.387 + : _hpp(decl_file), _cpp(def_file), _globals(globals), _AD(AD), _name(name) {}; 1.388 + // Access files used by this routine 1.389 + FILE *decl_file() { return _hpp; } 1.390 + FILE *def_file() { return _cpp; } 1.391 + // Positions in iteration that derived class will be told about 1.392 + enum position { BEGIN_OPERANDS, 1.393 + BEGIN_OPCLASSES, 1.394 + BEGIN_INTERNALS, 1.395 + BEGIN_INSTRUCTIONS, 1.396 + BEGIN_INST_CHAIN_RULES, 1.397 + END_INST_CHAIN_RULES, 1.398 + BEGIN_REMATERIALIZE, 1.399 + END_REMATERIALIZE, 1.400 + END_INSTRUCTIONS 1.401 + }; 1.402 + // Output routines specific to the derived class 1.403 + virtual void declaration() {} 1.404 + virtual void definition() {} 1.405 + virtual void closing() { fprintf(_cpp, "};\n"); } 1.406 + virtual void map(OperandForm &oper) { } 1.407 + virtual void map(OpClassForm &opc) { } 1.408 + virtual void map(char *internal_name) { } 1.409 + // Allow enum-MachOperands to turn-off instructions 1.410 + virtual bool do_instructions() { return true; } 1.411 + virtual void map(InstructForm &inst) { } 1.412 + // Allow derived class to output name and position specific info 1.413 + virtual void record_position(OutputMap::position place, int index) {} 1.414 +}; 1.415 + 1.416 +#endif // SHARE_VM_ADLC_ARCHDESC_HPP