24
24
25
25
using namespace llvm ;
26
26
27
+ // Corresponds to definition of spir_private and spir_local in
28
+ // "clang/lib/Basic/Target/SPIR.h", "SPIRDefIsGenMap".
27
29
constexpr static unsigned PrivateAS{0 };
28
30
constexpr static unsigned LocalAS{3 };
29
31
@@ -191,15 +193,12 @@ static void remapIndices(GetElementPtrInst *GEPI, std::size_t LocalSize) {
191
193
auto *NewIndex = [&]() -> Value * {
192
194
if (LocalSize == 1 ) {
193
195
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));
202
196
}
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));
203
202
}();
204
203
GEPI->idx_begin ()->set (NewIndex);
205
204
}
@@ -323,7 +322,7 @@ Error SYCLInternalizerImpl::checkArgsPromotable(
323
322
<< " of function " << F->getName ().str () << " : "
324
323
<< SE.getMessage () << " \n " ;
325
324
});
326
- llvm:: Error NewErr =
325
+ Error NewErr =
327
326
createStringError (inconvertibleErrorCode (), ErrorMessage.str ());
328
327
DeferredErrs = joinErrors (std::move (DeferredErrs), std::move (NewErr));
329
328
}
@@ -346,9 +345,9 @@ void SYCLInternalizerImpl::promoteCall(CallBase *C, const Value *Val,
346
345
const SmallVector<size_t > InternInfo =
347
346
getUsagesInternalization (C, Val, LocalSize);
348
347
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 );
352
351
353
352
C->setCalledFunction (NewF);
354
353
}
@@ -369,9 +368,7 @@ void SYCLInternalizerImpl::promoteGEPI(GetElementPtrInst *GEPI,
369
368
void SYCLInternalizerImpl::promoteValue (Value *Val,
370
369
std::size_t LocalSize) const {
371
370
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);
375
372
switch (I->getOpcode ()) {
376
373
case Instruction::Call:
377
374
case Instruction::Invoke:
@@ -402,7 +399,7 @@ getPromotedFunctionType(FunctionType *OrigTypes,
402
399
if (Arg.value () == 0 ) {
403
400
continue ;
404
401
}
405
- llvm:: Type *&Ty = Types[Arg.index ()];
402
+ Type *&Ty = Types[Arg.index ()];
406
403
// TODO: Catch this case earlier
407
404
if (auto *PtrTy = dyn_cast<PointerType>(Ty)) {
408
405
Ty = PointerType::getWithSamePointeeType (PtrTy, AS);
@@ -416,10 +413,10 @@ static Function *
416
413
getPromotedFunctionDeclaration (Function *F,
417
414
ArrayRef<std::size_t > PromoteToLocal,
418
415
unsigned AS, bool ChangeTypes) {
419
- llvm:: FunctionType *Ty = F->getFunctionType ();
416
+ FunctionType *Ty = F->getFunctionType ();
420
417
// If we do not need to change the types, we just copy the function
421
418
// declaration.
422
- llvm:: FunctionType *NewTy =
419
+ FunctionType *NewTy =
423
420
ChangeTypes ? getPromotedFunctionType (Ty, PromoteToLocal, AS) : Ty;
424
421
return Function::Create (NewTy, F->getLinkage (), F->getAddressSpace (),
425
422
F->getName (), F->getParent ());
@@ -479,7 +476,7 @@ Value *replaceByNewAlloca(Argument *Arg, unsigned AS, std::size_t LocalSize) {
479
476
IRBuilder<> Builder{
480
477
&*Arg->getParent ()->getEntryBlock ().getFirstInsertionPt ()};
481
478
auto *PtrTy = cast<PointerType>(Arg->getType ());
482
- llvm:: Type *Ty = getElementTypeFromUses (Arg);
479
+ Type *Ty = getElementTypeFromUses (Arg);
483
480
assert (Ty && " Could not determine pointer element type" );
484
481
auto *ArrTy = ArrayType::get (Ty, LocalSize);
485
482
auto *Alloca = Builder.CreateAlloca (ArrTy, PtrTy->getAddressSpace ());
@@ -502,7 +499,7 @@ Function *SYCLInternalizerImpl::promoteFunctionArgs(
502
499
IntegerType::get (OldF->getContext (), AddressSpaceBitWidth), AS));
503
500
504
501
// We first declare the promoted function with the new signature.
505
- llvm:: Function *NewF =
502
+ Function *NewF =
506
503
getPromotedFunctionDeclaration (OldF, PromoteToLocal, AS,
507
504
/* ChangeTypes*/ !CreateAllocas);
508
505
@@ -554,7 +551,7 @@ Function *SYCLInternalizerImpl::promoteFunctionArgs(
554
551
const auto Index = I.index ();
555
552
if (const auto *PtrTy =
556
553
dyn_cast<PointerType>(NewF->getArg (Index)->getType ())) {
557
- if (PtrTy->getAddressSpace () == 3 ) {
554
+ if (PtrTy->getAddressSpace () == LocalAS ) {
558
555
NewInfo[Index] = NewAddrspace;
559
556
}
560
557
}
@@ -579,7 +576,7 @@ SYCLInternalizerImpl::operator()(Module &M, ModuleAnalysisManager &AM) const {
579
576
}
580
577
}
581
578
for (auto *F : ToUpdate) {
582
- llvm:: Expected<SmallVector<size_t >> IndicesOrErr =
579
+ Expected<SmallVector<size_t >> IndicesOrErr =
583
580
getInternalizationFromMD (F, Kind);
584
581
if (auto E = IndicesOrErr.takeError ()) {
585
582
handleAllErrors (std::move (E), [](const StringError &SE) {
0 commit comments