Skip to content

Commit 5afe859

Browse files
committed
[OMPIRBuilder] Remove unnecessary pointer bitcasts (NFCI)
Not needed with opaque pointers.
1 parent 4cc806f commit 5afe859

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,8 +1314,7 @@ static void targetParallelCallback(
13141314
/* if expression */ Cond,
13151315
/* number of threads */ NumThreads ? NumThreads : Builder.getInt32(-1),
13161316
/* Proc bind */ Builder.getInt32(-1),
1317-
/* outlined function */
1318-
Builder.CreateBitCast(&OutlinedFn, OMPIRBuilder->ParallelTaskPtr),
1317+
/* outlined function */ &OutlinedFn,
13191318
/* wrapper function */ NullPtrValue,
13201319
/* arguments of the outlined funciton*/ Args,
13211320
/* number of arguments */ Builder.getInt64(NumCapturedVars)};
@@ -1389,9 +1388,8 @@ hostParallelCallback(OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn,
13891388
Builder.SetInsertPoint(CI);
13901389

13911390
// Build call __kmpc_fork_call[_if](Ident, n, microtask, var1, .., varn);
1392-
Value *ForkCallArgs[] = {
1393-
Ident, Builder.getInt32(NumCapturedVars),
1394-
Builder.CreateBitCast(&OutlinedFn, OMPIRBuilder->ParallelTaskPtr)};
1391+
Value *ForkCallArgs[] = {Ident, Builder.getInt32(NumCapturedVars),
1392+
&OutlinedFn};
13951393

13961394
SmallVector<Value *, 16> RealArgs;
13971395
RealArgs.append(std::begin(ForkCallArgs), std::end(ForkCallArgs));
@@ -1408,8 +1406,6 @@ hostParallelCallback(OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn,
14081406
Value *NullPtrValue = Constant::getNullValue(PtrTy);
14091407
RealArgs.push_back(NullPtrValue);
14101408
}
1411-
if (IfCondition && RealArgs.back()->getType() != PtrTy)
1412-
RealArgs.back() = Builder.CreateBitCast(RealArgs.back(), PtrTy);
14131409

14141410
Builder.CreateCall(RTLFn, RealArgs);
14151411

@@ -4494,18 +4490,19 @@ getKmpcForStaticLoopForType(Type *Ty, OpenMPIRBuilder *OMPBuilder,
44944490

44954491
// Inserts a call to proper OpenMP Device RTL function which handles
44964492
// loop worksharing.
4497-
static void createTargetLoopWorkshareCall(
4498-
OpenMPIRBuilder *OMPBuilder, WorksharingLoopType LoopType,
4499-
BasicBlock *InsertBlock, Value *Ident, Value *LoopBodyArg,
4500-
Type *ParallelTaskPtr, Value *TripCount, Function &LoopBodyFn) {
4493+
static void createTargetLoopWorkshareCall(OpenMPIRBuilder *OMPBuilder,
4494+
WorksharingLoopType LoopType,
4495+
BasicBlock *InsertBlock, Value *Ident,
4496+
Value *LoopBodyArg, Value *TripCount,
4497+
Function &LoopBodyFn) {
45014498
Type *TripCountTy = TripCount->getType();
45024499
Module &M = OMPBuilder->M;
45034500
IRBuilder<> &Builder = OMPBuilder->Builder;
45044501
FunctionCallee RTLFn =
45054502
getKmpcForStaticLoopForType(TripCountTy, OMPBuilder, LoopType);
45064503
SmallVector<Value *, 8> RealArgs;
45074504
RealArgs.push_back(Ident);
4508-
RealArgs.push_back(Builder.CreateBitCast(&LoopBodyFn, ParallelTaskPtr));
4505+
RealArgs.push_back(&LoopBodyFn);
45094506
RealArgs.push_back(LoopBodyArg);
45104507
RealArgs.push_back(TripCount);
45114508
if (LoopType == WorksharingLoopType::DistributeStaticLoop) {
@@ -4529,12 +4526,10 @@ static void createTargetLoopWorkshareCall(
45294526
Builder.CreateCall(RTLFn, RealArgs);
45304527
}
45314528

4532-
static void
4533-
workshareLoopTargetCallback(OpenMPIRBuilder *OMPIRBuilder,
4534-
CanonicalLoopInfo *CLI, Value *Ident,
4535-
Function &OutlinedFn, Type *ParallelTaskPtr,
4536-
const SmallVector<Instruction *, 4> &ToBeDeleted,
4537-
WorksharingLoopType LoopType) {
4529+
static void workshareLoopTargetCallback(
4530+
OpenMPIRBuilder *OMPIRBuilder, CanonicalLoopInfo *CLI, Value *Ident,
4531+
Function &OutlinedFn, const SmallVector<Instruction *, 4> &ToBeDeleted,
4532+
WorksharingLoopType LoopType) {
45384533
IRBuilder<> &Builder = OMPIRBuilder->Builder;
45394534
BasicBlock *Preheader = CLI->getPreheader();
45404535
Value *TripCount = CLI->getTripCount();
@@ -4581,8 +4576,7 @@ workshareLoopTargetCallback(OpenMPIRBuilder *OMPIRBuilder,
45814576
OutlinedFnCallInstruction->eraseFromParent();
45824577

45834578
createTargetLoopWorkshareCall(OMPIRBuilder, LoopType, Preheader, Ident,
4584-
LoopBodyArg, ParallelTaskPtr, TripCount,
4585-
OutlinedFn);
4579+
LoopBodyArg, TripCount, OutlinedFn);
45864580

45874581
for (auto &ToBeDeletedItem : ToBeDeleted)
45884582
ToBeDeletedItem->eraseFromParent();
@@ -4676,8 +4670,8 @@ OpenMPIRBuilder::applyWorkshareLoopTarget(DebugLoc DL, CanonicalLoopInfo *CLI,
46764670
//
46774671
OI.PostOutlineCB = [=, ToBeDeletedVec =
46784672
std::move(ToBeDeleted)](Function &OutlinedFn) {
4679-
workshareLoopTargetCallback(this, CLI, Ident, OutlinedFn, ParallelTaskPtr,
4680-
ToBeDeletedVec, LoopType);
4673+
workshareLoopTargetCallback(this, CLI, Ident, OutlinedFn, ToBeDeletedVec,
4674+
LoopType);
46814675
};
46824676
addOutlineInfo(std::move(OI));
46834677
return CLI->getAfterIP();
@@ -8126,7 +8120,7 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
81268120
// Convert the size in bytes into the number of array elements.
81278121
TypeSize ElementSize = M.getDataLayout().getTypeStoreSize(ElemTy);
81288122
Size = Builder.CreateExactUDiv(Size, Builder.getInt64(ElementSize));
8129-
Value *PtrBegin = Builder.CreateBitCast(BeginIn, Builder.getPtrTy());
8123+
Value *PtrBegin = BeginIn;
81308124
Value *PtrEnd = Builder.CreateGEP(ElemTy, PtrBegin, Size);
81318125

81328126
// Emit array initiation if this is an array section and \p MapType indicates
@@ -8170,10 +8164,8 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
81708164

81718165
// Fill up the runtime mapper handle for all components.
81728166
for (unsigned I = 0; I < Info->BasePointers.size(); ++I) {
8173-
Value *CurBaseArg =
8174-
Builder.CreateBitCast(Info->BasePointers[I], Builder.getPtrTy());
8175-
Value *CurBeginArg =
8176-
Builder.CreateBitCast(Info->Pointers[I], Builder.getPtrTy());
8167+
Value *CurBaseArg = Info->BasePointers[I];
8168+
Value *CurBeginArg = Info->Pointers[I];
81778169
Value *CurSizeArg = Info->Sizes[I];
81788170
Value *CurNameArg = Info->Names.size()
81798171
? Info->Names[I]

0 commit comments

Comments
 (0)