Rename MachineInstr::getInstrDescriptor -> getDesc(), which reflects
[oota-llvm.git] / include / llvm / Target / TargetInstrInfo.h
1 //===-- llvm/Target/TargetInstrInfo.h - Instruction Info --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the target machine instructions to the code generator.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETINSTRINFO_H
15 #define LLVM_TARGET_TARGETINSTRINFO_H
16
17 #include "llvm/CodeGen/MachineBasicBlock.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <vector>
21 #include <cassert>
22
23 namespace llvm {
24
25 class MachineInstr;
26 class TargetMachine;
27 class TargetRegisterClass;
28 class LiveVariables;
29 class CalleeSavedInfo;
30 class SDNode;
31 class SelectionDAG;
32
33 template<class T> class SmallVectorImpl;
34
35 //---------------------------------------------------------------------------
36 // Data types used to define information about a single machine instruction
37 //---------------------------------------------------------------------------
38
39 typedef short MachineOpCode;
40 typedef unsigned InstrSchedClass;
41
42 //---------------------------------------------------------------------------
43 // struct TargetInstrDescriptor:
44 //  Predefined information about each machine instruction.
45 //  Designed to initialized statically.
46 //
47
48 const unsigned M_BRANCH_FLAG           = 1 << 0;
49 const unsigned M_CALL_FLAG             = 1 << 1;
50 const unsigned M_RET_FLAG              = 1 << 2;
51 const unsigned M_BARRIER_FLAG          = 1 << 3;
52 const unsigned M_DELAY_SLOT_FLAG       = 1 << 4;
53   
54 /// M_SIMPLE_LOAD_FLAG - This flag is set for instructions that are simple loads
55 /// from memory.  This should only be set on instructions that load a value from
56 /// memory and return it in their only virtual register definition.
57 const unsigned M_SIMPLE_LOAD_FLAG      = 1 << 5;
58   
59 /// M_MAY_STORE_FLAG - This flag is set to any instruction that could possibly
60 /// modify memory.  Instructions with this flag set are not necessarily simple
61 /// store instructions, they may store a modified value based on their operands,
62 /// or may not actually modify anything, for example.
63 const unsigned M_MAY_STORE_FLAG        = 1 << 6;
64   
65 const unsigned M_INDIRECT_FLAG         = 1 << 7;
66 const unsigned M_IMPLICIT_DEF_FLAG     = 1 << 8;
67
68 // M_CONVERTIBLE_TO_3_ADDR - This is a 2-address instruction which can be
69 // changed into a 3-address instruction if the first two operands cannot be
70 // assigned to the same register.  The target must implement the
71 // TargetInstrInfo::convertToThreeAddress method for this instruction.
72 const unsigned M_CONVERTIBLE_TO_3_ADDR = 1 << 9;
73
74 // This M_COMMUTABLE - is a 2- or 3-address instruction (of the form X = op Y,
75 // Z), which produces the same result if Y and Z are exchanged.
76 const unsigned M_COMMUTABLE            = 1 << 10;
77
78 // M_TERMINATOR_FLAG - Is this instruction part of the terminator for a basic
79 // block?  Typically this is things like return and branch instructions.
80 // Various passes use this to insert code into the bottom of a basic block, but
81 // before control flow occurs.
82 const unsigned M_TERMINATOR_FLAG       = 1 << 11;
83
84 // M_USES_CUSTOM_DAG_SCHED_INSERTION - Set if this instruction requires custom
85 // insertion support when the DAG scheduler is inserting it into a machine basic
86 // block.
87 const unsigned M_USES_CUSTOM_DAG_SCHED_INSERTION = 1 << 12;
88
89 // M_VARIABLE_OPS - Set if this instruction can have a variable number of extra
90 // operands in addition to the minimum number operands specified.
91 const unsigned M_VARIABLE_OPS          = 1 << 13;
92
93 // M_PREDICABLE - Set if this instruction has a predicate operand that
94 // controls execution. It may be set to 'always'.
95 const unsigned M_PREDICABLE            = 1 << 14;
96
97 // M_REMATERIALIZIBLE - Set if this instruction can be trivally re-materialized
98 // at any time, e.g. constant generation, load from constant pool.
99 const unsigned M_REMATERIALIZIBLE      = 1 << 15;
100
101 // M_NOT_DUPLICABLE - Set if this instruction cannot be safely duplicated.
102 // (e.g. instructions with unique labels attached).
103 const unsigned M_NOT_DUPLICABLE        = 1 << 16;
104
105 // M_HAS_OPTIONAL_DEF - Set if this instruction has an optional definition, e.g.
106 // ARM instructions which can set condition code if 's' bit is set.
107 const unsigned M_HAS_OPTIONAL_DEF      = 1 << 17;
108
109 // M_NEVER_HAS_SIDE_EFFECTS - Set if this instruction has no side effects that
110 // are not captured by any operands of the instruction or other flags, and when
111 // *all* instances of the instruction of that opcode have no side effects.
112 //
113 // Note: This and M_MAY_HAVE_SIDE_EFFECTS are mutually exclusive. You can't set
114 // both! If neither flag is set, then the instruction *always* has side effects.
115 const unsigned M_NEVER_HAS_SIDE_EFFECTS = 1 << 18;
116
117 // M_MAY_HAVE_SIDE_EFFECTS - Set if some instances of this instruction can have
118 // side effects. The virtual method "isReallySideEffectFree" is called to
119 // determine this. Load instructions are an example of where this is useful. In
120 // general, loads always have side effects. However, loads from constant pools
121 // don't. We let the specific back end make this determination.
122 //
123 // Note: This and M_NEVER_HAS_SIDE_EFFECTS are mutually exclusive. You can't set
124 // both! If neither flag is set, then the instruction *always* has side effects.
125 const unsigned M_MAY_HAVE_SIDE_EFFECTS = 1 << 19;
126
127 // Machine operand flags
128 // M_LOOK_UP_PTR_REG_CLASS - Set if this operand is a pointer value and it
129 // requires a callback to look up its register class.
130 const unsigned M_LOOK_UP_PTR_REG_CLASS = 1 << 0;
131
132 /// M_PREDICATE_OPERAND - Set if this is one of the operands that made up of the
133 /// predicate operand that controls an M_PREDICATED instruction.
134 const unsigned M_PREDICATE_OPERAND = 1 << 1;
135
136 /// M_OPTIONAL_DEF_OPERAND - Set if this operand is a optional def.
137 ///
138 const unsigned M_OPTIONAL_DEF_OPERAND = 1 << 2;
139
140 namespace TOI {
141   // Operand constraints: only "tied_to" for now.
142   enum OperandConstraint {
143     TIED_TO = 0  // Must be allocated the same register as.
144   };
145 }
146
147 /// TargetOperandInfo - This holds information about one operand of a machine
148 /// instruction, indicating the register class for register operands, etc.
149 ///
150 class TargetOperandInfo {
151 public:
152   /// RegClass - This specifies the register class enumeration of the operand 
153   /// if the operand is a register.  If not, this contains 0.
154   unsigned short RegClass;
155   unsigned short Flags;
156   /// Lower 16 bits are used to specify which constraints are set. The higher 16
157   /// bits are used to specify the value of constraints (4 bits each).
158   unsigned int Constraints;
159   /// Currently no other information.
160 };
161
162
163 class TargetInstrDescriptor {
164 public:
165   MachineOpCode   Opcode;        // The opcode.
166   unsigned short  numOperands;   // Num of args (may be more if variable_ops).
167   unsigned short  numDefs;       // Num of args that are definitions.
168   const char *    Name;          // Assembly language mnemonic for the opcode.
169   InstrSchedClass schedClass;    // enum  identifying instr sched class
170   unsigned        Flags;         // flags identifying machine instr class
171   unsigned        TSFlags;       // Target Specific Flag values
172   const unsigned *ImplicitUses;  // Registers implicitly read by this instr
173   const unsigned *ImplicitDefs;  // Registers implicitly defined by this instr
174   const TargetOperandInfo *OpInfo; // 'numOperands' entries about operands.
175
176   /// getOperandConstraint - Returns the value of the specific constraint if
177   /// it is set. Returns -1 if it is not set.
178   int getOperandConstraint(unsigned OpNum,
179                            TOI::OperandConstraint Constraint) const {
180     assert((OpNum < numOperands || (Flags & M_VARIABLE_OPS)) &&
181            "Invalid operand # of TargetInstrInfo");
182     if (OpNum < numOperands &&
183         (OpInfo[OpNum].Constraints & (1 << Constraint))) {
184       unsigned Pos = 16 + Constraint * 4;
185       return (int)(OpInfo[OpNum].Constraints >> Pos) & 0xf;
186     }
187     return -1;
188   }
189
190   /// findTiedToSrcOperand - Returns the operand that is tied to the specified
191   /// dest operand. Returns -1 if there isn't one.
192   int findTiedToSrcOperand(unsigned OpNum) const;
193   
194   bool isCall() const {
195     return Flags & M_CALL_FLAG;
196   }
197   
198   bool isBranch() const {
199     return Flags & M_BRANCH_FLAG;
200   }
201   
202   bool isTerminator() const {
203     return Flags & M_TERMINATOR_FLAG;
204   }
205   
206   bool isIndirectBranch() const {
207     return Flags & M_INDIRECT_FLAG;
208   }
209   
210   bool isPredicable() const {
211     return Flags & M_PREDICABLE;
212   }
213   
214   bool isNotDuplicable() const {
215     return Flags & M_NOT_DUPLICABLE;
216   }
217   
218   
219   
220   /// isSimpleLoad - Return true for instructions that are simple loads from
221   /// memory.  This should only be set on instructions that load a value from
222   /// memory and return it in their only virtual register definition.
223   /// Instructions that return a value loaded from memory and then modified in
224   /// some way should not return true for this.
225   bool isSimpleLoad() const {
226     return Flags & M_SIMPLE_LOAD_FLAG;
227   }
228   
229   /// mayStore - Return true if this instruction could possibly modify memory.
230   /// Instructions with this flag set are not necessarily simple store
231   /// instructions, they may store a modified value based on their operands, or
232   /// may not actually modify anything, for example.
233   bool mayStore() const {
234     return Flags & M_MAY_STORE_FLAG;
235   }
236   
237   /// isBarrier - Returns true if the specified instruction stops control flow
238   /// from executing the instruction immediately following it.  Examples include
239   /// unconditional branches and return instructions.
240   bool isBarrier() const {
241     return Flags & M_BARRIER_FLAG;
242   }
243   
244   /// hasDelaySlot - Returns true if the specified instruction has a delay slot
245   /// which must be filled by the code generator.
246   bool hasDelaySlot() const {
247     return Flags & M_DELAY_SLOT_FLAG;
248   }
249 };
250
251
252 //---------------------------------------------------------------------------
253 ///
254 /// TargetInstrInfo - Interface to description of machine instructions
255 ///
256 class TargetInstrInfo {
257   const TargetInstrDescriptor* desc;    // raw array to allow static init'n
258   unsigned NumOpcodes;                  // number of entries in the desc array
259   unsigned numRealOpCodes;              // number of non-dummy op codes
260
261   TargetInstrInfo(const TargetInstrInfo &);  // DO NOT IMPLEMENT
262   void operator=(const TargetInstrInfo &);   // DO NOT IMPLEMENT
263 public:
264   TargetInstrInfo(const TargetInstrDescriptor *desc, unsigned NumOpcodes);
265   virtual ~TargetInstrInfo();
266
267   // Invariant opcodes: All instruction sets have these as their low opcodes.
268   enum { 
269     PHI = 0,
270     INLINEASM = 1,
271     LABEL = 2,
272     EXTRACT_SUBREG = 3,
273     INSERT_SUBREG = 4
274   };
275
276   unsigned getNumOpcodes() const { return NumOpcodes; }
277
278   /// get - Return the machine instruction descriptor that corresponds to the
279   /// specified instruction opcode.
280   ///
281   const TargetInstrDescriptor& get(MachineOpCode Opcode) const {
282     assert((unsigned)Opcode < NumOpcodes);
283     return desc[Opcode];
284   }
285
286   const char *getName(MachineOpCode Opcode) const {
287     return get(Opcode).Name;
288   }
289
290   int getNumOperands(MachineOpCode Opcode) const {
291     return get(Opcode).numOperands;
292   }
293
294   int getNumDefs(MachineOpCode Opcode) const {
295     return get(Opcode).numDefs;
296   }
297
298   InstrSchedClass getSchedClass(MachineOpCode Opcode) const {
299     return get(Opcode).schedClass;
300   }
301
302   const unsigned *getImplicitUses(MachineOpCode Opcode) const {
303     return get(Opcode).ImplicitUses;
304   }
305
306   const unsigned *getImplicitDefs(MachineOpCode Opcode) const {
307     return get(Opcode).ImplicitDefs;
308   }
309
310
311   //
312   // Query instruction class flags according to the machine-independent
313   // flags listed above.
314   //
315   bool isReturn(MachineOpCode Opcode) const {
316     return get(Opcode).Flags & M_RET_FLAG;
317   }
318
319   bool isCommutableInstr(MachineOpCode Opcode) const {
320     return get(Opcode).Flags & M_COMMUTABLE;
321   }
322   
323   /// usesCustomDAGSchedInsertionHook - Return true if this instruction requires
324   /// custom insertion support when the DAG scheduler is inserting it into a
325   /// machine basic block.
326   bool usesCustomDAGSchedInsertionHook(MachineOpCode Opcode) const {
327     return get(Opcode).Flags & M_USES_CUSTOM_DAG_SCHED_INSERTION;
328   }
329
330   bool hasVariableOperands(MachineOpCode Opcode) const {
331     return get(Opcode).Flags & M_VARIABLE_OPS;
332   }
333
334   bool hasOptionalDef(MachineOpCode Opcode) const {
335     return get(Opcode).Flags & M_HAS_OPTIONAL_DEF;
336   }
337
338   /// isTriviallyReMaterializable - Return true if the instruction is trivially
339   /// rematerializable, meaning it has no side effects and requires no operands
340   /// that aren't always available.
341   bool isTriviallyReMaterializable(MachineInstr *MI) const {
342     return (MI->getDesc()->Flags & M_REMATERIALIZIBLE) &&
343            isReallyTriviallyReMaterializable(MI);
344   }
345
346   /// hasUnmodelledSideEffects - Returns true if the instruction has side
347   /// effects that are not captured by any operands of the instruction or other
348   /// flags.
349   bool hasUnmodelledSideEffects(MachineInstr *MI) const {
350     const TargetInstrDescriptor *TID = MI->getDesc();
351     if (TID->Flags & M_NEVER_HAS_SIDE_EFFECTS) return false;
352     if (!(TID->Flags & M_MAY_HAVE_SIDE_EFFECTS)) return true;
353     return !isReallySideEffectFree(MI); // May have side effects
354   }
355 protected:
356   /// isReallyTriviallyReMaterializable - For instructions with opcodes for
357   /// which the M_REMATERIALIZABLE flag is set, this function tests whether the
358   /// instruction itself is actually trivially rematerializable, considering
359   /// its operands.  This is used for targets that have instructions that are
360   /// only trivially rematerializable for specific uses.  This predicate must
361   /// return false if the instruction has any side effects other than
362   /// producing a value, or if it requres any address registers that are not
363   /// always available.
364   virtual bool isReallyTriviallyReMaterializable(MachineInstr *MI) const {
365     return true;
366   }
367
368   /// isReallySideEffectFree - If the M_MAY_HAVE_SIDE_EFFECTS flag is set, this
369   /// method is called to determine if the specific instance of this
370   /// instruction has side effects. This is useful in cases of instructions,
371   /// like loads, which generally always have side effects. A load from a
372   /// constant pool doesn't have side effects, though. So we need to
373   /// differentiate it from the general case.
374   virtual bool isReallySideEffectFree(MachineInstr *MI) const {
375     return false;
376   }
377 public:
378   /// getOperandConstraint - Returns the value of the specific constraint if
379   /// it is set. Returns -1 if it is not set.
380   int getOperandConstraint(MachineOpCode Opcode, unsigned OpNum,
381                            TOI::OperandConstraint Constraint) const {
382     return get(Opcode).getOperandConstraint(OpNum, Constraint);
383   }
384
385   /// Return true if the instruction is a register to register move
386   /// and leave the source and dest operands in the passed parameters.
387   virtual bool isMoveInstr(const MachineInstr& MI,
388                            unsigned& sourceReg,
389                            unsigned& destReg) const {
390     return false;
391   }
392   
393   /// isLoadFromStackSlot - If the specified machine instruction is a direct
394   /// load from a stack slot, return the virtual or physical register number of
395   /// the destination along with the FrameIndex of the loaded stack slot.  If
396   /// not, return 0.  This predicate must return 0 if the instruction has
397   /// any side effects other than loading from the stack slot.
398   virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const{
399     return 0;
400   }
401   
402   /// isStoreToStackSlot - If the specified machine instruction is a direct
403   /// store to a stack slot, return the virtual or physical register number of
404   /// the source reg along with the FrameIndex of the loaded stack slot.  If
405   /// not, return 0.  This predicate must return 0 if the instruction has
406   /// any side effects other than storing to the stack slot.
407   virtual unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const {
408     return 0;
409   }
410
411   /// convertToThreeAddress - This method must be implemented by targets that
412   /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
413   /// may be able to convert a two-address instruction into one or more true
414   /// three-address instructions on demand.  This allows the X86 target (for
415   /// example) to convert ADD and SHL instructions into LEA instructions if they
416   /// would require register copies due to two-addressness.
417   ///
418   /// This method returns a null pointer if the transformation cannot be
419   /// performed, otherwise it returns the last new instruction.
420   ///
421   virtual MachineInstr *
422   convertToThreeAddress(MachineFunction::iterator &MFI,
423                    MachineBasicBlock::iterator &MBBI, LiveVariables &LV) const {
424     return 0;
425   }
426
427   /// commuteInstruction - If a target has any instructions that are commutable,
428   /// but require converting to a different instruction or making non-trivial
429   /// changes to commute them, this method can overloaded to do this.  The
430   /// default implementation of this method simply swaps the first two operands
431   /// of MI and returns it.
432   ///
433   /// If a target wants to make more aggressive changes, they can construct and
434   /// return a new machine instruction.  If an instruction cannot commute, it
435   /// can also return null.
436   ///
437   virtual MachineInstr *commuteInstruction(MachineInstr *MI) const = 0;
438
439   /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
440   /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
441   /// implemented for a target).  Upon success, this returns false and returns
442   /// with the following information in various cases:
443   ///
444   /// 1. If this block ends with no branches (it just falls through to its succ)
445   ///    just return false, leaving TBB/FBB null.
446   /// 2. If this block ends with only an unconditional branch, it sets TBB to be
447   ///    the destination block.
448   /// 3. If this block ends with an conditional branch and it falls through to
449   ///    an successor block, it sets TBB to be the branch destination block and a
450   ///    list of operands that evaluate the condition. These
451   ///    operands can be passed to other TargetInstrInfo methods to create new
452   ///    branches.
453   /// 4. If this block ends with an conditional branch and an unconditional
454   ///    block, it returns the 'true' destination in TBB, the 'false' destination
455   ///    in FBB, and a list of operands that evaluate the condition. These
456   ///    operands can be passed to other TargetInstrInfo methods to create new
457   ///    branches.
458   ///
459   /// Note that RemoveBranch and InsertBranch must be implemented to support
460   /// cases where this method returns success.
461   ///
462   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
463                              MachineBasicBlock *&FBB,
464                              std::vector<MachineOperand> &Cond) const {
465     return true;
466   }
467   
468   /// RemoveBranch - Remove the branching code at the end of the specific MBB.
469   /// this is only invoked in cases where AnalyzeBranch returns success. It
470   /// returns the number of instructions that were removed.
471   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const {
472     assert(0 && "Target didn't implement TargetInstrInfo::RemoveBranch!"); 
473     return 0;
474   }
475   
476   /// InsertBranch - Insert a branch into the end of the specified
477   /// MachineBasicBlock.  This operands to this method are the same as those
478   /// returned by AnalyzeBranch.  This is invoked in cases where AnalyzeBranch
479   /// returns success and when an unconditional branch (TBB is non-null, FBB is
480   /// null, Cond is empty) needs to be inserted. It returns the number of
481   /// instructions inserted.
482   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
483                             MachineBasicBlock *FBB,
484                             const std::vector<MachineOperand> &Cond) const {
485     assert(0 && "Target didn't implement TargetInstrInfo::InsertBranch!"); 
486     return 0;
487   }
488   
489   /// copyRegToReg - Add a copy between a pair of registers
490   virtual void copyRegToReg(MachineBasicBlock &MBB,
491                             MachineBasicBlock::iterator MI,
492                             unsigned DestReg, unsigned SrcReg,
493                             const TargetRegisterClass *DestRC,
494                             const TargetRegisterClass *SrcRC) const {
495     assert(0 && "Target didn't implement TargetInstrInfo::copyRegToReg!");
496   }
497   
498   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
499                                    MachineBasicBlock::iterator MI,
500                                    unsigned SrcReg, bool isKill, int FrameIndex,
501                                    const TargetRegisterClass *RC) const {
502     assert(0 && "Target didn't implement TargetInstrInfo::storeRegToStackSlot!");
503   }
504
505   virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
506                               SmallVectorImpl<MachineOperand> &Addr,
507                               const TargetRegisterClass *RC,
508                               SmallVectorImpl<MachineInstr*> &NewMIs) const {
509     assert(0 && "Target didn't implement TargetInstrInfo::storeRegToAddr!");
510   }
511
512   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
513                                     MachineBasicBlock::iterator MI,
514                                     unsigned DestReg, int FrameIndex,
515                                     const TargetRegisterClass *RC) const {
516     assert(0 && "Target didn't implement TargetInstrInfo::loadRegFromStackSlot!");
517   }
518
519   virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
520                                SmallVectorImpl<MachineOperand> &Addr,
521                                const TargetRegisterClass *RC,
522                                SmallVectorImpl<MachineInstr*> &NewMIs) const {
523     assert(0 && "Target didn't implement TargetInstrInfo::loadRegFromAddr!");
524   }
525   
526   /// spillCalleeSavedRegisters - Issues instruction(s) to spill all callee
527   /// saved registers and returns true if it isn't possible / profitable to do
528   /// so by issuing a series of store instructions via
529   /// storeRegToStackSlot(). Returns false otherwise.
530   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
531                                          MachineBasicBlock::iterator MI,
532                                 const std::vector<CalleeSavedInfo> &CSI) const {
533     return false;
534   }
535
536   /// restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee
537   /// saved registers and returns true if it isn't possible / profitable to do
538   /// so by issuing a series of load instructions via loadRegToStackSlot().
539   /// Returns false otherwise.
540   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
541                                            MachineBasicBlock::iterator MI,
542                                 const std::vector<CalleeSavedInfo> &CSI) const {
543     return false;
544   }
545   
546   /// foldMemoryOperand - Attempt to fold a load or store of the specified stack
547   /// slot into the specified machine instruction for the specified operand(s).
548   /// If this is possible, a new instruction is returned with the specified
549   /// operand folded, otherwise NULL is returned. The client is responsible for
550   /// removing the old instruction and adding the new one in the instruction
551   /// stream.
552   virtual MachineInstr* foldMemoryOperand(MachineInstr* MI,
553                                           SmallVectorImpl<unsigned> &Ops,
554                                           int FrameIndex) const {
555     return 0;
556   }
557
558   /// foldMemoryOperand - Same as the previous version except it allows folding
559   /// of any load and store from / to any address, not just from a specific
560   /// stack slot.
561   virtual MachineInstr* foldMemoryOperand(MachineInstr* MI,
562                                           SmallVectorImpl<unsigned> &Ops,
563                                           MachineInstr* LoadMI) const {
564     return 0;
565   }
566
567   /// canFoldMemoryOperand - Returns true if the specified load / store is
568   /// folding is possible.
569   virtual
570   bool canFoldMemoryOperand(MachineInstr *MI,
571                             SmallVectorImpl<unsigned> &Ops) const{
572     return false;
573   }
574
575   /// unfoldMemoryOperand - Separate a single instruction which folded a load or
576   /// a store or a load and a store into two or more instruction. If this is
577   /// possible, returns true as well as the new instructions by reference.
578   virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
579                                 unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
580                                   SmallVectorImpl<MachineInstr*> &NewMIs) const{
581     return false;
582   }
583
584   virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
585                                    SmallVectorImpl<SDNode*> &NewNodes) const {
586     return false;
587   }
588
589   /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
590   /// instruction after load / store are unfolded from an instruction of the
591   /// specified opcode. It returns zero if the specified unfolding is not
592   /// possible.
593   virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
594                                       bool UnfoldLoad, bool UnfoldStore) const {
595     return 0;
596   }
597   
598   /// BlockHasNoFallThrough - Return true if the specified block does not
599   /// fall-through into its successor block.  This is primarily used when a
600   /// branch is unanalyzable.  It is useful for things like unconditional
601   /// indirect branches (jump tables).
602   virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const {
603     return false;
604   }
605   
606   /// ReverseBranchCondition - Reverses the branch condition of the specified
607   /// condition list, returning false on success and true if it cannot be
608   /// reversed.
609   virtual bool ReverseBranchCondition(std::vector<MachineOperand> &Cond) const {
610     return true;
611   }
612   
613   /// insertNoop - Insert a noop into the instruction stream at the specified
614   /// point.
615   virtual void insertNoop(MachineBasicBlock &MBB, 
616                           MachineBasicBlock::iterator MI) const {
617     assert(0 && "Target didn't implement insertNoop!");
618     abort();
619   }
620
621   /// isPredicated - Returns true if the instruction is already predicated.
622   ///
623   virtual bool isPredicated(const MachineInstr *MI) const {
624     return false;
625   }
626
627   /// isUnpredicatedTerminator - Returns true if the instruction is a
628   /// terminator instruction that has not been predicated.
629   virtual bool isUnpredicatedTerminator(const MachineInstr *MI) const;
630
631   /// PredicateInstruction - Convert the instruction into a predicated
632   /// instruction. It returns true if the operation was successful.
633   virtual
634   bool PredicateInstruction(MachineInstr *MI,
635                             const std::vector<MachineOperand> &Pred) const = 0;
636
637   /// SubsumesPredicate - Returns true if the first specified predicate
638   /// subsumes the second, e.g. GE subsumes GT.
639   virtual
640   bool SubsumesPredicate(const std::vector<MachineOperand> &Pred1,
641                          const std::vector<MachineOperand> &Pred2) const {
642     return false;
643   }
644
645   /// DefinesPredicate - If the specified instruction defines any predicate
646   /// or condition code register(s) used for predication, returns true as well
647   /// as the definition predicate(s) by reference.
648   virtual bool DefinesPredicate(MachineInstr *MI,
649                                 std::vector<MachineOperand> &Pred) const {
650     return false;
651   }
652
653   /// getPointerRegClass - Returns a TargetRegisterClass used for pointer
654   /// values.
655   virtual const TargetRegisterClass *getPointerRegClass() const {
656     assert(0 && "Target didn't implement getPointerRegClass!");
657     abort();
658     return 0; // Must return a value in order to compile with VS 2005
659   }
660 };
661
662 /// TargetInstrInfoImpl - This is the default implementation of
663 /// TargetInstrInfo, which just provides a couple of default implementations
664 /// for various methods.  This separated out because it is implemented in
665 /// libcodegen, not in libtarget.
666 class TargetInstrInfoImpl : public TargetInstrInfo {
667 protected:
668   TargetInstrInfoImpl(const TargetInstrDescriptor *desc, unsigned NumOpcodes)
669   : TargetInstrInfo(desc, NumOpcodes) {}
670 public:
671   virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
672   virtual bool PredicateInstruction(MachineInstr *MI,
673                               const std::vector<MachineOperand> &Pred) const;
674   
675 };
676
677 } // End llvm namespace
678
679 #endif