[llvm] b36e3a8 - [IRMover] Set Address Space for moved global values

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 16:33:05 PST 2019


Author: Teresa Johnson
Date: 2019-11-05T16:32:48-08:00
New Revision: b36e3a8bac3ee95a5a67ab0acb6ef2a2602226a7

URL: https://github.com/llvm/llvm-project/commit/b36e3a8bac3ee95a5a67ab0acb6ef2a2602226a7
DIFF: https://github.com/llvm/llvm-project/commit/b36e3a8bac3ee95a5a67ab0acb6ef2a2602226a7.diff

LOG: [IRMover] Set Address Space for moved global values

Summary:
Set Address Space when creating a new function (from another).

Fix PR41154.

Patch by Ehud Katz <ehudkatz at gmail.com>

Reviewers: tejohnson, chandlerc

Reviewed By: tejohnson

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

Added: 
    llvm/test/Linker/addrspace.ll

Modified: 
    llvm/lib/Linker/IRMover.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 1cef0e84a308..1b17d825b98b 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -654,9 +654,9 @@ AttributeList IRLinker::mapAttributeTypes(LLVMContext &C, AttributeList Attrs) {
 Function *IRLinker::copyFunctionProto(const Function *SF) {
   // If there is no linkage to be performed or we are linking from the source,
   // bring SF over.
-  auto *F =
-      Function::Create(TypeMap.get(SF->getFunctionType()),
-                       GlobalValue::ExternalLinkage, SF->getName(), &DstM);
+  auto *F = Function::Create(TypeMap.get(SF->getFunctionType()),
+                             GlobalValue::ExternalLinkage,
+                             SF->getAddressSpace(), SF->getName(), &DstM);
   F->copyAttributesFrom(SF);
   F->setAttributes(mapAttributeTypes(F->getContext(), F->getAttributes()));
   return F;
@@ -695,7 +695,8 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
     else if (SGV->getValueType()->isFunctionTy())
       NewGV =
           Function::Create(cast<FunctionType>(TypeMap.get(SGV->getValueType())),
-                           GlobalValue::ExternalLinkage, SGV->getName(), &DstM);
+                           GlobalValue::ExternalLinkage, SGV->getAddressSpace(),
+                           SGV->getName(), &DstM);
     else
       NewGV =
           new GlobalVariable(DstM, TypeMap.get(SGV->getValueType()),

diff  --git a/llvm/test/Linker/addrspace.ll b/llvm/test/Linker/addrspace.ll
new file mode 100644
index 000000000000..713aa01fc9dd
--- /dev/null
+++ b/llvm/test/Linker/addrspace.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-link %s -S | FileCheck %s
+
+ at G = addrspace(2) global i32 256 
+; CHECK: @G = addrspace(2) global i32
+
+ at GA = alias i32, i32 addrspace(2)* @G
+; CHECK: @GA = alias i32, i32 addrspace(2)* @G
+
+define void @foo() addrspace(3) {
+; CHECK: define void @foo() addrspace(3)
+  ret void
+}


        


More information about the llvm-commits mailing list