Skip to content

Commit 05d3be6

Browse files
author
Brox Chen
authored
[SYCL] Add a builtin for SYCL ptr annotation (#10267)
added a "__builtin_intel_sycl_ptr_annotation(ptr, PROPERTY1, VALUE1, PROPERTY2, VALUE2 ...)" builtin function for FPGA SYCL ptr annotation using SYCL extension properties. Updated the "annotated_ptr.hpp" to use "__builtin_intel_sycl_ptr_annotation" to pass annotation instead of using "add_sycl_ir_member_annotation". This helps to insert the llvm.ptr.annotation at the correct position Update the compileTimeProperties pass to consume "sycl-alignment" and thus do not propagate this annotation to SPIRV translator --------------------------------------------------------------------- After using "__builtin_intel_sycl_ptr_annotation" , IR generated are changed from: ``` %ptr.to.ptr = GEP %ptr.to.ptr.annotated = llvm.ptr.annotation %ptr.to.ptr %ptr = load %ptr.to.ptr.annotated %4 = load %ptr ``` to ``` %ptr.to.ptr = GEP %ptr = load %ptr.to.ptr %ptr.annotated = llvm.ptr.annotation %ptr %4 = load %ptr.annotated ``` Thus, SYCLLowerIR pass are expecting different IR forms and thus these two changes are merged together.
1 parent 25cc354 commit 05d3be6

File tree

15 files changed

+616
-57
lines changed

15 files changed

+616
-57
lines changed

clang/include/clang/Basic/Builtins.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,9 @@ BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
17541754
// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
17551755
LANGBUILTIN(__arithmetic_fence, "v.", "tE", ALL_LANGUAGES)
17561756

1757+
// Builtins for Intel SYCL
1758+
BUILTIN(__builtin_intel_sycl_ptr_annotation, "v.", "nt")
1759+
17571760
// Builtins for Intel FPGA
17581761
BUILTIN(__builtin_intel_fpga_reg, "v.", "nt")
17591762
BUILTIN(__builtin_intel_fpga_mem, "v.", "nt")

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ def err_intel_fpga_mem_arg_mismatch
167167
"a pointer"
168168
"|a non-negative integer constant}0">;
169169

170+
def err_intel_sycl_ptr_annotation_arg_number_mismatch
171+
:Error<"number of parameters must be odd number">;
172+
def err_intel_sycl_ptr_annotation_mismatch
173+
: Error<"builtin parameter must be %select{"
174+
"a pointer"
175+
"|a string literal or constexpr const char*}0">;
176+
170177
// C99 variable-length arrays
171178
def ext_vla : Extension<"variable length arrays are a C99 feature">,
172179
InGroup<VLAExtension>;

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14015,6 +14015,9 @@ class Sema final {
1401514015
bool CheckIntelFPGARegBuiltinFunctionCall(unsigned BuiltinID, CallExpr *Call);
1401614016
bool CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *Call);
1401714017

14018+
bool CheckIntelSYCLPtrAnnotationBuiltinFunctionCall(unsigned BuiltinID,
14019+
CallExpr *Call);
14020+
1401814021
bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall);
1401914022
bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call);
1402014023
bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5573,7 +5573,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
55735573
return EmitIntelFPGARegBuiltin(E, ReturnValue);
55745574
case Builtin::BI__builtin_intel_fpga_mem:
55755575
return EmitIntelFPGAMemBuiltin(E);
5576-
5576+
case Builtin::BI__builtin_intel_sycl_ptr_annotation:
5577+
return EmitIntelSYCLPtrAnnotationBuiltin(E);
55775578
case Builtin::BI__builtin_get_device_side_mangled_name: {
55785579
auto Name = CGM.getCUDARuntime().getDeviceSideName(
55795580
cast<DeclRefExpr>(E->getArg(0)->IgnoreImpCasts())->getDecl());
@@ -22540,6 +22541,43 @@ llvm::CallInst *CodeGenFunction::EmitFPBuiltinIndirectCall(
2254022541
return nullptr;
2254122542
}
2254222543

22544+
RValue CodeGenFunction::EmitIntelSYCLPtrAnnotationBuiltin(const CallExpr *E) {
22545+
const Expr *PtrArg = E->getArg(0);
22546+
Value *PtrVal = EmitScalarExpr(PtrArg);
22547+
auto &Ctx = CGM.getContext();
22548+
22549+
// Create the pointer annotation.
22550+
Function *F = CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation,
22551+
{PtrVal->getType(), CGM.ConstGlobalsPtrTy});
22552+
22553+
SmallString<256> AnnotStr;
22554+
llvm::raw_svector_ostream Out(AnnotStr);
22555+
22556+
SmallVector<std::pair<std::string, std::string>, 4> Properties;
22557+
22558+
for (unsigned I = 1, N = E->getNumArgs(); I <= N / 2; I++) {
22559+
auto Arg = E->getArg(I)->IgnoreParenCasts();
22560+
const StringLiteral *Str = dyn_cast<const StringLiteral>(Arg);
22561+
Expr::EvalResult Result;
22562+
if (!Str && Arg->EvaluateAsRValue(Result, Ctx) && Result.Val.isLValue()) {
22563+
const auto *LVE = Result.Val.getLValueBase().dyn_cast<const Expr *>();
22564+
Str = dyn_cast<const StringLiteral>(LVE);
22565+
}
22566+
assert(Str && "Constant parameter string is invalid?");
22567+
22568+
auto IntVal = E->getArg(I + N / 2)->getIntegerConstantExpr(Ctx);
22569+
assert(IntVal.has_value() &&
22570+
"Constant integer arg isn't actually constant?");
22571+
22572+
Properties.push_back(
22573+
std::make_pair(Str->getString().str(), toString(IntVal.value(), 10)));
22574+
}
22575+
22576+
llvm::Value *Ann =
22577+
EmitSYCLAnnotationCall(F, PtrVal, E->getExprLoc(), Properties);
22578+
return RValue::get(Ann);
22579+
}
22580+
2254322581
Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2254422582
const CallExpr *E,
2254522583
ReturnValueSlot ReturnValue) {

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2836,13 +2836,25 @@ Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
28362836
llvm::Value *CodeGenFunction::EmitSYCLAnnotationCall(
28372837
llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal,
28382838
SourceLocation Location, const SYCLAddIRAnnotationsMemberAttr *Attr) {
2839+
2840+
llvm::SmallVector<std::pair<std::string, std::string>, 4>
2841+
AnnotationNameValPairs =
2842+
Attr->getFilteredAttributeNameValuePairs(getContext());
2843+
return EmitSYCLAnnotationCall(AnnotationFn, AnnotatedVal, Location,
2844+
AnnotationNameValPairs);
2845+
}
2846+
2847+
llvm::Value *CodeGenFunction::EmitSYCLAnnotationCall(
2848+
llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal,
2849+
SourceLocation Location,
2850+
SmallVectorImpl<std::pair<std::string, std::string>> &Pair) {
28392851
SmallVector<llvm::Value *, 5> Args = {
28402852
AnnotatedVal,
28412853
Builder.CreateBitCast(CGM.EmitAnnotationString("sycl-properties"),
28422854
ConstGlobalsPtrTy),
28432855
Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location),
28442856
ConstGlobalsPtrTy),
2845-
CGM.EmitAnnotationLineNo(Location), CGM.EmitSYCLAnnotationArgs(Attr)};
2857+
CGM.EmitAnnotationLineNo(Location), CGM.EmitSYCLAnnotationArgs(Pair)};
28462858
return Builder.CreateCall(AnnotationFn, Args);
28472859
}
28482860

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4321,6 +4321,8 @@ class CodeGenFunction : public CodeGenTypeCache {
43214321
ReturnValueSlot ReturnValue);
43224322
RValue EmitIntelFPGAMemBuiltin(const CallExpr *E);
43234323

