Skip to content

Commit f560496

Browse files
YuriPlyakhinigcbot
authored andcommitted
Use CCommand error field instead of CodeGenContext
Using CodeGenContext error to define if resolving of built-in is successful doesn't work if CodeGenContext is already in error state. Instead we should use CCommand own error field, to indicate if built-in replacement had errors.
1 parent abc3b9b commit f560496

File tree

3 files changed

+83
-7
lines changed

3 files changed

+83
-7
lines changed

IGC/Compiler/Optimizer/OCLBIUtils.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ void CCommand::replaceGenISACallInst(GenISAIntrinsic::ID intrinsicName, ArrayRef
7777
m_pCallInst->replaceAllUsesWith(newCall);
7878
}
7979

80+
void CCommand::emitError(const char *ErrorStr, const Value *Context)
81+
{
82+
m_pCodeGenContext->EmitError(ErrorStr, Context);
83+
m_bHasError = true;
84+
}
85+
8086
void CImagesBI::prepareZeroOffsets()
8187
{
8288
m_args.push_back(m_pIntZero); // offsetU
@@ -123,7 +129,7 @@ void CImagesBI::prepareCoords(Dimension Dim, Value* Coord, Value* Zero)
123129
// no need to extract since in 1 Dim Coord isn't a vector
124130
break;
125131
case DIM_UNKNOWN:
126-
m_pCodeGenContext->EmitError("Unexpected dimension", NULL);
132+
emitError("Unexpected dimension", NULL);
127133
break;
128134
}
129135
}
@@ -191,7 +197,7 @@ void CImagesBI::verifyCommand()
191197
{
192198
if (m_IncorrectBti)
193199
{
194-
m_pCodeGenContext->EmitError("Inconsistent use of image!", NULL);
200+
emitError("Inconsistent use of image!", NULL);
195201
}
196202
}
197203

@@ -392,7 +398,7 @@ class COCL_sample : public CImagesBI
392398
ConstantInt* samplerIndex = nullptr;
393399
Value* samplerParam = ValueTracker::track(m_pCallInst, 1, m_pMdUtils, m_modMD);
394400
if (!samplerParam) {
395-
m_pCodeGenContext->EmitError("There are instructions that use a sampler, but no sampler found in the kernel!", m_pCallInst);
401+
emitError("There are instructions that use a sampler, but no sampler found in the kernel!", m_pCallInst);
396402
return nullptr;
397403
}
398404

@@ -660,7 +666,7 @@ class COCL_sample : public CImagesBI
660666
// no need to extract since in 1 Dim gradient is not a vector.
661667
break;
662668
case DIM_UNKNOWN:
663-
m_pCodeGenContext->EmitError("Unexpected dimension", NULL);
669+
emitError("Unexpected dimension", NULL);
664670
break;
665671
}
666672
}
@@ -922,7 +928,7 @@ class CGetImageProperty : public CImagesBI
922928
prop = builder.CreateExtractElement(info, builder.getInt32(1));
923929
break;
924930
default:
925-
m_pCodeGenContext->EmitError("Unsupported bindless image property requested.", NULL);
931+
emitError("Unsupported bindless image property requested.", NULL);
926932
}
927933
m_pCallInst->replaceAllUsesWith(prop);
928934
}
@@ -1645,5 +1651,5 @@ bool CBuiltinsResolver::resolveBI(CallInst* Inst)
16451651
m_CommandMap[calleeName]->execute(Inst, m_CodeGenContext);
16461652
m_CommandMap[calleeName]->verifyCommand();
16471653

1648-
return !m_CodeGenContext->HasError();
1654+
return !m_CommandMap[calleeName]->hasError();
16491655
}

IGC/Compiler/Optimizer/OCLBIUtils.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ namespace IGC
7474
void init(llvm::CallInst* Inst, IGC::CodeGenContext* CodeGenContext);
7575
void clearArgsList(void);
7676

