Add branch weights to branches for static initializers.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Jul 2017 22:01:09 +0000 (22:01 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 26 Jul 2017 22:01:09 +0000 (22:01 +0000)
commitae8d62c9c539bb3f5ae9033c7c107ed37e902969
tree3f385e16b4f9211feb9d23afddf6d4e67c0ab319
parentf63d4d121b6abcd36d7d90809f110fbce8a72e74
Add branch weights to branches for static initializers.

The initializer for a static local variable cannot be hot, because it runs at
most once per program. That's not quite the same thing as having a low branch
probability, but under the assumption that the function is invoked many times,
modeling this as a branch probability seems reasonable.

For TLS variables, the situation is less clear, since the initialization side
of the branch can run multiple times in a program execution, but we still
expect initialization to be rare relative to non-initialization uses. It would
seem worthwhile to add a PGO counter along this path to make this estimation
more accurate in future.

For globals with guarded initialization, we don't yet apply any branch weights.
Due to our use of COMDATs, the guard will be reached exactly once per DSO, but
we have no idea how many DSOs will define the variable.

llvm-svn: 309195
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp
clang/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
clang/test/CodeGenCXX/static-init-wasm.cpp
clang/test/CodeGenCXX/static-initializer-branch-weights.cpp [new file with mode: 0644]