-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[OMPIRBuilder] - Fix emitTargetTaskProxyFunc to not generate empty functions #126958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7022,10 +7022,11 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder, | |||||||||||||||||||||
| Function *KernelLaunchFunction = StaleCI->getCalledFunction(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // StaleCI is the CallInst which is the call to the outlined | ||||||||||||||||||||||
| // target kernel launch function. If there are values that the | ||||||||||||||||||||||
| // outlined function uses then these are aggregated into a structure | ||||||||||||||||||||||
| // which is passed as the second argument. If not, then there's | ||||||||||||||||||||||
| // only one argument, the threadID. So, StaleCI can be | ||||||||||||||||||||||
| // target kernel launch function. If there are local live-in values | ||||||||||||||||||||||
| // that the outlined function uses then these are aggregated into a structure | ||||||||||||||||||||||
| // which is passed as the second argument. If there are no local live-in | ||||||||||||||||||||||
| // vallues or if all values used by the outlined kernel are global variables, | ||||||||||||||||||||||
| // then there's only one argument, the threadID. So, StaleCI can be | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // %structArg = alloca { ptr, ptr }, align 8 | ||||||||||||||||||||||
| // %gep_ = getelementptr { ptr, ptr }, ptr %structArg, i32 0, i32 0 | ||||||||||||||||||||||
|
|
@@ -7063,6 +7064,8 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder, | |||||||||||||||||||||
| // host and device. | ||||||||||||||||||||||
| assert((!HasShareds || (StaleCI->arg_size() == 2)) && | ||||||||||||||||||||||
| "StaleCI with shareds should have exactly two arguments."); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Value *ThreadId = ProxyFn->getArg(0); | ||||||||||||||||||||||
| if (HasShareds) { | ||||||||||||||||||||||
| auto *ArgStructAlloca = dyn_cast<AllocaInst>(StaleCI->getArgOperand(1)); | ||||||||||||||||||||||
| assert(ArgStructAlloca && | ||||||||||||||||||||||
|
|
@@ -7073,7 +7076,6 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder, | |||||||||||||||||||||
| AllocaInst *NewArgStructAlloca = | ||||||||||||||||||||||
| Builder.CreateAlloca(ArgStructType, nullptr, "structArg"); | ||||||||||||||||||||||
| Value *TaskT = ProxyFn->getArg(1); | ||||||||||||||||||||||
| Value *ThreadId = ProxyFn->getArg(0); | ||||||||||||||||||||||
| Value *SharedsSize = | ||||||||||||||||||||||
| Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -7086,7 +7088,9 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder, | |||||||||||||||||||||
| LoadShared->getPointerAlignment(M.getDataLayout()), SharedsSize); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Builder.CreateCall(KernelLaunchFunction, {ThreadId, NewArgStructAlloca}); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } else | ||||||||||||||||||||||
| Builder.CreateCall(KernelLaunchFunction, {ThreadId}); | ||||||||||||||||||||||
bhandarkar-pranav marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Builder.CreateRetVoid(); | ||||||||||||||||||||||
| return ProxyFn; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -7229,11 +7233,28 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask( | |||||||||||||||||||||
| Builder, AllocaIP, ToBeDeleted, TargetTaskAllocaIP, "global.tid", false)); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Builder.restoreIP(TargetTaskBodyIP); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (Error Err = TaskBodyCB(DeviceID, RTLoc, TargetTaskAllocaIP)) | ||||||||||||||||||||||
| return Err; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| OI.ExitBB = Builder.saveIP().getBlock(); | ||||||||||||||||||||||
| // The outliner (CodeExtractor) extract a sequence or vector of blocks that | ||||||||||||||||||||||
| // it is given. These blocks are enumerated by | ||||||||||||||||||||||
| // OpenMPIRBuilder::OutlineInfo::collectBlocks which expects the OI.ExitBlock | ||||||||||||||||||||||
| // to be outside the region. In other words, OI.ExitBlock is expected to be | ||||||||||||||||||||||
| // the start of the region after the outlining. We used to set OI.ExitBlock | ||||||||||||||||||||||
| // to the InsertBlock after TaskBodyCB is done. This is fine in most cases | ||||||||||||||||||||||
| // except when the task body is a single basic block. In that case, | ||||||||||||||||||||||
| // OI.ExitBlock is set to the single task body block and will get left out of | ||||||||||||||||||||||
| // the outlining process. So, simply create a new empty block to which we | ||||||||||||||||||||||
| // uncoditionally branch from where TaskBodyCB left off | ||||||||||||||||||||||
| BasicBlock *TargetTaskContBlock = | ||||||||||||||||||||||
| BasicBlock::Create(Builder.getContext(), "target.task.cont"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| auto *CurFn = Builder.GetInsertBlock()->getParent(); | ||||||||||||||||||||||
| emitBranch(TargetTaskContBlock); | ||||||||||||||||||||||
| emitBlock(TargetTaskContBlock, CurFn, /*IsFinished=*/true); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| OI.ExitBB = TargetTaskContBlock; | ||||||||||||||||||||||
|
||||||||||||||||||||||
| BasicBlock *TargetTaskContBlock = | |
| BasicBlock::Create(Builder.getContext(), "target.task.cont"); | |
| auto *CurFn = Builder.GetInsertBlock()->getParent(); | |
| emitBranch(TargetTaskContBlock); | |
| emitBlock(TargetTaskContBlock, CurFn, /*IsFinished=*/true); | |
| OI.ExitBB = TargetTaskContBlock; | |
| OI.ExitBB = splitBB(Builder, /*CreateBranch=*/true, "target.task.cont"); | |
| emitBlock(OI.ExitBB, OI.ExitBB->getParent(), /*IsFinished=*/true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emitBlock isn't needed as splitBB calls BasicBlock::create with a Function *. This results in the block being inserted into the function. Calling emitBlock after splitBlock triggers asserts.
Uh oh!
There was an error while loading. Please reload this page.