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