1 //===-- AMDGPUUtil.cpp - TODO: Add brief description -------===//
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 // TODO: Add full description
12 //===----------------------------------------------------------------------===//
14 #include "AMDGPUUtil.h"
15 #include "AMDGPURegisterInfo.h"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/Support/ErrorHandling.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 llvm::isPlaceHolderOpcode(unsigned opcode
)
32 default: return false;
33 case AMDIL::EXPORT_REG
:
35 case AMDIL::LOAD_INPUT
:
37 case AMDIL::MASK_WRITE
:
38 case AMDIL::RESERVE_REG
:
43 bool llvm::isTransOp(unsigned opcode
)
46 default: return false;
55 case AMDIL::MUL_LIT_r600
:
56 case AMDIL::MUL_LIT_eg
:
60 case AMDIL::EXP_IEEE_r600
:
61 case AMDIL::EXP_IEEE_eg
:
62 case AMDIL::LOG_CLAMPED_r600
:
63 case AMDIL::LOG_IEEE_r600
:
64 case AMDIL::LOG_CLAMPED_eg
:
65 case AMDIL::LOG_IEEE_eg
:
71 bool llvm::isTexOp(unsigned opcode
)
74 default: return false;
76 case AMDIL::TEX_GET_TEXTURE_RESINFO
:
77 case AMDIL::TEX_SAMPLE
:
78 case AMDIL::TEX_SAMPLE_C
:
79 case AMDIL::TEX_SAMPLE_L
:
80 case AMDIL::TEX_SAMPLE_C_L
:
81 case AMDIL::TEX_SAMPLE_LB
:
82 case AMDIL::TEX_SAMPLE_C_LB
:
83 case AMDIL::TEX_SAMPLE_G
:
84 case AMDIL::TEX_SAMPLE_C_G
:
85 case AMDIL::TEX_GET_GRADIENTS_H
:
86 case AMDIL::TEX_GET_GRADIENTS_V
:
91 bool llvm::isReductionOp(unsigned opcode
)
94 default: return false;
95 case AMDIL::DOT4_r600
:
101 bool llvm::isFCOp(unsigned opcode
)
104 default: return false;
105 case AMDIL::BREAK_LOGICALZ_f32
:
106 case AMDIL::BREAK_LOGICALNZ_i32
:
107 case AMDIL::BREAK_LOGICALZ_i32
:
108 case AMDIL::BREAK_LOGICALNZ_f32
:
109 case AMDIL::CONTINUE_LOGICALNZ_f32
:
110 case AMDIL::IF_LOGICALNZ_i32
:
111 case AMDIL::IF_LOGICALZ_f32
:
115 case AMDIL::IF_LOGICALNZ_f32
:
116 case AMDIL::WHILELOOP
:
121 void AMDGPU::utilAddLiveIn(MachineFunction
* MF
, MachineRegisterInfo
& MRI
,
122 const struct TargetInstrInfo
* TII
, unsigned physReg
, unsigned virtReg
)
124 if (!MRI
.isLiveIn(physReg
)) {
125 MRI
.addLiveIn(physReg
, virtReg
);
126 MF
->front().addLiveIn(physReg
);
127 BuildMI(MF
->front(), MF
->front().begin(), DebugLoc(),
128 TII
->get(TargetOpcode::COPY
), virtReg
)
131 MRI
.replaceRegWith(virtReg
, MRI
.getLiveInVirtReg(physReg
));