Skip to content

Commit f22c5cd

Browse files
committed
[SQUASH] Fixes after code review comments implementation.
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 32584d8 commit f22c5cd

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

llvm/lib/SYCLLowerIR/LowerESIMD.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <cctype>
3434
#include <cstring>
3535
#include <unordered_map>
36+
#include <iostream>
3637

3738
using namespace llvm;
3839
namespace id = itanium_demangle;
@@ -385,12 +386,7 @@ static const ESIMDIntrinDesc &getIntrinDesc(StringRef SrcSpelling) {
385386

386387
if (It == Table.end()) {
387388
Twine Msg("unknown ESIMD intrinsic: " + SrcSpelling);
388-
389-
llvm::errs() << Msg << "\n";
390-
// TODO warning message for now, to enable compiling tests with intrinsics
391-
// that are not implemented yet
392-
// llvm::report_fatal_error(Msg, false/*no crash diag*/);
393-
return InvalidDesc;
389+
llvm::report_fatal_error(Msg, false /*no crash diag*/);
394390
}
395391
return It->second;
396392
}
@@ -454,8 +450,8 @@ static const T *castNodeImpl(const id::Node *N, id::Node::Kind K) {
454450

455451
static APInt parseTemplateArg(id::FunctionEncoding *FE, unsigned int N,
456452
Type *&Ty, LLVMContext &Ctx) {
457-
auto *Nm = castNode(FE->getName(), NameWithTemplateArgs);
458-
auto *ArgsN = castNode(Nm->TemplateArgs, TemplateArgs);
453+
const auto *Nm = castNode(FE->getName(), NameWithTemplateArgs);
454+
const auto *ArgsN = castNode(Nm->TemplateArgs, TemplateArgs);
459455
id::NodeArray Args = ArgsN->getParams();
460456
assert(N < Args.size() && "too few template arguments");
461457
id::StringView Val;
@@ -652,7 +648,7 @@ static void translatePackMask(CallInst &CI) {
652648
IRBuilder<> Builder(&CI);
653649
llvm::Value *Trunc = Builder.CreateTrunc(
654650
CI.getArgOperand(0),
655-
llvm::VectorType::get(llvm::Type::getInt1Ty(Context), N));
651+
llvm::FixedVectorType::get(llvm::Type::getInt1Ty(Context), N));
656652
llvm::Type *Ty = llvm::Type::getIntNTy(Context, N);
657653

658654
llvm::Value *BitCast = Builder.CreateBitCast(Trunc, Ty);
@@ -699,11 +695,11 @@ static void translateUnPackMask(CallInst &CI) {
699695
}
700696
assert(Arg0->getType()->getPrimitiveSizeInBits() == N);
701697
Arg0 = Builder.CreateBitCast(
702-
Arg0, llvm::VectorType::get(llvm::Type::getInt1Ty(Context), N));
698+
Arg0, llvm::FixedVectorType::get(llvm::Type::getInt1Ty(Context), N));
703699

704700
// get N x i16
705701
llvm::Value *TransCI = Builder.CreateZExt(
706-
Arg0, llvm::VectorType::get(llvm::Type::getInt16Ty(Context), N));
702+
Arg0, llvm::FixedVectorType::get(llvm::Type::getInt16Ty(Context), N));
707703
TransCI->takeName(&CI);
708704
cast<llvm::Instruction>(TransCI)->setDebugLoc(CI.getDebugLoc());
709705
CI.replaceAllUsesWith(TransCI);
@@ -782,7 +778,7 @@ static Instruction *generateVectorGenXForSpirv(CallInst &CI, StringRef Suff,
782778
LLVMContext &Ctx = CI.getModule()->getContext();
783779
Type *I32Ty = Type::getInt32Ty(Ctx);
784780
Function *NewFDecl = GenXIntrinsic::getGenXDeclaration(
785-
CI.getModule(), ID, {VectorType::get(I32Ty, 3)});
781+
CI.getModule(), ID, {FixedVectorType::get(I32Ty, 3)});
786782
Instruction *IntrI =
787783
IntrinsicInst::Create(NewFDecl, {}, CI.getName() + ".esimd", &CI);
788784
int ExtractIndex = getIndexForSuffix(Suff);
@@ -825,8 +821,7 @@ translateSpirvIntrinsic(CallInst *CI, StringRef SpirvIntrName,
825821
auto translateSpirvIntr = [&SpirvIntrName, &ESIMDToErases,
826822
CI](StringRef SpvIName, auto TranslateFunc) {
827823
if (SpirvIntrName.consume_front(SpvIName)) {
828-
Value *TranslatedV =
829-
TranslateFunc(*CI, SpirvIntrName.front()));
824+
Value *TranslatedV = TranslateFunc(*CI, SpirvIntrName);
830825
CI->replaceAllUsesWith(TranslatedV);
831826
ESIMDToErases.push_back(CI);
832827
}
@@ -1025,8 +1020,7 @@ static void translateESIMDIntrinsicCall(CallInst &CI) {
10251020
using Demangler = id::ManglingParser<SimpleAllocator>;
10261021
Function *F = CI.getCalledFunction();
10271022
StringRef MnglName = F->getName();
1028-
const char *MnglNameCStr = MnglName.data();
1029-
Demangler Parser(MnglName.begin(), MnglName.end()));
1023+
Demangler Parser(MnglName.begin(), MnglName.end());
10301024
id::Node *AST = Parser.parse();
10311025

10321026
if (!AST || !Parser.ForwardTemplateRefs.empty()) {
@@ -1219,7 +1213,7 @@ PreservedAnalyses SYCLLowerESIMDPass::run(Function &F,
12191213
IRBuilder<> Builder(&I);
12201214
llvm::Value *Src = CastOp->getOperand(0);
12211215
auto TmpTy =
1222-
llvm::VectorType::get(llvm::Type::getInt32Ty(DstTy->getContext()),
1216+
llvm::FixedVectorType::get(llvm::Type::getInt32Ty(DstTy->getContext()),
12231217
cast<VectorType>(DstTy)->getNumElements());
12241218
Src = Builder.CreateFPToSI(Src, TmpTy);
12251219

@@ -1241,22 +1235,22 @@ PreservedAnalyses SYCLLowerESIMDPass::run(Function &F,
12411235
if (!Name.consume_front(ESIMD_INTRIN_PREF0))
12421236
continue;
12431237
// now skip the digits
1244-
StringRef Name1 = Name1.drop_while([](char C) { return std::isdigit(C); });
1238+
Name = Name.drop_while([](char C) { return std::isdigit(C); });
12451239

12461240
// process ESIMD builtins that go through special handling instead of
12471241
// the translation procedure
1248-
if (Name1.startswith("cl4sycl5intel3gpu8slm_init")) {
1242+
if (Name.startswith("N2cl4sycl5intel3gpu8slm_init")) {
12491243
// tag the kernel with meta-data SLMSize, and remove this builtin
12501244
translateSLMInit(*CI);
12511245
ESIMDToErases.push_back(CI);
12521246
continue;
12531247
}
1254-
if (Name1.startswith("__esimd_pack_mask")) {
1248+
if (Name.startswith("__esimd_pack_mask")) {
12551249
translatePackMask(*CI);
12561250
ESIMDToErases.push_back(CI);
12571251
continue;
12581252
}
1259-
if (Name1.startswith("__esimd_unpack_mask")) {
1253+
if (Name.startswith("__esimd_unpack_mask")) {
12601254
translateUnPackMask(*CI);
12611255
ESIMDToErases.push_back(CI);
12621256
continue;
@@ -1265,32 +1259,32 @@ PreservedAnalyses SYCLLowerESIMDPass::run(Function &F,
12651259
// those globals marked as genx_volatile, We can translate
12661260
// them directly into generic load/store inst. In this way
12671261
// those insts can be optimized by llvm ASAP.
1268-
if (Name1.startswith("__esimd_vload")) {
1262+
if (Name.startswith("__esimd_vload")) {
12691263
if (translateVLoad(*CI, GVTS)) {
12701264
ESIMDToErases.push_back(CI);
12711265
continue;
12721266
}
12731267
}
1274-
if (Name1.startswith("__esimd_vstore")) {
1268+
if (Name.startswith("__esimd_vstore")) {
12751269
if (translateVStore(*CI, GVTS)) {
12761270
ESIMDToErases.push_back(CI);
12771271
continue;
12781272
}
12791273
}
12801274

1281-
if (Name1.startswith("__esimd_get_value")) {
1275+
if (Name.startswith("__esimd_get_value")) {
12821276
translateGetValue(*CI);
12831277
ESIMDToErases.push_back(CI);
12841278
continue;
12851279
}
12861280

1287-
if (Name1.consume_front(SPIRV_INTRIN_PREF)) {
1288-
translateSpirvIntrinsic(CI, Name1, ESIMDToErases);
1281+
if (Name.consume_front(SPIRV_INTRIN_PREF)) {
1282+
translateSpirvIntrinsic(CI, Name, ESIMDToErases);
12891283
// For now: if no match, just let it go untranslated.
12901284
continue;
12911285
}
12921286

1293-
if (Name1.empty() || !Name1.startswith(ESIMD_INTRIN_PREF1))
1287+
if (Name.empty() || !Name.startswith(ESIMD_INTRIN_PREF1))
12941288
continue;
12951289
// this is ESIMD intrinsic - record for later translation
12961290
ESIMDIntrCalls.push_back(CI);

llvm/test/SYCLLowerIR/esimd_lower_intrins.ll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ define dso_local spir_func void @FUNC_29() !sycl_explicit_simd !1 {
163163
ret void
164164
}
165165

166+
define dso_local spir_kernel void @FUNC_30() !sycl_explicit_simd !1 {
167+
; CHECK: define dso_local spir_kernel void @FUNC_30() !sycl_explicit_simd !1
168+
call spir_func void @_ZN2cl4sycl5intel3gpu8slm_initEj(i32 1023)
169+
ret void
170+
; CHECK-NEXT: ret void
171+
}
172+
166173
declare dso_local spir_func <32 x i32> @_Z20__esimd_flat_atomic0ILN2cm3gen14CmAtomicOpTypeE2EjLi32ELNS1_9CacheHintE0ELS3_0EENS1_13__vector_typeIT0_XT1_EE4typeENS4_IyXT1_EE4typeENS4_ItXT1_EE4typeE(<32 x i64> %0, <32 x i16> %1)
167174
declare dso_local spir_func <32 x i32> @_Z20__esimd_flat_atomic1ILN2cm3gen14CmAtomicOpTypeE0EjLi32ELNS1_9CacheHintE0ELS3_0EENS1_13__vector_typeIT0_XT1_EE4typeENS4_IyXT1_EE4typeES7_NS4_ItXT1_EE4typeE(<32 x i64> %0, <32 x i32> %1, <32 x i16> %2)
168175
declare dso_local spir_func <32 x i32> @_Z20__esimd_flat_atomic2ILN2cm3gen14CmAtomicOpTypeE7EjLi32ELNS1_9CacheHintE0ELS3_0EENS1_13__vector_typeIT0_XT1_EE4typeENS4_IyXT1_EE4typeES7_S7_NS4_ItXT1_EE4typeE(<32 x i64> %0, <32 x i32> %1, <32 x i32> %2, <32 x i16> %3)
@@ -192,7 +199,13 @@ declare dso_local spir_func <32 x i32> @_Z24__esimd_media_block_loadIiLi4ELi8E14
192199
declare dso_local spir_func void @_Z25__esimd_media_block_storeIiLi4ELi8E14ocl_image2d_woEvjT2_jjjjN2cm3gen13__vector_typeIT_XmlT0_T1_EE4typeE(i32 %0, %opencl.image2d_wo_t addrspace(1)* %1, i32 %2, i32 %3, i32 %4, i32 %5, <32 x i32> %6)
193200
declare dso_local spir_func <32 x i32> @_Z13__esimd_vloadIiLi32EEN2cm3gen13__vector_typeIT_XT0_EE4typeEPKS5_(<32 x i32> addrspace(4)* %0)
194201
declare dso_local spir_func void @_Z14__esimd_vstoreIfLi16EEvPN2cm3gen13__vector_typeIT_XT0_EE4typeES5_(<16 x float> addrspace(4)* %0, <16 x float> %1)
202+
declare dso_local spir_func void @_ZN2cl4sycl5intel3gpu8slm_initEj(i32)
195203

196204
attributes #0 = { "genx_byte_offset"="192" "genx_volatile" }
197205

198-
!1 = !{}
206+
!genx.kernels = !{!0}
207+
208+
!0 = !{void ()* @"FUNC_30", !"FUNC_30", !1, i32 0, i32 0, !1, !2, i32 0, i32 0}
209+
; CHECK: !0 = !{void ()* @FUNC_30, !"FUNC_30", !1, i32 1023, i32 0, !1, !2, i32 0, i32 0}
210+
!1 = !{i32 0, i32 0}
211+
!2 = !{}

0 commit comments

Comments
 (0)