File: InstLegalChecker.cpp

package info (click to toggle)
intel-graphics-compiler 1.0.12504.6-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 83,912 kB
  • sloc: cpp: 910,147; lisp: 202,655; ansic: 15,197; python: 4,025; yacc: 2,241; lex: 1,570; pascal: 244; sh: 104; makefile: 25
file content (291 lines) | stat: -rw-r--r-- 9,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#include "TypeLegalizer.h"
#include "InstLegalChecker.h"
#include "common/LLVMWarningsPush.hpp"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "common/LLVMWarningsPop.hpp"
#include "Probe/Assertion.h"

#define DEBUG_TYPE "type-legalizer"

using namespace llvm;
using namespace IGC::Legalizer;

// By default, capture all missing instructions!
LegalizeAction InstLegalChecker::visitInstruction(Instruction& I) {
#if LLVM_VERSION_MAJOR >= 10
    if (isa<FreezeInst>(I))
        return Legal;
#endif // LLVM_VERSION_MAJOR >= 10

    LLVM_DEBUG(dbgs() << "LEGAL-CHECK: " << I << '\n');
    IGC_ASSERT_EXIT_MESSAGE(0, "UNKNOWN INSTRUCTION IS BEING LEGAL-CHECKED!");
}

/// Terminator instructions
///

LegalizeAction InstLegalChecker::visitReturnInst(ReturnInst& I) {
    // It's legal iff the return value (if any) is legal.
    if (Value * V = I.getReturnValue())
        return TL->getTypeLegalizeAction(V->getType());
    // Otherwise, 'ret void' is always legal.
    return Legal;
}

LegalizeAction InstLegalChecker::visitTerminatorInst(IGCLLVM::TerminatorInst&) {
    // FIXME: Shall we treat all terminator insts as legal, e.g. do we
    // support 'indirectbr' or 'resume'.
    return Legal;
}

/// Standard binary operators
///

LegalizeAction InstLegalChecker::visitBinaryOperator(BinaryOperator& I) {
    // It's legal iff the return type is legal (as two operands have the same
    // type as the result value, even for shift operators.)
    return TL->getTypeLegalizeAction(I.getType());
}

/// Memory operators
///

LegalizeAction InstLegalChecker::visitAllocaInst(AllocaInst& I) {
    LegalizeAction Act;
    // FIXME: Do we really check the allocated type?
    // It's legal if the allocated type is legal.
    if ((Act = TL->getTypeLegalizeAction(I.getAllocatedType())) != Legal)
        return Act;
    // If it's array allocation, check array size as well.
    if (I.isArrayAllocation())
        return TL->getTypeLegalizeAction(I.getArraySize()->getType());
    return Legal;
}

LegalizeAction InstLegalChecker::visitLoadInst(LoadInst& I) {
    // It's legal iff the result is legal.
    return TL->getTypeLegalizeAction(I.getType());
}

LegalizeAction InstLegalChecker::visitStoreInst(StoreInst& I) {
    // It's legal iff the value operand is legal.
    return TL->getTypeLegalizeAction(I.getValueOperand()->getType());
}

LegalizeAction InstLegalChecker::visitGetElementPtrInst(GetElementPtrInst& I) {
    LegalizeAction Act;
    // If the result type is illegal, i.e. vector of pointers, it's illegal.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Otherwise, check all index operands.
    for (auto II = I.idx_begin(), IE = I.idx_end(); II != IE; ++II)
        if ((Act = TL->getTypeLegalizeAction((*II)->getType())) != Legal)
            return Act;
    return Legal;
}

LegalizeAction InstLegalChecker::visitFenceInst(FenceInst&) {
    // FIXME: Do we have illegal cases?
    return Legal;
}

LegalizeAction InstLegalChecker::visitAtomicCmpXchgInst(AtomicCmpXchgInst&) {
    // FIXME: Do we have illegal cases?
    return Legal;
}

LegalizeAction InstLegalChecker::visitAtomicRMWInst(AtomicRMWInst&) {
    // FIXME: Do we have illegal cases?
    return Legal;
}

/// Cast operators
///

LegalizeAction InstLegalChecker::visitCastInst(CastInst& I) {
    LegalizeAction Act;
    // It's legal iff both the result and source are legal.
    if ((Act = TL->getTypeLegalizeAction(I.getDestTy())) != Legal)
        return Act;
    return TL->getTypeLegalizeAction(I.getSrcTy());
}

/// Other operators
///

LegalizeAction InstLegalChecker::visitCmpInst(CmpInst& I) {
    LegalizeAction Act;
    // It's legal iff the return value and one of its operands (both operands
    // has the same type) are legal.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    return TL->getTypeLegalizeAction(I.getOperand(0)->getType());
}

LegalizeAction InstLegalChecker::visitPHINode(PHINode& I) {
    // It's legal iff the result is legal (as all value operands have the
    // same type.
    return TL->getTypeLegalizeAction(I.getType());
}

