clang
20.0.0git
lib
Sema
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
11
#include "
clang/Sema/SemaSPIRV.h
"
12
#include "
clang/Basic/TargetBuiltins.h
"
13
#include "
clang/Sema/Sema.h
"
14
15
namespace
clang
{
16
17
SemaSPIRV::SemaSPIRV
(
Sema
&S) :
SemaBase
(S) {}
18
19
bool
SemaSPIRV::CheckSPIRVBuiltinFunctionCall
(
unsigned
BuiltinID,
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
) {
30
SemaRef
.
Diag
(A.
get
()->
getBeginLoc
(),
31
diag::err_typecheck_convert_incompatible)
32
<< ArgTyA
33
<<
SemaRef
.
Context
.
getVectorType
(ArgTyA, 2,
VectorKind::Generic
) << 1
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
) {
42
SemaRef
.
Diag
(A.
get
()->
getBeginLoc
(),
43
diag::err_typecheck_convert_incompatible)
44
<< ArgTyB
45
<<
SemaRef
.
Context
.
getVectorType
(ArgTyB, 2,
VectorKind::Generic
) << 1
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
SemaSPIRV.h
This file declares semantic analysis for SPIRV constructs.
Sema.h
TargetBuiltins.h
Enumerates target-specific builtins in their own namespaces within namespace clang.
clang::ASTContext::getVectorType
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
Definition:
ASTContext.cpp:4497
clang::ActionResult< Expr * >
clang::ActionResult::get
PtrTy get() const
Definition:
Ownership.h:170
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition:
Expr.h:2874
clang::CallExpr::getArg
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition:
Expr.h:3068
clang::Expr::setType
void setType(QualType t)
Definition:
Expr.h:143
clang::Expr::getType
QualType getType() const
Definition:
Expr.h:142
clang::QualType
A (possibly-)qualified type.
Definition:
Type.h:929
clang::SemaBase
Definition:
SemaBase.h:36
clang::SemaBase::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition:
SemaBase.cpp:60
clang::SemaBase::SemaRef
Sema & SemaRef
Definition:
SemaBase.h:40
clang::SemaSPIRV::CheckSPIRVBuiltinFunctionCall
bool CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall)
Definition:
SemaSPIRV.cpp:19
clang::SemaSPIRV::SemaSPIRV
SemaSPIRV(Sema &S)
Definition:
SemaSPIRV.cpp:17
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition:
Sema.h:464
clang::Sema::Context
ASTContext & Context
Definition:
Sema.h:909
clang::Sema::checkArgCount
bool checkArgCount(CallExpr *Call, unsigned DesiredArgCount)
Checks that a call expression's argument count is the desired number.
Definition:
SemaChecking.cpp:154
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition:
Stmt.cpp:345
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition:
Type.h:8731
clang::VectorType
Represents a GCC generic vector type.
Definition:
Type.h:4034
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
clang::VectorKind::Generic
@ Generic
not a target-specific vector type
Generated on Wed Feb 19 2025 16:09:02 for clang by
1.9.6