llvm-project/clang/lib/CodeGen
Jordan Rose b1312a5495 Force a load when creating a reference to a temporary copied from a bitfield.
For this source:
  const int &ref = someStruct.bitfield;

We used to generate this AST:

  DeclStmt [...]
  `-VarDecl [...] ref 'const int &'
    `-MaterializeTemporaryExpr [...] 'const int' lvalue
      `-ImplicitCastExpr [...] 'const int' lvalue <NoOp>
        `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...]
          `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X'

Notice the lvalue inside the MaterializeTemporaryExpr, which is very
confusing (and caused an assertion to fire in the analyzer - PR15694).

We now generate this:

  DeclStmt [...]
  `-VarDecl [...] ref 'const int &'
    `-MaterializeTemporaryExpr [...] 'const int' lvalue
      `-ImplicitCastExpr [...] 'int' <LValueToRValue>
        `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...]
          `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X'

Which makes a lot more sense. This allows us to remove code in both
CodeGen and AST that hacked around this special case.

The commit also makes Clang accept this (legal) C++11 code:

  int &&ref = std::move(someStruct).bitfield

PR15694 / <rdar://problem/13600396>

llvm-svn: 179250
2013-04-11 00:58:58 +00:00
..
ABIInfo.h Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
BackendUtil.cpp Plumb through the -fsplit-stack option using the existing backend 2013-04-04 06:29:47 +00:00
CGAtomic.cpp Promote atomic type sizes up to a power of two, capped by 2013-03-07 21:37:17 +00:00
CGBlocks.cpp Don't copy just to capture a strong block pointer under ARC. 2013-04-08 23:27:49 +00:00
CGBlocks.h Remove useless 'llvm::' qualifier from names like StringRef and others that are 2013-01-12 19:30:44 +00:00
CGBuilder.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
CGBuiltin.cpp Add RDSEED intrinsic support defined in AVX2 extension 2013-03-29 05:17:55 +00:00
CGCUDANV.cpp Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGCUDARuntime.cpp Sort all of Clang's files under 'lib', and fix up the broken headers 2012-12-04 09:13:33 +00:00
CGCUDARuntime.h CUDA: IR generation support for device stubs 2011-10-06 18:51:56 +00:00
CGCXX.cpp Better support for constructors with -cxx-abi microsoft, partly fixes PR12784 2013-02-27 13:46:31 +00:00
CGCXXABI.cpp [ms-cxxabi] Implement member data pointers for non-dynamic classes 2013-03-22 19:02:54 +00:00
CGCXXABI.h [ms-cxxabi] Implement member data pointers for non-dynamic classes 2013-03-22 19:02:54 +00:00
CGCall.cpp Fix uninitialized read of CalleeWithThisReturn. 2013-03-26 18:29:15 +00:00
CGCall.h Under ARC, when we're passing the address of a strong variable 2013-03-23 02:35:54 +00:00
CGClass.cpp Exploit this-return of a callsite in a this-return function. 2013-03-20 16:59:38 +00:00
CGCleanup.cpp Change hasAggregateLLVMType, which conflates complex and 2013-03-07 21:37:08 +00:00
CGCleanup.h Documentation cleanup: 2012-06-15 22:10:14 +00:00
CGDebugInfo.cpp Revert "Revert r178079, it caused PR15637." 2013-04-02 22:59:11 +00:00
CGDebugInfo.h Revert "Revert r178079, it caused PR15637." 2013-04-02 22:59:11 +00:00
CGDecl.cpp Add 178663 back. 2013-04-03 19:27:57 +00:00
CGDeclCXX.cpp Change hasAggregateLLVMType, which conflates complex and 2013-03-07 21:37:08 +00:00
CGException.cpp Change hasAggregateLLVMType, which conflates complex and 2013-03-07 21:37:08 +00:00
CGExpr.cpp Force a load when creating a reference to a temporary copied from a bitfield. 2013-04-11 00:58:58 +00:00
CGExprAgg.cpp Promote atomic type sizes up to a power of two, capped by 2013-03-07 21:37:17 +00:00
CGExprCXX.cpp Tighten up the rules for precise lifetime and document 2013-03-13 03:10:54 +00:00
CGExprComplex.cpp Promote atomic type sizes up to a power of two, capped by 2013-03-07 21:37:17 +00:00
CGExprConstant.cpp Allow EmitConstantInit() to emit constant initializers for objects with trivial constructors and non-trivial destructors. Test that such objects are ignored by init-order checker. 2013-04-05 07:47:28 +00:00
CGExprScalar.cpp UBSan: Don't diagnose inf/nan conversions between floating-point types. It's far from clear whether these have undefined behavior, and these checks are helping no-one. Keep the double->float overflow warnings, though, since those are useful in practice, even though it's unclear whether such operations have defined behavior. 2013-03-27 23:20:25 +00:00
CGObjC.cpp Protect the values of array and dictionary literals from the 2013-04-04 00:20:38 +00:00
CGObjCGNU.cpp Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGObjCMac.cpp In ObjC++ on legacy runtimes, push an EH cleanup as well as 2013-04-03 00:56:07 +00:00
CGObjCRuntime.cpp Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGObjCRuntime.h Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGOpenCLRuntime.cpp Add OpenCL samplers as Clang builtin types and check sampler related restrictions. 2013-02-07 10:55:47 +00:00
CGOpenCLRuntime.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
CGRTTI.cpp Add OpenCL samplers as Clang builtin types and check sampler related restrictions. 2013-02-07 10:55:47 +00:00
CGRecordLayout.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
CGRecordLayoutBuilder.cpp First pass at abstracting out a class for the target C++ ABI. 2013-01-25 22:30:49 +00:00
CGStmt.cpp Remove useGlobalsForAutomaticVariables. 2013-03-26 18:41:47 +00:00
CGVTT.cpp simplify a bunch of code to use the well-known LLVM IR types computed by CodeGenModule. 2012-02-07 00:39:47 +00:00
CGVTables.cpp Change hasAggregateLLVMType, which conflates complex and 2013-03-07 21:37:08 +00:00
CGVTables.h The standard ARM C++ ABI dictates that inline functions are 2013-01-25 22:31:03 +00:00
CGValue.h Initial support for struct-path aware TBAA. 2013-04-04 21:53:22 +00:00
CMakeLists.txt The IRReader header is now part of its own library. Update the include 2013-03-26 02:25:54 +00:00
CodeGenAction.cpp The IRReader header is now part of its own library. Update the include 2013-03-26 02:25:54 +00:00
CodeGenFunction.cpp Fix uninitialized read of CalleeWithThisReturn. 2013-03-26 18:29:15 +00:00
CodeGenFunction.h Initial support for struct-path aware TBAA. 2013-04-04 21:53:22 +00:00
CodeGenModule.cpp Remove nondeterminism introduced in r178950. 2013-04-06 07:07:44 +00:00
CodeGenModule.h Remove nondeterminism introduced in r178950. 2013-04-06 07:07:44 +00:00
CodeGenTBAA.cpp Initial support for struct-path aware TBAA. 2013-04-04 21:53:22 +00:00
CodeGenTBAA.h Initial support for struct-path aware TBAA. 2013-04-04 21:53:22 +00:00
CodeGenTypes.cpp Promote atomic type sizes up to a power of two, capped by 2013-03-07 21:37:17 +00:00
CodeGenTypes.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
ItaniumCXXABI.cpp [cxxabi] Get ptrdiff_t from the CodeGenModule instead of caching it 2013-03-22 16:13:10 +00:00
Makefile
MicrosoftCXXABI.cpp [ms-cxxabi] Implement member data pointers for non-dynamic classes 2013-03-22 19:02:54 +00:00
ModuleBuilder.cpp Pass the target options through to code generation. 2013-02-14 08:09:20 +00:00
README.txt
TargetInfo.cpp The PNaCl target no longer permits __attribute__((regparm)). 2013-04-08 21:31:01 +00:00
TargetInfo.h Fix the required args count for variadic blocks. 2012-12-07 07:03:17 +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!

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