diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 034a866902327..6999e8f55f8b9 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -1905,8 +1905,15 @@ as follows: must be a multiple of 8-bits. If omitted, the natural stack alignment defaults to "unspecified", which does not prevent any alignment promotions. +``P
`` + Specifies the address space that corresponds to program memory. + Harvard architectures can use this to specify what space LLVM + should place things such as functions into. If omitted, the + 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. ``A
`` - Specifies the address space of objects created by '``alloca``'. + Specifies the address space of objects created by '``alloca``'. Defaults to the default address space of 0. ``p[n]::::`` This specifies the *size* of a pointer and its ```` and diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h index 551160b6321a2..00eb952315299 100644 --- a/llvm/include/llvm/IR/DataLayout.h +++ b/llvm/include/llvm/IR/DataLayout.h @@ -115,6 +115,7 @@ class DataLayout { unsigned AllocaAddrSpace; unsigned StackNaturalAlign; + unsigned ProgramAddrSpace; enum ManglingModeT { MM_None, @@ -199,6 +200,7 @@ class DataLayout { BigEndian = DL.isBigEndian(); AllocaAddrSpace = DL.AllocaAddrSpace; StackNaturalAlign = DL.StackNaturalAlign; + ProgramAddrSpace = DL.ProgramAddrSpace; ManglingMode = DL.ManglingMode; LegalIntWidths = DL.LegalIntWidths; Alignments = DL.Alignments; @@ -255,6 +257,8 @@ class DataLayout { unsigned getStackAlignment() const { return StackNaturalAlign; } unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; } + unsigned getProgramAddressSpace() const { return ProgramAddrSpace; } + bool hasMicrosoftFastStdCallMangling() const { return ManglingMode == MM_WinCOFFX86; } diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 289001d202055..fff2f67fe5add 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -184,6 +184,7 @@ void DataLayout::reset(StringRef Desc) { BigEndian = false; AllocaAddrSpace = 0; StackNaturalAlign = 0; + ProgramAddrSpace = 0; ManglingMode = MM_None; NonIntegralAddressSpaces.clear(); @@ -224,6 +225,13 @@ static unsigned inBytes(unsigned Bits) { return Bits / 8; } +static unsigned getAddrSpace(StringRef R) { + unsigned AddrSpace = getInt(R); + if (!isUInt<24>(AddrSpace)) + report_fatal_error("Invalid address space, must be a 24-bit integer"); + return AddrSpace; +} + void DataLayout::parseSpecifier(StringRef Desc) { StringRepresentation = Desc; while (!Desc.empty()) { @@ -372,10 +380,12 @@ void DataLayout::parseSpecifier(StringRef Desc) { StackNaturalAlign = inBytes(getInt(Tok)); break; } + case 'P': { // Function address space. + ProgramAddrSpace = getAddrSpace(Tok); + break; + } case 'A': { // Default stack/alloca address space. - AllocaAddrSpace = getInt(Tok); - if (!isUInt<24>(AllocaAddrSpace)) - report_fatal_error("Invalid address space, must be a 24bit integer"); + AllocaAddrSpace = getAddrSpace(Tok); break; } case 'm': @@ -422,6 +432,7 @@ bool DataLayout::operator==(const DataLayout &Other) const { bool Ret = BigEndian == Other.BigEndian && AllocaAddrSpace == Other.AllocaAddrSpace && StackNaturalAlign == Other.StackNaturalAlign && + ProgramAddrSpace == Other.ProgramAddrSpace && ManglingMode == Other.ManglingMode && LegalIntWidths == Other.LegalIntWidths && Alignments == Other.Alignments && Pointers == Other.Pointers; diff --git a/llvm/test/Assembler/datalayout-program-addrspace.ll b/llvm/test/Assembler/datalayout-program-addrspace.ll new file mode 100644 index 0000000000000..2f250ebf055b8 --- /dev/null +++ b/llvm/test/Assembler/datalayout-program-addrspace.ll @@ -0,0 +1,5 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +; CHECK: target datalayout = "P1" +target datalayout = "P1" + diff --git a/llvm/test/Assembler/invalid-datalayout-alloca-addrspace.ll b/llvm/test/Assembler/invalid-datalayout-alloca-addrspace.ll index 9a0e07acf7669..f0407da73e4fc 100644 --- a/llvm/test/Assembler/invalid-datalayout-alloca-addrspace.ll +++ b/llvm/test/Assembler/invalid-datalayout-alloca-addrspace.ll @@ -1,4 +1,4 @@ ; RUN: not llvm-as < %s 2>&1 | FileCheck %s target datalayout = "A16777216" -; CHECK: Invalid address space, must be a 24bit integer +; CHECK: Invalid address space, must be a 24-bit integer diff --git a/llvm/test/Assembler/invalid-datalayout-program-addrspace.ll b/llvm/test/Assembler/invalid-datalayout-program-addrspace.ll new file mode 100644 index 0000000000000..e636b75dee4d0 --- /dev/null +++ b/llvm/test/Assembler/invalid-datalayout-program-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 = "P16777216"