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