1 //===-- SIInstrInfo.cpp - SI Instruction Information ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // SI Implementation of TargetInstrInfo.
12 //===----------------------------------------------------------------------===//
15 #include "SIInstrInfo.h"
16 #include "AMDGPUTargetMachine.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/MC/MCInstrDesc.h"
24 SIInstrInfo::SIInstrInfo(AMDGPUTargetMachine &tm)
25 : AMDGPUInstrInfo(tm),
29 const SIRegisterInfo &SIInstrInfo::getRegisterInfo() const
35 SIInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
36 MachineBasicBlock::iterator MI, DebugLoc DL,
37 unsigned DestReg, unsigned SrcReg,
40 BuildMI(MBB, MI, DL, get(AMDGPU::V_MOV_B32_e32), DestReg)
41 .addReg(SrcReg, getKillRegState(KillSrc));
44 unsigned SIInstrInfo::getEncodingType(const MachineInstr &MI) const
46 return get(MI.getOpcode()).TSFlags & SI_INSTR_FLAGS_ENCODING_MASK;
49 unsigned SIInstrInfo::getEncodingBytes(const MachineInstr &MI) const
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) {
60 /* This instruction always has a literal */
61 if (MI.getOpcode() == AMDGPU::S_MOV_IMM_I32) {
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:
79 MachineInstr * SIInstrInfo::getMovImmInstr(MachineFunction *MF, unsigned DstReg,
82 MachineInstr * MI = MF->CreateMachineInstr(get(AMDGPU::V_MOV_IMM_I32), DebugLoc());
83 MachineInstrBuilder(MI).addReg(DstReg, RegState::Define);
84 MachineInstrBuilder(MI).addImm(Imm);
90 bool SIInstrInfo::isMov(unsigned Opcode) const
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: