llvm-project/clang/lib/CodeGen
Douglas Gregor 7dc5c17d92 When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.

This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:

  - Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
    when the declaration is in an anonymous namespace.
  - Added Type::getLinkage() to determine the linkage of a type, which
    is defined as the minimum linkage of the types (when we're dealing
    with a compound type that is not a struct/class/union).
  - Extended NamedDecl::getLinkage() to consider the linkage of the
    template arguments and template parameters of function template
    specializations and class template specializations.
  - Taught code generation to rely on NamedDecl::getLinkage() when
    determining the linkage of variables and functions, also
    considering the linkage of the types of those variables and
    functions (C++ only). Map UniqueExternalLinkage to internal
    linkage, taking out the explicit checks for
    isInAnonymousNamespace().

This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:

LLVM:
  Expected Passes    : 4006
  Expected Failures  : 32
  Unsupported Tests  : 40
  Unexpected Failures: 736

Clang:
  Expected Passes    : 1903
  Expected Failures  : 14
  Unexpected Failures: 75

Overall:
  Expected Passes    : 5909
  Expected Failures  : 46
  Unsupported Tests  : 40
  Unexpected Failures: 811

Still to do:
  - Improve testing
  - Check whether we should allow the presence of types with
  InternalLinkage (in addition to UniqueExternalLinkage) given
  variables/functions internal linkage in C++, as mentioned in
  PR5792. 
  - Determine how expensive the getLinkage() calls are in practice;
  consider caching the result in NamedDecl.
  - Assess the feasibility of Chris's idea in comment #1 of PR5792.

