Skip to content

Commit 1b68ffd

Browse files
authored
[SYCL][Fusion] Fix kernel fusion passes tests (#7719)
Fix tests for kernel fusion passes in static builds by using correct library, loadable by `opt`, for tests. Also fixes post-commit feedback from @AlexeySachkov in #7661. Signed-off-by: Lukas Sommer <[email protected]>
1 parent a916b93 commit 1b68ffd

17 files changed

+108
-126
lines changed

sycl-fusion/passes/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Module library for usage as library/pass-plugin with LLVM opt.
2-
add_llvm_library(SYCLKernelFusion SHARED
2+
add_llvm_library(SYCLKernelFusion MODULE
33
SYCLFusionPasses.cpp
44
kernel-fusion/SYCLKernelFusion.cpp
55
kernel-info/SYCLKernelInfo.cpp

sycl-fusion/passes/cleanup/Cleanup.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void copyAttributesFrom(const BitVector &Mask, Function *NF,
3737
NF->copyAttributesFrom(F);
3838
// Drop masked-out attributes.
3939
SmallVector<AttributeSet> Attributes;
40-
const llvm::AttributeList PAL = NF->getAttributes();
40+
const AttributeList PAL = NF->getAttributes();
4141
std::transform(Mask.set_bits_begin(), Mask.set_bits_end(),
4242
std::back_inserter(Attributes),
4343
[&](unsigned I) { return PAL.getParamAttrs(I); });
@@ -47,11 +47,9 @@ static void copyAttributesFrom(const BitVector &Mask, Function *NF,
4747

4848
static Function *createMaskedFunction(const BitVector &Mask, Function *F) {
4949
// Declare
50-
llvm::FunctionType *NFTy =
51-
createMaskedFunctionType(Mask, F->getFunctionType());
52-
llvm::Function *NF =
53-
Function::Create(NFTy, F->getLinkage(), F->getAddressSpace(),
54-
F->getName(), F->getParent());
50+
FunctionType *NFTy = createMaskedFunctionType(Mask, F->getFunctionType());
51+
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getAddressSpace(),
52+
F->getName(), F->getParent());
5553
copyAttributesFrom(Mask, NF, F);
5654
NF->setComdat(F->getComdat());
5755
NF->takeName(F);
@@ -74,7 +72,7 @@ static Function *createMaskedFunction(const BitVector &Mask, Function *F) {
7472
// Copy metadata.
7573
SmallVector<std::pair<unsigned, MDNode *>> MDs;
7674
F->getAllMetadata(MDs);
77-
for (auto MD : MDs) {
75+
for (auto &MD : MDs) {
7876
NF->addMetadata(MD.first, *MD.second);
7977
}
8078
}
@@ -108,7 +106,7 @@ static void applyArgMask(const jit_compiler::ArgUsageMask &NewArgInfo,
108106
const BitVector &Mask, Function *F,
109107
ModuleAnalysisManager &AM) {
110108
// Create the function without the masked-out args.
111-
llvm::Function *NF = createMaskedFunction(Mask, F);
109+
Function *NF = createMaskedFunction(Mask, F);
112110
// Update the unused args mask.
113111
jit_compiler::SYCLModuleInfo *ModuleInfo =
114112
AM.getResult<SYCLModuleInfoAnalysis>(*NF->getParent()).ModuleInfo;

sycl-fusion/passes/internalization/Internalization.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
using namespace llvm;
2626

27+
// Corresponds to definition of spir_private and spir_local in
28+
// "clang/lib/Basic/Target/SPIR.h", "SPIRDefIsGenMap".
2729
constexpr static unsigned PrivateAS{0};
2830
constexpr static unsigned LocalAS{3};
2931

@@ -191,15 +193,12 @@ static void remapIndices(GetElementPtrInst *GEPI, std::size_t LocalSize) {
191193
auto *NewIndex = [&]() -> Value * {
192194
if (LocalSize == 1) {
193195
return Builder.getInt64(0);
194-
} else {
195-
SmallVector<Value *> OldIndexValue = getIndices(Builder, GEPI);
196-
auto *OldIndexSum =
197-
std::accumulate(std::next(OldIndexValue.begin()), OldIndexValue.end(),
198-
OldIndexValue[0], [&](Value *Lhs, Value *Rhs) {
199-
return Builder.CreateAdd(Lhs, Rhs);
200-
});
201-
return Builder.CreateURem(OldIndexSum, Builder.getInt64(LocalSize));
202196
}
197+
SmallVector<Value *> OldIndexValue = getIndices(Builder, GEPI);
198+
auto *OldIndexSum = std::accumulate(
199+
std::next(OldIndexValue.begin()), OldIndexValue.end(), OldIndexValue[0],
200+
[&](Value *Lhs, Value *Rhs) { return Builder.CreateAdd(Lhs, Rhs); });
201+
return Builder.CreateURem(OldIndexSum, Builder.getInt64(LocalSize));
203202
}();
204203
GEPI->idx_begin()->set(NewIndex);
205204
}
@@ -323,7 +322,7 @@ Error SYCLInternalizerImpl::checkArgsPromotable(
323322
<< " of function " << F->getName().str() << ": "
324323
<< SE.getMessage() << "\n";
325324
});
326-
llvm::Error NewErr =
325+
Error NewErr =
327326
createStringError(inconvertibleErrorCode(), ErrorMessage.str());
328327
DeferredErrs = joinErrors(std::move(DeferredErrs), std::move(NewErr));
329328
}
@@ -346,9 +345,9 @@ void SYCLInternalizerImpl::promoteCall(CallBase *C, const Value *Val,
346345
const SmallVector<size_t> InternInfo =
347346
getUsagesInternalization(C, Val, LocalSize);
348347
assert(!InternInfo.empty() && "Value must be used at least once");
349-
llvm::Function *NewF = promoteFunctionArgs(C->getCalledFunction(), InternInfo,
350-
/* CreateAllocas */ false,
351-
/*KeepOriginal*/ true);
348+
Function *NewF = promoteFunctionArgs(C->getCalledFunction(), InternInfo,
349+
/* CreateAllocas */ false,
350+
/*KeepOriginal*/ true);
352351

353352
C->setCalledFunction(NewF);
354353
}
@@ -369,9 +368,7 @@ void SYCLInternalizerImpl::promoteGEPI(GetElementPtrInst *GEPI,
369368
void SYCLInternalizerImpl::promoteValue(Value *Val,
370369
std::size_t LocalSize) const {
371370
for (auto *U : Val->users()) {
372-
auto *I = dyn_cast<Instruction>(U);
373-
assert(I &&
374-
"Cannot promote value used in a place other than an instruction");
371+
auto *I = cast<Instruction>(U);
375372
switch (I->getOpcode()) {
376373
case Instruction::Call:
377374
case Instruction::Invoke:
@@ -402,7 +399,7 @@ getPromotedFunctionType(FunctionType *OrigTypes,
402399
if (Arg.value() == 0) {
403400
continue;
404401
}
405-
llvm::Type *&Ty = Types[Arg.index()];
402+
Type *&Ty = Types[Arg.index()];
406403
// TODO: Catch this case earlier
407404
if (auto *PtrTy = dyn_cast<PointerType>(Ty)) {
408405
Ty = PointerType::getWithSamePointeeType(PtrTy, AS);
@@ -416,10 +413,10 @@ static Function *
416413
getPromotedFunctionDeclaration(Function *F,
417414
ArrayRef<std::size_t> PromoteToLocal,
418415
unsigned AS, bool ChangeTypes) {
419-
llvm::FunctionType *Ty = F->getFunctionType();
416+
FunctionType *Ty = F->getFunctionType();
420417
// If we do not need to change the types, we just copy the function
421418
// declaration.
422-
llvm::FunctionType *NewTy =
419+
FunctionType *NewTy =
423420
ChangeTypes ? getPromotedFunctionType(Ty, PromoteToLocal, AS) : Ty;
424421
return Function::Create(NewTy, F->getLinkage(), F->getAddressSpace(),
425422
F->getName(), F->getParent());
@@ -479,7 +476,7 @@ Value *replaceByNewAlloca(Argument *Arg, unsigned AS, std::size_t LocalSize) {
479476
IRBuilder<> Builder{
480477
&*Arg->getParent()->getEntryBlock().getFirstInsertionPt()};
481478
auto *PtrTy = cast<PointerType>(Arg->getType());
482-
llvm::Type *Ty = getElementTypeFromUses(Arg);
479+
Type *Ty = getElementTypeFromUses(Arg);
483480
assert(Ty && "Could not determine pointer element type");
484481
auto *ArrTy = ArrayType::get(Ty, LocalSize);
485482
auto *Alloca = Builder.CreateAlloca(ArrTy, PtrTy->getAddressSpace());
@@ -502,7 +499,7 @@ Function *SYCLInternalizerImpl::promoteFunctionArgs(
502499
IntegerType::get(OldF->getContext(), AddressSpaceBitWidth), AS));
503500

504501
// We first declare the promoted function with the new signature.
505-
llvm::Function *NewF =
502+
Function *NewF =
506503
getPromotedFunctionDeclaration(OldF, PromoteToLocal, AS,
507504
/*ChangeTypes*/ !CreateAllocas);
508505

@@ -554,7 +551,7 @@ Function *SYCLInternalizerImpl::promoteFunctionArgs(
554551
const auto Index = I.index();
555552
if (const auto *PtrTy =
556553
dyn_cast<PointerType>(NewF->getArg(Index)->getType())) {
557-
if (PtrTy->getAddressSpace() == 3) {
554+
if (PtrTy->getAddressSpace() == LocalAS) {
558555
NewInfo[Index] = NewAddrspace;
559556
}
560557
}
@@ -579,7 +576,7 @@ SYCLInternalizerImpl::operator()(Module &M, ModuleAnalysisManager &AM) const {
579576
}
580577
}
581578
for (auto *F : ToUpdate) {
582-
llvm::Expected<SmallVector<size_t>> IndicesOrErr =
579+
Expected<SmallVector<size_t>> IndicesOrErr =
583580
getInternalizationFromMD(F, Kind);
584581
if (auto E = IndicesOrErr.takeError()) {
585582
handleAllErrors(std::move(E), [](const StringError &SE) {

0 commit comments

Comments
 (0)