diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2055,6 +2055,10 @@ program memory space defaults to the default address space of 0, which corresponds to a Von Neumann architecture that has code and data in the same space. +``G
`` + Specifies the address space that should be used for global variables. + If omitted, the globals address space defaults to the default address + space of 0. ``A
`` Specifies the address space of objects created by '``alloca``'. Defaults to the default address space of 0. diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -123,6 +123,7 @@ unsigned AllocaAddrSpace; MaybeAlign StackNaturalAlign; unsigned ProgramAddrSpace; + unsigned GlobalsAddrSpace; MaybeAlign FunctionPtrAlign; FunctionPtrAlignType TheFunctionPtrAlignType; @@ -212,6 +213,7 @@ FunctionPtrAlign = DL.FunctionPtrAlign; TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType; ProgramAddrSpace = DL.ProgramAddrSpace; + GlobalsAddrSpace = DL.GlobalsAddrSpace; ManglingMode = DL.ManglingMode; LegalIntWidths = DL.LegalIntWidths; Alignments = DL.Alignments; @@ -284,6 +286,7 @@ } unsigned getProgramAddressSpace() const { return ProgramAddrSpace; } + unsigned getGlobalsAddressSpace() const { return GlobalsAddrSpace; } bool hasMicrosoftFastStdCallMangling() const { return ManglingMode == MM_WinCOFFX86; diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -179,6 +179,7 @@ AllocaAddrSpace = 0; StackNaturalAlign.reset(); ProgramAddrSpace = 0; + GlobalsAddrSpace = 0; FunctionPtrAlign.reset(); TheFunctionPtrAlignType = FunctionPtrAlignType::Independent; ManglingMode = MM_None; @@ -419,6 +420,10 @@ AllocaAddrSpace = getAddrSpace(Tok); break; } + case 'G': { // Default address space for global variables. + GlobalsAddrSpace = getAddrSpace(Tok); + break; + } case 'm': if (!Tok.empty()) report_fatal_error("Unexpected trailing characters after mangling specifier in datalayout string"); @@ -464,6 +469,7 @@ AllocaAddrSpace == Other.AllocaAddrSpace && StackNaturalAlign == Other.StackNaturalAlign && ProgramAddrSpace == Other.ProgramAddrSpace && + GlobalsAddrSpace == Other.GlobalsAddrSpace && FunctionPtrAlign == Other.FunctionPtrAlign && TheFunctionPtrAlignType == Other.TheFunctionPtrAlignType && ManglingMode == Other.ManglingMode && diff --git a/llvm/test/Assembler/invalid-datalayout-globals-addrspace.ll b/llvm/test/Assembler/invalid-datalayout-globals-addrspace.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Assembler/invalid-datalayout-globals-addrspace.ll @@ -0,0 +1,4 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +; CHECK: Invalid address space, must be a 24-bit integer +target datalayout = "G16777216"