llvm-project/clang/lib/CodeGen
Reid Kleckner 61c9b7cb9f [MS] Skip vbase construction in abstract class ctors
As background, when constructing a complete object, virtual bases are
constructed first. If an exception is thrown later in the ctor, those
virtual bases are destroyed, so sema marks the relevant constructors and
destructors of virtual bases as referenced. If necessary, they are
emitted.

However, an abstract class can never be used to construct a complete
object. In the Itanium C++ ABI, this works out nicely, because we never
end up emitting the "complete" constructor variant, only the "base"
constructor variant, which can be called by constructors of derived
classes. Clang's Sema::MarkBaseAndMemberDestructorsReferenced is aware
of this optimization, and it does not mark ctors and dtors of virtual
bases referenced when the constructor of an abstract class is emitted.

In the Microsoft ABI, there are no complete/base variants, so before
this change, the constructor of an abstract class could reference ctors
and dtors of a virtual base without marking them referenced. This could
lead to unresolved symbol errors at link time, as reported in PR41065.

The fix is to implement the same optimization as Sema: If the class is
abstract, don't bother initializing its virtual bases. The "is this
class the most derived class" check in the constructor will never pass,
and the virtual base constructor calls are always dead. Skip them.

I think Richard noticed this missed optimization back in 2016 when he
was implementing inheriting constructors. I wasn't able to find any bugs
or email about it, though.

Fixes PR41065