77+
/// @brief returns true if command executed with errors
78+
bool hasError() const {return m_bHasError;}
79+
7780
enum CoordType
7881
{
7982
FloatType,
@@ -89,11 +92,17 @@ namespace IGC
8992
m_pCtx(nullptr),
9093
m_pCodeGenContext(nullptr),
9194
m_pFloatType(nullptr),
92-
m_pIntType(nullptr)
95+
m_pIntType(nullptr),
96+
m_bHasError(false)
9397
{}
9498
virtual ~CCommand(void) {};
9599

96100
protected:
101+
/// @brief emits error using CodeGenContext, sets error state of CCommand to true
102+
/// @param ErrorStr error string to emit
103+
/// @param Context Value to get debug location to print out the relevant info.
104+
void emitError(const char* ErrorStr, const llvm::Value *Context);
105+
97106
llvm::Value* m_pFloatZero;
98107
llvm::Value* m_pIntZero;
99108
llvm::Value* m_pIntOne;
@@ -105,6 +114,7 @@ namespace IGC
105114
llvm::DebugLoc m_DL;
106115
llvm::Type* m_pFloatType;
107116
llvm::IntegerType* m_pIntType;
117+
bool m_bHasError;
108118
};
109119

110120
static inline BufferType ResourceTypeMap(ResourceTypeEnum type)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; Test checks that even if there was previous error recorded in CodeGenContext,
10+
; built-ins like __builtin_IB_get_image_width are still erased after resolving
11+
; for bindless images
12+
13+
; RUN: igc_opt -platformdg1 -igc-error-check -igc-conv-ocl-to-common -S %s 2>&1 | FileCheck %s
14+
15+
; CHECK: define spir_kernel void @kernel(%spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)* %img) {
16+
; CHECK-NOT: __builtin_IB_get_image_width
17+
; CHECK-NOT: __builtin_IB_get_image_height
18+
; CHECK: ret void
19+
; CHECK: error: Double type is not supported on this platform.
20+
21+
%spirv.Image._void_1_0_0_0_0_0_0 = type opaque
22+
23+
define void @test_error(double %src) {
24+
%1 = fadd double %src, %src
25+
ret void
26+
}
27+
28+
define spir_kernel void @kernel(%spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)* %img) {
29+
%data = ptrtoint %spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)* %img to i64
30+
%1 = trunc i64 %data to i32
31+
%call.i.i.i = call spir_func i32 @__builtin_IB_get_image_width(i32 %1)
32+
%call1.i.i.i = call spir_func i32 @__builtin_IB_get_image_height(i32 %1)
33+
ret void
34+
}
35+
36+
declare spir_func i32 @__builtin_IB_get_image_width(i32)
37+
declare spir_func i32 @__builtin_IB_get_image_height(i32)
38+
39+
!igc.functions = !{!0}
40+
!IGCMetadata = !{!3}
41+
42+
!0 = !{void (%spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)*)* @kernel, !1}
43+
!1 = !{!2}
44+
!2 = !{!"function_type", i32 0}
45+
!3 = !{!"ModuleMD", !4, !15, !18}
46+
!4 = !{!"FuncMD", !5, !6}
47+
!5 = distinct !{!"FuncMDMap[0]", void (%spirv.Image._void_1_0_0_0_0_0_0 addrspace(1)*)* @kernel}
48+
!6 = !{!"FuncMDValue[0]", !7, !8, !9}
49+
!7 = !{!"funcArgs"}
50+
!8 = !{!"functionType", !"KernelFunction"}
51+
!9 = !{!"resAllocMD", !10}
52+
!10 = !{!"argAllocMDList", !11}
53+
!11 = !{!"argAllocMDListVec[0]", !12, !13, !14}
54+
!12 = !{!"type", i32 4}
55+
!13 = !{!"extensionType", i32 0}
56+
!14 = !{!"indexType", i32 0}
57+
!15 = !{!"compOpt", !16, !17}
58+
!16 = !{!"UseBindlessMode", i1 true}
59+
!17 = !{!"UseLegacyBindlessMode", i1 false}
60+
!18 = !{!"UseBindlessImage", i1 true}

0 commit comments

Comments
 (0)