|
52 | 52 | #include "clang/Basic/Builtins.h" |
53 | 53 | #include "clang/Basic/DiagnosticSema.h" |
54 | 54 | #include "clang/Basic/TargetBuiltins.h" |
| 55 | +#include "clang/Basic/IdentifierTable.h" |
55 | 56 | #include "clang/Basic/TargetInfo.h" |
56 | 57 | #include "llvm/ADT/APFixedPoint.h" |
57 | 58 | #include "llvm/ADT/Sequence.h" |
@@ -9918,6 +9919,26 @@ static bool isOneByteCharacterType(QualType T) { |
9918 | 9919 | return T->isCharType() || T->isChar8Type(); |
9919 | 9920 | } |
9920 | 9921 |
|
| 9922 | +static const SYCLKernelInfo *GetSYCLKernelInfo(ASTContext &Ctx, |
| 9923 | + const CallExpr *E) { |
| 9924 | + // Argument to the builtin is a type trait which is used to retrieve the |
| 9925 | + // kernel name type. |
| 9926 | + // FIXME: Improve the comment. |
| 9927 | + const Expr *NameExpr = E->getArg(0); |
| 9928 | + // FIXME: Implement diagnostic instead of assert. |
| 9929 | + assert(NameExpr->isEvaluatable(Ctx) && |
| 9930 | + "KernelNameType should be evaluatable"); |
| 9931 | + RecordDecl *RD = NameExpr->getType()->castAs<RecordType>()->getDecl(); |
| 9932 | + IdentifierTable &IdentTable = Ctx.Idents; |
| 9933 | + auto Name = DeclarationName(&(IdentTable.get("type"))); |
| 9934 | + NamedDecl *ND = (RD->lookup(Name)).front(); |
| 9935 | + TypedefNameDecl *TD = cast<TypedefNameDecl>(ND); |
| 9936 | + CanQualType KernelNameType = Ctx.getCanonicalType(TD->getUnderlyingType()); |
| 9937 | + |
| 9938 | + // Retrieve KernelInfo using the kernel name. |
| 9939 | + return Ctx.findSYCLKernelInfo(KernelNameType); |
| 9940 | +} |
| 9941 | + |
9921 | 9942 | bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, |
9922 | 9943 | unsigned BuiltinOp) { |
9923 | 9944 | if (IsOpaqueConstantCall(E)) |
@@ -10273,6 +10294,23 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E, |
10273 | 10294 | return false; |
10274 | 10295 | } |
10275 | 10296 | } |
| 10297 | + case Builtin::BI__builtin_sycl_kernel_name: { |
| 10298 | + const SYCLKernelInfo *KernelInfo = GetSYCLKernelInfo(Info.Ctx, E); |
| 10299 | + assert(KernelInfo && "Type does not correspond to a SYCL kernel name."); |
| 10300 | + // Retrieve the mangled name corresponding to kernel name type. |
| 10301 | + std::string ResultStr = KernelInfo->GetKernelName(); |
| 10302 | + APInt Size(Info.Ctx.getTypeSize(Info.Ctx.getSizeType()), |
| 10303 | + ResultStr.size() + 1); |
| 10304 | + QualType StrTy = |
| 10305 | + Info.Ctx.getConstantArrayType(Info.Ctx.CharTy.withConst(), Size, |
| 10306 | + nullptr, ArraySizeModifier::Normal, 0); |
| 10307 | + StringLiteral *SL = |
| 10308 | + StringLiteral::Create(Info.Ctx, ResultStr, StringLiteralKind::Ordinary, |
| 10309 | + /*Pascal*/ false, StrTy, SourceLocation()); |
| 10310 | + evaluateLValue(SL, Result); |
| 10311 | + Result.addArray(Info, E, cast<ConstantArrayType>(StrTy)); |
| 10312 | + return true; |
| 10313 | + } |
10276 | 10314 |
|
10277 | 10315 | default: |
10278 | 10316 | return false; |
|
0 commit comments