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