blob: adcffa8bbdb1268d5ce08ce9a84b13605fd3c974 [file] [log] [blame]
Tom Stellardf98f2ce2012-12-11 21:25:42 +00001//===-- 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/// \file
11/// \brief SI Implementation of TargetInstrInfo.
12//
13//===----------------------------------------------------------------------===//
14
15
16#include "SIInstrInfo.h"
17#include "AMDGPUTargetMachine.h"
18#include "llvm/CodeGen/MachineInstrBuilder.h"
19#include "llvm/CodeGen/MachineRegisterInfo.h"
20#include "llvm/MC/MCInstrDesc.h"
21
22#include <stdio.h>
23
24using namespace llvm;
25
26SIInstrInfo::SIInstrInfo(AMDGPUTargetMachine &tm)
27 : AMDGPUInstrInfo(tm),
28 RI(tm, *this)
29 { }
30
31const SIRegisterInfo &SIInstrInfo::getRegisterInfo() const {
32 return RI;
33}
34
35void
36SIInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
37 MachineBasicBlock::iterator MI, DebugLoc DL,
38 unsigned DestReg, unsigned SrcReg,
39 bool KillSrc) const {
40 // If we are trying to copy to or from SCC, there is a bug somewhere else in
41 // the backend. While it may be theoretically possible to do this, it should
42 // never be necessary.
43 assert(DestReg != AMDGPU::SCC && SrcReg != AMDGPU::SCC);
44
45 if (AMDGPU::SReg_64RegClass.contains(DestReg)) {
46 assert(AMDGPU::SReg_64RegClass.contains(SrcReg));
47 BuildMI(MBB, MI, DL, get(AMDGPU::S_MOV_B64), DestReg)
48 .addReg(SrcReg, getKillRegState(KillSrc));
49 } else if (AMDGPU::VReg_32RegClass.contains(DestReg)) {
50 assert(AMDGPU::VReg_32RegClass.contains(SrcReg) ||
51 AMDGPU::SReg_32RegClass.contains(SrcReg));
52 BuildMI(MBB, MI, DL, get(AMDGPU::V_MOV_B32_e32), DestReg)
53 .addReg(SrcReg, getKillRegState(KillSrc));
54 } else {
55 assert(AMDGPU::SReg_32RegClass.contains(DestReg));
56 assert(AMDGPU::SReg_32RegClass.contains(SrcReg));
57 BuildMI(MBB, MI, DL, get(AMDGPU::S_MOV_B32), DestReg)
58 .addReg(SrcReg, getKillRegState(KillSrc));
59 }
60}
61
62MachineInstr * SIInstrInfo::getMovImmInstr(MachineFunction *MF, unsigned DstReg,
63 int64_t Imm) const {
64 MachineInstr * MI = MF->CreateMachineInstr(get(AMDGPU::V_MOV_IMM_I32), DebugLoc());
NAKAMURA Takumi6b207d32012-12-20 00:22:11 +000065 MachineInstrBuilder MIB(*MF, MI);
66 MIB.addReg(DstReg, RegState::Define);
67 MIB.addImm(Imm);
Tom Stellardf98f2ce2012-12-11 21:25:42 +000068
69 return MI;
70
71}
72
73bool SIInstrInfo::isMov(unsigned Opcode) const {
74 switch(Opcode) {
75 default: return false;
76 case AMDGPU::S_MOV_B32:
77 case AMDGPU::S_MOV_B64:
78 case AMDGPU::V_MOV_B32_e32:
79 case AMDGPU::V_MOV_B32_e64:
80 case AMDGPU::V_MOV_IMM_F32:
81 case AMDGPU::V_MOV_IMM_I32:
82 case AMDGPU::S_MOV_IMM_I32:
83 return true;
84 }
85}
86
87bool
88SIInstrInfo::isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const {
89 return RC != &AMDGPU::EXECRegRegClass;
90}