[llvm] r246788 - Allow global address space forward decls using IDs in .ll files.
Karl Schimpf via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 11:06:44 PDT 2015
Author: kschimpf
Date: Thu Sep 3 13:06:44 2015
New Revision: 246788
URL: http://llvm.org/viewvc/llvm-project?rev=246788&view=rev
Log:
Allow global address space forward decls using IDs in .ll files.
Summary:
This fixes bugzilla bug 24656. Fixes the case where there is a forward
reference to a global variable using an ID (i.e. @0). It does this by
passing the address space of the initializer pointer for which the
forward referenced global is used.
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/test/Assembler/global-addrspace-forwardref.ll
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=246788&r1=246787&r2=246788&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Thu Sep 3 13:06:44 2015
@@ -1040,6 +1040,17 @@ bool LLParser::ParseFnAttributeValuePair
// GlobalValue Reference/Resolution Routines.
//===----------------------------------------------------------------------===//
+static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy,
+ const std::string &Name) {
+ if (auto *FT = dyn_cast<FunctionType>(PTy->getElementType()))
+ return Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
+ else
+ return new GlobalVariable(*M, PTy->getElementType(), false,
+ GlobalValue::ExternalWeakLinkage, nullptr, Name,
+ nullptr, GlobalVariable::NotThreadLocal,
+ PTy->getAddressSpace());
+}
+
/// GetGlobalVal - Get a value with the specified name or ID, creating a
/// forward reference record if needed. This can return null if the value
/// exists but does not have the right type.
@@ -1073,15 +1084,7 @@ GlobalValue *LLParser::GetGlobalVal(cons
}
// Otherwise, create a new forward reference for this value and remember it.
- GlobalValue *FwdVal;
- if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
- FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
- else
- FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, nullptr, Name,
- nullptr, GlobalVariable::NotThreadLocal,
- PTy->getAddressSpace());
-
+ GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, Name);
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
return FwdVal;
}
@@ -1113,13 +1116,7 @@ GlobalValue *LLParser::GetGlobalVal(unsi
}
// Otherwise, create a new forward reference for this value and remember it.
- GlobalValue *FwdVal;
- if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
- FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
- else
- FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, nullptr, "");
-
+ GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, "");
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
return FwdVal;
}
Modified: llvm/trunk/test/Assembler/global-addrspace-forwardref.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/global-addrspace-forwardref.ll?rev=246788&r1=246787&r2=246788&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/global-addrspace-forwardref.ll (original)
+++ llvm/trunk/test/Assembler/global-addrspace-forwardref.ll Thu Sep 3 13:06:44 2015
@@ -7,3 +7,12 @@
; CHECK: @a = addrspace(1) global i8 0
@a2 = global i8 addrspace(1)* @a
@a = addrspace(1) global i8 0
+
+; Now test with global IDs instead of global names.
+
+; CHECK: @a3 = global i8 addrspace(1)* @0
+; CHECK: @0 = addrspace(1) global i8 0
+
+ at a3 = global i8 addrspace(1)* @0
+ at 0 = addrspace(1) global i8 0
+
More information about the llvm-commits
mailing list