[llvm] r325479 - Add default address space for functions to the data layout (1/3)
Dylan McKay via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 01:56:22 PST 2018
Author: dylanmckay
Date: Mon Feb 19 01:56:22 2018
New Revision: 325479
URL: http://llvm.org/viewvc/llvm-project?rev=325479&view=rev
Log:
Add default address space for functions to the data layout (1/3)
Summary:
This adds initial support for letting targets specify which address
spaces their functions should reside in by default.
If a function is created by a frontend, it will get the default address space specified in the DataLayout, unless the frontend explicitly uses a more general `llvm::Function` constructor. Function address spaces will become a part of the bitcode and textual IR forms, as we do not have access to a data layout whilst parsing LL.
It will be possible to write IR that explicitly has `addrspace(n)` on a function. In this case, the function will reside in the specified space, ignoring the default in the DL.
This is the first step towards placing functions into the correct
address space for Harvard architectures.
Full patchset
* Add program address space to data layout D37052
* Require address space to be specified when creating functions D37054
* [clang] Require address space to be specified when creating functions D37057
Reviewers: pcc, arsenm, kparzysz, hfinkel, theraven
Reviewed By: theraven
Subscribers: arichardson, simoncook, rengolin, wdng, uabelho, bjope, asb, llvm-commits
Differential Revision: https://reviews.llvm.org/D37052
Added:
llvm/trunk/test/Assembler/datalayout-program-addrspace.ll
llvm/trunk/test/Assembler/invalid-datalayout-program-addrspace.ll
Modified:
llvm/trunk/docs/LangRef.rst
llvm/trunk/include/llvm/IR/DataLayout.h
llvm/trunk/lib/IR/DataLayout.cpp
llvm/trunk/test/Assembler/invalid-datalayout-alloca-addrspace.ll
Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=325479&r1=325478&r2=325479&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Mon Feb 19 01:56:22 2018
@@ -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<address space>``
+ 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<address space>``
- 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]:<size>:<abi>:<pref>:<idx>``
This specifies the *size* of a pointer and its ``<abi>`` and
Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=325479&r1=325478&r2=325479&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Mon Feb 19 01:56:22 2018
@@ -115,6 +115,7 @@ private:
unsigned AllocaAddrSpace;
unsigned StackNaturalAlign;
+ unsigned ProgramAddrSpace;
enum ManglingModeT {
MM_None,
@@ -199,6 +200,7 @@ public:
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 @@ public:
unsigned getStackAlignment() const { return StackNaturalAlign; }
unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; }
+ unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
+
bool hasMicrosoftFastStdCallMangling() const {
return ManglingMode == MM_WinCOFFX86;
}
Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=325479&r1=325478&r2=325479&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Mon Feb 19 01:56:22 2018
@@ -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(StringRe
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 DataLa
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;
Added: llvm/trunk/test/Assembler/datalayout-program-addrspace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/datalayout-program-addrspace.ll?rev=325479&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/datalayout-program-addrspace.ll (added)
+++ llvm/trunk/test/Assembler/datalayout-program-addrspace.ll Mon Feb 19 01:56:22 2018
@@ -0,0 +1,5 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; CHECK: target datalayout = "P1"
+target datalayout = "P1"
+
Modified: llvm/trunk/test/Assembler/invalid-datalayout-alloca-addrspace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout-alloca-addrspace.ll?rev=325479&r1=325478&r2=325479&view=diff
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout-alloca-addrspace.ll (original)
+++ llvm/trunk/test/Assembler/invalid-datalayout-alloca-addrspace.ll Mon Feb 19 01:56:22 2018
@@ -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
Added: llvm/trunk/test/Assembler/invalid-datalayout-program-addrspace.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/invalid-datalayout-program-addrspace.ll?rev=325479&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/invalid-datalayout-program-addrspace.ll (added)
+++ llvm/trunk/test/Assembler/invalid-datalayout-program-addrspace.ll Mon Feb 19 01:56:22 2018
@@ -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"
More information about the llvm-commits
mailing list