LegalizeAction InstLegalChecker::visitIntrinsicInst(IntrinsicInst& I) {
    switch (I.getIntrinsicID()) {
        // Intrinsics on floating point are legal iff their result types are
        // legal.
    case Intrinsic::fma:
    case Intrinsic::fmuladd:
    case Intrinsic::sqrt:
    case Intrinsic::powi:
    case Intrinsic::sin:
    case Intrinsic::cos:
    case Intrinsic::pow:
    case Intrinsic::log:
    case Intrinsic::log10:
    case Intrinsic::log2:
    case Intrinsic::exp:
    case Intrinsic::exp2:
    case Intrinsic::fabs:
    case Intrinsic::copysign:
    case Intrinsic::floor:
    case Intrinsic::ceil:
    case Intrinsic::trunc:
    case Intrinsic::rint:
    case Intrinsic::nearbyint:
        // case Intrinsic::round:
        return TL->getTypeLegalizeAction(I.getType());
        // Intrinsics on integer are legal iff their result types are legal.
    case Intrinsic::bswap:
    case Intrinsic::ctpop:
    case Intrinsic::ctlz:
    case Intrinsic::cttz:
    case Intrinsic::sadd_with_overflow:
    case Intrinsic::uadd_with_overflow:
    case Intrinsic::ssub_with_overflow:
    case Intrinsic::usub_with_overflow:
    case Intrinsic::smul_with_overflow:
    case Intrinsic::umul_with_overflow:
    case Intrinsic::bitreverse:
        return TL->getTypeLegalizeAction(I.getType());
    default:
        // By default, all intrinsics are regarded as being legal.
        break;
    }
    return Legal;
}

LegalizeAction InstLegalChecker::visitGenIntrinsicInst(GenIntrinsicInst& I) {
    // By default, all Gen intrinsics are regarded as being legal.
    return Legal;
}

LegalizeAction InstLegalChecker::visitCallInst(CallInst& I) {
    // Check Gen intrinsic instruction separately.
    if (isa<GenIntrinsicInst>(&I))
        return visitGenIntrinsicInst(static_cast<GenIntrinsicInst&>(I));
    // FIXME: So far, calls (including GenISA intrinsics) are treated as
    // being legal.
    return Legal;
}

LegalizeAction InstLegalChecker::visitSelectInst(SelectInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and the condition operand are legal (as two
    // value operands has the same type).
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    return TL->getTypeLegalizeAction(I.getCondition()->getType());
}

LegalizeAction InstLegalChecker::visitVAArgInst(VAArgInst&) {
    // FIXME: Do we support it?
    return Legal;
}

LegalizeAction
InstLegalChecker::visitExtractElementInst(ExtractElementInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and all operands are legal. Check return value
    // first.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Check vector operand.
    if ((Act =
        TL->getTypeLegalizeAction(I.getVectorOperand()->getType())) != Legal)
        return Act;
    // Check index operand.
    return TL->getTypeLegalizeAction(I.getIndexOperand()->getType());
}

LegalizeAction InstLegalChecker::visitInsertElementInst(InsertElementInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and all operands are legal. Check return value
    // first. No need to check vector operand which has the same type of return
    // value.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Check index operand
    if ((Act = TL->getTypeLegalizeAction(I.getOperand(1)->getType())) != Legal)
        return Act;
    // Check scalar operand.
    return TL->getTypeLegalizeAction(I.getOperand(2)->getType());
}

LegalizeAction InstLegalChecker::visitShuffleVectorInst(ShuffleVectorInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and all operands are legal. Check return
    // value first since it's known as a vector value.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Check source operand.
    if ((Act = TL->getTypeLegalizeAction(I.getOperand(0)->getType())) != Legal)
        return Act;
    // Check the constant mask.
    return TL->getTypeLegalizeAction(I.
#if LLVM_VERSION_MAJOR <= 10
        getMask
#else
        getShuffleMaskForBitcode
#endif
        ()->getType());
}

LegalizeAction InstLegalChecker::visitExtractValueInst(ExtractValueInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and all operands are legal. Check return value
    // first.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Check aggregate operand.
    return TL->getTypeLegalizeAction(I.getAggregateOperand()->getType());
}

LegalizeAction InstLegalChecker::visitInsertValueInst(InsertValueInst& I) {
    LegalizeAction Act;
    // It's legal iff the result and all operands are legal. Check its return
    // value first since it's known as an aggregate value.
    if ((Act = TL->getTypeLegalizeAction(I.getType())) != Legal)
        return Act;
    // Check its operands.
    return TL->getTypeLegalizeAction(I.getInsertedValueOperand()->getType());
}

LegalizeAction InstLegalChecker::visitLandingPadInst(LandingPadInst&) {
    // FIXME: Do we support it?
    return Legal;
}

#if LLVM_VERSION_MAJOR >= 10
LegalizeAction InstLegalChecker::visitFNeg(llvm::UnaryOperator& I) {
    return Legal;
}
#endif