[Clang] Undef attribute for global variables
authorJon Chesterfield <jonathanchesterfield@gmail.com>
Tue, 17 Mar 2020 21:22:04 +0000 (21:22 +0000)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Tue, 17 Mar 2020 21:22:23 +0000 (21:22 +0000)
commitc45eaeabb77a926f4f1cf3c1e9311e9d66e0ee2a
tree60deb3a34af4d6eca92113199c11cf4d09c6f4a5
parent1458bb92dffa87f8a2faa546c36f935ddffaa34f
[Clang] Undef attribute for global variables

Summary:
[Clang] Attribute to allow defining undef global variables

Initializing global variables is very cheap on hosted implementations. The
C semantics of zero initializing globals work very well there. It is not
necessarily cheap on freestanding implementations. Where there is no loader
available, code must be emitted near the start point to write the appropriate
values into memory.

At present, external variables can be declared in C++ and definitions provided
in assembly (or IR) to achive this effect. This patch provides an attribute in
order to remove this reason for writing assembly for performance sensitive
freestanding implementations.

A close analogue in tree is LDS memory for amdgcn, where the kernel is
responsible for initializing the memory after it starts executing on the gpu.
Uninitalized variables in LDS are observably cheaper than zero initialized.

Patch is loosely based on the cuda __shared__ and opencl __local variable
implementation which also produces undef global variables.

Reviewers: kcc, rjmccall, rsmith, glider, vitalybuka, pcc, eugenis, vlad.tsyrklevich, jdoerfert, gregrodgers, jfb, aaron.ballman

Reviewed By: rjmccall, aaron.ballman

Subscribers: Anastasia, aaron.ballman, davidb, Quuxplusone, dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74361
13 files changed:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/DeclBase.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/attr-loader-uninitialized.c [new file with mode: 0644]
clang/test/CodeGenCXX/attr-loader-uninitialized.cpp [new file with mode: 0644]
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/Sema/attr-loader-uninitialized.c [new file with mode: 0644]
clang/test/Sema/attr-loader-uninitialized.cpp [new file with mode: 0644]