forked from OSchip/llvm-project
[CodeGen] Avoid pointer element type access for blocks
Pass the block struct type down to the TargetInfo hooks.
This commit is contained in:
parent
33d74170a3
commit
6e1e99dc07
|
@ -1105,7 +1105,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
|
|||
|
||||
if (IsOpenCL) {
|
||||
CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
|
||||
result);
|
||||
result, blockInfo.StructureType);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1401,7 +1401,8 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
|
|||
if (CGM.getContext().getLangOpts().OpenCL)
|
||||
CGM.getOpenCLRuntime().recordBlockInfo(
|
||||
blockInfo.BlockExpression,
|
||||
cast<llvm::Function>(blockFn->stripPointerCasts()), Result);
|
||||
cast<llvm::Function>(blockFn->stripPointerCasts()), Result,
|
||||
literal->getValueType());
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,13 +148,14 @@ static const BlockExpr *getBlockExpr(const Expr *E) {
|
|||
/// corresponding block expression.
|
||||
void CGOpenCLRuntime::recordBlockInfo(const BlockExpr *E,
|
||||
llvm::Function *InvokeF,
|
||||
llvm::Value *Block) {
|
||||
llvm::Value *Block, llvm::Type *BlockTy) {
|
||||
assert(EnqueuedBlockMap.find(E) == EnqueuedBlockMap.end() &&
|
||||
"Block expression emitted twice");
|
||||
assert(isa<llvm::Function>(InvokeF) && "Invalid invoke function");
|
||||
assert(Block->getType()->isPointerTy() && "Invalid block literal type");
|
||||
EnqueuedBlockMap[E].InvokeFunc = InvokeF;
|
||||
EnqueuedBlockMap[E].BlockArg = Block;
|
||||
EnqueuedBlockMap[E].BlockTy = BlockTy;
|
||||
EnqueuedBlockMap[E].Kernel = nullptr;
|
||||
}
|
||||
|
||||
|
@ -179,8 +180,7 @@ CGOpenCLRuntime::emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, const Expr *E) {
|
|||
}
|
||||
|
||||
auto *F = CGF.getTargetHooks().createEnqueuedBlockKernel(
|
||||
CGF, EnqueuedBlockMap[Block].InvokeFunc,
|
||||
EnqueuedBlockMap[Block].BlockArg->stripPointerCasts());
|
||||
CGF, EnqueuedBlockMap[Block].InvokeFunc, EnqueuedBlockMap[Block].BlockTy);
|
||||
|
||||
// The common part of the post-processing of the kernel goes here.
|
||||
F->addFnAttr(llvm::Attribute::NoUnwind);
|
||||
|
|
|
@ -46,6 +46,7 @@ protected:
|
|||
llvm::Function *InvokeFunc; /// Block invoke function.
|
||||
llvm::Function *Kernel; /// Enqueued block kernel.
|
||||
llvm::Value *BlockArg; /// The first argument to enqueued block kernel.
|
||||
llvm::Type *BlockTy; /// Type of the block argument.
|
||||
};
|
||||
/// Maps block expression to block information.
|
||||
llvm::DenseMap<const Expr *, EnqueuedBlockInfo> EnqueuedBlockMap;
|
||||
|
@ -93,7 +94,7 @@ public:
|
|||
/// \param InvokeF invoke function emitted for the block expression.
|
||||
/// \param Block block literal emitted for the block expression.
|
||||
void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF,
|
||||
llvm::Value *Block);
|
||||
llvm::Value *Block, llvm::Type *BlockTy);
|
||||
|
||||
/// \return LLVM block invoke function emitted for an expression derived from
|
||||
/// the block expression.
|
||||
|
|
|
@ -9214,7 +9214,7 @@ public:
|
|||
llvm::Function *
|
||||
createEnqueuedBlockKernel(CodeGenFunction &CGF,
|
||||
llvm::Function *BlockInvokeFunc,
|
||||
llvm::Value *BlockLiteral) const override;
|
||||
llvm::Type *BlockTy) const override;
|
||||
bool shouldEmitStaticExternCAliases() const override;
|
||||
void setCUDAKernelCallingConvention(const FunctionType *&FT) const override;
|
||||
};
|
||||
|
@ -11461,7 +11461,7 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
|
|||
llvm::Function *
|
||||
TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction &CGF,
|
||||
llvm::Function *Invoke,
|
||||
llvm::Value *BlockLiteral) const {
|
||||
llvm::Type *BlockTy) const {
|
||||
auto *InvokeFT = Invoke->getFunctionType();
|
||||
llvm::SmallVector<llvm::Type *, 2> ArgTys;
|
||||
for (auto &P : InvokeFT->params())
|
||||
|
@ -11495,11 +11495,10 @@ TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction &CGF,
|
|||
/// has "enqueued-block" function attribute and kernel argument metadata.
|
||||
llvm::Function *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel(
|
||||
CodeGenFunction &CGF, llvm::Function *Invoke,
|
||||
llvm::Value *BlockLiteral) const {
|
||||
llvm::Type *BlockTy) const {
|
||||
auto &Builder = CGF.Builder;
|
||||
auto &C = CGF.getLLVMContext();
|
||||
|
||||
auto *BlockTy = BlockLiteral->getType()->getPointerElementType();
|
||||
auto *InvokeFT = Invoke->getFunctionType();
|
||||
llvm::SmallVector<llvm::Type *, 2> ArgTys;
|
||||
llvm::SmallVector<llvm::Metadata *, 8> AddressQuals;
|
||||
|
|
|
@ -329,7 +329,7 @@ public:
|
|||
virtual llvm::Function *
|
||||
createEnqueuedBlockKernel(CodeGenFunction &CGF,
|
||||
llvm::Function *BlockInvokeFunc,
|
||||
llvm::Value *BlockLiteral) const;
|
||||
llvm::Type *BlockTy) const;
|
||||
|
||||
/// \return true if the target supports alias from the unmangled name to the
|
||||
/// mangled name of functions declared within an extern "C" region and marked
|
||||
|
|
Loading…
Reference in New Issue