Add a quick pass to optimize sign / zero extension instructions. For targets where...
[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 instruction set to the code generator.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETINSTRINFO_H
15 #define LLVM_TARGET_TARGETINSTRINFO_H
16
17 #include "llvm/Target/TargetInstrDesc.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19
20 namespace llvm {
21
22 class MCAsmInfo;
23 class TargetRegisterClass;
24 class TargetRegisterInfo;
25 class LiveVariables;
26 class CalleeSavedInfo;
27 class SDNode;
28 class SelectionDAG;
29 class MachineMemOperand;
30
31 template<class T> class SmallVectorImpl;
32
33
34 //---------------------------------------------------------------------------
35 ///
36 /// TargetInstrInfo - Interface to description of machine instruction set
37 ///
38 class TargetInstrInfo {
39   const TargetInstrDesc *Descriptors; // Raw array to allow static init'n
40   unsigned NumOpcodes;                // Number of entries in the desc array
41
42   TargetInstrInfo(const TargetInstrInfo &);  // DO NOT IMPLEMENT
43   void operator=(const TargetInstrInfo &);   // DO NOT IMPLEMENT
44 public:
45   TargetInstrInfo(const TargetInstrDesc *desc, unsigned NumOpcodes);
46   virtual ~TargetInstrInfo();
47
48   // Invariant opcodes: All instruction sets have these as their low opcodes.
49   enum { 
50     PHI = 0,
51     INLINEASM = 1,
52     DBG_LABEL = 2,
53     EH_LABEL = 3,
54     GC_LABEL = 4,
55
56     /// KILL - This instruction is a noop that is used only to adjust the liveness
57     /// of registers. This can be useful when dealing with sub-registers.
58     KILL = 5,
59
60     /// EXTRACT_SUBREG - This instruction takes two operands: a register
61     /// that has subregisters, and a subregister index. It returns the
62     /// extracted subregister value. This is commonly used to implement
63     /// truncation operations on target architectures which support it.
64     EXTRACT_SUBREG = 6,
65
66     /// INSERT_SUBREG - This instruction takes three operands: a register
67     /// that has subregisters, a register providing an insert value, and a
68     /// subregister index. It returns the value of the first register with
69     /// the value of the second register inserted. The first register is
70     /// often defined by an IMPLICIT_DEF, as is commonly used to implement
71     /// anyext operations on target architectures which support it.
72     INSERT_SUBREG = 7,
73
74     /// IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
75     IMPLICIT_DEF = 8,
76
77     /// SUBREG_TO_REG - This instruction is similar to INSERT_SUBREG except
78     /// that the first operand is an immediate integer constant. This constant
79     /// is often zero, as is commonly used to implement zext operations on
80     /// target architectures which support it, such as with x86-64 (with
81     /// zext from i32 to i64 via implicit zero-extension).
82     SUBREG_TO_REG = 9,
83
84     /// COPY_TO_REGCLASS - This instruction is a placeholder for a plain
85     /// register-to-register copy into a specific register class. This is only
86     /// used between instruction selection and MachineInstr creation, before
87     /// virtual registers have been created for all the instructions, and it's
88     /// only needed in cases where the register classes implied by the
89     /// instructions are insufficient. The actual MachineInstrs to perform
90     /// the copy are emitted with the TargetInstrInfo::copyRegToReg hook.
91     COPY_TO_REGCLASS = 10,
92
93     // DEBUG_VALUE - a mapping of the llvm.dbg.value intrinsic
94     DEBUG_VALUE = 11,
95
96     // DEBUG_DECLARE - a mapping of the llvm.dbg.declare intrinsic
97     DEBUG_DECLARE = 12
98   };
99
100   unsigned getNumOpcodes() const { return NumOpcodes; }
101
102   /// get - Return the machine instruction descriptor that corresponds to the
103   /// specified instruction opcode.
104   ///
105   const TargetInstrDesc &get(unsigned Opcode) const {
106     assert(Opcode < NumOpcodes && "Invalid opcode!");
107     return Descriptors[Opcode];
108   }
109
110   /// isTriviallyReMaterializable - Return true if the instruction is trivially
111   /// rematerializable, meaning it has no side effects and requires no operands
112   /// that aren't always available.
113   bool isTriviallyReMaterializable(const MachineInstr *MI,
114                                    AliasAnalysis *AA = 0) const {
115     return MI->getOpcode() == IMPLICIT_DEF ||
116            (MI->getDesc().isRematerializable() &&
117             (isReallyTriviallyReMaterializable(MI, AA) ||
118              isReallyTriviallyReMaterializableGeneric(MI, AA)));
119   }
120
121 protected:
122   /// isReallyTriviallyReMaterializable - For instructions with opcodes for
123   /// which the M_REMATERIALIZABLE flag is set, this hook lets the target
124   /// specify whether the instruction is actually trivially rematerializable,
125   /// taking into consideration its operands. This predicate must return false
126   /// if the instruction has any side effects other than producing a value, or
127   /// if it requres any address registers that are not always available.
128   virtual bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
129                                                  AliasAnalysis *AA) const {
130     return false;
131   }
132
133 private:
134   /// isReallyTriviallyReMaterializableGeneric - For instructions with opcodes
135   /// for which the M_REMATERIALIZABLE flag is set and the target hook
136   /// isReallyTriviallyReMaterializable returns false, this function does
137   /// target-independent tests to determine if the instruction is really
138   /// trivially rematerializable.
139   bool isReallyTriviallyReMaterializableGeneric(const MachineInstr *MI,
140                                                 AliasAnalysis *AA) const;
141
142 public:
143   /// isMoveInstr - Return true if the instruction is a register to register
144   /// move and return the source and dest operands and their sub-register
145   /// indices by reference.
146   virtual bool isMoveInstr(const MachineInstr& MI,
147                            unsigned& SrcReg, unsigned& DstReg,
148                            unsigned& SrcSubIdx, unsigned& DstSubIdx) const {
149     return false;
150   }
151
152   /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
153   /// extension instruction. That is, it's like a copy where it's legal for the
154   /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
155   /// true, then it's expected the pre-extension value is available as a subreg
156   /// of the result register. This also returns the sub-register index in
157   /// SubIdx.
158   virtual bool isCoalescableExtInstr(const MachineInstr &MI,
159                                      unsigned &SrcReg, unsigned &DstReg,
160                                      unsigned &SubIdx) const {
161     return false;
162   }
163
164   /// isIdentityCopy - Return true if the instruction is a copy (or
165   /// extract_subreg, insert_subreg, subreg_to_reg) where the source and
166   /// destination registers are the same.
167   bool isIdentityCopy(const MachineInstr &MI) const {
168     unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
169     if (isMoveInstr(MI, SrcReg, DstReg, SrcSubIdx, DstSubIdx) &&
170         SrcReg == DstReg)
171       return true;
172
173     if (MI.getOpcode() == TargetInstrInfo::EXTRACT_SUBREG &&
174         MI.getOperand(0).getReg() == MI.getOperand(1).getReg())
175     return true;
176
177     if ((MI.getOpcode() == TargetInstrInfo::INSERT_SUBREG ||
178          MI.getOpcode() == TargetInstrInfo::SUBREG_TO_REG) &&
179         MI.getOperand(0).getReg() == MI.getOperand(2).getReg())
180       return true;
181     return false;
182   }
183   
184   /// isLoadFromStackSlot - If the specified machine instruction is a direct
185   /// load from a stack slot, return the virtual or physical register number of
186   /// the destination along with the FrameIndex of the loaded stack slot.  If
187   /// not, return 0.  This predicate must return 0 if the instruction has
188   /// any side effects other than loading from the stack slot.
189   virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
190                                        int &FrameIndex) const {
191     return 0;
192   }
193
194   /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
195   /// stack locations as well.  This uses a heuristic so it isn't
196   /// reliable for correctness.
197   virtual unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
198                                              int &FrameIndex) const {
199     return 0;
200   }
201
202   /// hasLoadFromStackSlot - If the specified machine instruction has
203   /// a load from a stack slot, return true along with the FrameIndex
204   /// of the loaded stack slot and the machine mem operand containing
205   /// the reference.  If not, return false.  Unlike
206   /// isLoadFromStackSlot, this returns true for any instructions that
207   /// loads from the stack.  This is just a hint, as some cases may be
208   /// missed.
209   virtual bool hasLoadFromStackSlot(const MachineInstr *MI,
210                                     const MachineMemOperand *&MMO,
211                                     int &FrameIndex) const {
212     return 0;
213   }
214   
215   /// isStoreToStackSlot - If the specified machine instruction is a direct
216   /// store to a stack slot, return the virtual or physical register number of
217   /// the source reg along with the FrameIndex of the loaded stack slot.  If
218   /// not, return 0.  This predicate must return 0 if the instruction has
219   /// any side effects other than storing to the stack slot.
220   virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
221                                       int &FrameIndex) const {
222     return 0;
223   }
224
225   /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
226   /// stack locations as well.  This uses a heuristic so it isn't
227   /// reliable for correctness.
228   virtual unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
229                                             int &FrameIndex) const {
230     return 0;
231   }
232
233   /// hasStoreToStackSlot - If the specified machine instruction has a
234   /// store to a stack slot, return true along with the FrameIndex of
235   /// the loaded stack slot and the machine mem operand containing the
236   /// reference.  If not, return false.  Unlike isStoreToStackSlot,
237   /// this returns true for any instructions that loads from the
238   /// stack.  This is just a hint, as some cases may be missed.
239   virtual bool hasStoreToStackSlot(const MachineInstr *MI,
240                                    const MachineMemOperand *&MMO,
241                                    int &FrameIndex) const {
242     return 0;
243   }
244
245   /// reMaterialize - Re-issue the specified 'original' instruction at the
246   /// specific location targeting a new destination register.
247   virtual void reMaterialize(MachineBasicBlock &MBB,
248                              MachineBasicBlock::iterator MI,
249                              unsigned DestReg, unsigned SubIdx,
250                              const MachineInstr *Orig,
251                              const TargetRegisterInfo *TRI) const = 0;
252
253   /// duplicate - Create a duplicate of the Orig instruction in MF. This is like
254   /// MachineFunction::CloneMachineInstr(), but the target may update operands
255   /// that are required to be unique.
256   ///
257   /// The instruction must be duplicable as indicated by isNotDuplicable().
258   virtual MachineInstr *duplicate(MachineInstr *Orig,
259                                   MachineFunction &MF) const = 0;
260
261   /// convertToThreeAddress - This method must be implemented by targets that
262   /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
263   /// may be able to convert a two-address instruction into one or more true
264   /// three-address instructions on demand.  This allows the X86 target (for
265   /// example) to convert ADD and SHL instructions into LEA instructions if they
266   /// would require register copies due to two-addressness.
267   ///
268   /// This method returns a null pointer if the transformation cannot be
269   /// performed, otherwise it returns the last new instruction.
270   ///
271   virtual MachineInstr *
272   convertToThreeAddress(MachineFunction::iterator &MFI,
273                    MachineBasicBlock::iterator &MBBI, LiveVariables *LV) const {
274     return 0;
275   }
276
277   /// commuteInstruction - If a target has any instructions that are commutable,
278   /// but require converting to a different instruction or making non-trivial
279   /// changes to commute them, this method can overloaded to do this.  The
280   /// default implementation of this method simply swaps the first two operands
281   /// of MI and returns it.
282   ///
283   /// If a target wants to make more aggressive changes, they can construct and
284   /// return a new machine instruction.  If an instruction cannot commute, it
285   /// can also return null.
286   ///
287   /// If NewMI is true, then a new machine instruction must be created.
288   ///
289   virtual MachineInstr *commuteInstruction(MachineInstr *MI,
290                                            bool NewMI = false) const = 0;
291
292   /// findCommutedOpIndices - If specified MI is commutable, return the two
293   /// operand indices that would swap value. Return true if the instruction
294   /// is not in a form which this routine understands.
295   virtual bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
296                                      unsigned &SrcOpIdx2) const = 0;
297
298   /// isIdentical - Return true if two instructions are identical. This differs
299   /// from MachineInstr::isIdenticalTo() in that it does not require the
300   /// virtual destination registers to be the same. This is used by MachineLICM
301   /// and other MI passes to perform CSE.
302   virtual bool isIdentical(const MachineInstr *MI,
303                            const MachineInstr *Other,
304                            const MachineRegisterInfo *MRI) const = 0;
305
306   /// AnalyzeBranch - Analyze the branching code at the end of MBB, returning
307   /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
308   /// implemented for a target).  Upon success, this returns false and returns
309   /// with the following information in various cases:
310   ///
311   /// 1. If this block ends with no branches (it just falls through to its succ)
312   ///    just return false, leaving TBB/FBB null.
313   /// 2. If this block ends with only an unconditional branch, it sets TBB to be
314   ///    the destination block.
315   /// 3. If this block ends with a conditional branch and it falls through to a
316   ///    successor block, it sets TBB to be the branch destination block and a
317   ///    list of operands that evaluate the condition. These operands can be
318   ///    passed to other TargetInstrInfo methods to create new branches.
319   /// 4. If this block ends with a conditional branch followed by an
320   ///    unconditional branch, it returns the 'true' destination in TBB, the
321   ///    'false' destination in FBB, and a list of operands that evaluate the
322   ///    condition.  These operands can be passed to other TargetInstrInfo
323   ///    methods to create new branches.
324   ///
325   /// Note that RemoveBranch and InsertBranch must be implemented to support
326   /// cases where this method returns success.
327   ///
328   /// If AllowModify is true, then this routine is allowed to modify the basic
329   /// block (e.g. delete instructions after the unconditional branch).
330   ///
331   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
332                              MachineBasicBlock *&FBB,
333                              SmallVectorImpl<MachineOperand> &Cond,
334                              bool AllowModify = false) const {
335     return true;
336   }
337
338   /// RemoveBranch - Remove the branching code at the end of the specific MBB.
339   /// This is only invoked in cases where AnalyzeBranch returns success. It
340   /// returns the number of instructions that were removed.
341   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const {
342     assert(0 && "Target didn't implement TargetInstrInfo::RemoveBranch!"); 
343     return 0;
344   }
345
346   /// InsertBranch - Insert branch code into the end of the specified
347   /// MachineBasicBlock.  The operands to this method are the same as those
348   /// returned by AnalyzeBranch.  This is only invoked in cases where
349   /// AnalyzeBranch returns success. It returns the number of instructions
350   /// inserted.
351   ///
352   /// It is also invoked by tail merging to add unconditional branches in
353   /// cases where AnalyzeBranch doesn't apply because there was no original
354   /// branch to analyze.  At least this much must be implemented, else tail
355   /// merging needs to be disabled.
356   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
357                             MachineBasicBlock *FBB,
358                             const SmallVectorImpl<MachineOperand> &Cond) const {
359     assert(0 && "Target didn't implement TargetInstrInfo::InsertBranch!"); 
360     return 0;
361   }
362   
363   /// copyRegToReg - Emit instructions to copy between a pair of registers. It
364   /// returns false if the target does not how to copy between the specified
365   /// registers.
366   virtual bool copyRegToReg(MachineBasicBlock &MBB,
367                             MachineBasicBlock::iterator MI,
368                             unsigned DestReg, unsigned SrcReg,
369                             const TargetRegisterClass *DestRC,
370                             const TargetRegisterClass *SrcRC) const {
371     assert(0 && "Target didn't implement TargetInstrInfo::copyRegToReg!");
372     return false;
373   }
374   
375   /// storeRegToStackSlot - Store the specified register of the given register
376   /// class to the specified stack frame index. The store instruction is to be
377   /// added to the given machine basic block before the specified machine
378   /// instruction. If isKill is true, the register operand is the last use and
379   /// must be marked kill.
380   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
381                                    MachineBasicBlock::iterator MI,
382                                    unsigned SrcReg, bool isKill, int FrameIndex,
383                                    const TargetRegisterClass *RC) const {
384     assert(0 && "Target didn't implement TargetInstrInfo::storeRegToStackSlot!");
385   }
386
387   /// loadRegFromStackSlot - Load the specified register of the given register
388   /// class from the specified stack frame index. The load instruction is to be
389   /// added to the given machine basic block before the specified machine
390   /// instruction.
391   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
392                                     MachineBasicBlock::iterator MI,
393                                     unsigned DestReg, int FrameIndex,
394                                     const TargetRegisterClass *RC) const {
395     assert(0 && "Target didn't implement TargetInstrInfo::loadRegFromStackSlot!");
396   }
397   
398   /// spillCalleeSavedRegisters - Issues instruction(s) to spill all callee
399   /// saved registers and returns true if it isn't possible / profitable to do
400   /// so by issuing a series of store instructions via
401   /// storeRegToStackSlot(). Returns false otherwise.
402   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
403                                          MachineBasicBlock::iterator MI,
404                                 const std::vector<CalleeSavedInfo> &CSI) const {
405     return false;
406   }
407
408   /// restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee
409   /// saved registers and returns true if it isn't possible / profitable to do
410   /// so by issuing a series of load instructions via loadRegToStackSlot().
411   /// Returns false otherwise.
412   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
413                                            MachineBasicBlock::iterator MI,
414                                 const std::vector<CalleeSavedInfo> &CSI) const {
415     return false;
416   }
417   
418   /// foldMemoryOperand - Attempt to fold a load or store of the specified stack
419   /// slot into the specified machine instruction for the specified operand(s).
420   /// If this is possible, a new instruction is returned with the specified
421   /// operand folded, otherwise NULL is returned. The client is responsible for
422   /// removing the old instruction and adding the new one in the instruction
423   /// stream.
424   MachineInstr* foldMemoryOperand(MachineFunction &MF,
425                                   MachineInstr* MI,
426                                   const SmallVectorImpl<unsigned> &Ops,
427                                   int FrameIndex) const;
428
429   /// foldMemoryOperand - Same as the previous version except it allows folding
430   /// of any load and store from / to any address, not just from a specific
431   /// stack slot.
432   MachineInstr* foldMemoryOperand(MachineFunction &MF,
433                                   MachineInstr* MI,
434                                   const SmallVectorImpl<unsigned> &Ops,
435                                   MachineInstr* LoadMI) const;
436
437 protected:
438   /// foldMemoryOperandImpl - Target-dependent implementation for
439   /// foldMemoryOperand. Target-independent code in foldMemoryOperand will
440   /// take care of adding a MachineMemOperand to the newly created instruction.
441   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
442                                           MachineInstr* MI,
443                                           const SmallVectorImpl<unsigned> &Ops,
444                                           int FrameIndex) const {
445     return 0;
446   }
447
448   /// foldMemoryOperandImpl - Target-dependent implementation for
449   /// foldMemoryOperand. Target-independent code in foldMemoryOperand will
450   /// take care of adding a MachineMemOperand to the newly created instruction.
451   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
452                                               MachineInstr* MI,
453                                               const SmallVectorImpl<unsigned> &Ops,
454                                               MachineInstr* LoadMI) const {
455     return 0;
456   }
457
458 public:
459   /// canFoldMemoryOperand - Returns true for the specified load / store if
460   /// folding is possible.
461   virtual
462   bool canFoldMemoryOperand(const MachineInstr *MI,
463                             const SmallVectorImpl<unsigned> &Ops) const {
464     return false;
465   }
466
467   /// unfoldMemoryOperand - Separate a single instruction which folded a load or
468   /// a store or a load and a store into two or more instruction. If this is
469   /// possible, returns true as well as the new instructions by reference.
470   virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
471                                 unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
472                                  SmallVectorImpl<MachineInstr*> &NewMIs) const{
473     return false;
474   }
475
476   virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
477                                    SmallVectorImpl<SDNode*> &NewNodes) const {
478     return false;
479   }
480
481   /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
482   /// instruction after load / store are unfolded from an instruction of the
483   /// specified opcode. It returns zero if the specified unfolding is not
484   /// possible. If LoadRegIndex is non-null, it is filled in with the operand
485   /// index of the operand which will hold the register holding the loaded
486   /// value.
487   virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
488                                       bool UnfoldLoad, bool UnfoldStore,
489                                       unsigned *LoadRegIndex = 0) const {
490     return 0;
491   }
492   
493   /// ReverseBranchCondition - Reverses the branch condition of the specified
494   /// condition list, returning false on success and true if it cannot be
495   /// reversed.
496   virtual
497   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
498     return true;
499   }
500   
501   /// insertNoop - Insert a noop into the instruction stream at the specified
502   /// point.
503   virtual void insertNoop(MachineBasicBlock &MBB, 
504                           MachineBasicBlock::iterator MI) const;
505   
506   /// isPredicated - Returns true if the instruction is already predicated.
507   ///
508   virtual bool isPredicated(const MachineInstr *MI) const {
509     return false;
510   }
511
512   /// isUnpredicatedTerminator - Returns true if the instruction is a
513   /// terminator instruction that has not been predicated.
514   virtual bool isUnpredicatedTerminator(const MachineInstr *MI) const;
515
516   /// PredicateInstruction - Convert the instruction into a predicated
517   /// instruction. It returns true if the operation was successful.
518   virtual
519   bool PredicateInstruction(MachineInstr *MI,
520                         const SmallVectorImpl<MachineOperand> &Pred) const = 0;
521
522   /// SubsumesPredicate - Returns true if the first specified predicate
523   /// subsumes the second, e.g. GE subsumes GT.
524   virtual
525   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
526                          const SmallVectorImpl<MachineOperand> &Pred2) const {
527     return false;
528   }
529
530   /// DefinesPredicate - If the specified instruction defines any predicate
531   /// or condition code register(s) used for predication, returns true as well
532   /// as the definition predicate(s) by reference.
533   virtual bool DefinesPredicate(MachineInstr *MI,
534                                 std::vector<MachineOperand> &Pred) const {
535     return false;
536   }
537
538   /// isPredicable - Return true if the specified instruction can be predicated.
539   /// By default, this returns true for every instruction with a
540   /// PredicateOperand.
541   virtual bool isPredicable(MachineInstr *MI) const {
542     return MI->getDesc().isPredicable();
543   }
544
545   /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
546   /// instruction that defines the specified register class.
547   virtual bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
548     return true;
549   }
550
551   /// GetInstSize - Returns the size of the specified Instruction.
552   /// 
553   virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const {
554     assert(0 && "Target didn't implement TargetInstrInfo::GetInstSize!");
555     return 0;
556   }
557
558   /// GetFunctionSizeInBytes - Returns the size of the specified
559   /// MachineFunction.
560   /// 
561   virtual unsigned GetFunctionSizeInBytes(const MachineFunction &MF) const = 0;
562   
563   /// Measure the specified inline asm to determine an approximation of its
564   /// length.
565   virtual unsigned getInlineAsmLength(const char *Str,
566                                       const MCAsmInfo &MAI) const;
567 };
568
569 /// TargetInstrInfoImpl - This is the default implementation of
570 /// TargetInstrInfo, which just provides a couple of default implementations
571 /// for various methods.  This separated out because it is implemented in
572 /// libcodegen, not in libtarget.
573 class TargetInstrInfoImpl : public TargetInstrInfo {
574 protected:
575   TargetInstrInfoImpl(const TargetInstrDesc *desc, unsigned NumOpcodes)
576   : TargetInstrInfo(desc, NumOpcodes) {}
577 public:
578   virtual MachineInstr *commuteInstruction(MachineInstr *MI,
579                                            bool NewMI = false) const;
580   virtual bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
581                                      unsigned &SrcOpIdx2) const;
582   virtual bool PredicateInstruction(MachineInstr *MI,
583                             const SmallVectorImpl<MachineOperand> &Pred) const;
584   virtual void reMaterialize(MachineBasicBlock &MBB,
585                              MachineBasicBlock::iterator MI,
586                              unsigned DestReg, unsigned SubReg,
587                              const MachineInstr *Orig,
588                              const TargetRegisterInfo *TRI) const;
589   virtual MachineInstr *duplicate(MachineInstr *Orig,
590                                   MachineFunction &MF) const;
591   virtual bool isIdentical(const MachineInstr *MI,
592                            const MachineInstr *Other,
593                            const MachineRegisterInfo *MRI) const;
594
595   virtual unsigned GetFunctionSizeInBytes(const MachineFunction &MF) const;
596 };
597
598 } // End llvm namespace
599
600 #endif