archDesc.hpp revision 1879
0N/A/*
1879N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_ADLC_ARCHDESC_HPP
1879N/A#define SHARE_VM_ADLC_ARCHDESC_HPP
1879N/A
0N/A// Definitions for Error Flags
0N/A#define WARN 0
0N/A#define SYNERR 1
0N/A#define SEMERR 2
0N/A#define INTERNAL_ERR 3
0N/A
0N/A// Minimal declarations for include files
0N/Aclass OutputMap;
0N/Aclass ProductionState;
0N/Aclass Expr;
0N/A
0N/A// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
0N/Atypedef BufferedFile ADLFILE;
0N/A
0N/A//---------------------------ChainList-----------------------------------------
0N/Aclass ChainList {
0N/A NameList _name;
0N/A NameList _cost;
0N/A NameList _rule;
0N/A
0N/Apublic:
0N/A void insert(const char *name, const char *cost, const char *rule);
0N/A bool search(const char *name);
0N/A
0N/A void reset();
0N/A bool iter(const char * &name, const char * &cost, const char * &rule);
0N/A
0N/A void dump();
0N/A void output(FILE *fp);
0N/A
0N/A ChainList();
0N/A ~ChainList();
0N/A};
0N/A
0N/A//---------------------------MatchList-----------------------------------------
0N/Aclass MatchList {
0N/Aprivate:
0N/A MatchList *_next;
0N/A Predicate *_pred; // Predicate which applies to this match rule
0N/A const char *_cost;
0N/A
0N/Apublic:
0N/A const char *_opcode;
0N/A const char *_resultStr;
0N/A const char *_lchild;
0N/A const char *_rchild;
0N/A
0N/A MatchList(MatchList *nxt, Predicate *prd): _next(nxt), _pred(prd), _cost(NULL){
0N/A _resultStr = _lchild = _rchild = _opcode = NULL; }
0N/A
0N/A MatchList(MatchList *nxt, Predicate *prd, const char *cost,
0N/A const char *opcode, const char *resultStr, const char *lchild,
0N/A const char *rchild)
0N/A : _next(nxt), _pred(prd), _cost(cost), _opcode(opcode),
0N/A _resultStr(resultStr), _lchild(lchild), _rchild(rchild) { }
0N/A
0N/A MatchList *get_next(void) { return _next; }
0N/A char *get_pred(void) { return (_pred?_pred->_pred:NULL); }
0N/A Predicate *get_pred_obj(void) { return _pred; }
0N/A const char *get_cost(void) { return _cost == NULL ? "0" :_cost; }
0N/A bool search(const char *opc, const char *res, const char *lch,
0N/A const char *rch, Predicate *pr);
0N/A
0N/A void dump();
0N/A void output(FILE *fp);
0N/A};
0N/A
0N/A//---------------------------ArchDesc------------------------------------------
0N/Aclass ArchDesc {
0N/Aprivate:
0N/A FormDict _globalNames; // Global names
0N/A Dict _idealIndex; // Map ideal names to index in enumeration
0N/A ExprDict _globalDefs; // Global definitions, #defines
0N/A int _internalOpCounter; // Internal Operand Counter
0N/A
0N/A FormList _header; // List of Source Code Forms for hpp file
0N/A FormList _pre_header; // ditto for the very top of the hpp file
0N/A FormList _source; // List of Source Code Forms for output
0N/A FormList _instructions; // List of Instruction Forms for output
0N/A FormList _machnodes; // List of Node Classes (special for pipelining)
0N/A FormList _operands; // List of Operand Forms for output
0N/A FormList _opclass; // List of Operand Class Forms for output
0N/A FormList _attributes; // List of Attribute Forms for parsing
0N/A RegisterForm *_register; // Only one Register Form allowed
0N/A FrameForm *_frame; // Describe stack-frame layout
0N/A EncodeForm *_encode; // Only one Encode Form allowed
0N/A PipelineForm *_pipeline; // Pipeline Form for output
0N/A
0N/A bool _has_match_rule[_last_opcode]; // found AD rule for ideal node in <arch>.ad
0N/A
0N/A MatchList *_mlistab[_last_opcode]; // Array of MatchLists
0N/A
0N/A // The Architecture Description identifies which user-defined operand can be used
0N/A // to access [stack_pointer + offset]
0N/A OperandForm *_cisc_spill_operand;
0N/A
0N/A // Methods for outputting the DFA
0N/A void gen_match(FILE *fp, MatchList &mlist, ProductionState &status, Dict &operands_chained_from);
0N/A void chain_rule(FILE *fp, const char *indent, const char *ideal,
0N/A const Expr *icost, const char *irule,
0N/A Dict &operands_chained_from, ProductionState &status);
0N/A void chain_rule_c(FILE *fp, char *indent, char *ideal, char *irule); // %%%%% TODO: remove this
0N/A void expand_opclass(FILE *fp, const char *indent, const Expr *cost,
0N/A const char *result_type, ProductionState &status);
0N/A Expr *calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status);
0N/A void prune_matchlist(Dict &minimize, MatchList &mlist);
0N/A
0N/A // Helper function that outputs code to generate an instruction in MachNodeGenerator
0N/A void buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent);
0N/A
0N/Apublic:
0N/A ArchDesc();
0N/A ~ArchDesc();
0N/A
0N/A // Option flags which control miscellaneous behaviors throughout the code
0N/A int _TotalLines; // Line Counter
0N/A int _no_output; // Flag to disable output of DFA, etc.
0N/A int _quiet_mode; // Do not output banner messages, etc.
0N/A int _disable_warnings; // Do not output warning messages
0N/A int _dfa_debug; // Debug Flag for generated DFA
0N/A int _dfa_small; // Debug Flag for generated DFA
0N/A int _adl_debug; // Debug Flag for ADLC
0N/A int _adlocation_debug; // Debug Flag to use ad file locations
0N/A bool _cisc_spill_debug; // Debug Flag to see cisc-spill-instructions
0N/A bool _short_branch_debug; // Debug Flag to see short branch instructions
0N/A
0N/A // Error/Warning Counts
0N/A int _syntax_errs; // Count of syntax errors
0N/A int _semantic_errs; // Count of semantic errors
0N/A int _warnings; // Count warnings
0N/A int _internal_errs; // Count of internal errors
0N/A
0N/A // Accessor for private data.
0N/A void has_match_rule(int opc, const bool b) { _has_match_rule[opc] = b; }
0N/A
0N/A // I/O Files
0N/A ADLFILE _ADL_file; // Input Architecture Description File
0N/A // Machine dependent files, built from architecture definition
0N/A ADLFILE _DFA_file; // File for definition of Matcher::DFA
0N/A ADLFILE _HPP_file; // File for ArchNode class declarations
0N/A ADLFILE _CPP_file; // File for ArchNode class defintions
0N/A ADLFILE _CPP_CLONE_file; // File for MachNode/Oper clone defintions
0N/A ADLFILE _CPP_EXPAND_file; // File for MachNode expand methods
0N/A ADLFILE _CPP_FORMAT_file; // File for MachNode/Oper format defintions
0N/A ADLFILE _CPP_GEN_file; // File for MachNode/Oper generator methods
0N/A ADLFILE _CPP_MISC_file; // File for miscellaneous MachNode/Oper tables & methods
0N/A ADLFILE _CPP_PEEPHOLE_file; // File for MachNode peephole methods
0N/A ADLFILE _CPP_PIPELINE_file; // File for MachNode pipeline defintions
0N/A ADLFILE _VM_file; // File for constants needed in VM code
0N/A ADLFILE _bug_file; // DFA debugging file
0N/A
0N/A // I/O helper methods
0N/A int open_file(bool required, ADLFILE & adf, const char *action);
0N/A void close_file(int delete_out, ADLFILE & adf);
0N/A int open_files(void);
0N/A void close_files(int delete_out);
0N/A
0N/A Dict _chainRules; // Maps user operand names to ChainRules
0N/A Dict _internalOps; // Maps match strings to internal operand names
0N/A NameList _internalOpNames; // List internal operand names
0N/A Dict _internalMatch; // Map internal name to its MatchNode
0N/A
0N/A NameList _preproc_list; // Preprocessor flag names
0N/A FormDict _preproc_table;// Preprocessor flag bindings
0N/A char* get_preproc_def(const char* flag);
0N/A void set_preproc_def(const char* flag, const char* def);
0N/A
0N/A FormDict& globalNames() {return _globalNames;} // map global names to forms
0N/A void initKeywords(FormDict& globals); // Add keywords to global name table
0N/A
0N/A ExprDict& globalDefs() {return _globalDefs;} // map global names to expressions
0N/A
0N/A OperandForm *constructOperand(const char *ident, bool ideal_only);
0N/A void initBaseOpTypes(); // Import predefined base types.
0N/A
0N/A void addForm(PreHeaderForm *ptr); // Add objects to pre-header list
0N/A void addForm(HeaderForm *ptr); // Add objects to header list
0N/A void addForm(SourceForm *ptr); // Add objects to source list
0N/A void addForm(EncodeForm *ptr); // Add objects to encode list
0N/A void addForm(InstructForm *ptr); // Add objects to the instruct list
0N/A void addForm(OperandForm *ptr); // Add objects to the operand list
0N/A void addForm(OpClassForm *ptr); // Add objects to the opclasss list
0N/A void addForm(AttributeForm *ptr); // Add objects to the attributes list
0N/A void addForm(RegisterForm *ptr); // Add objects to the register list
0N/A void addForm(FrameForm *ptr); // Add objects to the frame list
0N/A void addForm(PipelineForm *ptr); // Add objects to the pipeline list
0N/A void addForm(MachNodeForm *ptr); // Add objects to the machnode list
0N/A
0N/A int operandFormCount(); // Count number of OperandForms defined
0N/A int opclassFormCount(); // Count number of OpClassForms defined
0N/A int instructFormCount(); // Count number of InstructForms defined
0N/A
0N/A inline void getForm(EncodeForm **ptr) { *ptr = _encode; }
0N/A
0N/A bool verify();
0N/A void dump();
0N/A
0N/A // Helper utility that gets MatchList components from inside MatchRule
0N/A void check_optype(MatchRule *mrule);
0N/A void build_chain_rule(OperandForm *oper);
0N/A void add_chain_rule_entry(const char *src, const char *cost,
0N/A const char *result);
0N/A const char *getMatchListIndex(MatchRule &mrule);
0N/A void generateMatchLists(); // Build MatchList array and populate it
0N/A void inspectOperands(); // Build MatchLists for all operands
0N/A void inspectOpClasses(); // Build MatchLists for all operands
0N/A void inspectInstructions(); // Build MatchLists for all operands
0N/A void buildDFA(FILE *fp); // Driver for constructing the DFA
0N/A void gen_dfa_state_body(FILE *fp, Dict &minmize, ProductionState &status, Dict &chained, int i); // Driver for constructing the DFA state bodies
0N/A
0N/A // Helper utilities to generate reduction maps for internal operands
0N/A const char *reduceLeft (char *internalName);
0N/A const char *reduceRight(char *internalName);
0N/A
0N/A // Build enumerations, (1) dense operand index, (2) operands and opcodes
0N/A const char *machOperEnum(const char *opName); // create dense index names using static function
0N/A static const char *getMachOperEnum(const char *opName);// create dense index name
0N/A void buildMachOperEnum(FILE *fp_hpp);// dense enumeration for operands
0N/A void buildMachOpcodesEnum(FILE *fp_hpp);// enumeration for MachOpers & MachNodes
0N/A
0N/A // Helper utilities to generate Register Masks
0N/A RegisterForm *get_registers() { return _register; }
0N/A const char *reg_mask(OperandForm &opForm);
0N/A const char *reg_mask(InstructForm &instForm);
0N/A const char *reg_class_to_reg_mask(const char *reg_class);
0N/A char *stack_or_reg_mask(OperandForm &opForm); // name of cisc_spillable version
0N/A // This register class should also generate a stack_or_reg_mask
0N/A void set_stack_or_reg(const char *reg_class_name); // for cisc-spillable reg classes
0N/A // Generate an enumeration of register mask names and the RegMask objects.
0N/A void declare_register_masks(FILE *fp_cpp);
0N/A void build_register_masks(FILE *fp_cpp);
0N/A // Generate enumeration of machine register numbers
0N/A void buildMachRegisterNumbers(FILE *fp_hpp);
0N/A // Generate enumeration of machine register encodings
0N/A void buildMachRegisterEncodes(FILE *fp_hpp);
0N/A // Generate Regsiter Size Array
0N/A void declareRegSizes(FILE *fp_hpp);
0N/A // Generate Pipeline Class information
0N/A void declare_pipe_classes(FILE *fp_hpp);
0N/A // Generate Pipeline definitions
0N/A void build_pipeline_enums(FILE *fp_cpp);
0N/A // Generate Pipeline Class information
0N/A void build_pipe_classes(FILE *fp_cpp);
0N/A
0N/A // Declare and define mappings from rules to result and input types
0N/A void build_map(OutputMap &map);
0N/A void buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp);
0N/A // build flags for signaling that our machine needs this instruction cloned
0N/A void buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp);
0N/A
0N/A // output SUN copyright info
0N/A void addSunCopyright(char* legal, int size, FILE *fp);
1879N/A // output the start of an include guard.
1879N/A void addIncludeGuardStart(ADLFILE &adlfile, const char* guardString);
1879N/A // output the end of an include guard.
1879N/A void addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString);
1879N/A // output the #include line for this file.
1879N/A void addInclude(ADLFILE &adlfile, const char* fileName);
1879N/A void addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName);
0N/A // Output C preprocessor code to verify the backend compilation environment.
0N/A void addPreprocessorChecks(FILE *fp);
0N/A // Output C source and header (source_hpp) blocks.
0N/A void addPreHeaderBlocks(FILE *fp_hpp);
0N/A void addHeaderBlocks(FILE *fp_hpp);
0N/A void addSourceBlocks(FILE *fp_cpp);
0N/A void generate_adlc_verification(FILE *fp_cpp);
0N/A
0N/A // output declaration of class State
0N/A void defineStateClass(FILE *fp);
0N/A
0N/A // Generator for MachOper objects given integer type
0N/A void buildMachOperGenerator(FILE *fp_cpp);
0N/A // Generator for MachNode objects given integer type
0N/A void buildMachNodeGenerator(FILE *fp_cpp);
0N/A
0N/A // Generator for Expand methods for instructions with expand rules
0N/A void defineExpand(FILE *fp, InstructForm *node);
0N/A // Generator for Peephole methods for instructions with peephole rules
0N/A void definePeephole(FILE *fp, InstructForm *node);
0N/A // Generator for Size methods for instructions
0N/A void defineSize(FILE *fp, InstructForm &node);
0N/A // Generator for Emit methods for instructions
0N/A void defineEmit(FILE *fp, InstructForm &node);
0N/A // Define a MachOper encode method
0N/A void define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals,
0N/A const char *name, const char *encoding);
0N/A
0N/A // Methods to construct the MachNode class hierarchy
0N/A // Return the type signature for the ideal operation
0N/A const char *getIdealType(const char *idealOp);
0N/A // Declare and define the classes derived from MachOper and MachNode
0N/A void declareClasses(FILE *fp_hpp);
0N/A void defineClasses(FILE *fp_cpp);
0N/A
0N/A // Emit an ADLC message
0N/A void internal_err( const char *fmt, ...);
0N/A void syntax_err ( int lineno, const char *fmt, ...);
0N/A int emit_msg(int quiet, int flag, int linenum, const char *fmt,
0N/A va_list args);
0N/A
0N/A // Generator for has_match_rule methods
0N/A void buildInstructMatchCheck(FILE *fp_cpp) const;
0N/A
0N/A // Generator for Frame Methods
0N/A void buildFrameMethods(FILE *fp_cpp);
0N/A
0N/A // Generate CISC_spilling oracle and MachNode::cisc_spill() methods
0N/A void build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp);
0N/A void identify_cisc_spill_instructions();
0N/A void identify_short_branches();
0N/A void identify_unique_operands();
0N/A void set_cisc_spill_operand(OperandForm *opForm) { _cisc_spill_operand = opForm; }
0N/A OperandForm *cisc_spill_operand() { return _cisc_spill_operand; }
0N/A bool can_cisc_spill() { return _cisc_spill_operand != NULL; }
0N/A
0N/A
0N/Aprotected:
0N/A // build MatchList from MatchRule
0N/A void buildMatchList(MatchRule *mrule, const char *resultStr,
0N/A const char *rootOp, Predicate *pred, const char *cost);
0N/A
0N/A void buildMList(MatchNode *node, const char *rootOp, const char *resultOp,
0N/A Predicate *pred, const char *cost);
0N/A
0N/A friend class ADLParser;
0N/A
0N/A};
0N/A
0N/A
0N/A// -------------------------------- maps ------------------------------------
0N/A
0N/A// Base class for generating a mapping from rule number to value.
0N/A// Used with ArchDesc::build_map() for all maps except "enum MachOperands"
0N/A// A derived class defines the appropriate output for a specific mapping.
0N/Aclass OutputMap {
0N/Aprotected:
0N/A FILE *_hpp;
0N/A FILE *_cpp;
0N/A FormDict &_globals;
0N/A ArchDesc &_AD;
0N/Apublic:
0N/A OutputMap (FILE *decl_file, FILE *def_file, FormDict &globals, ArchDesc &AD)
0N/A : _hpp(decl_file), _cpp(def_file), _globals(globals), _AD(AD) {};
0N/A // Access files used by this routine
0N/A FILE *decl_file() { return _hpp; }
0N/A FILE *def_file() { return _cpp; }
0N/A // Positions in iteration that derived class will be told about
0N/A enum position { BEGIN_OPERANDS,
0N/A BEGIN_OPCLASSES,
0N/A BEGIN_INTERNALS,
0N/A BEGIN_INSTRUCTIONS,
0N/A BEGIN_INST_CHAIN_RULES,
0N/A END_INST_CHAIN_RULES,
0N/A BEGIN_REMATERIALIZE,
0N/A END_REMATERIALIZE,
0N/A END_INSTRUCTIONS
0N/A };
0N/A // Output routines specific to the derived class
0N/A virtual void declaration() {}
0N/A virtual void definition() {}
0N/A virtual void closing() { fprintf(_cpp, "};\n"); }
0N/A virtual void map(OperandForm &oper) { }
0N/A virtual void map(OpClassForm &opc) { }
0N/A virtual void map(char *internal_name) { }
0N/A // Allow enum-MachOperands to turn-off instructions
0N/A virtual bool do_instructions() { return true; }
0N/A virtual void map(InstructForm &inst) { }
0N/A // Allow derived class to output name and position specific info
0N/A virtual void record_position(OutputMap::position place, int index) {}
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_ADLC_ARCHDESC_HPP