src/share/vm/adlc/archDesc.hpp

Wed, 04 Feb 2009 11:44:57 -0800

author
never
date
Wed, 04 Feb 2009 11:44:57 -0800
changeset 997
1580954e694c
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6798785: Crash in OopFlow::build_oop_map: incorrect comparison of 64bit pointers
Reviewed-by: phh, kvn

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Definitions for Error Flags
duke@435 26 #define WARN 0
duke@435 27 #define SYNERR 1
duke@435 28 #define SEMERR 2
duke@435 29 #define INTERNAL_ERR 3
duke@435 30
duke@435 31 // Minimal declarations for include files
duke@435 32 class OutputMap;
duke@435 33 class ProductionState;
duke@435 34 class Expr;
duke@435 35
duke@435 36 // STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
duke@435 37 typedef BufferedFile ADLFILE;
duke@435 38
duke@435 39 //---------------------------ChainList-----------------------------------------
duke@435 40 class ChainList {
duke@435 41 NameList _name;
duke@435 42 NameList _cost;
duke@435 43 NameList _rule;
duke@435 44
duke@435 45 public:
duke@435 46 void insert(const char *name, const char *cost, const char *rule);
duke@435 47 bool search(const char *name);
duke@435 48
duke@435 49 void reset();
duke@435 50 bool iter(const char * &name, const char * &cost, const char * &rule);
duke@435 51
duke@435 52 void dump();
duke@435 53 void output(FILE *fp);
duke@435 54
duke@435 55 ChainList();
duke@435 56 ~ChainList();
duke@435 57 };
duke@435 58
duke@435 59 //---------------------------MatchList-----------------------------------------
duke@435 60 class MatchList {
duke@435 61 private:
duke@435 62 MatchList *_next;
duke@435 63 Predicate *_pred; // Predicate which applies to this match rule
duke@435 64 const char *_cost;
duke@435 65
duke@435 66 public:
duke@435 67 const char *_opcode;
duke@435 68 const char *_resultStr;
duke@435 69 const char *_lchild;
duke@435 70 const char *_rchild;
duke@435 71
duke@435 72 MatchList(MatchList *nxt, Predicate *prd): _next(nxt), _pred(prd), _cost(NULL){
duke@435 73 _resultStr = _lchild = _rchild = _opcode = NULL; }
duke@435 74
duke@435 75 MatchList(MatchList *nxt, Predicate *prd, const char *cost,
duke@435 76 const char *opcode, const char *resultStr, const char *lchild,
duke@435 77 const char *rchild)
duke@435 78 : _next(nxt), _pred(prd), _cost(cost), _opcode(opcode),
duke@435 79 _resultStr(resultStr), _lchild(lchild), _rchild(rchild) { }
duke@435 80
duke@435 81 MatchList *get_next(void) { return _next; }
duke@435 82 char *get_pred(void) { return (_pred?_pred->_pred:NULL); }
duke@435 83 Predicate *get_pred_obj(void) { return _pred; }
duke@435 84 const char *get_cost(void) { return _cost == NULL ? "0" :_cost; }
duke@435 85 bool search(const char *opc, const char *res, const char *lch,
duke@435 86 const char *rch, Predicate *pr);
duke@435 87
duke@435 88 void dump();
duke@435 89 void output(FILE *fp);
duke@435 90 };
duke@435 91
duke@435 92 //---------------------------ArchDesc------------------------------------------
duke@435 93 class ArchDesc {
duke@435 94 private:
duke@435 95 FormDict _globalNames; // Global names
duke@435 96 Dict _idealIndex; // Map ideal names to index in enumeration
duke@435 97 ExprDict _globalDefs; // Global definitions, #defines
duke@435 98 int _internalOpCounter; // Internal Operand Counter
duke@435 99
duke@435 100 FormList _header; // List of Source Code Forms for hpp file
duke@435 101 FormList _pre_header; // ditto for the very top of the hpp file
duke@435 102 FormList _source; // List of Source Code Forms for output
duke@435 103 FormList _instructions; // List of Instruction Forms for output
duke@435 104 FormList _machnodes; // List of Node Classes (special for pipelining)
duke@435 105 FormList _operands; // List of Operand Forms for output
duke@435 106 FormList _opclass; // List of Operand Class Forms for output
duke@435 107 FormList _attributes; // List of Attribute Forms for parsing
duke@435 108 RegisterForm *_register; // Only one Register Form allowed
duke@435 109 FrameForm *_frame; // Describe stack-frame layout
duke@435 110 EncodeForm *_encode; // Only one Encode Form allowed
duke@435 111 PipelineForm *_pipeline; // Pipeline Form for output
duke@435 112
duke@435 113 bool _has_match_rule[_last_opcode]; // found AD rule for ideal node in <arch>.ad
duke@435 114
duke@435 115 MatchList *_mlistab[_last_opcode]; // Array of MatchLists
duke@435 116
duke@435 117 // The Architecture Description identifies which user-defined operand can be used
duke@435 118 // to access [stack_pointer + offset]
duke@435 119 OperandForm *_cisc_spill_operand;
duke@435 120
duke@435 121 // Methods for outputting the DFA
duke@435 122 void gen_match(FILE *fp, MatchList &mlist, ProductionState &status, Dict &operands_chained_from);
duke@435 123 void chain_rule(FILE *fp, const char *indent, const char *ideal,
duke@435 124 const Expr *icost, const char *irule,
duke@435 125 Dict &operands_chained_from, ProductionState &status);
duke@435 126 void chain_rule_c(FILE *fp, char *indent, char *ideal, char *irule); // %%%%% TODO: remove this
duke@435 127 void expand_opclass(FILE *fp, const char *indent, const Expr *cost,
duke@435 128 const char *result_type, ProductionState &status);
duke@435 129 Expr *calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status);
duke@435 130 void prune_matchlist(Dict &minimize, MatchList &mlist);
duke@435 131
duke@435 132 // Helper function that outputs code to generate an instruction in MachNodeGenerator
duke@435 133 void buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent);
duke@435 134
duke@435 135 public:
duke@435 136 ArchDesc();
duke@435 137 ~ArchDesc();
duke@435 138
duke@435 139 // Option flags which control miscellaneous behaviors throughout the code
duke@435 140 int _TotalLines; // Line Counter
duke@435 141 int _no_output; // Flag to disable output of DFA, etc.
duke@435 142 int _quiet_mode; // Do not output banner messages, etc.
duke@435 143 int _disable_warnings; // Do not output warning messages
duke@435 144 int _dfa_debug; // Debug Flag for generated DFA
duke@435 145 int _dfa_small; // Debug Flag for generated DFA
duke@435 146 int _adl_debug; // Debug Flag for ADLC
duke@435 147 int _adlocation_debug; // Debug Flag to use ad file locations
duke@435 148 bool _cisc_spill_debug; // Debug Flag to see cisc-spill-instructions
duke@435 149 bool _short_branch_debug; // Debug Flag to see short branch instructions
duke@435 150
duke@435 151 // Error/Warning Counts
duke@435 152 int _syntax_errs; // Count of syntax errors
duke@435 153 int _semantic_errs; // Count of semantic errors
duke@435 154 int _warnings; // Count warnings
duke@435 155 int _internal_errs; // Count of internal errors
duke@435 156
duke@435 157 // Accessor for private data.
duke@435 158 void has_match_rule(int opc, const bool b) { _has_match_rule[opc] = b; }
duke@435 159
duke@435 160 // I/O Files
duke@435 161 ADLFILE _ADL_file; // Input Architecture Description File
duke@435 162 // Machine dependent files, built from architecture definition
duke@435 163 ADLFILE _DFA_file; // File for definition of Matcher::DFA
duke@435 164 ADLFILE _HPP_file; // File for ArchNode class declarations
duke@435 165 ADLFILE _CPP_file; // File for ArchNode class defintions
duke@435 166 ADLFILE _CPP_CLONE_file; // File for MachNode/Oper clone defintions
duke@435 167 ADLFILE _CPP_EXPAND_file; // File for MachNode expand methods
duke@435 168 ADLFILE _CPP_FORMAT_file; // File for MachNode/Oper format defintions
duke@435 169 ADLFILE _CPP_GEN_file; // File for MachNode/Oper generator methods
duke@435 170 ADLFILE _CPP_MISC_file; // File for miscellaneous MachNode/Oper tables & methods
duke@435 171 ADLFILE _CPP_PEEPHOLE_file; // File for MachNode peephole methods
duke@435 172 ADLFILE _CPP_PIPELINE_file; // File for MachNode pipeline defintions
duke@435 173 ADLFILE _VM_file; // File for constants needed in VM code
duke@435 174 ADLFILE _bug_file; // DFA debugging file
duke@435 175
duke@435 176 // I/O helper methods
duke@435 177 int open_file(bool required, ADLFILE & adf, const char *action);
duke@435 178 void close_file(int delete_out, ADLFILE & adf);
duke@435 179 int open_files(void);
duke@435 180 void close_files(int delete_out);
duke@435 181
duke@435 182 Dict _chainRules; // Maps user operand names to ChainRules
duke@435 183 Dict _internalOps; // Maps match strings to internal operand names
duke@435 184 NameList _internalOpNames; // List internal operand names
duke@435 185 Dict _internalMatch; // Map internal name to its MatchNode
duke@435 186
duke@435 187 NameList _preproc_list; // Preprocessor flag names
duke@435 188 FormDict _preproc_table;// Preprocessor flag bindings
duke@435 189 char* get_preproc_def(const char* flag);
duke@435 190 void set_preproc_def(const char* flag, const char* def);
duke@435 191
duke@435 192 FormDict& globalNames() {return _globalNames;} // map global names to forms
duke@435 193 void initKeywords(FormDict& globals); // Add keywords to global name table
duke@435 194
duke@435 195 ExprDict& globalDefs() {return _globalDefs;} // map global names to expressions
duke@435 196
duke@435 197 OperandForm *constructOperand(const char *ident, bool ideal_only);
duke@435 198 void initBaseOpTypes(); // Import predefined base types.
duke@435 199
duke@435 200 void addForm(PreHeaderForm *ptr); // Add objects to pre-header list
duke@435 201 void addForm(HeaderForm *ptr); // Add objects to header list
duke@435 202 void addForm(SourceForm *ptr); // Add objects to source list
duke@435 203 void addForm(EncodeForm *ptr); // Add objects to encode list
duke@435 204 void addForm(InstructForm *ptr); // Add objects to the instruct list
duke@435 205 void addForm(OperandForm *ptr); // Add objects to the operand list
duke@435 206 void addForm(OpClassForm *ptr); // Add objects to the opclasss list
duke@435 207 void addForm(AttributeForm *ptr); // Add objects to the attributes list
duke@435 208 void addForm(RegisterForm *ptr); // Add objects to the register list
duke@435 209 void addForm(FrameForm *ptr); // Add objects to the frame list
duke@435 210 void addForm(PipelineForm *ptr); // Add objects to the pipeline list
duke@435 211 void addForm(MachNodeForm *ptr); // Add objects to the machnode list
duke@435 212
duke@435 213 int operandFormCount(); // Count number of OperandForms defined
duke@435 214 int opclassFormCount(); // Count number of OpClassForms defined
duke@435 215 int instructFormCount(); // Count number of InstructForms defined
duke@435 216
duke@435 217 inline void getForm(EncodeForm **ptr) { *ptr = _encode; }
duke@435 218
duke@435 219 bool verify();
duke@435 220 void dump();
duke@435 221
duke@435 222 // Helper utility that gets MatchList components from inside MatchRule
duke@435 223 void check_optype(MatchRule *mrule);
duke@435 224 void build_chain_rule(OperandForm *oper);
duke@435 225 void add_chain_rule_entry(const char *src, const char *cost,
duke@435 226 const char *result);
duke@435 227 const char *getMatchListIndex(MatchRule &mrule);
duke@435 228 void generateMatchLists(); // Build MatchList array and populate it
duke@435 229 void inspectOperands(); // Build MatchLists for all operands
duke@435 230 void inspectOpClasses(); // Build MatchLists for all operands
duke@435 231 void inspectInstructions(); // Build MatchLists for all operands
duke@435 232 void buildDFA(FILE *fp); // Driver for constructing the DFA
duke@435 233 void gen_dfa_state_body(FILE *fp, Dict &minmize, ProductionState &status, Dict &chained, int i); // Driver for constructing the DFA state bodies
duke@435 234
duke@435 235 // Helper utilities to generate reduction maps for internal operands
duke@435 236 const char *reduceLeft (char *internalName);
duke@435 237 const char *reduceRight(char *internalName);
duke@435 238
duke@435 239 // Build enumerations, (1) dense operand index, (2) operands and opcodes
duke@435 240 const char *machOperEnum(const char *opName); // create dense index names using static function
duke@435 241 static const char *getMachOperEnum(const char *opName);// create dense index name
duke@435 242 void buildMachOperEnum(FILE *fp_hpp);// dense enumeration for operands
duke@435 243 void buildMachOpcodesEnum(FILE *fp_hpp);// enumeration for MachOpers & MachNodes
duke@435 244
duke@435 245 // Helper utilities to generate Register Masks
duke@435 246 RegisterForm *get_registers() { return _register; }
duke@435 247 const char *reg_mask(OperandForm &opForm);
duke@435 248 const char *reg_mask(InstructForm &instForm);
duke@435 249 const char *reg_class_to_reg_mask(const char *reg_class);
duke@435 250 char *stack_or_reg_mask(OperandForm &opForm); // name of cisc_spillable version
duke@435 251 // This register class should also generate a stack_or_reg_mask
duke@435 252 void set_stack_or_reg(const char *reg_class_name); // for cisc-spillable reg classes
duke@435 253 // Generate an enumeration of register mask names and the RegMask objects.
duke@435 254 void declare_register_masks(FILE *fp_cpp);
duke@435 255 void build_register_masks(FILE *fp_cpp);
duke@435 256 // Generate enumeration of machine register numbers
duke@435 257 void buildMachRegisterNumbers(FILE *fp_hpp);
duke@435 258 // Generate enumeration of machine register encodings
duke@435 259 void buildMachRegisterEncodes(FILE *fp_hpp);
duke@435 260 // Generate Regsiter Size Array
duke@435 261 void declareRegSizes(FILE *fp_hpp);
duke@435 262 // Generate Pipeline Class information
duke@435 263 void declare_pipe_classes(FILE *fp_hpp);
duke@435 264 // Generate Pipeline definitions
duke@435 265 void build_pipeline_enums(FILE *fp_cpp);
duke@435 266 // Generate Pipeline Class information
duke@435 267 void build_pipe_classes(FILE *fp_cpp);
duke@435 268
duke@435 269 // Declare and define mappings from rules to result and input types
duke@435 270 void build_map(OutputMap &map);
duke@435 271 void buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp);
duke@435 272 // build flags for signaling that our machine needs this instruction cloned
duke@435 273 void buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp);
duke@435 274
duke@435 275 // output SUN copyright info
duke@435 276 void addSunCopyright(char* legal, int size, FILE *fp);
duke@435 277 // output #include declarations for machine specific files
duke@435 278 void machineDependentIncludes(ADLFILE &adlfile);
duke@435 279 // Output C preprocessor code to verify the backend compilation environment.
duke@435 280 void addPreprocessorChecks(FILE *fp);
duke@435 281 // Output C source and header (source_hpp) blocks.
duke@435 282 void addPreHeaderBlocks(FILE *fp_hpp);
duke@435 283 void addHeaderBlocks(FILE *fp_hpp);
duke@435 284 void addSourceBlocks(FILE *fp_cpp);
duke@435 285 void generate_adlc_verification(FILE *fp_cpp);
duke@435 286
duke@435 287 // output declaration of class State
duke@435 288 void defineStateClass(FILE *fp);
duke@435 289
duke@435 290 // Generator for MachOper objects given integer type
duke@435 291 void buildMachOperGenerator(FILE *fp_cpp);
duke@435 292 // Generator for MachNode objects given integer type
duke@435 293 void buildMachNodeGenerator(FILE *fp_cpp);
duke@435 294
duke@435 295 // Generator for Expand methods for instructions with expand rules
duke@435 296 void defineExpand(FILE *fp, InstructForm *node);
duke@435 297 // Generator for Peephole methods for instructions with peephole rules
duke@435 298 void definePeephole(FILE *fp, InstructForm *node);
duke@435 299 // Generator for Size methods for instructions
duke@435 300 void defineSize(FILE *fp, InstructForm &node);
duke@435 301 // Generator for Emit methods for instructions
duke@435 302 void defineEmit(FILE *fp, InstructForm &node);
duke@435 303 // Define a MachOper encode method
duke@435 304 void define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals,
duke@435 305 const char *name, const char *encoding);
duke@435 306
duke@435 307 // Methods to construct the MachNode class hierarchy
duke@435 308 // Return the type signature for the ideal operation
duke@435 309 const char *getIdealType(const char *idealOp);
duke@435 310 // Declare and define the classes derived from MachOper and MachNode
duke@435 311 void declareClasses(FILE *fp_hpp);
duke@435 312 void defineClasses(FILE *fp_cpp);
duke@435 313
duke@435 314 // Emit an ADLC message
duke@435 315 void internal_err( const char *fmt, ...);
duke@435 316 void syntax_err ( int lineno, const char *fmt, ...);
duke@435 317 int emit_msg(int quiet, int flag, int linenum, const char *fmt,
duke@435 318 va_list args);
duke@435 319
duke@435 320 // Generator for has_match_rule methods
duke@435 321 void buildInstructMatchCheck(FILE *fp_cpp) const;
duke@435 322
duke@435 323 // Generator for Frame Methods
duke@435 324 void buildFrameMethods(FILE *fp_cpp);
duke@435 325
duke@435 326 // Generate CISC_spilling oracle and MachNode::cisc_spill() methods
duke@435 327 void build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp);
duke@435 328 void identify_cisc_spill_instructions();
duke@435 329 void identify_short_branches();
duke@435 330 void identify_unique_operands();
duke@435 331 void set_cisc_spill_operand(OperandForm *opForm) { _cisc_spill_operand = opForm; }
duke@435 332 OperandForm *cisc_spill_operand() { return _cisc_spill_operand; }
duke@435 333 bool can_cisc_spill() { return _cisc_spill_operand != NULL; }
duke@435 334
duke@435 335
duke@435 336 protected:
duke@435 337 // build MatchList from MatchRule
duke@435 338 void buildMatchList(MatchRule *mrule, const char *resultStr,
duke@435 339 const char *rootOp, Predicate *pred, const char *cost);
duke@435 340
duke@435 341 void buildMList(MatchNode *node, const char *rootOp, const char *resultOp,
duke@435 342 Predicate *pred, const char *cost);
duke@435 343
duke@435 344 friend class ADLParser;
duke@435 345
duke@435 346 };
duke@435 347
duke@435 348
duke@435 349 // -------------------------------- maps ------------------------------------
duke@435 350
duke@435 351 // Base class for generating a mapping from rule number to value.
duke@435 352 // Used with ArchDesc::build_map() for all maps except "enum MachOperands"
duke@435 353 // A derived class defines the appropriate output for a specific mapping.
duke@435 354 class OutputMap {
duke@435 355 protected:
duke@435 356 FILE *_hpp;
duke@435 357 FILE *_cpp;
duke@435 358 FormDict &_globals;
duke@435 359 ArchDesc &_AD;
duke@435 360 public:
duke@435 361 OutputMap (FILE *decl_file, FILE *def_file, FormDict &globals, ArchDesc &AD)
duke@435 362 : _hpp(decl_file), _cpp(def_file), _globals(globals), _AD(AD) {};
duke@435 363 // Access files used by this routine
duke@435 364 FILE *decl_file() { return _hpp; }
duke@435 365 FILE *def_file() { return _cpp; }
duke@435 366 // Positions in iteration that derived class will be told about
duke@435 367 enum position { BEGIN_OPERANDS,
duke@435 368 BEGIN_OPCLASSES,
duke@435 369 BEGIN_INTERNALS,
duke@435 370 BEGIN_INSTRUCTIONS,
duke@435 371 BEGIN_INST_CHAIN_RULES,
duke@435 372 END_INST_CHAIN_RULES,
duke@435 373 BEGIN_REMATERIALIZE,
duke@435 374 END_REMATERIALIZE,
duke@435 375 END_INSTRUCTIONS
duke@435 376 };
duke@435 377 // Output routines specific to the derived class
duke@435 378 virtual void declaration() {}
duke@435 379 virtual void definition() {}
duke@435 380 virtual void closing() { fprintf(_cpp, "};\n"); }
duke@435 381 virtual void map(OperandForm &oper) { }
duke@435 382 virtual void map(OpClassForm &opc) { }
duke@435 383 virtual void map(char *internal_name) { }
duke@435 384 // Allow enum-MachOperands to turn-off instructions
duke@435 385 virtual bool do_instructions() { return true; }
duke@435 386 virtual void map(InstructForm &inst) { }
duke@435 387 // Allow derived class to output name and position specific info
duke@435 388 virtual void record_position(OutputMap::position place, int index) {}
duke@435 389 };

mercurial