yaxunl marked 4 inline comments as done.
yaxunl added inline comments.

================
Comment at: lib/CodeGen/CGOpenCLRuntime.cpp:144
+  if (auto *I = dyn_cast<llvm::Instruction>(V)) {
+    // If the block literal is emitted as an instruction, it is an alloca
+    // and the block invoke function is stored to GEP of this alloca.
----------------
Anastasia wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > Why do we need to replace original block calls with the kernels? I think 
> > > in case of calling a block we could use the original block function and 
> > > only for enqueue use the kernel that would call the block function 
> > > inside. The pointer to the kernel wrapper could be passed as an 
> > > additional parameter to `enqueue_kernel` calls. We won't need to iterate 
> > > through all IR then.
> > `CGF.EmitScalarExpr(Block)` returns the block literal structure which 
> > contains the size/align/invoke_function/captures. The block invoke function 
> > is stored to the struct by a `StoreInst`. To create the wrapper kernel, we 
> > need to get the block invoke function, therefore we have to iterate through 
> > IR.
> > 
> > Since we need to find the store instruction any way, it is simpler to just 
> > replace the stored function with the kernel and pass the block literal 
> > struct, instead of passing the kernel separately.
> So we cann't get the invoke function from the block literal structure passed 
> into the kernel wrapper directly knowing its offset? Iterating through IR 
> adds extra time and also I am not sure how reliable this is wrt different 
> corner cases of IR.
Unfortunately the invoke function is not returned directly. Instead, it is 
buried in an LLVM value. And to extract the invoke function from the LLVM value 
we have to wade through a bunch of LLVM IRs.

There is one way to get the invoke function directly instead of going through 
IRs, but we need to change the functions for generating code for the blocks a 
little bit so that they return the block invoke function.


https://reviews.llvm.org/D38134



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to