[PATCH] Make global named registers internal variables

Renato Golin renato.golin at linaro.org
Tue May 20 07:00:48 PDT 2014


Hi rnk,

To avoid emission of the global variable (on both IR and asm/obj), we need to mark it internal (ie. "should not emit").

http://reviews.llvm.org/D3847

Files:
  lib/AST/ASTContext.cpp
  test/CodeGen/named_reg_global.c

Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -7874,6 +7874,9 @@
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
     if (!VD->isFileVarDecl())
       return false;
+    // Global named register variables (GNU extension) are never emitted.
+    if (VD->getStorageClass() == SC_Register && !VD->isLocalVarDecl())
+      return false;
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     // We never need to emit an uninstantiated function template.
     if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
Index: test/CodeGen/named_reg_global.c
===================================================================
--- test/CodeGen/named_reg_global.c
+++ test/CodeGen/named_reg_global.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
 // RUN: %clang_cc1 -triple armv7-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
 
+// CHECK-NOT: @sp = common global
 register unsigned long current_stack_pointer asm("sp");
 
 // CHECK: define{{.*}} i[[bits:[0-9]+]] @get_stack_pointer_addr()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3847.9621.patch
Type: text/x-patch
Size: 1170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140520/bea35b0b/attachment.bin>


More information about the cfe-commits mailing list