Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/archDesc.hpp
32285 views
/*1* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_ADLC_ARCHDESC_HPP25#define SHARE_VM_ADLC_ARCHDESC_HPP2627// Definitions for Error Flags28#define WARN 029#define SYNERR 130#define SEMERR 231#define INTERNAL_ERR 33233// Minimal declarations for include files34class OutputMap;35class ProductionState;36class Expr;3738// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES39typedef BufferedFile ADLFILE;4041//---------------------------ChainList-----------------------------------------42class ChainList {43NameList _name;44NameList _cost;45NameList _rule;4647public:48void insert(const char *name, const char *cost, const char *rule);49bool search(const char *name);5051void reset();52bool iter(const char * &name, const char * &cost, const char * &rule);5354void dump();55void output(FILE *fp);5657ChainList();58~ChainList();59};6061//---------------------------MatchList-----------------------------------------62class MatchList {63private:64MatchList *_next;65Predicate *_pred; // Predicate which applies to this match rule66const char *_cost;6768public:69const char *_opcode;70const char *_resultStr;71const char *_lchild;72const char *_rchild;7374MatchList(MatchList *nxt, Predicate *prd): _next(nxt), _pred(prd), _cost(NULL){75_resultStr = _lchild = _rchild = _opcode = NULL; }7677MatchList(MatchList *nxt, Predicate *prd, const char *cost,78const char *opcode, const char *resultStr, const char *lchild,79const char *rchild)80: _next(nxt), _pred(prd), _cost(cost), _opcode(opcode),81_resultStr(resultStr), _lchild(lchild), _rchild(rchild) { }8283MatchList *get_next(void) { return _next; }84char *get_pred(void) { return (_pred?_pred->_pred:NULL); }85Predicate *get_pred_obj(void) { return _pred; }86const char *get_cost(void) { return _cost == NULL ? "0" :_cost; }87bool search(const char *opc, const char *res, const char *lch,88const char *rch, Predicate *pr);8990void dump();91void output(FILE *fp);92};9394//---------------------------ArchDesc------------------------------------------95class ArchDesc {96private:97FormDict _globalNames; // Global names98Dict _idealIndex; // Map ideal names to index in enumeration99ExprDict _globalDefs; // Global definitions, #defines100int _internalOpCounter; // Internal Operand Counter101102FormList _header; // List of Source Code Forms for hpp file103FormList _pre_header; // ditto for the very top of the hpp file104FormList _source; // List of Source Code Forms for output105FormList _instructions; // List of Instruction Forms for output106FormList _machnodes; // List of Node Classes (special for pipelining)107FormList _operands; // List of Operand Forms for output108FormList _opclass; // List of Operand Class Forms for output109FormList _attributes; // List of Attribute Forms for parsing110RegisterForm *_register; // Only one Register Form allowed111FrameForm *_frame; // Describe stack-frame layout112EncodeForm *_encode; // Only one Encode Form allowed113PipelineForm *_pipeline; // Pipeline Form for output114115bool _has_match_rule[_last_opcode]; // found AD rule for ideal node in <arch>.ad116117MatchList *_mlistab[_last_opcode]; // Array of MatchLists118119// The Architecture Description identifies which user-defined operand can be used120// to access [stack_pointer + offset]121OperandForm *_cisc_spill_operand;122123// If a Call node uses $constanttablebase, it gets MachConstantBaseNode124// by the matcher and the matcher will modify the jvms. If so, jvm states125// always have to be cloned when a node is cloned. Adlc generates126// Compile::needs_clone_jvms() accordingly.127bool _needs_clone_jvms;128129// Methods for outputting the DFA130void gen_match(FILE *fp, MatchList &mlist, ProductionState &status, Dict &operands_chained_from);131void chain_rule(FILE *fp, const char *indent, const char *ideal,132const Expr *icost, const char *irule,133Dict &operands_chained_from, ProductionState &status);134void expand_opclass(FILE *fp, const char *indent, const Expr *cost,135const char *result_type, ProductionState &status);136Expr *calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status);137void prune_matchlist(Dict &minimize, MatchList &mlist);138139// Helper function that outputs code to generate an instruction in MachNodeGenerator140void buildMachNode(FILE *fp_cpp, InstructForm *inst, const char *indent);141142public:143ArchDesc();144~ArchDesc();145146// Option flags which control miscellaneous behaviors throughout the code147int _TotalLines; // Line Counter148int _no_output; // Flag to disable output of DFA, etc.149int _quiet_mode; // Do not output banner messages, etc.150int _disable_warnings; // Do not output warning messages151int _dfa_debug; // Debug Flag for generated DFA152int _dfa_small; // Debug Flag for generated DFA153int _adl_debug; // Debug Flag for ADLC154int _adlocation_debug; // Debug Flag to use ad file locations155bool _cisc_spill_debug; // Debug Flag to see cisc-spill-instructions156bool _short_branch_debug; // Debug Flag to see short branch instructions157158// Error/Warning Counts159int _syntax_errs; // Count of syntax errors160int _semantic_errs; // Count of semantic errors161int _warnings; // Count warnings162int _internal_errs; // Count of internal errors163164// Accessor for private data.165void has_match_rule(int opc, const bool b) { _has_match_rule[opc] = b; }166167// I/O Files168ADLFILE _ADL_file; // Input Architecture Description File169// Machine dependent files, built from architecture definition170ADLFILE _DFA_file; // File for definition of Matcher::DFA171ADLFILE _HPP_file; // File for ArchNode class declarations172ADLFILE _CPP_file; // File for ArchNode class defintions173ADLFILE _CPP_CLONE_file; // File for MachNode/Oper clone defintions174ADLFILE _CPP_EXPAND_file; // File for MachNode expand methods175ADLFILE _CPP_FORMAT_file; // File for MachNode/Oper format defintions176ADLFILE _CPP_GEN_file; // File for MachNode/Oper generator methods177ADLFILE _CPP_MISC_file; // File for miscellaneous MachNode/Oper tables & methods178ADLFILE _CPP_PEEPHOLE_file; // File for MachNode peephole methods179ADLFILE _CPP_PIPELINE_file; // File for MachNode pipeline defintions180ADLFILE _VM_file; // File for constants needed in VM code181ADLFILE _bug_file; // DFA debugging file182183// I/O helper methods184int open_file(bool required, ADLFILE & adf, const char *action);185void close_file(int delete_out, ADLFILE & adf);186int open_files(void);187void close_files(int delete_out);188189Dict _chainRules; // Maps user operand names to ChainRules190Dict _internalOps; // Maps match strings to internal operand names191NameList _internalOpNames; // List internal operand names192Dict _internalMatch; // Map internal name to its MatchNode193194NameList _preproc_list; // Preprocessor flag names195FormDict _preproc_table;// Preprocessor flag bindings196char* get_preproc_def(const char* flag);197void set_preproc_def(const char* flag, const char* def);198199FormDict& globalNames() {return _globalNames;} // map global names to forms200void initKeywords(FormDict& globals); // Add keywords to global name table201202ExprDict& globalDefs() {return _globalDefs;} // map global names to expressions203204OperandForm *constructOperand(const char *ident, bool ideal_only);205void initBaseOpTypes(); // Import predefined base types.206207void addForm(PreHeaderForm *ptr); // Add objects to pre-header list208void addForm(HeaderForm *ptr); // Add objects to header list209void addForm(SourceForm *ptr); // Add objects to source list210void addForm(EncodeForm *ptr); // Add objects to encode list211void addForm(InstructForm *ptr); // Add objects to the instruct list212void addForm(OperandForm *ptr); // Add objects to the operand list213void addForm(OpClassForm *ptr); // Add objects to the opclasss list214void addForm(AttributeForm *ptr); // Add objects to the attributes list215void addForm(RegisterForm *ptr); // Add objects to the register list216void addForm(FrameForm *ptr); // Add objects to the frame list217void addForm(PipelineForm *ptr); // Add objects to the pipeline list218void addForm(MachNodeForm *ptr); // Add objects to the machnode list219220int operandFormCount(); // Count number of OperandForms defined221int opclassFormCount(); // Count number of OpClassForms defined222int instructFormCount(); // Count number of InstructForms defined223224inline void getForm(EncodeForm **ptr) { *ptr = _encode; }225226bool verify();227void dump();228229// Helper utility that gets MatchList components from inside MatchRule230void check_optype(MatchRule *mrule);231void build_chain_rule(OperandForm *oper);232void add_chain_rule_entry(const char *src, const char *cost,233const char *result);234const char *getMatchListIndex(MatchRule &mrule);235void generateMatchLists(); // Build MatchList array and populate it236void inspectOperands(); // Build MatchLists for all operands237void inspectOpClasses(); // Build MatchLists for all operands238void inspectInstructions(); // Build MatchLists for all operands239void buildDFA(FILE *fp); // Driver for constructing the DFA240void gen_dfa_state_body(FILE *fp, Dict &minmize, ProductionState &status, Dict &chained, int i); // Driver for constructing the DFA state bodies241242// Helper utilities to generate reduction maps for internal operands243const char *reduceLeft (char *internalName);244const char *reduceRight(char *internalName);245246// Build enumerations, (1) dense operand index, (2) operands and opcodes247const char *machOperEnum(const char *opName); // create dense index names using static function248static const char *getMachOperEnum(const char *opName);// create dense index name249void buildMachOperEnum(FILE *fp_hpp);// dense enumeration for operands250void buildMachOpcodesEnum(FILE *fp_hpp);// enumeration for MachOpers & MachNodes251252// Helper utilities to generate Register Masks253RegisterForm *get_registers() { return _register; }254const char *reg_mask(OperandForm &opForm);255const char *reg_mask(InstructForm &instForm);256const char *reg_class_to_reg_mask(const char *reg_class);257char *stack_or_reg_mask(OperandForm &opForm); // name of cisc_spillable version258// This register class should also generate a stack_or_reg_mask259void set_stack_or_reg(const char *reg_class_name); // for cisc-spillable reg classes260// Generate an enumeration of register mask names and the RegMask objects.261void declare_register_masks(FILE *fp_cpp);262void build_register_masks(FILE *fp_cpp);263// Generate enumeration of machine register numbers264void buildMachRegisterNumbers(FILE *fp_hpp);265// Generate enumeration of machine register encodings266void buildMachRegisterEncodes(FILE *fp_hpp);267// Generate Regsiter Size Array268void declareRegSizes(FILE *fp_hpp);269// Generate Pipeline Class information270void declare_pipe_classes(FILE *fp_hpp);271// Generate Pipeline definitions272void build_pipeline_enums(FILE *fp_cpp);273// Generate Pipeline Class information274void build_pipe_classes(FILE *fp_cpp);275276// Declare and define mappings from rules to result and input types277void build_map(OutputMap &map);278void buildReduceMaps(FILE *fp_hpp, FILE *fp_cpp);279// build flags for signaling that our machine needs this instruction cloned280void buildMustCloneMap(FILE *fp_hpp, FILE *fp_cpp);281282// output SUN copyright info283void addSunCopyright(char* legal, int size, FILE *fp);284// output the start of an include guard.285void addIncludeGuardStart(ADLFILE &adlfile, const char* guardString);286// output the end of an include guard.287void addIncludeGuardEnd(ADLFILE &adlfile, const char* guardString);288// output the #include line for this file.289void addInclude(ADLFILE &adlfile, const char* fileName);290void addInclude(ADLFILE &adlfile, const char* includeDir, const char* fileName);291// Output C preprocessor code to verify the backend compilation environment.292void addPreprocessorChecks(FILE *fp);293// Output C source and header (source_hpp) blocks.294void addPreHeaderBlocks(FILE *fp_hpp);295void addHeaderBlocks(FILE *fp_hpp);296void addSourceBlocks(FILE *fp_cpp);297void generate_needs_clone_jvms(FILE *fp_cpp);298void generate_adlc_verification(FILE *fp_cpp);299300// output declaration of class State301void defineStateClass(FILE *fp);302303// Generator for MachOper objects given integer type304void buildMachOperGenerator(FILE *fp_cpp);305// Generator for MachNode objects given integer type306void buildMachNodeGenerator(FILE *fp_cpp);307308// Generator for Expand methods for instructions with expand rules309void defineExpand (FILE *fp, InstructForm *node);310// Generator for Peephole methods for instructions with peephole rules311void definePeephole (FILE *fp, InstructForm *node);312// Generator for Size methods for instructions313void defineSize (FILE *fp, InstructForm &node);314315public:316// Generator for EvalConstantValue methods for instructions317void defineEvalConstant(FILE *fp, InstructForm &node);318// Generator for Emit methods for instructions319void defineEmit (FILE *fp, InstructForm &node);320// Generator for postalloc_expand methods for instructions.321void define_postalloc_expand(FILE *fp, InstructForm &node);322323// Define a MachOper encode method324void define_oper_interface(FILE *fp, OperandForm &oper, FormDict &globals,325const char *name, const char *encoding);326327// Methods to construct the MachNode class hierarchy328// Return the type signature for the ideal operation329const char *getIdealType(const char *idealOp);330// Declare and define the classes derived from MachOper and MachNode331void declareClasses(FILE *fp_hpp);332void defineClasses(FILE *fp_cpp);333334// Emit an ADLC message335void internal_err( const char *fmt, ...);336void syntax_err ( int lineno, const char *fmt, ...);337int emit_msg(int quiet, int flag, int linenum, const char *fmt,338va_list args);339340// Generator for has_match_rule methods341void buildInstructMatchCheck(FILE *fp_cpp) const;342343// Generator for Frame Methods344void buildFrameMethods(FILE *fp_cpp);345346// Generate CISC_spilling oracle and MachNode::cisc_spill() methods347void build_cisc_spill_instructions(FILE *fp_hpp, FILE *fp_cpp);348void identify_cisc_spill_instructions();349void identify_short_branches();350void identify_unique_operands();351void set_cisc_spill_operand(OperandForm *opForm) { _cisc_spill_operand = opForm; }352OperandForm *cisc_spill_operand() { return _cisc_spill_operand; }353bool can_cisc_spill() { return _cisc_spill_operand != NULL; }354355356protected:357// build MatchList from MatchRule358void buildMatchList(MatchRule *mrule, const char *resultStr,359const char *rootOp, Predicate *pred, const char *cost);360361void buildMList(MatchNode *node, const char *rootOp, const char *resultOp,362Predicate *pred, const char *cost);363364friend class ADLParser;365366};367368369// -------------------------------- maps ------------------------------------370371// Base class for generating a mapping from rule number to value.372// Used with ArchDesc::build_map() for all maps except "enum MachOperands"373// A derived class defines the appropriate output for a specific mapping.374class OutputMap {375protected:376FILE *_hpp;377FILE *_cpp;378FormDict &_globals;379ArchDesc &_AD;380const char *_name;381public:382OutputMap (FILE *decl_file, FILE *def_file, FormDict &globals, ArchDesc &AD, const char *name)383: _hpp(decl_file), _cpp(def_file), _globals(globals), _AD(AD), _name(name) {};384// Access files used by this routine385FILE *decl_file() { return _hpp; }386FILE *def_file() { return _cpp; }387// Positions in iteration that derived class will be told about388enum position { BEGIN_OPERANDS,389BEGIN_OPCLASSES,390BEGIN_INTERNALS,391BEGIN_INSTRUCTIONS,392BEGIN_INST_CHAIN_RULES,393END_INST_CHAIN_RULES,394BEGIN_REMATERIALIZE,395END_REMATERIALIZE,396END_INSTRUCTIONS397};398// Output routines specific to the derived class399virtual void declaration() {}400virtual void definition() {}401virtual void closing() { fprintf(_cpp, "};\n"); }402virtual void map(OperandForm &oper) { }403virtual void map(OpClassForm &opc) { }404virtual void map(char *internal_name) { }405// Allow enum-MachOperands to turn-off instructions406virtual bool do_instructions() { return true; }407virtual void map(InstructForm &inst) { }408// Allow derived class to output name and position specific info409virtual void record_position(OutputMap::position place, int index) {}410};411412#endif // SHARE_VM_ADLC_ARCHDESC_HPP413414415