4324+
RValue EmitIntelSYCLPtrAnnotationBuiltin(const CallExpr *E);
4325+
43244326
llvm::CallInst *
43254327
EmitFPBuiltinIndirectCall(llvm::FunctionType *IRFuncTy,
43264328
const SmallVectorImpl<llvm::Value *> &IRArgs,
@@ -4589,6 +4591,11 @@ class CodeGenFunction : public CodeGenTypeCache {
45894591
llvm::Value *AnnotatedVal, SourceLocation Location,
45904592
const SYCLAddIRAnnotationsMemberAttr *Attr);
45914593

4594+
llvm::Value *EmitSYCLAnnotationCall(
4595+
llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal,
4596+
SourceLocation Location,
4597+
llvm::SmallVectorImpl<std::pair<std::string, std::string>> &Pair);
4598+
45924599
/// Emit sycl field annotations for given field & value. Returns the
45934600
/// annotation result.
45944601
Address EmitFieldSYCLAnnotations(const FieldDecl *D, Address V);

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,10 +3496,9 @@ void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D,
34963496
}
34973497

34983498
llvm::Constant *CodeGenModule::EmitSYCLAnnotationArgs(
3499-
const SYCLAddIRAnnotationsMemberAttr *Attr) {
3500-
llvm::SmallVector<std::pair<std::string, std::string>, 4>
3501-
AnnotationNameValPairs =
3502-
Attr->getFilteredAttributeNameValuePairs(getContext());
3499+
llvm::SmallVectorImpl<std::pair<std::string, std::string>>
3500+
&AnnotationNameValPairs) {
3501+
35033502
if (AnnotationNameValPairs.empty())
35043503
return llvm::ConstantPointerNull::get(ConstGlobalsPtrTy);
35053504

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,8 @@ class CodeGenModule : public CodeGenTypeCache {
13821382
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV);
13831383

13841384
/// Emit additional args of the annotation.
1385-
llvm::Constant *
1386-
EmitSYCLAnnotationArgs(const SYCLAddIRAnnotationsMemberAttr *Attr);
1385+
llvm::Constant *EmitSYCLAnnotationArgs(
1386+
SmallVectorImpl<std::pair<std::string, std::string>> &Pairs);
13871387

13881388
/// Add attributes from add_ir_attributes_global_variable on TND to GV.
13891389
void AddGlobalSYCLIRAttributes(llvm::GlobalVariable *GV,

clang/lib/Sema/SemaChecking.cpp

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
using namespace clang;
103103
using namespace sema;
104104

105+
static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
106+
const Expr *E);
107+
105108
SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
106109
unsigned ByteNo) const {
107110
return SL->getLocationOfByte(ByteNo, getSourceManager(), LangOpts,
@@ -2590,6 +2593,16 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
25902593
if (CheckIntelFPGARegBuiltinFunctionCall(BuiltinID, TheCall))
25912594
return ExprError();
25922595
break;
2596+
case Builtin::BI__builtin_intel_sycl_ptr_annotation:
2597+
if (!Context.getLangOpts().SYCLIsDevice) {
2598+
Diag(TheCall->getBeginLoc(), diag::err_builtin_requires_language)
2599+
<< "__builtin_intel_sycl_ptr_annotation"
2600+
<< "SYCL device";
2601+
return ExprError();
2602+
}
2603+
if (CheckIntelSYCLPtrAnnotationBuiltinFunctionCall(BuiltinID, TheCall))
2604+
return ExprError();
2605+
break;
25932606
case Builtin::BI__builtin_intel_fpga_mem:
25942607
if (!Context.getLangOpts().SYCLIsDevice) {
25952608
Diag(TheCall->getBeginLoc(), diag::err_builtin_requires_language)
@@ -6018,6 +6031,56 @@ bool Sema::CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *TheCall) {
60186031
return false;
60196032
}
60206033

6034+
bool Sema::CheckIntelSYCLPtrAnnotationBuiltinFunctionCall(unsigned BuiltinID,
6035+
CallExpr *TheCall) {
6036+
unsigned NumArgs = TheCall->getNumArgs();
6037+
// Make sure we have the minimum number of provided arguments.
6038+
if (checkArgCountAtLeast(*this, TheCall, 1)) {
6039+
return true;
6040+
}
6041+
6042+
// Make sure we have odd number of arguments.
6043+
if (!(NumArgs & 0x1)) {
6044+
return Diag(TheCall->getEndLoc(),
6045+
diag::err_intel_sycl_ptr_annotation_arg_number_mismatch);
6046+
}
6047+
6048+
// First argument should be a pointer.
6049+
Expr *PointerArg = TheCall->getArg(0);
6050+
QualType PointerArgType = PointerArg->getType();
6051+
6052+
if (!isa<PointerType>(PointerArgType))
6053+
return Diag(PointerArg->getBeginLoc(),
6054+
diag::err_intel_sycl_ptr_annotation_mismatch)
6055+
<< 0;
6056+
6057+
// Following arguments are paired in format ("String", integer).
6058+
unsigned I = 1;
6059+
for (; I <= NumArgs / 2; ++I) {
6060+
// must be string Literal/const char*
6061+
auto Arg = TheCall->getArg(I)->IgnoreParenImpCasts();
6062+
Expr::EvalResult Result;
6063+
if (!isa<StringLiteral>(Arg) &&
6064+
!maybeConstEvalStringLiteral(this->Context, Arg)) {
6065+
Diag(TheCall->getArg(I)->getBeginLoc(),
6066+
diag::err_intel_sycl_ptr_annotation_mismatch)
6067+
<< 1;
6068+
return true;
6069+
}
6070+
}
6071+
6072+
llvm::APSInt Result;
6073+
for (; I != NumArgs; ++I) {
6074+
// must be integer
6075+
if (SemaBuiltinConstantArg(TheCall, I, Result))
6076+
return true;
6077+
}
6078+
6079+
// Set the return type to be the same as the type of the first argument
6080+
TheCall->setType(PointerArgType);
6081+
return false;
6082+
}
6083+
60216084
/// Given a FunctionDecl's FormatAttr, attempts to populate the FomatStringInfo
60226085
/// parameter with the FormatAttr's correct format_idx and firstDataArg.
60236086
/// Returns true when the format fits the function and the FormatStringInfo has
@@ -9160,9 +9223,6 @@ static void CheckFormatString(
91609223
llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
91619224
bool IgnoreStringsWithoutSpecifiers);
91629225

9163-
static const Expr *maybeConstEvalStringLiteral(ASTContext &Context,
9164-
const Expr *E);
9165-
91669226
// Determine if an expression is a string literal or constant string.
91679227
// If this function returns false on the arguments to a function expecting a
91689228
// format string, we will usually need to emit a warning.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-linux -disable-llvm-passes -emit-llvm %s -internal-isystem %S/Inputs -o - | FileCheck %s
2+
3+
// This test checks that using of __builtin_intel_sycl_ptr_annotation results in correct
4+
// generation of annotations in LLVM IR.
5+
#include "sycl.hpp"
6+
class kernel;
7+
// CHECK: [[STRUCT:%.*]] = type { i32, float }
8+
struct State {
9+
int x;
10+
float y;
11+
};
12+
13+
// CHECK-DAG: [[ANN1:@.str[\.]*[0-9]*]] = {{.*}}"testA\00"
14+
// CHECK-DAG: [[ANN2:@.str[\.]*[0-9]*]] = {{.*}}"testB\00"
15+
// CHECK-DAG: [[ANN3:@.str[\.]*[0-9]*]] = {{.*}}"testC\00"
16+
// CHECK-DAG: [[ANN4:@.str[\.]*[0-9]*]] = {{.*}}"testD\00"
17+
// CHECK-DAG: [[ANN5:@.str[\.]*[0-9]*]] = {{.*}}"testE\00"
18+
// CHECK-DAG: [[ANN6:@.str[\.]*[0-9]*]] = {{.*}}"testF\00"
19+
// CHECK-DAG: [[ANN7:@.str[\.]*[0-9]*]] = {{.*}}"0\00"
20+
// CHECK-DAG: [[ANN8:@.str[\.]*[0-9]*]] = {{.*}}"127\00"
21+
// CHECK-DAG: [[ANN9:@.str[\.]*[0-9]*]] = {{.*}}"7\00"
22+
// CHECK-DAG: [[ANN10:@.str[\.]*[0-9]*]] = {{.*}}"8\00"
23+
// CHECK-DAG: [[ANN11:@.str[\.]*[0-9]*]] = {{.*}}"testG\00"
24+
// CHECK-DAG: [[ANN12:@.str[\.]*[0-9]*]] = {{.*}}"testH\00"
25+
// CHECK-DAG: [[ARG1:@.args[\.]*[0-9]*]] = {{.*}}[[ANN1]]{{.*}}[[ANN7]]
26+
// CHECK-DAG: [[ARG2:@.args[\.]*[0-9]*]] = {{.*}}[[ANN2]]{{.*}}[[ANN8]]
27+
// CHECK-DAG: [[ARG3:@.args[\.]*[0-9]*]] = {{.*}}[[ANN3]]{{.*}}[[ANN7]]
28+
// CHECK-DAG: [[ARG4:@.args[\.]*[0-9]*]] = {{.*}}[[ANN4]]{{.*}}[[ANN7]]
29+
// CHECK-DAG: [[ARG5:@.args[\.]*[0-9]*]] = {{.*}}[[ANN5]]{{.*}}[[ANN7]]
30+
// CHECK-DAG: [[ARG6:@.args[\.]*[0-9]*]] = {{.*}}[[ANN6]]{{.*}}[[ANN7]]{{.*}}[[ANN9]]{{.*}}[[ANN10]]
31+
// CHECK-DAG: [[ARG7:@.args[\.]*[0-9]*]] = {{.*}}[[ANN11]]{{.*}}[[ANN7]]
32+
// CHECK-DAG: [[ARG8:@.args[\.]*[0-9]*]] = {{.*}}[[ANN12]]{{.*}}[[ANN7]]
33+
34+
35+
// CHECK: define {{.*}}spir_func void @{{.*}}(ptr addrspace(4) noundef %A, ptr addrspace(4) noundef %B, ptr addrspace(4) noundef %C, ptr addrspace(4){{.*}}%D)
36+
void foo(float *A, int *B, State *C, State &D) {
37+
float *x;
38+
int *y;
39+
State *z;
40+
double *f;
41+
42+
// CHECK-DAG: [[Aaddr:%.*]] = alloca ptr addrspace(4)
43+
// CHECK-DAG: [[Baddr:%.*]] = alloca ptr addrspace(4)
44+
// CHECK-DAG: [[Caddr:%.*]] = alloca ptr addrspace(4)
45+
// CHECK-DAG: [[Daddr:%.*]] = alloca ptr addrspace(4)
46+
47+
// CHECK-DAG: [[A:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Aaddr]]
48+
// CHECK-DAG: [[PTR1:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[A]]{{.*}}[[ARG1]]{{.*}}
49+
// CHECK-DAG: store ptr addrspace(4) [[PTR1]], ptr addrspace(4) %x
50+
x = __builtin_intel_sycl_ptr_annotation(A, "testA", 0);
51+
52+
// CHECK-DAG: [[B:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Baddr]]
53+
// CHECK-DAG: [[PTR2:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[B]]{{.*}}[[ARG1]]{{.*}}
54+
// CHECK-DAG: store ptr addrspace(4) [[PTR2]], ptr addrspace(4) %y
55+
y = __builtin_intel_sycl_ptr_annotation(B, "testA", 0);
56+
57+
// CHECK-DAG: [[C:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Caddr]]
58+
// CHECK-DAG: [[PTR3:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[C]]{{.*}}[[ARG1]]{{.*}}
59+
// CHECK-DAG: store ptr addrspace(4) [[PTR3]], ptr addrspace(4) %z
60+
z = __builtin_intel_sycl_ptr_annotation(C, "testA", 0);
61+
62+
// CHECK-DAG: [[A2:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Aaddr]]
63+
// CHECK-DAG: [[PTR4:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[A2]]{{.*}}[[ARG2]]{{.*}}
64+
// CHECK-DAG: store ptr addrspace(4) [[PTR4]], ptr addrspace(4) %x
65+
x = __builtin_intel_sycl_ptr_annotation(A, "testB", 127);
66+
67+
// CHECK-DAG: [[B2:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Baddr]]
68+
// CHECK-DAG: [[PTR5:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[B2]]{{.*}}[[ARG2]]{{.*}}
69+
// CHECK-DAG: store ptr addrspace(4) [[PTR5]], ptr addrspace(4) %y
70+
y = __builtin_intel_sycl_ptr_annotation(B, "testB", 127);
71+
72+
// CHECK-DAG: [[C2:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Caddr]]
73+
// CHECK-DAG: [[PTR6:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[C2]]{{.*}}[[ARG2]]{{.*}}
74+
// CHECK-DAG: store ptr addrspace(4) [[PTR6]], ptr addrspace(4) %z
75+
z = __builtin_intel_sycl_ptr_annotation(C, "testB", 127);
76+
77+
// CHECK-DAG: [[D:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Daddr]]
78+
// CHECK-DAG: [[PTR7:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[D]]{{.*}}[[ARG2]]{{.*}}
79+
// CHECK-DAG: store ptr addrspace(4) [[PTR7]], ptr addrspace(4) %z
80+
z = __builtin_intel_sycl_ptr_annotation(&D, "testB", 127);
81+
82+
// CHECK-DAG: [[A3:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Aaddr]]
83+
// CHECK-DAG: [[PTR9:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[A3]]{{.*}}[[ARG3]]{{.*}}
84+
// CHECK-DAG: store ptr addrspace(4) [[PTR9]], ptr addrspace(4) %x
85+
x = __builtin_intel_sycl_ptr_annotation(A, "testC", "testC", "testC", 0, 0, 0);
86+
87+
// CHECK-DAG: [[A4:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Aaddr]]
88+
// CHECK-DAG: [[PTR10:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[A4]]{{.*}}[[ARG4]]{{.*}}
89+
// CHECK-DAG: store ptr addrspace(4) [[PTR10]], ptr addrspace(4) %x
90+
x = __builtin_intel_sycl_ptr_annotation(A, "testD", "testD", "testD", 0, 0, 0);
91+
92+
// CHECK-DAG: [[B3:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Baddr]]
93+
// CHECK-DAG: [[PTR11:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[B3]]{{.*}}[[ARG5]]{{.*}}
94+
// CHECK-DAG: store ptr addrspace(4) [[PTR11]], ptr addrspace(4) %y
95+
y = __builtin_intel_sycl_ptr_annotation(B, "testE", "testE", 0, 0);
96+
97+
constexpr int TestVal1 = 7;
98+
constexpr int TestVal2 = 8;
99+
100+
// CHECK-DAG: [[D1:%[0-9]+]] = load ptr addrspace(4), ptr addrspace(4) [[Daddr]]
101+
// CHECK-DAG: [[PTR12:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[D1]]{{.*}}[[ARG6]]{{.*}}
102+
// CHECK-DAG: store ptr addrspace(4) [[PTR12]], ptr addrspace(4) %z
103+
z = __builtin_intel_sycl_ptr_annotation(&D, "testF", "testF", "testF", "testF", 0, 0, TestVal1, TestVal2);
104+
}
105+
106+
// This check makes sure the generated LoadInst consumes the annotated ptr directly
107+
// CHECK: define {{.*}}spir_func noundef i32 @{{.*}}(ptr addrspace(4) noundef %g)
108+
int annotation_with_load(int* g) {
109+
// CHECK: [[PTR13:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[ARG7]]{{.*}}
110+
// CHECK: load i32, ptr addrspace(4) [[PTR13]]
111+
return *__builtin_intel_sycl_ptr_annotation(g, "testG", 0);
112+
}
113+
114+
// This check makes sure the generated StoreInst consumes the annotated ptr directly
115+
// CHECK: define {{.*}}spir_func void @{{.*}}(ptr addrspace(4) noundef %h)
116+
void annotation_with_store(int* h) {
117+
// CHECK: [[PTR14:%[0-9]+]] = call ptr addrspace(4) @llvm.ptr.annotation{{.*}}[[ARG8]]{{.*}}
118+
// CHECK: store i32 1, ptr addrspace(4) [[PTR14]]
119+
*__builtin_intel_sycl_ptr_annotation(h, "testH", 0) = 1;
120+
}
121+
122+
int main() {
123+
sycl::queue q;
124+
q.submit([&](sycl::handler &h) {
125+
h.single_task<class kernel>([=](){
126+
float *A;
127+
int *B;
128+
State *C;
129+
State D;
130+
foo(A, B, C, D);
131+
132+
int *a;
133+
annotation_with_load(a);
134+
annotation_with_store(a);
135+
});
136+
});
137+
return 0;
138+
}

0 commit comments

Comments
 (0)