Skip to content

Commit dc036b7

Browse files
committed
Update documentation and add option to print address space names
1 parent 36f457e commit dc036b7

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

llvm/docs/LangRef.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,7 @@ as follows:
33313331
``A<address space>``
33323332
Specifies the address space of objects created by '``alloca``'.
33333333
Defaults to the default address space of 0.
3334-
``p[<flags>][<as>]:<size>:<abi>[:<pref>[:<idx>]]``
3334+
``p[<flags>][<as>][(<name>)]:<size>:<abi>[:<pref>[:<idx>]]``
33353335
This specifies the properties of a pointer in address space ``as``.
33363336
The ``<size>`` parameter specifies the size of the bitwise representation.
33373337
For :ref:`non-integral pointers <nointptrtype>` the representation size may
@@ -3350,7 +3350,11 @@ as follows:
33503350
The optional ``<flags>`` are used to specify properties of pointers in this
33513351
address space: the character ``u`` marks pointers as having an unstable
33523352
representation, and ``e`` marks pointers having external state. See
3353-
:ref:`Non-Integral Pointer Types <nointptrtype>`.
3353+
:ref:`Non-Integral Pointer Types <nointptrtype>`. The ``<name>`` is an
3354+
optional name of that address space, surrounded by ``(`` and ``)``. If the
3355+
name is specified, it must be unique to that address space and cannot be
3356+
``A``, ``G``, or ``P`` which are pre-defined names used to denote alloca,
3357+
global, and program address space respectively.
33543358

33553359
``i<size>:<abi>[:<pref>]``
33563360
This specifies the alignment for an integer type of a given bit

llvm/lib/IR/AsmWriter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ static cl::opt<bool> PreserveAssemblyUseListOrder(
107107
"preserve-ll-uselistorder", cl::Hidden, cl::init(false),
108108
cl::desc("Preserve use-list order when writing LLVM assembly."));
109109

110+
static cl::opt<bool>
111+
PrintSymbolicAddressSpace("print-sym-addr-space", cl::Hidden,
112+
cl::init(false),
113+
cl::desc("Print symbolic address space names"));
114+
110115
// Make virtual table appear in this compilation unit.
111116
AssemblyAnnotationWriter::~AssemblyAnnotationWriter() = default;
112117

@@ -638,7 +643,9 @@ static void printAddressSpace(const Module *M, unsigned AS, raw_ostream &OS,
638643
if (AS == 0 && !ForcePrint)
639644
return;
640645
OS << Prefix << "addrspace(";
641-
StringRef ASName = M ? M->getDataLayout().getAddressSpaceName(AS) : "";
646+
StringRef ASName = PrintSymbolicAddressSpace && M
647+
? M->getDataLayout().getAddressSpaceName(AS)
648+
: "";
642649
if (!ASName.empty())
643650
OS << "\"" << ASName << "\"";
644651
else

llvm/test/Assembler/symbolic-addrspace-datalayout.ll

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
;; Check support for printing and parsing of address space names specified in
22
;; the datalayout.
33
; RUN: split-file %s %t --leading-lines
4-
; RUN: llvm-as < %t/num-to-sym.ll | llvm-dis | FileCheck %t/num-to-sym.ll
5-
; RUN: llvm-as < %t/sym-to-sym.ll | llvm-dis | FileCheck %t/sym-to-sym.ll
4+
; RUN: llvm-as < %t/num-to-sym.ll | llvm-dis --print-sym-addr-space=true | FileCheck %t/num-to-sym.ll
5+
; RUN: llvm-as < %t/sym-to-sym.ll | llvm-dis --print-sym-addr-space=true | FileCheck %t/sym-to-sym.ll
6+
; RUN: llvm-as < %t/sym-to-num.ll | llvm-dis --print-sym-addr-space=false | FileCheck %t/sym-to-num.ll
67
; RUN: not llvm-as < %t/invalid-name.ll 2>&1 | FileCheck %t/invalid-name.ll
78

89
;--- num-to-sym.ll
@@ -45,6 +46,26 @@ define void @bar() addrspace(11) {
4546
ret void
4647
}
4748

49+
;--- sym-to-num.ll
50+
target datalayout = "P11-p2(global):32:8-p8(stack):8:8-p11(code):8:8"
51+
; CHECK: target datalayout = "P11-p2(global):32:8-p8(stack):8:8-p11(code):8:8"
52+
53+
; CHECK: @str = private addrspace(2) constant [4 x i8] c"str\00"
54+
@str = private addrspace("global") constant [4 x i8] c"str\00"
55+
56+
define void @foo() {
57+
; CHECK: %alloca = alloca i32, align 4, addrspace(8)
58+
%alloca = alloca i32, addrspace("stack")
59+
ret void
60+
}
61+
62+
; CHECK: define void @bar() addrspace(11)
63+
define void @bar() addrspace(11) {
64+
; CHECK: call addrspace(11) void @foo()
65+
call addrspace("code") void @foo()
66+
ret void
67+
}
68+
4869
;--- invalid-name.ll
4970
target datalayout = "P11-p2(global):32:8-p8(stack):8:8-p11(code):8:8"
5071
; CHECK: error: invalid symbolic addrspace 'global3'

0 commit comments

Comments
 (0)