Skip to content

Commit 78fcafd

Browse files
committed
modularize SemaSPIRV.cpp
1 parent 76950bd commit 78fcafd

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ constexpr vector<T, L> refract_vec_impl(vector<T, L> I, vector<T, L> N, T Eta) {
8888
#endif
8989
}
9090

91+
9192
template <typename T> constexpr T fmod_impl(T X, T Y) {
9293
#if !defined(__DIRECTX__)
9394
return __builtin_elementwise_fmod(X, Y);

clang/lib/Sema/SemaSPIRV.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,40 +230,20 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const TargetInfo &TI,
230230
if (SemaRef.checkArgCount(TheCall, 3))
231231
return true;
232232

233-
ExprResult A = TheCall->getArg(0);
234-
QualType ArgTyA = A.get()->getType();
235-
auto *VTyA = ArgTyA->getAs<VectorType>();
236-
if (VTyA == nullptr) {
237-
SemaRef.Diag(A.get()->getBeginLoc(),
238-
diag::err_typecheck_convert_incompatible)
239-
<< ArgTyA
240-
<< SemaRef.Context.getVectorType(ArgTyA, 2, VectorKind::Generic) << 1
241-
<< 0 << 0;
242-
return true;
243-
}
244-
245-
ExprResult B = TheCall->getArg(1);
246-
QualType ArgTyB = B.get()->getType();
247-
auto *VTyB = ArgTyB->getAs<VectorType>();
248-
if (VTyB == nullptr) {
249-
SemaRef.Diag(B.get()->getBeginLoc(),
250-
diag::err_typecheck_convert_incompatible)
251-
<< ArgTyB
252-
<< SemaRef.Context.getVectorType(ArgTyB, 2, VectorKind::Generic) << 1
253-
<< 0 << 0;
233+
// Use the helper function to check the first two arguments
234+
if (CheckVectorArgs(TheCall, 2))
254235
return true;
255-
}
256236

257237
ExprResult C = TheCall->getArg(2);
258238
QualType ArgTyC = C.get()->getType();
259-
if (!ArgTyC->hasFloatingRepresentation()) {
239+
if (!ArgTyC->isFloatingType()) {
260240
SemaRef.Diag(C.get()->getBeginLoc(), diag::err_builtin_invalid_arg_type)
261-
<< 3 << /* scalar or vector */ 5 << /* no int */ 0 << /* fp */ 1
241+
<< 3 << /* scalar*/ 5 << /* no int */ 0 << /* fp */ 1
262242
<< ArgTyC;
263243
return true;
264244
}
265245

266-
QualType RetTy = ArgTyA;
246+
QualType RetTy = TheCall->getArg(0)->getType();
267247
TheCall->setType(RetTy);
268248
assert(RetTy == ArgTyA);
269249
//assert(ArgTyB == ArgTyA);

clang/test/CodeGenSPIRV/Builtins/refract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
22

3-
// RUN: %clang_cc1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s
3+
// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | FileCheck %s
44

55
typedef float float2 __attribute__((ext_vector_type(2)));
66
typedef float float3 __attribute__((ext_vector_type(3)));

0 commit comments

Comments
 (0)