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