mibintc created this revision.
mibintc added reviewers: v_klochkov, Anastasia, yaxunl.
mibintc requested review of this revision.
Herald added a project: clang.

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. 
Due to wrong 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92721

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenOpenCLCXX/atexit.cl


Index: clang/test/CodeGenOpenCLCXX/atexit.cl
===================================================================
--- clang/test/CodeGenOpenCLCXX/atexit.cl
+++ clang/test/CodeGenOpenCLCXX/atexit.cl
@@ -5,7 +5,7 @@
 };
 S s;
 
-//CHECK-LABEL: define internal void @__cxx_global_var_init()
-//CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S 
addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* 
@__dso_handle)
+//CHECK-LABEL: define internal spir_func void @__cxx_global_var_init()
+//CHECK: call spir_func i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S 
addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* 
@__dso_handle)
 
-//CHECK: declare i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
+//CHECK: declare spir_func i32 @__cxa_atexit(void (i8*)*, i8*, i8 
addrspace(1)*)
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9979,15 +9979,30 @@
 // SPIR ABI Implementation
 
//===----------------------------------------------------------------------===//
 
+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 {


Index: clang/test/CodeGenOpenCLCXX/atexit.cl
===================================================================
--- clang/test/CodeGenOpenCLCXX/atexit.cl
+++ clang/test/CodeGenOpenCLCXX/atexit.cl
@@ -5,7 +5,7 @@
 };
 S s;
 
-//CHECK-LABEL: define internal void @__cxx_global_var_init()
-//CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* @__dso_handle)
+//CHECK-LABEL: define internal spir_func void @__cxx_global_var_init()
+//CHECK: call spir_func i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.S addrspace(4)*)* @_ZNU3AS41SD1Ev to void (i8*)*), i8* null, i8 addrspace(1)* @__dso_handle)
 
-//CHECK: declare i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
+//CHECK: declare spir_func i32 @__cxa_atexit(void (i8*)*, i8*, i8 addrspace(1)*)
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9979,15 +9979,30 @@
 // SPIR ABI Implementation
 //===----------------------------------------------------------------------===//
 
+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 {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to