arsenm updated this revision to Diff 488638. arsenm added a comment. Fix patch split. update_cc_test_checks misses the calling convention, so I'm going to precommit a test which verifies those are correct
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141447/new/ https://reviews.llvm.org/D141447 Files: clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGOpenCLRuntime.cpp clang/lib/CodeGen/CGOpenCLRuntime.h clang/lib/CodeGen/TargetInfo.cpp clang/lib/CodeGen/TargetInfo.h
Index: clang/lib/CodeGen/TargetInfo.h =================================================================== --- clang/lib/CodeGen/TargetInfo.h +++ clang/lib/CodeGen/TargetInfo.h @@ -339,7 +339,7 @@ /// convention and ABI as an OpenCL kernel. The wrapper function accepts /// block context and block arguments in target-specific way and calls /// the original block invoke function. - virtual llvm::Function * + virtual llvm::Value * createEnqueuedBlockKernel(CodeGenFunction &CGF, llvm::Function *BlockInvokeFunc, llvm::Type *BlockTy) const; Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -9424,10 +9424,9 @@ SyncScope Scope, llvm::AtomicOrdering Ordering, llvm::LLVMContext &Ctx) const override; - llvm::Function * - createEnqueuedBlockKernel(CodeGenFunction &CGF, - llvm::Function *BlockInvokeFunc, - llvm::Type *BlockTy) const override; + llvm::Value *createEnqueuedBlockKernel(CodeGenFunction &CGF, + llvm::Function *BlockInvokeFunc, + llvm::Type *BlockTy) const override; bool shouldEmitStaticExternCAliases() const override; void setCUDAKernelCallingConvention(const FunctionType *&FT) const override; }; @@ -12403,10 +12402,8 @@ /// The kernel has the same function type as the block invoke function. Its /// name is the name of the block invoke function postfixed with "_kernel". /// It simply calls the block invoke function then returns. -llvm::Function * -TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction &CGF, - llvm::Function *Invoke, - llvm::Type *BlockTy) const { +llvm::Value *TargetCodeGenInfo::createEnqueuedBlockKernel( + CodeGenFunction &CGF, llvm::Function *Invoke, llvm::Type *BlockTy) const { auto *InvokeFT = Invoke->getFunctionType(); auto &C = CGF.getLLVMContext(); std::string Name = Invoke->getName().str() + "_kernel"; @@ -12414,13 +12411,21 @@ InvokeFT->params(), false); auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, Name, &CGF.CGM.getModule()); + llvm::CallingConv::ID KernelCC = + CGF.getTypes().ClangCallConvToLLVMCallConv(CallingConv::CC_OpenCLKernel); + F->setCallingConv(KernelCC); + auto IP = CGF.Builder.saveIP(); auto *BB = llvm::BasicBlock::Create(C, "entry", F); auto &Builder = CGF.Builder; Builder.SetInsertPoint(BB); llvm::SmallVector<llvm::Value *, 2> Args(llvm::make_pointer_range(F->args())); - llvm::CallInst *call = Builder.CreateCall(Invoke, Args); - call->setCallingConv(Invoke->getCallingConv()); + llvm::CallInst *Call = Builder.CreateCall(Invoke, Args); + Call->setCallingConv(Invoke->getCallingConv()); + + // FIXME: Apply default attributes + F->addFnAttr(llvm::Attribute::NoUnwind); + Builder.CreateRetVoid(); Builder.restoreIP(IP); return F; @@ -12434,9 +12439,8 @@ /// allocates the same type of struct on stack and stores the block literal /// to it and passes its pointer to the block invoke function. The kernel /// has "enqueued-block" function attribute and kernel argument metadata. -llvm::Function *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel( - CodeGenFunction &CGF, llvm::Function *Invoke, - llvm::Type *BlockTy) const { +llvm::Value *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel( + CodeGenFunction &CGF, llvm::Function *Invoke, llvm::Type *BlockTy) const { auto &Builder = CGF.Builder; auto &C = CGF.getLLVMContext(); @@ -12470,7 +12474,12 @@ auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false); auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name, &CGF.CGM.getModule()); + F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL); + + // FIXME: Apply default attributes + F->addFnAttr(llvm::Attribute::NoUnwind); F->addFnAttr("enqueued-block"); + auto IP = CGF.Builder.saveIP(); auto *BB = llvm::BasicBlock::Create(C, "entry", F); Builder.SetInsertPoint(BB); Index: clang/lib/CodeGen/CGOpenCLRuntime.h =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.h +++ clang/lib/CodeGen/CGOpenCLRuntime.h @@ -44,7 +44,7 @@ /// Structure for enqueued block information. struct EnqueuedBlockInfo { llvm::Function *InvokeFunc; /// Block invoke function. - llvm::Function *Kernel; /// Enqueued block kernel. + llvm::Value *KernelHandle; /// Enqueued block kernel reference. llvm::Value *BlockArg; /// The first argument to enqueued block kernel. llvm::Type *BlockTy; /// Type of the block argument. }; Index: clang/lib/CodeGen/CGOpenCLRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenCLRuntime.cpp +++ clang/lib/CodeGen/CGOpenCLRuntime.cpp @@ -156,7 +156,7 @@ EnqueuedBlockMap[E].InvokeFunc = InvokeF; EnqueuedBlockMap[E].BlockArg = Block; EnqueuedBlockMap[E].BlockTy = BlockTy; - EnqueuedBlockMap[E].Kernel = nullptr; + EnqueuedBlockMap[E].KernelHandle = nullptr; } llvm::Function *CGOpenCLRuntime::getInvokeFunction(const Expr *E) { @@ -175,7 +175,7 @@ "Block expression not emitted"); // Do not emit the block wrapper again if it has been emitted. - if (EnqueuedBlockMap[Block].Kernel) { + if (EnqueuedBlockMap[Block].KernelHandle) { return EnqueuedBlockMap[Block]; } @@ -183,9 +183,6 @@ CGF, EnqueuedBlockMap[Block].InvokeFunc, EnqueuedBlockMap[Block].BlockTy); // The common part of the post-processing of the kernel goes here. - F->addFnAttr(llvm::Attribute::NoUnwind); - F->setCallingConv( - CGF.getTypes().ClangCallConvToLLVMCallConv(CallingConv::CC_OpenCLKernel)); - EnqueuedBlockMap[Block].Kernel = F; + EnqueuedBlockMap[Block].KernelHandle = F; return EnqueuedBlockMap[Block]; } Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -4921,7 +4921,7 @@ auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(3)); llvm::Value *Kernel = - Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); llvm::Value *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); @@ -4975,7 +4975,7 @@ auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(3)); llvm::Value *Kernel = - Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); llvm::Value *ElemPtr, *TmpSize, *TmpPtr; std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(4); @@ -5032,7 +5032,7 @@ auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(6)); llvm::Value *Kernel = - Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); llvm::Value *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); @@ -5082,7 +5082,8 @@ getContext().getTargetAddressSpace(LangAS::opencl_generic)); auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(0)); - Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Value *Kernel = + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); Value *Arg = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); return RValue::get(EmitRuntimeCall( CGM.CreateRuntimeFunction( @@ -5096,7 +5097,8 @@ getContext().getTargetAddressSpace(LangAS::opencl_generic)); auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(0)); - Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Value *Kernel = + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); Value *Arg = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); return RValue::get(EmitRuntimeCall( CGM.CreateRuntimeFunction( @@ -5113,7 +5115,8 @@ llvm::Value *NDRange = NDRangeL.getAddress(*this).getPointer(); auto Info = CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(1)); - Value *Kernel = Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy); + Value *Kernel = + Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy); Value *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); const char *Name = BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits