src/share/vm/adlc/archDesc.hpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 6499
ad3b94907eed
child 6876
710a3c8b516e
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

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

mercurial