1 //===-- AMDGPUUtil.cpp - AMDGPU Utility functions -------------------------===//
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 // Common utility functions used by hw codegen targets
12 //===----------------------------------------------------------------------===//
14 #include "AMDGPUUtil.h"
15 #include "AMDGPURegisterInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/CodeGen/MachineRegisterInfo.h"
20 #include "llvm/Target/TargetInstrInfo.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
26 // Some instructions act as place holders to emulate operations that the GPU
27 // hardware does automatically. This function can be used to check if
28 // an opcode falls into this category.
29 bool AMDGPU::isPlaceHolderOpcode(unsigned opcode
)
32 default: return false;
34 case AMDIL::LOAD_INPUT
:
36 case AMDIL::MASK_WRITE
:
37 case AMDIL::RESERVE_REG
:
42 bool AMDGPU::isTransOp(unsigned opcode
)
45 default: return false;
54 case AMDIL::MUL_LIT_r600
:
55 case AMDIL::MUL_LIT_eg
:
59 case AMDIL::EXP_IEEE_r600
:
60 case AMDIL::EXP_IEEE_eg
:
61 case AMDIL::LOG_CLAMPED_r600
:
62 case AMDIL::LOG_IEEE_r600
:
63 case AMDIL::LOG_CLAMPED_eg
:
64 case AMDIL::LOG_IEEE_eg
:
70 bool AMDGPU::isTexOp(unsigned opcode
)
73 default: return false;
75 case AMDIL::TEX_GET_TEXTURE_RESINFO
:
76 case AMDIL::TEX_SAMPLE
:
77 case AMDIL::TEX_SAMPLE_C
:
78 case AMDIL::TEX_SAMPLE_L
:
79 case AMDIL::TEX_SAMPLE_C_L
:
80 case AMDIL::TEX_SAMPLE_LB
:
81 case AMDIL::TEX_SAMPLE_C_LB
:
82 case AMDIL::TEX_SAMPLE_G
:
83 case AMDIL::TEX_SAMPLE_C_G
:
84 case AMDIL::TEX_GET_GRADIENTS_H
:
85 case AMDIL::TEX_GET_GRADIENTS_V
:
86 case AMDIL::TEX_SET_GRADIENTS_H
:
87 case AMDIL::TEX_SET_GRADIENTS_V
:
92 bool AMDGPU::isReductionOp(unsigned opcode
)
95 default: return false;
96 case AMDIL::DOT4_r600
:
102 bool AMDGPU::isCubeOp(unsigned opcode
)
105 default: return false;
106 case AMDIL::CUBE_r600
:
113 bool AMDGPU::isFCOp(unsigned opcode
)
116 default: return false;
117 case AMDIL::BREAK_LOGICALZ_f32
:
118 case AMDIL::BREAK_LOGICALNZ_i32
:
119 case AMDIL::BREAK_LOGICALZ_i32
:
120 case AMDIL::BREAK_LOGICALNZ_f32
:
121 case AMDIL::CONTINUE_LOGICALNZ_f32
:
122 case AMDIL::IF_LOGICALNZ_i32
:
123 case AMDIL::IF_LOGICALZ_f32
:
127 case AMDIL::IF_LOGICALNZ_f32
:
128 case AMDIL::WHILELOOP
:
133 void AMDGPU::utilAddLiveIn(llvm::MachineFunction
* MF
,
134 llvm::MachineRegisterInfo
& MRI
,
135 const llvm::TargetInstrInfo
* TII
,
136 unsigned physReg
, unsigned virtReg
)
138 if (!MRI
.isLiveIn(physReg
)) {
139 MRI
.addLiveIn(physReg
, virtReg
);
140 MF
->front().addLiveIn(physReg
);
141 BuildMI(MF
->front(), MF
->front().begin(), DebugLoc(),
142 TII
->get(TargetOpcode::COPY
), virtReg
)
145 MRI
.replaceRegWith(virtReg
, MRI
.getLiveInVirtReg(physReg
));