llvm-svn: 356425
2019-03-18 22:41:50 +00:00
..
ABIInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Address.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BackendUtil.cpp Add XCOFF triple object format type for AIX 2019-03-12 22:01:10 +00:00
CGAtomic.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGBlocks.cpp CodeGen: use COMDAT for block copy/destroy helpers 2019-02-22 16:29:50 +00:00
CGBlocks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGBuilder.h [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGBuiltin.cpp [WebAssembly] Use rethrow intrinsic in the rethrow block 2019-03-16 05:39:12 +00:00
CGCUDANV.cpp [HIP] change kernel stub name 2019-02-27 02:02:52 +00:00
CGCUDARuntime.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCUDARuntime.h [CUDA][HIP] Use device side kernel and variable names when registering them 2019-02-14 02:00:09 +00:00
CGCXX.cpp [opaque pointer types] Pass through function types for TLS 2019-02-07 01:14:17 +00:00
CGCXXABI.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCXXABI.h [opaque pointer types] Pass through function types for TLS 2019-02-07 01:14:17 +00:00
CGCall.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGCall.h [opaque pointer types] Make EmitCall pass Function Types to 2019-02-07 01:15:41 +00:00
CGClass.cpp [MS] Skip vbase construction in abstract class ctors 2019-03-18 22:41:50 +00:00
CGCleanup.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGCleanup.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCoroutine.cpp [opaque pointer types] Trivial changes towards CallInst requiring 2019-02-03 21:53:49 +00:00
CGDebugInfo.cpp [CUDA][HIP][DebugInfo] Skip reference device function 2019-03-06 21:16:27 +00:00
CGDebugInfo.h Reland r345009 "[DebugInfo] Generate debug information for labels." 2019-01-24 05:34:29 +00:00
CGDecl.cpp CodeGen: Preserve packed attribute in constStructWithPadding. 2019-03-16 19:25:39 +00:00
CGDeclCXX.cpp [opaque pointer types] Pass through function types for TLS 2019-02-07 01:14:17 +00:00
CGException.cpp [WebAssembly] Use rethrow intrinsic in the rethrow block 2019-03-16 05:39:12 +00:00
CGExpr.cpp [Fixed Point Arithmetic] Fixed Point and Integer Conversions 2019-03-06 00:28:43 +00:00
CGExprAgg.cpp [Fixed Point Arithmetic] Fixed Point and Integer Conversions 2019-03-06 00:28:43 +00:00
CGExprCXX.cpp Fix MSVC constructor call extension after b92d290e48 (r353181). 2019-02-06 00:06:03 +00:00
CGExprComplex.cpp [Fixed Point Arithmetic] Fixed Point and Integer Conversions 2019-03-06 00:28:43 +00:00
CGExprConstant.cpp [ObjC] Emit a boxed expression as a compile-time constant if the 2019-03-08 04:45:37 +00:00
CGExprScalar.cpp [Fixed Point Arithmetic] Fixed Point and Integer Conversions 2019-03-06 00:28:43 +00:00
CGGPUBuiltin.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGLoopInfo.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGLoopInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGNonTrivialStruct.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGObjC.cpp [ObjC] Emit a boxed expression as a compile-time constant if the 2019-03-08 04:45:37 +00:00
CGObjCGNU.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
CGObjCMac.cpp [CodeGen][ObjC] Remove the leading 'l' from symbols for protocol 2019-03-14 15:17:37 +00:00
CGObjCRuntime.cpp [opaque pointer types] Pass function types for runtime function calls. 2019-02-05 16:42:33 +00:00
CGObjCRuntime.h [opaque pointer types] Pass function types for runtime function calls. 2019-02-05 16:42:33 +00:00
CGOpenCLRuntime.cpp [OpenCL] Simplify LLVM IR generated for OpenCL blocks 2019-02-21 11:02:10 +00:00
CGOpenCLRuntime.h [OpenCL] Simplify LLVM IR generated for OpenCL blocks 2019-02-21 11:02:10 +00:00
CGOpenMPRuntime.cpp [OPENMP] Set scheduling for doacross loops as schedule, 1. 2019-03-18 18:40:00 +00:00
CGOpenMPRuntime.h [OPENMP] Set scheduling for doacross loops as schedule, 1. 2019-03-18 18:40:00 +00:00
CGOpenMPRuntimeNVPTX.cpp [OPENMP][NVPTX]Fix PR40893: Size doesn't match for 2019-03-13 18:21:10 +00:00
CGOpenMPRuntimeNVPTX.h [OPENMP]Target region: emit const firstprivates as globals with constant 2019-03-05 17:47:18 +00:00
CGRecordLayout.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGRecordLayoutBuilder.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGStmt.cpp [CodeGen] Consider tied operands when adjusting inline asm operands. 2019-03-14 19:46:51 +00:00
CGStmtOpenMP.cpp [OPENMP]Fix crash for the ordered(n) clause. 2019-03-14 20:36:00 +00:00
CGVTT.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGVTables.cpp [CodeGen] Set construction vtable visibility after creating initializer 2019-02-11 20:13:42 +00:00
CGVTables.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGValue.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CMakeLists.txt [CodeGen] Fix -DBUILD_SHARED_LIBS=on build after rC348907 2018-12-12 06:07:33 +00:00
CodeGenABITypes.cpp Remove redundant FunctionDecl argument from a couple functions. 2019-02-02 01:48:23 +00:00
CodeGenAction.cpp Reland "[Remarks] Add -foptimization-record-passes to filter remark emission" 2019-03-12 21:22:27 +00:00
CodeGenFunction.cpp [opaque pointer types] Trivial changes towards CallInst requiring 2019-02-03 21:53:49 +00:00
CodeGenFunction.h Revert "Add a new attribute, fortify_stdlib" 2019-03-13 21:37:01 +00:00
CodeGenModule.cpp Add XCOFF triple object format type for AIX 2019-03-12 22:01:10 +00:00
CodeGenModule.h [CodeGenObjC] Emit [[X alloc] init] as objc_alloc_init(X) when available 2019-02-14 19:58:37 +00:00
CodeGenPGO.cpp [MS] Don't emit coverage for deleting dtors 2019-02-26 20:42:52 +00:00
CodeGenPGO.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTBAA.cpp Fix file headers. NFC 2019-03-01 06:49:51 +00:00
CodeGenTBAA.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypeCache.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypes.cpp [OpenCL] Change type of block pointer for OpenCL 2019-02-19 15:19:06 +00:00
CodeGenTypes.h [opaque pointer types] Fix the CallInfo passed to EmitCall in some 2019-02-05 16:05:50 +00:00
ConstantEmitter.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ConstantInitBuilder.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CoverageMappingGen.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CoverageMappingGen.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
EHScopeStack.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ItaniumCXXABI.cpp [opaque pointer types] Cleanup CGBuilder's Create*GEP. 2019-02-09 22:22:28 +00:00
MacroPPCallbacks.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MacroPPCallbacks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MicrosoftCXXABI.cpp [opaque pointer types] Pass through function types for TLS 2019-02-07 01:14:17 +00:00
ModuleBuilder.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ObjectFilePCHContainerOperations.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
README.txt
SanitizerMetadata.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SanitizerMetadata.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SwiftCallingConv.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TargetInfo.cpp AMDGPU: Fix the mapping of sub group sync scope 2019-03-06 20:54:48 +00:00
TargetInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VarBypassDetector.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VarBypassDetector.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +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!

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