瀏覽代碼

Disable emitting static extern C aliases for amdgcn target for CUDA

Patch by Greg Rodgers.
Revised and lit test added by Yaxun Liu.

Differential Revision: https://reviews.llvm.org/D44987


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328793 91177308-0d34-0410-b5e6-96231b3b80d8
Yaxun Liu 7 年之前
父節點
當前提交
8a1c33e1b7
共有 4 個文件被更改,包括 19 次插入3 次删除
  1. 1 3
      lib/CodeGen/CodeGenModule.cpp
  2. 10 0
      lib/CodeGen/TargetInfo.cpp
  3. 5 0
      lib/CodeGen/TargetInfo.h
  4. 3 0
      test/CodeGenCUDA/alias.cu

+ 1 - 3
lib/CodeGen/CodeGenModule.cpp

@@ -4677,9 +4677,7 @@ static void EmitGlobalDeclMetadata(CodeGenModule &CGM,
 /// to such functions with an unmangled name from inline assembly within the
 /// to such functions with an unmangled name from inline assembly within the
 /// same translation unit.
 /// same translation unit.
 void CodeGenModule::EmitStaticExternCAliases() {
 void CodeGenModule::EmitStaticExternCAliases() {
-  // Don't do anything if we're generating CUDA device code -- the NVPTX
-  // assembly target doesn't support aliases.
-  if (Context.getTargetInfo().getTriple().isNVPTX())
+  if (!getTargetCodeGenInfo().shouldEmitStaticExternCAliases())
     return;
     return;
   for (auto &I : StaticExternCValues) {
   for (auto &I : StaticExternCValues) {
     IdentifierInfo *Name = I.first;
     IdentifierInfo *Name = I.first;

+ 10 - 0
lib/CodeGen/TargetInfo.cpp

@@ -6154,6 +6154,7 @@ public:
 
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
                            CodeGen::CodeGenModule &M) const override;
                            CodeGen::CodeGenModule &M) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 
 
 private:
 private:
   // Adds a NamedMDNode with F, Name, and Operand as operands, and adds the
   // Adds a NamedMDNode with F, Name, and Operand as operands, and adds the
@@ -6275,6 +6276,10 @@ void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::Function *F, StringRef Name,
   // Append metadata to nvvm.annotations
   // Append metadata to nvvm.annotations
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
 }
 }
+
+bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -7646,6 +7651,7 @@ public:
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
                             llvm::Function *BlockInvokeFunc,
                             llvm::Function *BlockInvokeFunc,
                             llvm::Value *BlockLiteral) const override;
                             llvm::Value *BlockLiteral) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 };
 };
 }
 }
 
 
@@ -7777,6 +7783,10 @@ AMDGPUTargetCodeGenInfo::getLLVMSyncScopeID(SyncScope S,
   return C.getOrInsertSyncScopeID(Name);
   return C.getOrInsertSyncScopeID(Name);
 }
 }
 
 
+bool AMDGPUTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
+
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
 // SPARC v8 ABI Implementation.
 // SPARC v8 ABI Implementation.
 // Based on the SPARC Compliance Definition version 2.4.1.
 // Based on the SPARC Compliance Definition version 2.4.1.

+ 5 - 0
lib/CodeGen/TargetInfo.h

@@ -296,6 +296,11 @@ public:
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
                             llvm::Function *BlockInvokeFunc,
                             llvm::Function *BlockInvokeFunc,
                             llvm::Value *BlockLiteral) const;
                             llvm::Value *BlockLiteral) 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
+  /// as 'used', and having internal linkage.
+  virtual bool shouldEmitStaticExternCAliases() const { return true; }
 };
 };
 
 
 } // namespace CodeGen
 } // namespace CodeGen

+ 3 - 0
test/CodeGenCUDA/alias.cu

@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 
 #include "Inputs/cuda.h"
 #include "Inputs/cuda.h"