7bbdfada12c793d3ff32e074c923d0b2bdfb4aec
[oota-llvm.git] / lib / Target / CellSPU / SPUInstrInfo.h
1 //===- SPUInstrInfo.h - Cell SPU Instruction Information --------*- 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 contains the CellSPU implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SPU_INSTRUCTIONINFO_H
15 #define SPU_INSTRUCTIONINFO_H
16
17 #include "SPU.h"
18 #include "llvm/Target/TargetInstrInfo.h"
19 #include "SPURegisterInfo.h"
20
21 namespace llvm {
22   //! Cell SPU instruction information class
23   class SPUInstrInfo : public TargetInstrInfoImpl {
24     SPUTargetMachine &TM;
25     const SPURegisterInfo RI;
26   protected:
27     virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
28                                             MachineInstr* MI,
29                                             const SmallVectorImpl<unsigned> &Ops,
30                                             int FrameIndex) const;
31
32     virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
33                                                 MachineInstr* MI,
34                                                 const SmallVectorImpl<unsigned> &Ops,
35                                                 MachineInstr* LoadMI) const {
36       return 0;
37     }
38
39   public:
40     explicit SPUInstrInfo(SPUTargetMachine &tm);
41
42     /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
43     /// such, whenever a client has an instance of instruction info, it should
44     /// always be able to get register info as well (through this method).
45     ///
46     virtual const SPURegisterInfo &getRegisterInfo() const { return RI; }
47
48     /// getPointerRegClass - Return the register class to use to hold pointers.
49     /// This is used for addressing modes.
50     virtual const TargetRegisterClass *getPointerRegClass() const;
51
52     /// Return true if the instruction is a register to register move and return
53     /// the source and dest operands and their sub-register indices by reference.
54     virtual bool isMoveInstr(const MachineInstr &MI,
55                              unsigned &SrcReg, unsigned &DstReg,
56                              unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
57
58     unsigned isLoadFromStackSlot(const MachineInstr *MI,
59                                  int &FrameIndex) const;
60     unsigned isStoreToStackSlot(const MachineInstr *MI,
61                                 int &FrameIndex) const;
62
63     virtual bool copyRegToReg(MachineBasicBlock &MBB,
64                               MachineBasicBlock::iterator MI,
65                               unsigned DestReg, unsigned SrcReg,
66                               const TargetRegisterClass *DestRC,
67                               const TargetRegisterClass *SrcRC) const;
68
69     //! Store a register to a stack slot, based on its register class.
70     virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
71                                      MachineBasicBlock::iterator MBBI,
72                                      unsigned SrcReg, bool isKill, int FrameIndex,
73                                      const TargetRegisterClass *RC) const;
74
75     //! Store a register to an address, based on its register class
76     virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
77                                                   SmallVectorImpl<MachineOperand> &Addr,
78                                                   const TargetRegisterClass *RC,
79                                                   SmallVectorImpl<MachineInstr*> &NewMIs) const;
80
81     //! Load a register from a stack slot, based on its register class.
82     virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
83                                       MachineBasicBlock::iterator MBBI,
84                                       unsigned DestReg, int FrameIndex,
85                                       const TargetRegisterClass *RC) const;
86
87     //! Loqad a register from an address, based on its register class
88     virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
89                                                          SmallVectorImpl<MachineOperand> &Addr,
90                                                          const TargetRegisterClass *RC,
91                                  SmallVectorImpl<MachineInstr*> &NewMIs) const;
92
93     //! Return true if the specified load or store can be folded
94     virtual
95     bool canFoldMemoryOperand(const MachineInstr *MI,
96                               const SmallVectorImpl<unsigned> &Ops) const;
97
98     //! Return true if the specified block does not fall through
99     virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
100
101     //! Reverses a branch's condition, returning false on success.
102     virtual
103     bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
104
105     virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
106                                MachineBasicBlock *&FBB,
107                                SmallVectorImpl<MachineOperand> &Cond) const;
108
109     virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
110
111     virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
112                               MachineBasicBlock *FBB,
113                               const SmallVectorImpl<MachineOperand> &Cond) const;
114    };
115 }
116
117 #endif