clang 20.0.0git
SemaSPIRV.cpp
Go to the documentation of this file.
1//===- SemaSPIRV.cpp - Semantic Analysis for SPIRV constructs--------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This implements Semantic Analysis for SPIRV constructs.
9//===----------------------------------------------------------------------===//
10
13#include "clang/Sema/Sema.h"
14
15namespace clang {
16
18
20 CallExpr *TheCall) {
21 switch (BuiltinID) {
22 case SPIRV::BI__builtin_spirv_distance: {
23 if (SemaRef.checkArgCount(TheCall, 2))
24 return true;
25
26 ExprResult A = TheCall->getArg(0);
27 QualType ArgTyA = A.get()->getType();
28 auto *VTyA = ArgTyA->getAs<VectorType>();
29 if (VTyA == nullptr) {
31 diag::err_typecheck_convert_incompatible)
32 << ArgTyA
34 << 0 << 0;
35 return true;
36 }
37
38 ExprResult B = TheCall->getArg(1);
39 QualType ArgTyB = B.get()->getType();
40 auto *VTyB = ArgTyB->getAs<VectorType>();
41 if (VTyB == nullptr) {
43 diag::err_typecheck_convert_incompatible)
44 << ArgTyB
46 << 0 << 0;
47 return true;
48 }
49
50 QualType RetTy = VTyA->getElementType();
51 TheCall->setType(RetTy);
52 break;
53 }
54 }
55 return false;
56}
57} // namespace clang
This file declares semantic analysis for SPIRV constructs.
Enumerates target-specific builtins in their own namespaces within namespace clang.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
PtrTy get() const
Definition: Ownership.h:170
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:3068
void setType(QualType t)
Definition: Expr.h:143
QualType getType() const
Definition: Expr.h:142
A (possibly-)qualified type.
Definition: Type.h:929
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
Sema & SemaRef
Definition: SemaBase.h:40
bool CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
Definition: SemaSPIRV.cpp:19
SemaSPIRV(Sema &S)
Definition: SemaSPIRV.cpp:17
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:464
ASTContext & Context
Definition: Sema.h:909
bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount)
Checks that a call expression's argument count is the desired number.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:345
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Represents a GCC generic vector type.
Definition: Type.h:4034
The JSON file list parser is used to communicate input to InstallAPI.
@ Generic
not a target-specific vector type