AMDGPU: Add core backend files for R600/SI codegen v6
[oota-llvm.git] / lib / Target / AMDGPU / SIInstrInfo.cpp
1 //===-- SIInstrInfo.cpp - SI Instruction Information  ---------------------===//
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 // SI Implementation of TargetInstrInfo.
11 //
12 //===----------------------------------------------------------------------===//
13
14
15 #include "SIInstrInfo.h"
16 #include "AMDGPUTargetMachine.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/MC/MCInstrDesc.h"
19
20 #include <stdio.h>
21
22 using namespace llvm;
23
24 SIInstrInfo::SIInstrInfo(AMDGPUTargetMachine &tm)
25   : AMDGPUInstrInfo(tm),
26     RI(tm, *this)
27     { }
28
29 const SIRegisterInfo &SIInstrInfo::getRegisterInfo() const
30 {
31   return RI;
32 }
33
34 void
35 SIInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
36                            MachineBasicBlock::iterator MI, DebugLoc DL,
37                            unsigned DestReg, unsigned SrcReg,
38                            bool KillSrc) const
39 {
40   BuildMI(MBB, MI, DL, get(AMDGPU::V_MOV_B32_e32), DestReg)
41    .addReg(SrcReg, getKillRegState(KillSrc));
42 }
43
44 unsigned SIInstrInfo::getEncodingType(const MachineInstr &MI) const
45 {
46   return get(MI.getOpcode()).TSFlags & SI_INSTR_FLAGS_ENCODING_MASK;
47 }
48
49 unsigned SIInstrInfo::getEncodingBytes(const MachineInstr &MI) const
50 {
51
52   /* Instructions with literal constants are expanded to 64-bits, and
53    * the constant is stored in bits [63:32] */
54   for (unsigned i = 0; i < MI.getNumOperands(); i++) {
55     if (MI.getOperand(i).getType() == MachineOperand::MO_FPImmediate) {
56       return 8;
57     }
58   }
59
60   /* This instruction always has a literal */
61   if (MI.getOpcode() == AMDGPU::S_MOV_IMM_I32) {
62     return 8;
63   }
64
65   unsigned encoding_type = getEncodingType(MI);
66   switch (encoding_type) {
67     case SIInstrEncodingType::EXP:
68     case SIInstrEncodingType::LDS:
69     case SIInstrEncodingType::MUBUF:
70     case SIInstrEncodingType::MTBUF:
71     case SIInstrEncodingType::MIMG:
72     case SIInstrEncodingType::VOP3:
73       return 8;
74     default:
75       return 4;
76   }
77 }
78
79 MachineInstr * SIInstrInfo::getMovImmInstr(MachineFunction *MF, unsigned DstReg,
80                                            int64_t Imm) const
81 {
82   MachineInstr * MI = MF->CreateMachineInstr(get(AMDGPU::V_MOV_IMM_I32), DebugLoc());
83   MachineInstrBuilder(MI).addReg(DstReg, RegState::Define);
84   MachineInstrBuilder(MI).addImm(Imm);
85
86   return MI;
87
88 }
89
90 bool SIInstrInfo::isMov(unsigned Opcode) const
91 {
92   switch(Opcode) {
93   default: return false;
94   case AMDGPU::S_MOV_B32:
95   case AMDGPU::S_MOV_B64:
96   case AMDGPU::V_MOV_B32_e32:
97   case AMDGPU::V_MOV_B32_e64:
98   case AMDGPU::V_MOV_IMM_F32:
99   case AMDGPU::V_MOV_IMM_I32:
100   case AMDGPU::S_MOV_IMM_I32:
101     return true;
102   }
103 }