diff options
author | Melanie Blower <melanie.blower@intel.com> | 2020-12-12 05:18:00 -0800 |
---|---|---|
committer | Melanie Blower <melanie.blower@intel.com> | 2020-12-12 05:48:20 -0800 |
commit | 320af6b138391d289fe70db39c51da92e8d3d9df (patch) | |
tree | 933c1ea2eb5c12d8ded87f4a407bca918c7d96fe /clang/lib/CodeGen/TargetInfo.cpp | |
parent | a01b26fb51c710a3a8ef88cc83b0701461f5b9ab (diff) | |
download | llvm-320af6b138391d289fe70db39c51da92e8d3d9df.zip llvm-320af6b138391d289fe70db39c51da92e8d3d9df.tar.gz llvm-320af6b138391d289fe70db39c51da92e8d3d9df.tar.bz2 |
Create SPIRABIInfo to enable SPIR_FUNC calling convention.
Background: Call to library arithmetic functions for div is emitted by the
compiler and it set wrong “C” calling convention for calls to these functions,
whereas library functions are declared with `spir_function` calling convention.
InstCombine optimization replaces such calls with “unreachable” instruction.
It looks like clang lacks SPIRABIInfo class which should specify default
calling conventions for “system” function calls. SPIR supports only
SPIR_FUNC and SPIR_KERNEL calling convention.
Reviewers: Erich Keane, Anastasia
Differential Revision: https://reviews.llvm.org/D92721
Diffstat (limited to 'clang/lib/CodeGen/TargetInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/TargetInfo.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index d4191b9..8d3a343c 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -9936,14 +9936,27 @@ void XCoreTargetCodeGenInfo::emitTargetMetadata( //===----------------------------------------------------------------------===// namespace { +class SPIRABIInfo : public DefaultABIInfo { +public: + SPIRABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) { setCCs(); } + +private: + void setCCs(); +}; +} // end anonymous namespace +namespace { class SPIRTargetCodeGenInfo : public TargetCodeGenInfo { public: SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) - : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {} + : TargetCodeGenInfo(std::make_unique<SPIRABIInfo>(CGT)) {} unsigned getOpenCLKernelCallingConv() const override; }; } // End anonymous namespace. +void SPIRABIInfo::setCCs() { + assert(getRuntimeCC() == llvm::CallingConv::C); + RuntimeCC = llvm::CallingConv::SPIR_FUNC; +} namespace clang { namespace CodeGen { @@ -11045,7 +11058,8 @@ TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction &CGF, llvm::SmallVector<llvm::Value *, 2> Args; for (auto &A : F->args()) Args.push_back(&A); - Builder.CreateCall(Invoke, Args); + llvm::CallInst *call = Builder.CreateCall(Invoke, Args); + call->setCallingConv(Invoke->getCallingConv()); Builder.CreateRetVoid(); Builder.restoreIP(IP); return F; @@ -11109,7 +11123,8 @@ llvm::Function *AMDGPUTargetCodeGenInfo::createEnqueuedBlockKernel( Args.push_back(Cast); for (auto I = F->arg_begin() + 1, E = F->arg_end(); I != E; ++I) Args.push_back(I); - Builder.CreateCall(Invoke, Args); + llvm::CallInst *call = Builder.CreateCall(Invoke, Args); + call->setCallingConv(Invoke->getCallingConv()); Builder.CreateRetVoid(); Builder.restoreIP(IP); |