radeon/llvm: add missing cases for BREAK/CONTINUE
[mesa.git] / src / gallium / drivers / radeon / AMDGPUUtil.cpp
1 //===-- AMDGPUUtil.cpp - TODO: Add brief description -------===//
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 // TODO: Add full description
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AMDGPUUtil.h"
15 #include "AMDGPURegisterInfo.h"
16 #include "AMDIL.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"
23
24 using namespace llvm;
25
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)
30 {
31 switch (opcode) {
32 default: return false;
33 case AMDIL::EXPORT_REG:
34 case AMDIL::RETURN:
35 case AMDIL::LOAD_INPUT:
36 case AMDIL::LAST:
37 case AMDIL::MASK_WRITE:
38 case AMDIL::RESERVE_REG:
39 return true;
40 }
41 }
42
43 bool llvm::isTransOp(unsigned opcode)
44 {
45 switch(opcode) {
46 default: return false;
47
48 case AMDIL::COS_f32:
49 case AMDIL::COS_r600:
50 case AMDIL::COS_eg:
51 case AMDIL::RSQ_f32:
52 case AMDIL::FTOI:
53 case AMDIL::ITOF:
54 case AMDIL::MULLIT:
55 case AMDIL::MUL_LIT_r600:
56 case AMDIL::MUL_LIT_eg:
57 case AMDIL::SHR_i32:
58 case AMDIL::SIN_f32:
59 case AMDIL::EXP_f32:
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:
66 case AMDIL::LOG_f32:
67 return true;
68 }
69 }
70
71 bool llvm::isTexOp(unsigned opcode)
72 {
73 switch(opcode) {
74 default: return false;
75 case AMDIL::TEX_LD:
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:
87 return true;
88 }
89 }
90
91 bool llvm::isReductionOp(unsigned opcode)
92 {
93 switch(opcode) {
94 default: return false;
95 case AMDIL::DOT4_r600:
96 case AMDIL::DOT4_eg:
97 return true;
98 }
99 }
100
101 bool llvm::isFCOp(unsigned opcode)
102 {
103 switch(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:
112 case AMDIL::ELSE:
113 case AMDIL::ENDIF:
114 case AMDIL::ENDLOOP:
115 case AMDIL::IF_LOGICALNZ_f32:
116 case AMDIL::WHILELOOP:
117 return true;
118 }
119 }
120
121 void AMDGPU::utilAddLiveIn(MachineFunction * MF, MachineRegisterInfo & MRI,
122 const struct TargetInstrInfo * TII, unsigned physReg, unsigned virtReg)
123 {
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)
129 .addReg(physReg);
130 } else {
131 MRI.replaceRegWith(virtReg, MRI.getLiveInVirtReg(physReg));
132 }
133 }