Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_ADLC_FORMSOPT_HPP |
aoqi@0 | 26 | #define SHARE_VM_ADLC_FORMSOPT_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | // FORMSOPT.HPP - ADL Parser Target Specific Optimization Forms Classes |
aoqi@0 | 29 | |
aoqi@0 | 30 | // Class List |
aoqi@0 | 31 | class Form; |
aoqi@0 | 32 | class InstructForm; |
aoqi@0 | 33 | class OperandForm; |
aoqi@0 | 34 | class OpClassForm; |
aoqi@0 | 35 | class AttributeForm; |
aoqi@0 | 36 | class RegisterForm; |
aoqi@0 | 37 | class PipelineForm; |
aoqi@0 | 38 | class SourceForm; |
aoqi@0 | 39 | class EncodeForm; |
aoqi@0 | 40 | class Component; |
aoqi@0 | 41 | class Constraint; |
aoqi@0 | 42 | class Predicate; |
aoqi@0 | 43 | class MatchRule; |
aoqi@0 | 44 | class Attribute; |
aoqi@0 | 45 | class Effect; |
aoqi@0 | 46 | class ExpandRule; |
aoqi@0 | 47 | class RewriteRule; |
aoqi@0 | 48 | class ConstructRule; |
aoqi@0 | 49 | class FormatRule; |
aoqi@0 | 50 | class Peephole; |
aoqi@0 | 51 | class PeepMatch; |
aoqi@0 | 52 | class PeepConstraint; |
aoqi@0 | 53 | class EncClass; |
aoqi@0 | 54 | class Interface; |
aoqi@0 | 55 | class RegInterface; |
aoqi@0 | 56 | class ConstInterface; |
aoqi@0 | 57 | class MemInterface; |
aoqi@0 | 58 | class CondInterface; |
aoqi@0 | 59 | class Opcode; |
aoqi@0 | 60 | class InsEncode; |
aoqi@0 | 61 | class RegDef; |
aoqi@0 | 62 | class RegClass; |
aoqi@0 | 63 | class AllocClass; |
aoqi@0 | 64 | class ResourceForm; |
aoqi@0 | 65 | class PipeClassForm; |
aoqi@0 | 66 | class PipeClassOperandForm; |
aoqi@0 | 67 | class PipeClassResourceForm; |
aoqi@0 | 68 | class PeepMatch; |
aoqi@0 | 69 | class PeepConstraint; |
aoqi@0 | 70 | class PeepReplace; |
aoqi@0 | 71 | class MatchList; |
aoqi@0 | 72 | |
aoqi@0 | 73 | class ArchDesc; |
aoqi@0 | 74 | |
aoqi@0 | 75 | //==============================Register Allocation============================ |
aoqi@0 | 76 | //------------------------------RegisterForm----------------------------------- |
aoqi@0 | 77 | class RegisterForm : public Form { |
aoqi@0 | 78 | private: |
aoqi@0 | 79 | AllocClass *_current_ac; // State used by iter_RegDefs() |
aoqi@0 | 80 | |
aoqi@0 | 81 | public: |
aoqi@0 | 82 | // Public Data |
aoqi@0 | 83 | NameList _rdefs; // List of register definition names |
aoqi@0 | 84 | Dict _regDef; // map register name to RegDef* |
aoqi@0 | 85 | |
aoqi@0 | 86 | NameList _rclasses; // List of register class names |
aoqi@0 | 87 | Dict _regClass; // map register class name to RegClass* |
aoqi@0 | 88 | |
aoqi@0 | 89 | NameList _aclasses; // List of allocation class names |
aoqi@0 | 90 | Dict _allocClass; // Dictionary of allocation classes |
aoqi@0 | 91 | |
aoqi@0 | 92 | static int _reg_ctr; // Register counter |
aoqi@0 | 93 | static int RegMask_Size(); // Compute RegMask size |
aoqi@0 | 94 | |
aoqi@0 | 95 | // Public Methods |
aoqi@0 | 96 | RegisterForm(); |
aoqi@0 | 97 | ~RegisterForm(); |
aoqi@0 | 98 | |
aoqi@0 | 99 | void addRegDef(char *regName, char *callingConv, char *c_conv, |
aoqi@0 | 100 | char * idealtype, char *encoding, char* concreteName); |
aoqi@0 | 101 | RegClass *addRegClass(const char *className); |
aoqi@0 | 102 | AllocClass *addAllocClass(char *allocName); |
aoqi@0 | 103 | void addSpillRegClass(); |
aoqi@0 | 104 | |
aoqi@0 | 105 | // Provide iteration over all register definitions |
aoqi@0 | 106 | // in the order used by the register allocator |
aoqi@0 | 107 | void reset_RegDefs(); |
aoqi@0 | 108 | RegDef *iter_RegDefs(); |
aoqi@0 | 109 | RegDef *getRegDef (const char *regName); |
aoqi@0 | 110 | |
aoqi@0 | 111 | RegClass *getRegClass(const char *className); |
aoqi@0 | 112 | |
aoqi@0 | 113 | // Return register mask, compressed chunk and register # |
aoqi@0 | 114 | uint reg_mask(char *register_class); |
aoqi@0 | 115 | |
aoqi@0 | 116 | // Check that register classes are compatible with chunks |
aoqi@0 | 117 | bool verify(); |
aoqi@0 | 118 | |
aoqi@0 | 119 | void dump(); // Debug printer |
aoqi@0 | 120 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 121 | }; |
aoqi@0 | 122 | |
aoqi@0 | 123 | //------------------------------RegDef----------------------------------------- |
aoqi@0 | 124 | class RegDef : public Form { |
aoqi@0 | 125 | public: |
aoqi@0 | 126 | // Public Data |
aoqi@0 | 127 | const char *_regname; // ADLC (Opto) Register name |
aoqi@0 | 128 | const char *_callconv; // Calling convention |
aoqi@0 | 129 | const char *_c_conv; // Native calling convention, 'C' |
aoqi@0 | 130 | const char *_idealtype; // Ideal Type for register save/restore |
aoqi@0 | 131 | const char *_concrete; // concrete register name |
aoqi@0 | 132 | |
aoqi@0 | 133 | private: |
aoqi@0 | 134 | const char *_register_encode; // The register encoding |
aoqi@0 | 135 | // The chunk and register mask bits define info for register allocation |
aoqi@0 | 136 | uint32 _register_num; // Which register am I |
aoqi@0 | 137 | |
aoqi@0 | 138 | public: |
aoqi@0 | 139 | // Public Methods |
aoqi@0 | 140 | RegDef(char *regname, char *callconv, char *c_conv, |
aoqi@0 | 141 | char *idealtype, char *encoding, char *concrete); |
aoqi@0 | 142 | ~RegDef(); // Destructor |
aoqi@0 | 143 | |
aoqi@0 | 144 | // Interface to define/redefine the register number |
aoqi@0 | 145 | void set_register_num(uint32 new_register_num); |
aoqi@0 | 146 | |
aoqi@0 | 147 | // Bit pattern used for generating machine code |
aoqi@0 | 148 | const char *register_encode() const; |
aoqi@0 | 149 | // Register number used in machine-independent code |
aoqi@0 | 150 | uint32 register_num() const; |
aoqi@0 | 151 | |
aoqi@0 | 152 | void dump(); // Debug printer |
aoqi@0 | 153 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 154 | }; |
aoqi@0 | 155 | |
aoqi@0 | 156 | //------------------------------RegClass--------------------------------------- |
aoqi@0 | 157 | class RegClass : public Form { |
aoqi@0 | 158 | public: |
aoqi@0 | 159 | // Public Data |
aoqi@0 | 160 | const char *_classid; // Name of class |
aoqi@0 | 161 | NameList _regDefs; // List of registers in class |
aoqi@0 | 162 | Dict _regDef; // Dictionary of registers in class |
aoqi@0 | 163 | bool _stack_or_reg; // Allowed on any stack slot |
aoqi@0 | 164 | char* _user_defined; |
aoqi@0 | 165 | |
aoqi@0 | 166 | // Public Methods |
aoqi@0 | 167 | RegClass(const char *classid);// Constructor |
aoqi@0 | 168 | |
aoqi@0 | 169 | void addReg(RegDef *regDef); // Add a register to this class |
aoqi@0 | 170 | |
aoqi@0 | 171 | uint size() const; // Number of registers in class |
aoqi@0 | 172 | int regs_in_word( int wordnum, bool stack_also ); |
aoqi@0 | 173 | |
aoqi@0 | 174 | const RegDef *get_RegDef(const char *regDef_name) const; |
aoqi@0 | 175 | |
aoqi@0 | 176 | // Returns the lowest numbered register in the mask. |
aoqi@0 | 177 | const RegDef* find_first_elem(); |
aoqi@0 | 178 | |
aoqi@0 | 179 | // Iteration support |
aoqi@0 | 180 | void reset(); // Reset the following two iterators |
aoqi@0 | 181 | RegDef *RegDef_iter(); // which move jointly, |
aoqi@0 | 182 | const char *rd_name_iter(); // invoking either advances both. |
aoqi@0 | 183 | |
aoqi@0 | 184 | void dump(); // Debug printer |
aoqi@0 | 185 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 186 | }; |
aoqi@0 | 187 | |
aoqi@0 | 188 | //------------------------------AllocClass------------------------------------- |
aoqi@0 | 189 | class AllocClass : public Form { |
aoqi@0 | 190 | private: |
aoqi@0 | 191 | |
aoqi@0 | 192 | public: |
aoqi@0 | 193 | // Public Data |
aoqi@0 | 194 | char *_classid; // Name of class |
aoqi@0 | 195 | NameList _regDefs; // List of registers in class |
aoqi@0 | 196 | Dict _regDef; // Dictionary of registers in class |
aoqi@0 | 197 | |
aoqi@0 | 198 | // Public Methods |
aoqi@0 | 199 | AllocClass(char *classid); // Constructor |
aoqi@0 | 200 | |
aoqi@0 | 201 | void addReg(RegDef *regDef); // Add a register to this class |
aoqi@0 | 202 | uint size() {return _regDef.Size();} // Number of registers in class |
aoqi@0 | 203 | |
aoqi@0 | 204 | void dump(); // Debug printer |
aoqi@0 | 205 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 206 | }; |
aoqi@0 | 207 | |
aoqi@0 | 208 | |
aoqi@0 | 209 | //==============================Frame Handling================================ |
aoqi@0 | 210 | //------------------------------FrameForm------------------------------------- |
aoqi@0 | 211 | class FrameForm : public Form { |
aoqi@0 | 212 | private: |
aoqi@0 | 213 | |
aoqi@0 | 214 | public: |
aoqi@0 | 215 | // Public Data |
aoqi@0 | 216 | bool _direction; // Direction of stack growth |
aoqi@0 | 217 | char *_sync_stack_slots; |
aoqi@0 | 218 | char *_inline_cache_reg; |
aoqi@0 | 219 | char *_interpreter_method_oop_reg; |
aoqi@0 | 220 | char *_interpreter_frame_pointer_reg; |
aoqi@0 | 221 | char *_cisc_spilling_operand_name; |
aoqi@0 | 222 | char *_frame_pointer; |
aoqi@0 | 223 | char *_c_frame_pointer; |
aoqi@0 | 224 | char *_alignment; |
aoqi@0 | 225 | bool _return_addr_loc; |
aoqi@0 | 226 | bool _c_return_addr_loc; |
aoqi@0 | 227 | char *_return_addr; |
aoqi@0 | 228 | char *_c_return_addr; |
aoqi@0 | 229 | char *_in_preserve_slots; |
aoqi@0 | 230 | char *_varargs_C_out_slots_killed; |
aoqi@0 | 231 | char *_calling_convention; |
aoqi@0 | 232 | char *_c_calling_convention; |
aoqi@0 | 233 | char *_return_value; |
aoqi@0 | 234 | char *_c_return_value; |
aoqi@0 | 235 | |
aoqi@0 | 236 | // Public Methods |
aoqi@0 | 237 | FrameForm(); |
aoqi@0 | 238 | ~FrameForm(); |
aoqi@0 | 239 | |
aoqi@0 | 240 | void dump(); // Debug printer |
aoqi@0 | 241 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 242 | }; |
aoqi@0 | 243 | |
aoqi@0 | 244 | |
aoqi@0 | 245 | //==============================Scheduling===================================== |
aoqi@0 | 246 | //------------------------------PipelineForm----------------------------------- |
aoqi@0 | 247 | class PipelineForm : public Form { |
aoqi@0 | 248 | private: |
aoqi@0 | 249 | |
aoqi@0 | 250 | public: |
aoqi@0 | 251 | // Public Data |
aoqi@0 | 252 | NameList _reslist; // List of pipeline resources |
aoqi@0 | 253 | FormDict _resdict; // Resource Name -> ResourceForm mapping |
aoqi@0 | 254 | int _rescount; // Number of resources (ignores OR cases) |
aoqi@0 | 255 | int _maxcycleused; // Largest cycle used relative to beginning of instruction |
aoqi@0 | 256 | |
aoqi@0 | 257 | NameList _stages; // List of pipeline stages on architecture |
aoqi@0 | 258 | int _stagecnt; // Number of stages listed |
aoqi@0 | 259 | |
aoqi@0 | 260 | NameList _classlist; // List of pipeline classes |
aoqi@0 | 261 | FormDict _classdict; // Class Name -> PipeClassForm mapping |
aoqi@0 | 262 | int _classcnt; // Number of classes |
aoqi@0 | 263 | |
aoqi@0 | 264 | NameList _noplist; // List of NOP instructions |
aoqi@0 | 265 | int _nopcnt; // Number of nop instructions |
aoqi@0 | 266 | |
aoqi@0 | 267 | bool _variableSizeInstrs; // Indicates if this architecture has variable sized instructions |
aoqi@0 | 268 | bool _branchHasDelaySlot; // Indicates that branches have delay slot instructions |
aoqi@0 | 269 | int _maxInstrsPerBundle; // Indicates the maximum number of instructions for ILP |
aoqi@0 | 270 | int _maxBundlesPerCycle; // Indicates the maximum number of bundles for ILP |
aoqi@0 | 271 | int _instrUnitSize; // The minimum instruction unit size, in bytes |
aoqi@0 | 272 | int _bundleUnitSize; // The bundle unit size, in bytes |
aoqi@0 | 273 | int _instrFetchUnitSize; // The size of the I-fetch unit, in bytes [must be power of 2] |
aoqi@0 | 274 | int _instrFetchUnits; // The number of I-fetch units processed per cycle |
aoqi@0 | 275 | |
aoqi@0 | 276 | // Public Methods |
aoqi@0 | 277 | PipelineForm(); |
aoqi@0 | 278 | ~PipelineForm(); |
aoqi@0 | 279 | |
aoqi@0 | 280 | void dump(); // Debug printer |
aoqi@0 | 281 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 282 | }; |
aoqi@0 | 283 | |
aoqi@0 | 284 | //------------------------------ResourceForm----------------------------------- |
aoqi@0 | 285 | class ResourceForm : public Form { |
aoqi@0 | 286 | public: |
aoqi@0 | 287 | unsigned mask() const { return _resmask; }; |
aoqi@0 | 288 | |
aoqi@0 | 289 | private: |
aoqi@0 | 290 | // Public Data |
aoqi@0 | 291 | unsigned _resmask; // Resource Mask (OR of resource specifier bits) |
aoqi@0 | 292 | |
aoqi@0 | 293 | public: |
aoqi@0 | 294 | |
aoqi@0 | 295 | // Virtual Methods |
aoqi@0 | 296 | virtual ResourceForm *is_resource() const; |
aoqi@0 | 297 | |
aoqi@0 | 298 | // Public Methods |
aoqi@0 | 299 | ResourceForm(unsigned resmask); // Constructor |
aoqi@0 | 300 | ~ResourceForm(); // Destructor |
aoqi@0 | 301 | |
aoqi@0 | 302 | void dump(); // Debug printer |
aoqi@0 | 303 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 304 | }; |
aoqi@0 | 305 | |
aoqi@0 | 306 | //------------------------------PipeClassOperandForm----------------------------- |
aoqi@0 | 307 | class PipeClassOperandForm : public Form { |
aoqi@0 | 308 | private: |
aoqi@0 | 309 | |
aoqi@0 | 310 | public: |
aoqi@0 | 311 | // Public Data |
aoqi@0 | 312 | const char *_stage; // Name of Stage |
aoqi@0 | 313 | unsigned _iswrite; // Read or Write |
aoqi@0 | 314 | unsigned _more_instrs; // Additional Instructions |
aoqi@0 | 315 | |
aoqi@0 | 316 | // Public Methods |
aoqi@0 | 317 | PipeClassOperandForm(const char *stage, unsigned iswrite, unsigned more_instrs) |
aoqi@0 | 318 | : _stage(stage) |
aoqi@0 | 319 | , _iswrite(iswrite) |
aoqi@0 | 320 | , _more_instrs(more_instrs) |
aoqi@0 | 321 | {}; |
aoqi@0 | 322 | |
aoqi@0 | 323 | ~PipeClassOperandForm() {}; // Destructor |
aoqi@0 | 324 | |
aoqi@0 | 325 | bool isWrite() const { return _iswrite != 0; } |
aoqi@0 | 326 | |
aoqi@0 | 327 | void dump(); // Debug printer |
aoqi@0 | 328 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 329 | }; |
aoqi@0 | 330 | |
aoqi@0 | 331 | //------------------------------PipeClassResourceForm-------------------------- |
aoqi@0 | 332 | class PipeClassResourceForm : public Form { |
aoqi@0 | 333 | private: |
aoqi@0 | 334 | |
aoqi@0 | 335 | public: |
aoqi@0 | 336 | // Public Data |
aoqi@0 | 337 | const char *_resource; // Resource |
aoqi@0 | 338 | const char *_stage; // Stage the resource is used in |
aoqi@0 | 339 | int _cycles; // Number of cycles the resource is used |
aoqi@0 | 340 | |
aoqi@0 | 341 | // Public Methods |
aoqi@0 | 342 | PipeClassResourceForm(const char *resource, const char *stage, int cycles) |
aoqi@0 | 343 | // Constructor |
aoqi@0 | 344 | : _resource(resource) |
aoqi@0 | 345 | , _stage(stage) |
aoqi@0 | 346 | , _cycles(cycles) |
aoqi@0 | 347 | {}; |
aoqi@0 | 348 | |
aoqi@0 | 349 | ~PipeClassResourceForm() {}; // Destructor |
aoqi@0 | 350 | |
aoqi@0 | 351 | void dump(); // Debug printer |
aoqi@0 | 352 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 353 | }; |
aoqi@0 | 354 | |
aoqi@0 | 355 | //------------------------------PipeClassForm---------------------------------- |
aoqi@0 | 356 | class PipeClassForm : public Form { |
aoqi@0 | 357 | private: |
aoqi@0 | 358 | |
aoqi@0 | 359 | public: |
aoqi@0 | 360 | |
aoqi@0 | 361 | // Public Data |
aoqi@0 | 362 | const char *_ident; // Name of class |
aoqi@0 | 363 | int _num; // Used in name of MachNode subclass |
aoqi@0 | 364 | NameList _parameters; // Locally defined names |
aoqi@0 | 365 | FormDict _localNames; // Table of operands & their types |
aoqi@0 | 366 | FormDict _localUsage; // Table of operand usage |
aoqi@0 | 367 | FormList _resUsage; // List of resource usage |
aoqi@0 | 368 | NameList _instructs; // List of instructions and machine nodes that use this pipeline class |
aoqi@0 | 369 | bool _has_fixed_latency; // Always takes this number of cycles |
aoqi@0 | 370 | int _fixed_latency; // Always takes this number of cycles |
aoqi@0 | 371 | int _instruction_count; // Number of instructions in first bundle |
aoqi@0 | 372 | bool _has_multiple_bundles; // Indicates if 1 or multiple bundles |
aoqi@0 | 373 | bool _has_branch_delay_slot; // Has branch delay slot as last instruction |
aoqi@0 | 374 | bool _force_serialization; // This node serializes relative to surrounding nodes |
aoqi@0 | 375 | bool _may_have_no_code; // This node may generate no code based on register allocation |
aoqi@0 | 376 | |
aoqi@0 | 377 | // Virtual Methods |
aoqi@0 | 378 | virtual PipeClassForm *is_pipeclass() const; |
aoqi@0 | 379 | |
aoqi@0 | 380 | // Public Methods |
aoqi@0 | 381 | PipeClassForm(const char *id, int num); |
aoqi@0 | 382 | // Constructor |
aoqi@0 | 383 | ~PipeClassForm(); // Destructor |
aoqi@0 | 384 | |
aoqi@0 | 385 | bool hasFixedLatency() { return _has_fixed_latency; } |
aoqi@0 | 386 | int fixedLatency() { return _fixed_latency; } |
aoqi@0 | 387 | |
aoqi@0 | 388 | void setFixedLatency(int fixed_latency) { _has_fixed_latency = 1; _fixed_latency = fixed_latency; } |
aoqi@0 | 389 | |
aoqi@0 | 390 | void setInstructionCount(int i) { _instruction_count = i; } |
aoqi@0 | 391 | void setMultipleBundles(bool b) { _has_multiple_bundles = b; } |
aoqi@0 | 392 | void setBranchDelay(bool s) { _has_branch_delay_slot = s; } |
aoqi@0 | 393 | void setForceSerialization(bool s) { _force_serialization = s; } |
aoqi@0 | 394 | void setMayHaveNoCode(bool s) { _may_have_no_code = s; } |
aoqi@0 | 395 | |
aoqi@0 | 396 | int InstructionCount() const { return _instruction_count; } |
aoqi@0 | 397 | bool hasMultipleBundles() const { return _has_multiple_bundles; } |
aoqi@0 | 398 | bool hasBranchDelay() const { return _has_branch_delay_slot; } |
aoqi@0 | 399 | bool forceSerialization() const { return _force_serialization; } |
aoqi@0 | 400 | bool mayHaveNoCode() const { return _may_have_no_code; } |
aoqi@0 | 401 | |
aoqi@0 | 402 | void dump(); // Debug printer |
aoqi@0 | 403 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 404 | }; |
aoqi@0 | 405 | |
aoqi@0 | 406 | |
aoqi@0 | 407 | //==============================Peephole Optimization========================== |
aoqi@0 | 408 | //------------------------------Peephole--------------------------------------- |
aoqi@0 | 409 | class Peephole : public Form { |
aoqi@0 | 410 | private: |
aoqi@0 | 411 | static int _peephole_counter;// Incremented by each peephole rule parsed |
aoqi@0 | 412 | int _peephole_number;// Remember my order in architecture description |
aoqi@0 | 413 | PeepMatch *_match; // Instruction pattern to match |
aoqi@0 | 414 | PeepConstraint *_constraint; // List of additional constraints |
aoqi@0 | 415 | PeepReplace *_replace; // Instruction pattern to substitute in |
aoqi@0 | 416 | |
aoqi@0 | 417 | Peephole *_next; |
aoqi@0 | 418 | |
aoqi@0 | 419 | public: |
aoqi@0 | 420 | // Public Methods |
aoqi@0 | 421 | Peephole(); |
aoqi@0 | 422 | ~Peephole(); |
aoqi@0 | 423 | |
aoqi@0 | 424 | // Append a peephole rule with the same root instruction |
aoqi@0 | 425 | void append_peephole(Peephole *next_peephole); |
aoqi@0 | 426 | |
aoqi@0 | 427 | // Store the components of this peephole rule |
aoqi@0 | 428 | void add_match(PeepMatch *only_one_match); |
aoqi@0 | 429 | void append_constraint(PeepConstraint *next_constraint); |
aoqi@0 | 430 | void add_replace(PeepReplace *only_one_replacement); |
aoqi@0 | 431 | |
aoqi@0 | 432 | // Access the components of this peephole rule |
aoqi@0 | 433 | int peephole_number() { return _peephole_number; } |
aoqi@0 | 434 | PeepMatch *match() { return _match; } |
aoqi@0 | 435 | PeepConstraint *constraints() { return _constraint; } |
aoqi@0 | 436 | PeepReplace *replacement() { return _replace; } |
aoqi@0 | 437 | Peephole *next() { return _next; } |
aoqi@0 | 438 | |
aoqi@0 | 439 | void dump(); // Debug printer |
aoqi@0 | 440 | void output(FILE *fp); // Write info to output files |
aoqi@0 | 441 | }; |
aoqi@0 | 442 | |
aoqi@0 | 443 | |
aoqi@0 | 444 | class PeepMatch : public Form { |
aoqi@0 | 445 | private: |
aoqi@0 | 446 | char *_rule; |
aoqi@0 | 447 | // NameList _depth; // Depth of this instruction |
aoqi@0 | 448 | NameList _parent; |
aoqi@0 | 449 | NameList _position; |
aoqi@0 | 450 | NameList _instrs; // List of instructions in match rule |
aoqi@0 | 451 | NameList _input; // input position in parent's instruction |
aoqi@0 | 452 | int _max_position; |
aoqi@0 | 453 | |
aoqi@0 | 454 | public: |
aoqi@0 | 455 | // Public Methods |
aoqi@0 | 456 | PeepMatch(char *rule); |
aoqi@0 | 457 | ~PeepMatch(); |
aoqi@0 | 458 | |
aoqi@0 | 459 | // Insert info into the match-rule |
aoqi@0 | 460 | void add_instruction(int parent, int position, const char *name, int input); |
aoqi@0 | 461 | |
aoqi@0 | 462 | // Access info about instructions in the peep-match rule |
aoqi@0 | 463 | int max_position(); |
aoqi@0 | 464 | const char *instruction_name(int position); |
aoqi@0 | 465 | // Iterate through all info on matched instructions |
aoqi@0 | 466 | void reset(); |
aoqi@0 | 467 | void next_instruction(int &parent, int &position, const char* &name, int &input); |
aoqi@0 | 468 | // 'true' if current position in iteration is a placeholder, not matched. |
aoqi@0 | 469 | bool is_placeholder(); |
aoqi@0 | 470 | |
aoqi@0 | 471 | void dump(); |
aoqi@0 | 472 | void output(FILE *fp); |
aoqi@0 | 473 | }; |
aoqi@0 | 474 | |
aoqi@0 | 475 | |
aoqi@0 | 476 | class PeepConstraint : public Form { |
aoqi@0 | 477 | private: |
aoqi@0 | 478 | PeepConstraint *_next; // Additional constraints ANDed together |
aoqi@0 | 479 | |
aoqi@0 | 480 | public: |
aoqi@0 | 481 | const int _left_inst; |
aoqi@0 | 482 | const char* _left_op; |
aoqi@0 | 483 | const char* _relation; |
aoqi@0 | 484 | const int _right_inst; |
aoqi@0 | 485 | const char* _right_op; |
aoqi@0 | 486 | |
aoqi@0 | 487 | public: |
aoqi@0 | 488 | // Public Methods |
aoqi@0 | 489 | PeepConstraint(int left_inst, char* left_op, char* relation, |
aoqi@0 | 490 | int right_inst, char* right_op); |
aoqi@0 | 491 | ~PeepConstraint(); |
aoqi@0 | 492 | |
aoqi@0 | 493 | // Check if constraints use instruction at position |
aoqi@0 | 494 | bool constrains_instruction(int position); |
aoqi@0 | 495 | |
aoqi@0 | 496 | // Add another constraint |
aoqi@0 | 497 | void append(PeepConstraint *next_peep_constraint); |
aoqi@0 | 498 | // Access the next constraint in the list |
aoqi@0 | 499 | PeepConstraint *next(); |
aoqi@0 | 500 | |
aoqi@0 | 501 | void dump(); |
aoqi@0 | 502 | void output(FILE *fp); |
aoqi@0 | 503 | }; |
aoqi@0 | 504 | |
aoqi@0 | 505 | |
aoqi@0 | 506 | class PeepReplace : public Form { |
aoqi@0 | 507 | private: |
aoqi@0 | 508 | char *_rule; |
aoqi@0 | 509 | NameList _instruction; |
aoqi@0 | 510 | NameList _operand_inst_num; |
aoqi@0 | 511 | NameList _operand_op_name; |
aoqi@0 | 512 | |
aoqi@0 | 513 | public: |
aoqi@0 | 514 | |
aoqi@0 | 515 | // Public Methods |
aoqi@0 | 516 | PeepReplace(char *rule); |
aoqi@0 | 517 | ~PeepReplace(); |
aoqi@0 | 518 | |
aoqi@0 | 519 | // Add contents of peepreplace |
aoqi@0 | 520 | void add_instruction(char *root); |
aoqi@0 | 521 | void add_operand( int inst_num, char *inst_operand ); |
aoqi@0 | 522 | |
aoqi@0 | 523 | // Access contents of peepreplace |
aoqi@0 | 524 | void reset(); |
aoqi@0 | 525 | void next_instruction(const char * &root); |
aoqi@0 | 526 | void next_operand(int &inst_num, const char * &inst_operand ); |
aoqi@0 | 527 | |
aoqi@0 | 528 | // Utilities |
aoqi@0 | 529 | void dump(); |
aoqi@0 | 530 | void output(FILE *fp); |
aoqi@0 | 531 | }; |
aoqi@0 | 532 | |
aoqi@0 | 533 | |
aoqi@0 | 534 | class PeepChild : public Form { |
aoqi@0 | 535 | public: |
aoqi@0 | 536 | const int _inst_num; // Number of instruction (-1 if only named) |
aoqi@0 | 537 | const char *_inst_op; // Instruction's operand, NULL if number == -1 |
aoqi@0 | 538 | const char *_inst_name; // Name of the instruction |
aoqi@0 | 539 | |
aoqi@0 | 540 | public: |
aoqi@0 | 541 | PeepChild(char *inst_name) |
aoqi@0 | 542 | : _inst_num(-1), _inst_op(NULL), _inst_name(inst_name) {}; |
aoqi@0 | 543 | PeepChild(int inst_num, char *inst_op, char *inst_name) |
aoqi@0 | 544 | : _inst_num(inst_num), _inst_op(inst_op), _inst_name(inst_name) {}; |
aoqi@0 | 545 | ~PeepChild(); |
aoqi@0 | 546 | |
aoqi@0 | 547 | bool use_leaf_operand() { return _inst_num != -1; }; |
aoqi@0 | 548 | bool generate_an_instruction() { return _inst_num == -1; } |
aoqi@0 | 549 | |
aoqi@0 | 550 | void dump(); |
aoqi@0 | 551 | void output(FILE *fp); |
aoqi@0 | 552 | }; |
aoqi@0 | 553 | |
aoqi@0 | 554 | #endif // SHARE_VM_ADLC_FORMSOPT_HPP |