1 <!--===- docs/Aliasing.md
3 Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 See https://llvm.org/LICENSE.txt for license information.
5 SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 # Bijective Internal Name Uniquing
17 FIR has a flat namespace. No two objects may have the same name at the module
18 level. (These would be functions, globals, etc.) This necessitates some sort
19 of encoding scheme to unique symbols from the front-end into FIR.
21 Another requirement is to be able to reverse these unique names and recover
22 the associated symbol in the symbol table.
24 Fortran is case insensitive, which allows the compiler to convert the user's
25 identifiers to all lower case. Such a universal conversion implies that all
26 upper case letters are available for use in uniquing.
30 All uniqued names have the prefix sequence `_Q` to indicate the name has been
31 uniqued. (Q is chosen because it is a [low frequency letter](http://pi.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html)
36 Symbols are scoped by any module, submodule, procedure, and block that
37 contains that symbol. After the `_Q` sigil, names are constructed from
38 outermost to innermost scope as
40 * Module name prefixed with `M`
41 * Submodule name/s prefixed with `S`
42 * Procedure name/s prefixed with `F`
43 * Innermost block index prefixed with `B`
47 submodule (mod:s1mod) s2mod
55 The uniqued name of `fun` becomes:
57 _QMmodSs1modSs2modFsubPfun
63 | ----| --------------------------------------------------------- |
64 | B | Block ("name" is a compiler generated integer index)
66 | D | Dispatch table (compiler internal)
68 | EC | Constant Entity
69 | F | procedure/Function (as a prefix)
74 | P | Procedure/function (as itself)
75 | Q | uniQue mangled name tag
78 | Y | tYpe descriptor (compiler internal)
79 | YI | tYpe descriptor for an Intrinsic type (compiler internal)
83 * A common block name will be prefixed with `C`
90 The uniqued name of `work` becomes:
100 The uniqued name in case of `blank common block` becomes:
105 ## Module scope global data
107 * A global data entity is prefixed with `E`
108 * A global entity that is constant (parameter) will be prefixed with `EC`
114 real, parameter :: pi = 3.14
118 The uniqued name of `intvar` becomes:
123 The uniqued name of `pi` becomes:
130 * A procedure/subprogram as itself is prefixed with `P`
131 * A procedure/subprogram as an ancestor name is prefixed with `F`
133 Procedures are the only names that are themselves uniqued, as well as
134 appearing as a prefix component of other uniqued names.
139 real, save :: x(1000)
142 The uniqued name of `sub` becomes:
146 The uniqued name of `x` becomes:
153 * A block is prefixed with `B`; the block "name" is a compiler generated
156 Each block has a per-procedure preorder index. The prefix for the immediately
157 containing block construct is unique within the procedure.
164 real, save :: x(1000)
170 The uniqued name of `x` becomes:
177 * A namelist group is prefixed with `N`
182 real, save :: x(1000)
186 The uniqued name of `temps` becomes:
193 * A derived type is prefixed with `T`
194 * If a derived type has KIND parameters, they are listed in a consistent
195 canonical order where each takes the form `Ki` and where _i_ is the
196 compile-time constant value. (All type parameters are integer.) If _i_
197 is a negative value, the prefix `KN` will be used and _i_ will reflect
198 the magnitude of the value.
208 The uniqued name of `mytype` becomes:
216 integer, kind :: k1, k2
222 The uniqued name of `yourtype` where `k1=4` and `k2=-6` (at compile-time):
227 * A derived type dispatch table is prefixed with `D`. The dispatch table
228 for `type t` would be `_QDTt`
229 * A type descriptor instance is prefixed with `C`. Intrinsic types can
230 be encoded with their names and kinds. The type descriptor for the
231 type `yourtype` above would be `_QCTyourtypeK4KN6`. The type
232 descriptor for `REAL(4)` would be `_QCrealK4`.
234 ## Compiler internal names
236 Compiler generated names do not have to be mapped back to Fortran. This
237 includes names prefixed with `_QQ`, tag `D` for a type bound procedure
238 dispatch table, and tags `Y` and `YI` for runtime type descriptors.