Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 1 | //===- PTXInstrInfo.h - PTX 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 PTX implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef PTX_INSTR_INFO_H |
| 15 | #define PTX_INSTR_INFO_H |
| 16 | |
| 17 | #include "PTXRegisterInfo.h" |
| 18 | #include "llvm/Target/TargetInstrInfo.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | class PTXTargetMachine; |
| 22 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 23 | class MachineSDNode; |
| 24 | class SDValue; |
| 25 | class SelectionDAG; |
| 26 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 27 | class PTXInstrInfo : public TargetInstrInfoImpl { |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 28 | private: |
| 29 | const PTXRegisterInfo RI; |
| 30 | PTXTargetMachine &TM; |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 31 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 32 | public: |
| 33 | explicit PTXInstrInfo(PTXTargetMachine &_TM); |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 34 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 35 | virtual const PTXRegisterInfo &getRegisterInfo() const { return RI; } |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 36 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 37 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 38 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 39 | unsigned DstReg, unsigned SrcReg, |
| 40 | bool KillSrc) const; |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 41 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 42 | virtual bool copyRegToReg(MachineBasicBlock &MBB, |
| 43 | MachineBasicBlock::iterator I, |
| 44 | unsigned DstReg, unsigned SrcReg, |
| 45 | const TargetRegisterClass *DstRC, |
| 46 | const TargetRegisterClass *SrcRC, |
| 47 | DebugLoc DL) const; |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 48 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 49 | virtual bool isMoveInstr(const MachineInstr& MI, |
| 50 | unsigned &SrcReg, unsigned &DstReg, |
| 51 | unsigned &SrcSubIdx, unsigned &DstSubIdx) const; |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 52 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 53 | // predicate support |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 54 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 55 | virtual bool isPredicated(const MachineInstr *MI) const; |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 56 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 57 | virtual bool isUnpredicatedTerminator(const MachineInstr *MI) const; |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 58 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 59 | virtual |
| 60 | bool PredicateInstruction(MachineInstr *MI, |
| 61 | const SmallVectorImpl<MachineOperand> &Pred) const; |
| 62 | |
| 63 | virtual |
| 64 | bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1, |
| 65 | const SmallVectorImpl<MachineOperand> &Pred2) const; |
| 66 | |
| 67 | virtual bool DefinesPredicate(MachineInstr *MI, |
| 68 | std::vector<MachineOperand> &Pred) const; |
| 69 | |
| 70 | // PTX is fully-predicable |
| 71 | virtual bool isPredicable(MachineInstr *MI) const { return true; } |
| 72 | |
Che-Liang Chiou | 5e0872e | 2011-03-22 14:12:00 +0000 | [diff] [blame] | 73 | // branch support |
| 74 | |
| 75 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 76 | MachineBasicBlock *&FBB, |
| 77 | SmallVectorImpl<MachineOperand> &Cond, |
| 78 | bool AllowModify = false) const; |
| 79 | |
| 80 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 81 | |
| 82 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 83 | MachineBasicBlock *FBB, |
| 84 | const SmallVectorImpl<MachineOperand> &Cond, |
| 85 | DebugLoc DL) const; |
| 86 | |
Justin Holewinski | df1c8d8 | 2011-06-20 15:56:20 +0000 | [diff] [blame^] | 87 | // Memory operand folding for spills |
| 88 | // TODO: Implement this eventually and get rid of storeRegToStackSlot and |
| 89 | // loadRegFromStackSlot. Doing so will get rid of the "stack" registers |
| 90 | // we currently use to spill, though I doubt the overall effect on ptxas |
| 91 | // output will be large. I have yet to see a case where ptxas is unable |
| 92 | // to see through the "stack" register usage and hence generates |
| 93 | // efficient code anyway. |
| 94 | // virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF, |
| 95 | // MachineInstr* MI, |
| 96 | // const SmallVectorImpl<unsigned> &Ops, |
| 97 | // int FrameIndex) const; |
| 98 | |
| 99 | virtual void storeRegToStackSlot(MachineBasicBlock& MBB, |
| 100 | MachineBasicBlock::iterator MII, |
| 101 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 102 | const TargetRegisterClass* RC, |
| 103 | const TargetRegisterInfo* TRI) const; |
| 104 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 105 | MachineBasicBlock::iterator MII, |
| 106 | unsigned DestReg, int FrameIdx, |
| 107 | const TargetRegisterClass *RC, |
| 108 | const TargetRegisterInfo *TRI) const; |
| 109 | |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 110 | // static helper routines |
| 111 | |
| 112 | static MachineSDNode *GetPTXMachineNode(SelectionDAG *DAG, unsigned Opcode, |
| 113 | DebugLoc dl, EVT VT, |
| 114 | SDValue Op1); |
| 115 | |
| 116 | static MachineSDNode *GetPTXMachineNode(SelectionDAG *DAG, unsigned Opcode, |
| 117 | DebugLoc dl, EVT VT, |
| 118 | SDValue Op1, SDValue Op2); |
| 119 | |
| 120 | static void AddDefaultPredicate(MachineInstr *MI); |
Che-Liang Chiou | 5e0872e | 2011-03-22 14:12:00 +0000 | [diff] [blame] | 121 | |
| 122 | static bool IsAnyKindOfBranch(const MachineInstr& inst); |
| 123 | |
| 124 | static bool IsAnySuccessorAlsoLayoutSuccessor(const MachineBasicBlock& MBB); |
| 125 | |
| 126 | static MachineBasicBlock *GetBranchTarget(const MachineInstr& inst); |
Che-Liang Chiou | c2ec0f9 | 2011-03-13 17:26:00 +0000 | [diff] [blame] | 127 | }; // class PTXInstrInfo |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 128 | } // namespace llvm |
| 129 | |
| 130 | #endif // PTX_INSTR_INFO_H |