llvm-svn: 95216
2010-02-03 09:33:45 +00:00
..
ABIInfo.h x86-64 ABI: If a type is a C++ record with either a non-trivial destructor or a non-trivial copy constructor, it should be passed in a pointer. Daniel, plz review. 2009-09-16 15:53:40 +00:00
CGBlocks.cpp Change the return type of ASTContext::getDeclAlignInBytes() to CharUnits and, 2010-01-27 17:10:57 +00:00
CGBlocks.h Use CharUnits for alignments in character units. 2010-01-26 19:13:33 +00:00
CGBuilder.h Disable generation of basic block names in NDEBUG mode. 2008-11-12 00:01:12 +00:00
CGBuiltin.cpp Add bzero builtin; this should help codegen quality for code using this 2010-01-23 19:00:10 +00:00
CGCXX.cpp Move a few more functions away from CGCXX and to CGClass and CGExprCXX. 2010-01-01 20:29:01 +00:00
CGCXX.h Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
CGCall.cpp Start creating CXXBindReferenceExpr nodes when binding complex types to references. 2010-01-31 18:34:51 +00:00
CGCall.h Fill in the return value slot in CGExprAgg::VisitCallExpr. This takes us halfway towards fixing PR5824. 2009-12-24 20:40:36 +00:00
CGClass.cpp Set the correct vtable pointers _before_ generating code for any member initializers. Fixes about ~2000 clang/LLVM tests in the clang-on-clang build. 2010-02-02 19:58:43 +00:00
CGDebugInfo.cpp Fix FIXME and surrounding comment. 2010-02-01 22:51:29 +00:00
CGDebugInfo.h Emit debug info for namespaces. 2010-02-01 19:16:32 +00:00
CGDecl.cpp Start creating CXXBindReferenceExpr nodes when binding complex types to references. 2010-01-31 18:34:51 +00:00
CGDeclCXX.cpp global variable that binds reference to a non-lvalue reproted 2010-01-25 21:40:39 +00:00
CGException.cpp Fix last patch, catch of reference to non-pointer. 2010-01-01 03:20:32 +00:00
CGExpr.cpp Move pointer to data member emission to CodeGenModule and use it in CGExprConstant. Fixes PR5674. 2010-02-02 03:37:46 +00:00
CGExprAgg.cpp Some class related cleanup. 2010-01-31 01:36:53 +00:00
CGExprCXX.cpp Provide a real fix for PR6199, reverting the old workaround. Here, we 2010-02-03 03:01:57 +00:00
CGExprComplex.cpp refactor pre/postinc logic into CGF and require the caller to pass in the 2010-01-09 21:40:03 +00:00
CGExprConstant.cpp Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
CGExprScalar.cpp Move pointer to data member emission to CodeGenModule and use it in CGExprConstant. Fixes PR5674. 2010-02-02 03:37:46 +00:00
CGObjC.cpp Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
CGObjCGNU.cpp Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
CGObjCMac.cpp Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
CGObjCRuntime.h Numerous changes to selector handling: 2010-02-03 02:09:30 +00:00
CGRTTI.cpp Fix linkage for RTTI names by re-using the logic for computing the 2010-01-06 22:00:56 +00:00
CGRecordLayoutBuilder.cpp Improve handling of emitting 'null' pointers to data members. 2010-02-02 05:17:25 +00:00
CGRecordLayoutBuilder.h Improve handling of emitting 'null' pointers to data members. 2010-02-02 05:17:25 +00:00
CGStmt.cpp More asm cleanup. 2010-01-30 20:05:21 +00:00
CGTemporaries.cpp Fix double-destruction assertion to account for temporaries in conditionals 2009-12-24 18:16:21 +00:00
CGVTT.cpp Move the VTT related code into its own file, CGVTT.cpp 2010-01-21 16:50:45 +00:00
CGValue.h Fix documentation. 2009-11-03 16:11:57 +00:00
CGVtable.cpp remove a big chunk of #if 0 code. 2010-02-03 05:28:17 +00:00
CGVtable.h Store the address points for constructor vtables directly in the VTT builder, because that's the only time they're needed. 2010-01-14 02:29:07 +00:00
CMakeLists.txt Move the VTT related code into its own file, CGVTT.cpp 2010-01-21 16:50:45 +00:00
CodeGenFunction.cpp Fix a nasty bug where temporaries weren't marked as being conditional in some cases. 2010-01-24 00:20:05 +00:00
CodeGenFunction.h Move pointer to data member emission to CodeGenModule and use it in CGExprConstant. Fixes PR5674. 2010-02-02 03:37:46 +00:00
CodeGenModule.cpp When a function or variable somehow depends on a type or declaration 2010-02-03 09:33:45 +00:00
CodeGenModule.h Move pointer to data member emission to CodeGenModule and use it in CGExprConstant. Fixes PR5674. 2010-02-02 03:37:46 +00:00
CodeGenTypes.cpp Use the new isInteger() method in a couple places, some random cleanup, and 2010-01-11 19:58:10 +00:00
CodeGenTypes.h Improve handling of emitting 'null' pointers to data members. 2010-02-02 05:17:25 +00:00
GlobalDecl.h update to match LLVM API change: 2009-12-15 07:26:51 +00:00
Makefile -fno-rtti is now the default. 2010-01-24 20:43:31 +00:00
Mangle.cpp When a function or variable somehow depends on a type or declaration 2010-02-03 09:33:45 +00:00
Mangle.h Work-in-progress: teach mangler how to mangle thunks for destructors. 2009-12-03 00:03:05 +00:00
ModuleBuilder.cpp Remove ';' after method definition. Noticed by clang++, which one would think 2009-12-19 17:50:07 +00:00
README.txt These IRgen improvements have been done. 2009-07-23 03:03:07 +00:00
TargetInfo.cpp Implement promotion for enumeration types. 2010-02-02 20:10:50 +00:00
TargetInfo.h Eliminate some Clang warnings 2010-01-22 15:41:14 +00:00

README.txt

IRgen optimization opportunities.

//===---------------------------------------------------------------------===//

The common pattern of
--
short x; // or char, etc
(x == 10)
--
generates an zext/sext of x which can easily be avoided.

//===---------------------------------------------------------------------===//

Bitfields accesses can be shifted to simplify masking and sign
extension. For example, if the bitfield width is 8 and it is
appropriately aligned then is is a lot shorter to just load the char
directly.

//===---------------------------------------------------------------------===//

It may be worth avoiding creation of alloca's for formal arguments
for the common situation where the argument is never written to or has
its address taken. The idea would be to begin generating code by using
the argument directly and if its address is taken or it is stored to
then generate the alloca and patch up the existing code.

In theory, the same optimization could be a win for block local
variables as long as the declaration dominates all statements in the
block.

NOTE: The main case we care about this for is for -O0 -g compile time
performance, and in that scenario we will need to emit the alloca
anyway currently to emit proper debug info. So this is blocked by
being able to emit debug information which refers to an LLVM
temporary, not an alloca.

//===---------------------------------------------------------------------===//

We should try and avoid generating basic blocks which only contain
jumps. At -O0, this penalizes us all the way from IRgen (malloc &
instruction overhead), all the way down through code generation and
assembly time.

On 176.gcc:expr.ll, it looks like over 12% of basic blocks are just
direct branches!

//===---------------------------------------------------------------------===//