Skip to content

Commit 96662a8

Browse files
author
Chen, Brox
committed
Merge branch 'sycl' of https://github.com/intel/llvm into reorg-folder
2 parents de02e5a + 99e8dbe commit 96662a8

File tree

90 files changed

+3486
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3486
-468
lines changed

clang/docs/ClangOffloadPackager.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ the following values for the :ref:`offload kind<table-offload_kind>` and the
112112
+------------+-------+---------------------------------------+
113113
| OFK_HIP | 0x03 | The producer was HIP |
114114
+------------+-------+---------------------------------------+
115+
| OFK_SYCL | 0x04 | The producer was SYCL |
116+
+------------+-------+---------------------------------------+
115117

116118
The flags are used to signify certain conditions, such as the presence of
117119
debugging information or whether or not LTO was used. The string entry table is

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: 55 additions & 4 deletions
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());
@@ -22414,6 +22415,12 @@ RValue CodeGenFunction::EmitIntelFPGAMemBuiltin(const CallExpr *E) {
2241422415
return RValue::get(Ann);
2241522416
}
2241622417

22418+
static bool hasFuncNameRequestedFPAccuracy(StringRef Name,
22419+
const LangOptions &LangOpts) {
22420+
auto FuncMapIt = LangOpts.FPAccuracyFuncMap.find(Name.str());
22421+
return (FuncMapIt != LangOpts.FPAccuracyFuncMap.end());
22422+
}
22423+
2241722424
llvm::CallInst *CodeGenFunction::EmitFPBuiltinIndirectCall(
2241822425
llvm::FunctionType *IRFuncTy, const SmallVectorImpl<llvm::Value *> &IRArgs,
2241922426
llvm::Value *FnPtr, const FunctionDecl *FD) {
@@ -22522,9 +22529,53 @@ llvm::CallInst *CodeGenFunction::EmitFPBuiltinIndirectCall(
2252222529
if (!FPAccuracyIntrinsicID)
2252322530
return nullptr;
2252422531

22525-
Func = CGM.getIntrinsic(FPAccuracyIntrinsicID, IRArgs[0]->getType());
22526-
return CreateBuiltinCallWithAttr(*this, Name, Func, ArrayRef(IRArgs),
22527-
FPAccuracyIntrinsicID);
22532+
// Create an intrinsic only if it exists in the map, or if there
22533+
// a TU fp-accuracy requested.
22534+
const LangOptions &LangOpts = getLangOpts();
22535+
if (hasFuncNameRequestedFPAccuracy(Name, LangOpts) ||
22536+
!LangOpts.FPAccuracyVal.empty()) {
22537+
Func = CGM.getIntrinsic(FPAccuracyIntrinsicID, IRArgs[0]->getType());
22538+
return CreateBuiltinCallWithAttr(*this, Name, Func, ArrayRef(IRArgs),
22539+
FPAccuracyIntrinsicID);
22540+
}
22541+
return nullptr;
22542+
}
22543+
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);
2252822579
}
2252922580

2253022581
Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ void CodeGenModule::getDefaultFunctionFPAccuracyAttributes(
18901890
StringRef FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin(
18911891
ID, FuncType, convertFPAccuracy(FuncMapIt->second));
18921892
assert(!FPAccuracyVal.empty() && "A valid accuracy value is expected");
1893-
FuncAttrs.addAttribute("fpbuiltin-max-error=", FPAccuracyVal);
1893+
FuncAttrs.addAttribute("fpbuiltin-max-error", FPAccuracyVal);
18941894
MD = llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
18951895
Int32Ty, convertFPAccuracyToAspect(FuncMapIt->second)));
18961896
}
@@ -1900,7 +1900,7 @@ void CodeGenModule::getDefaultFunctionFPAccuracyAttributes(
19001900
StringRef FPAccuracyVal = llvm::fp::getAccuracyForFPBuiltin(
19011901
ID, FuncType, convertFPAccuracy(getLangOpts().FPAccuracyVal));
19021902
assert(!FPAccuracyVal.empty() && "A valid accuracy value is expected");
1903-
FuncAttrs.addAttribute("fpbuiltin-max-error=", FPAccuracyVal);
1903+
FuncAttrs.addAttribute("fpbuiltin-max-error", FPAccuracyVal);
19041904
MD = llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
19051905
Int32Ty, convertFPAccuracyToAspect(getLangOpts().FPAccuracyVal)));
19061906
}

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.

0 commit comments

Comments
 (0)