@@ -2143,6 +2143,32 @@ struct OmpSs : public ModulePass {
2143
2143
// Set debug info from the task entry to all instructions
2144
2144
IRB.SetCurrentDebugLocation (DLoc);
2145
2145
2146
+ // Add a branch to the next basic block after the task region
2147
+ // and replace the terminator that exits the task region
2148
+ // Since this is a single entry single exit region this should
2149
+ // be done once.
2150
+ BasicBlock *NewRetBB = nullptr ;
2151
+ for (BasicBlock *Block : Blocks) {
2152
+ Instruction *DirInfo = Block->getTerminator ();
2153
+ for (unsigned i = 0 , e = DirInfo->getNumSuccessors (); i != e; ++i)
2154
+ if (!Blocks.count (DirInfo->getSuccessor (i))) {
2155
+ assert (!NewRetBB && " More than one exit in task code" );
2156
+
2157
+ BasicBlock *OldTarget = DirInfo->getSuccessor (i);
2158
+ // Create branch to next BB after the task region
2159
+ IRB.CreateBr (OldTarget);
2160
+
2161
+ NewRetBB = BasicBlock::Create (M.getContext (), " .exitStub" , newFunction);
2162
+ IRBuilder<> (NewRetBB).CreateRetVoid ();
2163
+
2164
+ // rewrite the original branch instruction with this new target
2165
+ DirInfo->setSuccessor (i, NewRetBB);
2166
+ }
2167
+ }
2168
+
2169
+ // Here we have a valid codeReplacer BasicBlock with its terminator
2170
+ IRB.SetInsertPoint (codeReplacer->getTerminator ());
2171
+
2146
2172
AllocaInst *TaskArgsVar = IRB.CreateAlloca (TaskArgsTy->getPointerTo ());
2147
2173
Value *TaskArgsVarCast = IRB.CreateBitCast (TaskArgsVar, IRB.getInt8PtrTy ()->getPointerTo ());
2148
2174
Value *TaskFlagsVar = computeTaskFlags (IRB, DirEnv);
@@ -2163,20 +2189,55 @@ struct OmpSs : public ModulePass {
2163
2189
2164
2190
Value *TaskArgsVLAsExtraSizeOf = computeTaskArgsVLAsExtraSizeOf (M, IRB, VLADimsInfo);
2165
2191
Value *TaskArgsSizeOf = IRB.CreateNUWAdd (TaskArgsStructSizeOf, TaskArgsVLAsExtraSizeOf);
2166
- int NumDependencies = DependsInfo.List .size ();
2167
- for (auto &DepInfo : DependsInfo.List ) {
2168
- if (isa<MultiDependInfo>(DepInfo.get ())) {
2169
- // TODO: build loop to compute the amount of dependencies in
2170
- // multideps. Fallback to -1 if the task has some dependency
2171
- NumDependencies = -1 ;
2172
- break ;
2192
+
2193
+ Instruction *NumDependencies = IRB.CreateAlloca (IRB.getInt64Ty (), nullptr , " num.deps" );
2194
+ if (DirEnv.isOmpSsTaskLoopDirective ()) {
2195
+ // If taskloop NumDeps = -1
2196
+ IRB.CreateStore (IRB.getInt64 (-1 ), NumDependencies);
2197
+ } else {
2198
+ IRB.CreateStore (IRB.getInt64 (0 ), NumDependencies);
2199
+ for (auto &DepInfo : DependsInfo.List ) {
2200
+ Instruction *NumDependenciesLoad = IRB.CreateLoad (NumDependencies);
2201
+ Value *NumDependenciesIncr = IRB.CreateAdd (NumDependenciesLoad, IRB.getInt64 (1 ));
2202
+ Instruction *NumDependenciesStore = IRB.CreateStore (NumDependenciesIncr, NumDependencies);
2203
+ if (const auto *MultiDepInfo = dyn_cast<MultiDependInfo>(DepInfo.get ())) {
2204
+
2205
+ // Build a BasicBlock containing the num_deps increment
2206
+ NumDependenciesLoad->getParent ()->splitBasicBlock (NumDependenciesLoad);
2207
+ Instruction *AfterNumDependenciesStore = NumDependenciesStore->getNextNode ();
2208
+ AfterNumDependenciesStore->getParent ()->splitBasicBlock (AfterNumDependenciesStore);
2209
+
2210
+ // NOTE: after spliting IRBuilder is pointing to a bad BasicBlock.
2211
+ // Set again the insert point
2212
+ IRB.SetInsertPoint (AfterNumDependenciesStore);
2213
+
2214
+ Function *ComputeMultiDepFun = MultiDepInfo->ComputeMultiDepFun ;
2215
+ auto Args = MultiDepInfo->Args ;
2216
+ for (size_t i = 0 ; i < MultiDepInfo->Iters .size (); i++) {
2217
+ Value *IndVar = MultiDepInfo->Iters [i];
2218
+ auto LBoundGen = [ComputeMultiDepFun, &Args, i](IRBuilder<> &IRB) {
2219
+ Value *ComputeMultiDepCall = IRB.CreateCall (ComputeMultiDepFun, Args);
2220
+ return IRB.CreateExtractValue (ComputeMultiDepCall, i*(3 + 1 ) + 0 );
2221
+ };
2222
+ auto RemapGen = [IndVar](IRBuilder<> &IRB) {
2223
+ // We do not need remap here
2224
+ return IRB.CreateLoad (IndVar);
2225
+ };
2226
+ auto UBoundGen = [ComputeMultiDepFun, &Args, i](IRBuilder<> &IRB) {
2227
+ Value *ComputeMultiDepCall = IRB.CreateCall (ComputeMultiDepFun, Args);
2228
+ return IRB.CreateExtractValue (ComputeMultiDepCall, i*(3 + 1 ) + 2 );
2229
+ };
2230
+ auto IncrGen = [ComputeMultiDepFun, &Args, i](IRBuilder<> &IRB) {
2231
+ Value *ComputeMultiDepCall = IRB.CreateCall (ComputeMultiDepFun, Args);
2232
+ return IRB.CreateExtractValue (ComputeMultiDepCall, i*(3 + 1 ) + 3 );
2233
+ };
2234
+ buildLoopForMultiDep (
2235
+ M, F, NumDependenciesLoad, NumDependenciesStore, IndVar, LBoundGen, RemapGen, UBoundGen, IncrGen);
2236
+ }
2237
+ }
2173
2238
}
2174
2239
}
2175
2240
2176
- // If taskloop NumDeps = -1
2177
- if (DirEnv.isOmpSsTaskLoopDirective ())
2178
- NumDependencies = -1 ;
2179
-
2180
2241
// Store label if it's not a string literal (i.e label("L1"))
2181
2242
if (DirEnv.Label && !isa<Constant>(DirEnv.Label )) {
2182
2243
Value *Idx[3 ];
@@ -2193,8 +2254,7 @@ struct OmpSs : public ModulePass {
2193
2254
TaskArgsVarCast,
2194
2255
TaskPtrVar,
2195
2256
TaskFlagsVar,
2196
- ConstantInt::get (IRB.getInt64Ty (),
2197
- NumDependencies)});
2257
+ IRB.CreateLoad (NumDependencies)});
2198
2258
2199
2259
// DSA capture
2200
2260
Value *TaskArgsVarL = IRB.CreateLoad (TaskArgsVar);
@@ -2398,29 +2458,6 @@ struct OmpSs : public ModulePass {
2398
2458
}
2399
2459
2400
2460
CallInst *TaskSubmitFuncCall = IRB.CreateCall (TaskSubmitFuncCallee, TaskPtrVarL);
2401
- // Add a branch to the next basic block after the task region
2402
- // and replace the terminator that exits the task region
2403
- // Since this is a single entry single exit region this should
2404
- // be done once.
2405
- BasicBlock *NewRetBB = nullptr ;
2406
- for (BasicBlock *Block : Blocks) {
2407
- Instruction *DirInfo = Block->getTerminator ();
2408
- for (unsigned i = 0 , e = DirInfo->getNumSuccessors (); i != e; ++i)
2409
- if (!Blocks.count (DirInfo->getSuccessor (i))) {
2410
- assert (!NewRetBB && " More than one exit in task code" );
2411
-
2412
- BasicBlock *OldTarget = DirInfo->getSuccessor (i);
2413
- // Create branch to next BB after the task region
2414
- IRB.CreateBr (OldTarget);
2415
-
2416
- NewRetBB = BasicBlock::Create (M.getContext (), " .exitStub" , newFunction);
2417
- IRBuilder<> (NewRetBB).CreateRetVoid ();
2418
-
2419
- // rewrite the original branch instruction with this new target
2420
- DirInfo->setSuccessor (i, NewRetBB);
2421
- }
2422
- }
2423
-
2424
2461
return TaskSubmitFuncCall;
2425
2462
};
2426
2463
0 commit comments