2010-05-26 03:52:27 +08:00
|
|
|
//===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides an abstract class for C++ code generation. Concrete subclasses
|
|
|
|
// of this implement code generation for specific C++ ABIs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
|
2010-05-26 03:52:27 +08:00
|
|
|
|
2010-08-31 15:33:07 +08:00
|
|
|
#include "CodeGenFunction.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2010-08-31 15:33:07 +08:00
|
|
|
|
2010-08-22 08:05:51 +08:00
|
|
|
namespace llvm {
|
2014-05-09 08:26:20 +08:00
|
|
|
class Constant;
|
|
|
|
class Type;
|
|
|
|
class Value;
|
2015-03-04 03:21:04 +08:00
|
|
|
class CallInst;
|
2010-08-22 08:05:51 +08:00
|
|
|
}
|
|
|
|
|
2010-05-26 03:52:27 +08:00
|
|
|
namespace clang {
|
2014-05-09 08:26:20 +08:00
|
|
|
class CastExpr;
|
|
|
|
class CXXConstructorDecl;
|
|
|
|
class CXXDestructorDecl;
|
|
|
|
class CXXMethodDecl;
|
|
|
|
class CXXRecordDecl;
|
|
|
|
class FieldDecl;
|
|
|
|
class MangleContext;
|
2010-08-22 08:05:51 +08:00
|
|
|
|
2010-05-26 03:52:27 +08:00
|
|
|
namespace CodeGen {
|
2016-10-27 07:46:34 +08:00
|
|
|
class CGCallee;
|
2014-05-09 08:26:20 +08:00
|
|
|
class CodeGenFunction;
|
|
|
|
class CodeGenModule;
|
2015-09-17 04:15:55 +08:00
|
|
|
struct CatchTypeInfo;
|
2010-05-26 03:52:27 +08:00
|
|
|
|
2012-06-15 15:35:42 +08:00
|
|
|
/// \brief Implements C++ ABI-specific code generation functions.
|
2010-08-16 11:33:14 +08:00
|
|
|
class CGCXXABI {
|
2010-08-22 18:59:02 +08:00
|
|
|
protected:
|
|
|
|
CodeGenModule &CGM;
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<MangleContext> MangleCtx;
|
2010-08-22 18:59:02 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
CGCXXABI(CodeGenModule &CGM)
|
|
|
|
: CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
|
2010-08-22 18:59:02 +08:00
|
|
|
|
2010-08-31 15:33:07 +08:00
|
|
|
protected:
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
ImplicitParamDecl *getThisDecl(CodeGenFunction &CGF) {
|
2012-02-11 10:57:39 +08:00
|
|
|
return CGF.CXXABIThisDecl;
|
2010-08-31 15:33:07 +08:00
|
|
|
}
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
llvm::Value *getThisValue(CodeGenFunction &CGF) {
|
2012-02-11 10:57:39 +08:00
|
|
|
return CGF.CXXABIThisValue;
|
2010-08-31 15:33:07 +08:00
|
|
|
}
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address getThisAddress(CodeGenFunction &CGF) {
|
|
|
|
return Address(CGF.CXXABIThisValue, CGF.CXXABIThisAlignment);
|
|
|
|
}
|
2010-08-31 15:33:07 +08:00
|
|
|
|
2013-03-23 03:02:54 +08:00
|
|
|
/// Issue a diagnostic about unsupported features in the ABI.
|
|
|
|
void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
|
|
|
|
|
|
|
|
/// Get a null value for unsupported member pointers.
|
|
|
|
llvm::Constant *GetBogusMemberPointer(QualType T);
|
|
|
|
|
2013-02-13 16:37:51 +08:00
|
|
|
ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
|
|
|
|
return CGF.CXXStructorImplicitParamDecl;
|
|
|
|
}
|
|
|
|
llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
|
|
|
|
return CGF.CXXStructorImplicitParamValue;
|
2010-08-31 15:33:07 +08:00
|
|
|
}
|
|
|
|
|
[MS] Apply adjustments after storing 'this'
Summary:
The MS ABI convention is that the 'this' pointer on entry is the address
of the vfptr that was used to make the virtual method call. In other
words, the pointer on entry always points to the base subobject that
introduced the virtual method. Consider this hierarchy:
struct A { virtual void f() = 0; };
struct B { virtual void g() = 0; };
struct C : A, B {
void f() override;
void g() override;
};
On entry to C::g, [ER]CX will contain the address of C's B subobject,
and C::g will have to subtract sizeof(A) to recover a pointer to C.
Before this change, we applied this adjustment in the prologue and
stored the new value into the "this" local variable alloca used for
debug info. However, MSVC does not do this, presumably because it is
often profitable to fold the adjustment into later field accesses. This
creates a problem, because the debugger expects the variable to be
unadjusted. Unfortunately, CodeView doesn't have anything like DWARF
expressions for computing variables that aren't in the program anymore,
so we have to declare 'this' to be the unadjusted value if we want the
debugger to see the right value.
This has the side benefit that, in optimized builds, the 'this' pointer
will usually be available on function entry because it doesn't require
any adjustment.
Reviewers: hans
Subscribers: aprantl, cfe-commits
Differential Revision: https://reviews.llvm.org/D40109
llvm-svn: 318440
2017-11-17 03:09:36 +08:00
|
|
|
/// Loads the incoming C++ this pointer as it was passed by the caller.
|
|
|
|
llvm::Value *loadIncomingCXXThis(CodeGenFunction &CGF);
|
|
|
|
|
|
|
|
void setCXXABIThisValue(CodeGenFunction &CGF, llvm::Value *ThisPtr);
|
2010-08-31 15:33:07 +08:00
|
|
|
|
2010-09-02 17:58:18 +08:00
|
|
|
ASTContext &getContext() const { return CGM.getContext(); }
|
|
|
|
|
2012-05-01 13:23:51 +08:00
|
|
|
virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
|
|
|
|
virtual bool requiresArrayCookie(const CXXNewExpr *E);
|
|
|
|
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
/// Determine whether there's something special about the rules of
|
|
|
|
/// the ABI tell us that 'this' is a complete object within the
|
|
|
|
/// given function. Obvious common logic like being defined on a
|
|
|
|
/// final class will have been taken care of by the caller.
|
|
|
|
virtual bool isThisCompleteObject(GlobalDecl GD) const = 0;
|
|
|
|
|
2010-05-26 03:52:27 +08:00
|
|
|
public:
|
2010-08-22 18:59:02 +08:00
|
|
|
|
2010-11-29 01:50:09 +08:00
|
|
|
virtual ~CGCXXABI();
|
2010-05-26 03:52:27 +08:00
|
|
|
|
|
|
|
/// Gets the mangle context.
|
2011-01-14 02:57:25 +08:00
|
|
|
MangleContext &getMangleContext() {
|
|
|
|
return *MangleCtx;
|
|
|
|
}
|
2010-08-22 08:05:51 +08:00
|
|
|
|
2013-07-01 04:40:16 +08:00
|
|
|
/// Returns true if the given constructor or destructor is one of the
|
|
|
|
/// kinds that the ABI says returns 'this' (only applies when called
|
|
|
|
/// non-virtually for destructors).
|
|
|
|
///
|
|
|
|
/// There currently is no way to indicate if a destructor returns 'this'
|
|
|
|
/// when called virtually, and code generation does not support the case.
|
2013-03-21 00:59:38 +08:00
|
|
|
virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
|
|
|
|
|
2014-11-01 04:09:12 +08:00
|
|
|
virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
|
|
|
|
|
2016-05-11 01:44:55 +08:00
|
|
|
/// Returns true if the target allows calling a function through a pointer
|
|
|
|
/// with a different signature than the actual function (or equivalently,
|
|
|
|
/// bitcasting a function or function pointer to a different function type).
|
|
|
|
/// In principle in the most general case this could depend on the target, the
|
|
|
|
/// calling convention, and the actual types of the arguments and return
|
|
|
|
/// value. Here it just means whether the signature mismatch could *ever* be
|
|
|
|
/// allowed; in other words, does the target do strict checking of signatures
|
|
|
|
/// for all calls.
|
|
|
|
virtual bool canCallMismatchedFunctionType() const { return true; }
|
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
/// If the C++ ABI requires the given type be returned in a particular way,
|
|
|
|
/// this method sets RetAI and returns true.
|
|
|
|
virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
|
2013-04-17 20:54:10 +08:00
|
|
|
|
|
|
|
/// Specify how one should pass an argument of a record type.
|
|
|
|
enum RecordArgABI {
|
|
|
|
/// Pass it using the normal C aggregate rules for the ABI, potentially
|
|
|
|
/// introducing extra copies and passing some or all of it in registers.
|
|
|
|
RAA_Default = 0,
|
|
|
|
|
|
|
|
/// Pass it on the stack using its defined layout. The argument must be
|
|
|
|
/// evaluated directly into the correct stack position in the arguments area,
|
|
|
|
/// and the call machinery must not move it or introduce extra copies.
|
|
|
|
RAA_DirectInMemory,
|
|
|
|
|
|
|
|
/// Pass it as a pointer to temporary memory.
|
|
|
|
RAA_Indirect
|
|
|
|
};
|
|
|
|
|
2014-05-15 00:02:09 +08:00
|
|
|
/// Returns true if C++ allows us to copy the memory of an object of type RD
|
|
|
|
/// when it is passed as an argument.
|
|
|
|
bool canCopyArgument(const CXXRecordDecl *RD) const;
|
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
/// Returns how an argument of the given record type should be passed.
|
|
|
|
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
|
|
|
|
|
2014-05-10 06:46:15 +08:00
|
|
|
/// Returns true if the implicit 'sret' parameter comes after the implicit
|
|
|
|
/// 'this' parameter of C++ instance methods.
|
|
|
|
virtual bool isSRetParameterAfterThis() const { return false; }
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Find the LLVM type used to represent the given member pointer
|
|
|
|
/// type.
|
2011-07-10 01:41:47 +08:00
|
|
|
virtual llvm::Type *
|
2010-08-23 09:21:21 +08:00
|
|
|
ConvertMemberPointerType(const MemberPointerType *MPT);
|
|
|
|
|
|
|
|
/// Load a member function from an object and a member function
|
|
|
|
/// pointer. Apply the this-adjustment and set 'This' to the
|
|
|
|
/// adjusted value.
|
2016-10-27 07:46:34 +08:00
|
|
|
virtual CGCallee EmitLoadOfMemberFunctionPointer(
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
CodeGenFunction &CGF, const Expr *E, Address This,
|
|
|
|
llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr,
|
|
|
|
const MemberPointerType *MPT);
|
2010-08-22 11:04:22 +08:00
|
|
|
|
2010-09-01 05:07:20 +08:00
|
|
|
/// Calculate an l-value from an object and a data member pointer.
|
2014-02-21 07:22:07 +08:00
|
|
|
virtual llvm::Value *
|
|
|
|
EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address Base, llvm::Value *MemPtr,
|
2014-02-21 07:22:07 +08:00
|
|
|
const MemberPointerType *MPT);
|
2010-09-01 05:07:20 +08:00
|
|
|
|
2012-02-15 09:22:51 +08:00
|
|
|
/// Perform a derived-to-base, base-to-derived, or bitcast member
|
|
|
|
/// pointer conversion.
|
2010-08-23 09:21:21 +08:00
|
|
|
virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
|
|
|
|
const CastExpr *E,
|
|
|
|
llvm::Value *Src);
|
2010-08-22 18:59:02 +08:00
|
|
|
|
2012-02-15 09:22:51 +08:00
|
|
|
/// Perform a derived-to-base, base-to-derived, or bitcast member
|
|
|
|
/// pointer conversion on a constant value.
|
|
|
|
virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
|
|
|
|
llvm::Constant *Src);
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Return true if the given member pointer can be zero-initialized
|
|
|
|
/// (in the C++ sense) with an LLVM zeroinitializer.
|
2010-08-23 05:01:12 +08:00
|
|
|
virtual bool isZeroInitializable(const MemberPointerType *MPT);
|
2010-08-22 12:16:24 +08:00
|
|
|
|
2014-08-08 06:56:13 +08:00
|
|
|
/// Return whether or not a member pointers type is convertible to an IR type.
|
|
|
|
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Create a null member pointer of the given type.
|
|
|
|
virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
|
2010-08-22 12:16:24 +08:00
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Create a member pointer for the given method.
|
2015-06-23 15:31:01 +08:00
|
|
|
virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD);
|
2010-08-22 14:43:33 +08:00
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Create a member pointer for the given field.
|
2011-02-03 16:15:49 +08:00
|
|
|
virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
|
|
|
|
CharUnits offset);
|
2010-08-22 16:30:07 +08:00
|
|
|
|
2012-01-14 12:30:29 +08:00
|
|
|
/// Create a member pointer for the given member pointer constant.
|
|
|
|
virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
|
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Emit a comparison between two member pointers. Returns an i1.
|
2010-08-22 16:30:07 +08:00
|
|
|
virtual llvm::Value *
|
2010-08-23 09:21:21 +08:00
|
|
|
EmitMemberPointerComparison(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *L,
|
|
|
|
llvm::Value *R,
|
|
|
|
const MemberPointerType *MPT,
|
|
|
|
bool Inequality);
|
2010-08-22 16:30:07 +08:00
|
|
|
|
2010-08-23 09:21:21 +08:00
|
|
|
/// Determine if a member pointer is non-null. Returns an i1.
|
2010-08-22 16:30:07 +08:00
|
|
|
virtual llvm::Value *
|
2010-08-23 09:21:21 +08:00
|
|
|
EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *MemPtr,
|
|
|
|
const MemberPointerType *MPT);
|
2010-08-31 15:33:07 +08:00
|
|
|
|
2012-02-15 09:22:51 +08:00
|
|
|
protected:
|
|
|
|
/// A utility method for computing the offset required for the given
|
|
|
|
/// base-to-derived or derived-to-base member-pointer conversion.
|
|
|
|
/// Does not handle virtual conversions (in case we ever fully
|
|
|
|
/// support an ABI that allows this). Returns null if no adjustment
|
|
|
|
/// is required.
|
|
|
|
llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
|
|
|
|
|
2013-05-10 05:01:17 +08:00
|
|
|
/// \brief Computes the non-virtual adjustment needed for a member pointer
|
|
|
|
/// conversion along an inheritance path stored in an APValue. Unlike
|
|
|
|
/// getMemberPointerAdjustment(), the adjustment can be negative if the path
|
|
|
|
/// is from a derived type to a base type.
|
|
|
|
CharUnits getMemberPointerPathAdjustment(const APValue &MP);
|
|
|
|
|
2012-02-15 09:22:51 +08:00
|
|
|
public:
|
2014-11-01 04:09:12 +08:00
|
|
|
virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
|
2014-11-01 15:37:17 +08:00
|
|
|
const CXXDeleteExpr *DE,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address Ptr, QualType ElementType,
|
2014-11-01 04:09:12 +08:00
|
|
|
const CXXDestructorDecl *Dtor) = 0;
|
2014-11-25 15:20:20 +08:00
|
|
|
virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
|
2015-03-05 08:46:22 +08:00
|
|
|
virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
|
2015-03-14 02:26:17 +08:00
|
|
|
virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
|
2012-09-25 18:10:39 +08:00
|
|
|
|
2015-09-15 08:37:06 +08:00
|
|
|
/// \brief Determine whether it's possible to emit a vtable for \p RD, even
|
|
|
|
/// though we do not know that the vtable has been marked as used by semantic
|
|
|
|
/// analysis.
|
|
|
|
virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
|
2015-07-24 12:04:49 +08:00
|
|
|
|
2015-03-04 03:21:04 +08:00
|
|
|
virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
|
|
|
|
|
|
|
|
virtual llvm::CallInst *
|
|
|
|
emitTerminateForUnexpectedException(CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Exn);
|
|
|
|
|
2015-03-18 04:35:00 +08:00
|
|
|
virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
|
2015-09-17 04:15:55 +08:00
|
|
|
virtual CatchTypeInfo
|
2015-03-30 05:55:10 +08:00
|
|
|
getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
|
2015-09-17 04:15:55 +08:00
|
|
|
virtual CatchTypeInfo getCatchAllTypeInfo();
|
2014-07-07 14:20:47 +08:00
|
|
|
|
2014-06-23 03:05:33 +08:00
|
|
|
virtual bool shouldTypeidBeNullChecked(bool IsDeref,
|
|
|
|
QualType SrcRecordTy) = 0;
|
|
|
|
virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
|
|
|
|
virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address ThisPtr,
|
2014-06-23 03:05:33 +08:00
|
|
|
llvm::Type *StdTypeInfoPtrTy) = 0;
|
|
|
|
|
|
|
|
virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
|
|
|
|
QualType SrcRecordTy) = 0;
|
|
|
|
|
|
|
|
virtual llvm::Value *
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
EmitDynamicCastCall(CodeGenFunction &CGF, Address Value,
|
2014-06-23 03:05:33 +08:00
|
|
|
QualType SrcRecordTy, QualType DestTy,
|
|
|
|
QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address Value,
|
2014-06-23 03:05:33 +08:00
|
|
|
QualType SrcRecordTy,
|
|
|
|
QualType DestTy) = 0;
|
|
|
|
|
|
|
|
virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
|
|
|
|
|
2013-05-30 02:02:47 +08:00
|
|
|
virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address This,
|
2013-05-30 02:02:47 +08:00
|
|
|
const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl) = 0;
|
|
|
|
|
2013-06-19 23:20:38 +08:00
|
|
|
virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
|
|
|
|
const CXXRecordDecl *RD);
|
2013-02-27 21:46:31 +08:00
|
|
|
|
2013-10-10 02:16:58 +08:00
|
|
|
/// Emit the code to initialize hidden members required
|
|
|
|
/// to handle virtual inheritance, if needed by the ABI.
|
|
|
|
virtual void
|
|
|
|
initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
|
|
|
|
const CXXRecordDecl *RD) {}
|
|
|
|
|
2013-08-05 01:30:04 +08:00
|
|
|
/// Emit constructor variants required by this ABI.
|
|
|
|
virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
|
|
|
|
|
2017-02-23 04:28:02 +08:00
|
|
|
/// Notes how many arguments were added to the beginning (Prefix) and ending
|
|
|
|
/// (Suffix) of an arg list.
|
|
|
|
///
|
|
|
|
/// Note that Prefix actually refers to the number of args *after* the first
|
|
|
|
/// one: `this` arguments always come first.
|
|
|
|
struct AddedStructorArgs {
|
|
|
|
unsigned Prefix = 0;
|
|
|
|
unsigned Suffix = 0;
|
|
|
|
AddedStructorArgs() = default;
|
|
|
|
AddedStructorArgs(unsigned P, unsigned S) : Prefix(P), Suffix(S) {}
|
|
|
|
static AddedStructorArgs prefix(unsigned N) { return {N, 0}; }
|
|
|
|
static AddedStructorArgs suffix(unsigned N) { return {0, N}; }
|
|
|
|
};
|
|
|
|
|
2014-09-09 00:01:27 +08:00
|
|
|
/// Build the signature of the given constructor or destructor variant by
|
|
|
|
/// adding any required parameters. For convenience, ArgTys has been
|
|
|
|
/// initialized with the type of 'this'.
|
2017-02-23 04:28:02 +08:00
|
|
|
virtual AddedStructorArgs
|
|
|
|
buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
|
|
|
|
SmallVectorImpl<CanQualType> &ArgTys) = 0;
|
2010-08-31 15:33:07 +08:00
|
|
|
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
/// Returns true if the given destructor type should be emitted as a linkonce
|
|
|
|
/// delegating thunk, regardless of whether the dtor is defined in this TU or
|
|
|
|
/// not.
|
|
|
|
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
|
|
|
|
CXXDtorType DT) const = 0;
|
|
|
|
|
|
|
|
/// Emit destructor variants required by this ABI.
|
|
|
|
virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
|
|
|
|
|
2013-08-21 14:25:03 +08:00
|
|
|
/// Get the type of the implicit "this" parameter used by a method. May return
|
|
|
|
/// zero if no specific type is applicable, e.g. if the ABI expects the "this"
|
|
|
|
/// parameter to point to some artificial offset in a complete object due to
|
|
|
|
/// vbases being reordered.
|
|
|
|
virtual const CXXRecordDecl *
|
|
|
|
getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
|
|
|
|
return MD->getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Perform ABI-specific "this" argument adjustment required prior to
|
2014-03-15 01:43:37 +08:00
|
|
|
/// a call of a virtual function.
|
|
|
|
/// The "VirtualCall" argument is true iff the call itself is virtual.
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
virtual Address
|
2014-03-15 01:43:37 +08:00
|
|
|
adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address This, bool VirtualCall) {
|
2013-08-21 14:25:03 +08:00
|
|
|
return This;
|
|
|
|
}
|
|
|
|
|
2013-12-18 03:46:40 +08:00
|
|
|
/// Build a parameter variable suitable for 'this'.
|
|
|
|
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
|
|
|
|
|
|
|
|
/// Insert any ABI-specific implicit parameters into the parameter list for a
|
|
|
|
/// function. This generally involves extra data for constructors and
|
|
|
|
/// destructors.
|
2010-08-31 15:33:07 +08:00
|
|
|
///
|
|
|
|
/// ABIs may also choose to override the return type, which has been
|
2013-07-01 04:40:16 +08:00
|
|
|
/// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
|
|
|
|
/// the formal return type of the function otherwise.
|
2013-12-18 03:46:40 +08:00
|
|
|
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
|
|
|
|
FunctionArgList &Params) = 0;
|
2010-08-31 15:33:07 +08:00
|
|
|
|
2016-07-01 10:41:25 +08:00
|
|
|
/// Get the ABI-specific "this" parameter adjustment to apply in the prologue
|
|
|
|
/// of a virtual function.
|
|
|
|
virtual CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) {
|
|
|
|
return CharUnits::Zero();
|
|
|
|
}
|
|
|
|
|
2010-08-31 15:33:07 +08:00
|
|
|
/// Emit the ABI-specific prolog for the function.
|
|
|
|
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
|
|
|
|
|
2013-12-18 03:46:40 +08:00
|
|
|
/// Add any ABI-specific implicit arguments needed to call a constructor.
|
|
|
|
///
|
2017-02-23 04:28:02 +08:00
|
|
|
/// \return The number of arguments added at the beginning and end of the
|
|
|
|
/// call, which is typically zero or one.
|
|
|
|
virtual AddedStructorArgs
|
2013-12-18 03:46:40 +08:00
|
|
|
addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type, bool ForVirtualBase,
|
|
|
|
bool Delegating, CallArgList &Args) = 0;
|
2013-02-27 21:46:31 +08:00
|
|
|
|
2013-12-13 08:53:54 +08:00
|
|
|
/// Emit the destructor call.
|
|
|
|
virtual void EmitDestructorCall(CodeGenFunction &CGF,
|
|
|
|
const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
bool ForVirtualBase, bool Delegating,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address This) = 0;
|
2013-12-13 08:53:54 +08:00
|
|
|
|
2013-09-27 22:48:01 +08:00
|
|
|
/// Emits the VTable definitions required for the given record type.
|
|
|
|
virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
|
|
|
|
const CXXRecordDecl *RD) = 0;
|
|
|
|
|
2015-09-15 08:37:06 +08:00
|
|
|
/// Checks if ABI requires extra virtual offset for vtable field.
|
|
|
|
virtual bool
|
|
|
|
isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
|
|
|
|
CodeGenFunction::VPtr Vptr) = 0;
|
|
|
|
|
2017-03-30 22:13:19 +08:00
|
|
|
/// Checks if ABI requires to initialize vptrs for given dynamic class.
|
2015-09-15 08:37:06 +08:00
|
|
|
virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 0;
|
|
|
|
|
|
|
|
/// Get the address point of the vtable for the given base subobject.
|
|
|
|
virtual llvm::Constant *
|
|
|
|
getVTableAddressPoint(BaseSubobject Base,
|
|
|
|
const CXXRecordDecl *VTableClass) = 0;
|
|
|
|
|
2013-09-27 22:48:01 +08:00
|
|
|
/// Get the address point of the vtable for the given base subobject while
|
2015-09-15 08:37:06 +08:00
|
|
|
/// building a constructor or a destructor.
|
|
|
|
virtual llvm::Value *
|
|
|
|
getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD,
|
|
|
|
BaseSubobject Base,
|
|
|
|
const CXXRecordDecl *NearestVBase) = 0;
|
2013-09-27 22:48:01 +08:00
|
|
|
|
|
|
|
/// Get the address point of the vtable for the given base subobject while
|
|
|
|
/// building a constexpr.
|
|
|
|
virtual llvm::Constant *
|
|
|
|
getVTableAddressPointForConstExpr(BaseSubobject Base,
|
|
|
|
const CXXRecordDecl *VTableClass) = 0;
|
|
|
|
|
|
|
|
/// Get the address of the vtable for the given record decl which should be
|
|
|
|
/// used for the vptr at the given offset in RD.
|
|
|
|
virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
|
|
|
|
CharUnits VPtrOffset) = 0;
|
|
|
|
|
2013-08-21 14:25:03 +08:00
|
|
|
/// Build a virtual function pointer in the ABI-specific way.
|
2016-10-27 07:46:34 +08:00
|
|
|
virtual CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF,
|
|
|
|
GlobalDecl GD,
|
|
|
|
Address This,
|
|
|
|
llvm::Type *Ty,
|
|
|
|
SourceLocation Loc) = 0;
|
2013-08-21 14:25:03 +08:00
|
|
|
|
2013-02-15 22:45:22 +08:00
|
|
|
/// Emit the ABI-specific virtual destructor call.
|
2014-11-01 04:09:12 +08:00
|
|
|
virtual llvm::Value *
|
|
|
|
EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
CXXDtorType DtorType, Address This,
|
2014-11-01 04:09:12 +08:00
|
|
|
const CXXMemberCallExpr *CE) = 0;
|
2013-02-15 22:45:22 +08:00
|
|
|
|
2013-10-09 17:23:58 +08:00
|
|
|
virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
|
|
|
|
GlobalDecl GD,
|
|
|
|
CallArgList &CallArgs) {}
|
|
|
|
|
2013-06-19 23:20:38 +08:00
|
|
|
/// Emit any tables needed to implement virtual inheritance. For Itanium,
|
|
|
|
/// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
|
|
|
|
/// base tables.
|
2013-09-27 22:48:01 +08:00
|
|
|
virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
|
2013-06-19 23:20:38 +08:00
|
|
|
|
2014-06-07 04:04:01 +08:00
|
|
|
virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
|
|
|
|
GlobalDecl GD, bool ReturnAdjustment) = 0;
|
2013-10-09 17:23:58 +08:00
|
|
|
|
2013-10-30 19:55:43 +08:00
|
|
|
virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address This,
|
2013-10-30 19:55:43 +08:00
|
|
|
const ThisAdjustment &TA) = 0;
|
|
|
|
|
|
|
|
virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
Address Ret,
|
2013-10-30 19:55:43 +08:00
|
|
|
const ReturnAdjustment &RA) = 0;
|
|
|
|
|
2010-08-31 15:33:07 +08:00
|
|
|
virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
|
|
|
|
RValue RV, QualType ResultType);
|
2010-09-02 17:58:18 +08:00
|
|
|
|
2014-09-12 07:05:02 +08:00
|
|
|
virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
|
|
|
|
FunctionArgList &Args) const = 0;
|
|
|
|
|
2015-11-02 17:01:44 +08:00
|
|
|
/// Gets the offsets of all the virtual base pointers in a given class.
|
|
|
|
virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD);
|
|
|
|
|
2012-07-18 01:10:11 +08:00
|
|
|
/// Gets the pure virtual member call function.
|
|
|
|
virtual StringRef GetPureVirtualCallName() = 0;
|
|
|
|
|
2012-10-17 06:56:05 +08:00
|
|
|
/// Gets the deleted virtual member call name.
|
|
|
|
virtual StringRef GetDeletedVirtualCallName() = 0;
|
|
|
|
|
2010-09-02 17:58:18 +08:00
|
|
|
/**************************** Array cookies ******************************/
|
|
|
|
|
|
|
|
/// Returns the extra size required in order to store the array
|
2012-06-22 18:16:05 +08:00
|
|
|
/// cookie for the given new-expression. May return 0 to indicate that no
|
2010-09-02 17:58:18 +08:00
|
|
|
/// array cookie is required.
|
|
|
|
///
|
|
|
|
/// Several cases are filtered out before this method is called:
|
|
|
|
/// - non-array allocations never need a cookie
|
2012-06-20 08:57:15 +08:00
|
|
|
/// - calls to \::operator new(size_t, void*) never need a cookie
|
2010-09-02 17:58:18 +08:00
|
|
|
///
|
2012-06-22 18:16:05 +08:00
|
|
|
/// \param expr - the new-expression being allocated.
|
2011-01-27 17:37:56 +08:00
|
|
|
virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
|
2010-09-02 17:58:18 +08:00
|
|
|
|
|
|
|
/// Initialize the array cookie for the given allocation.
|
|
|
|
///
|
|
|
|
/// \param NewPtr - a char* which is the presumed-non-null
|
|
|
|
/// return value of the allocation function
|
|
|
|
/// \param NumElements - the computed number of elements,
|
2012-05-01 13:23:51 +08:00
|
|
|
/// potentially collapsed from the multidimensional array case;
|
|
|
|
/// always a size_t
|
2010-09-02 17:58:18 +08:00
|
|
|
/// \param ElementType - the base element allocated type,
|
|
|
|
/// i.e. the allocated type after stripping all array types
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
virtual Address InitializeArrayCookie(CodeGenFunction &CGF,
|
|
|
|
Address NewPtr,
|
|
|
|
llvm::Value *NumElements,
|
|
|
|
const CXXNewExpr *expr,
|
|
|
|
QualType ElementType);
|
2010-09-02 17:58:18 +08:00
|
|
|
|
|
|
|
/// Reads the array cookie associated with the given pointer,
|
|
|
|
/// if it has one.
|
|
|
|
///
|
|
|
|
/// \param Ptr - a pointer to the first element in the array
|
|
|
|
/// \param ElementType - the base element type of elements of the array
|
|
|
|
/// \param NumElements - an out parameter which will be initialized
|
|
|
|
/// with the number of elements allocated, or zero if there is no
|
|
|
|
/// cookie
|
|
|
|
/// \param AllocPtr - an out parameter which will be initialized
|
|
|
|
/// with a char* pointing to the address returned by the allocation
|
|
|
|
/// function
|
|
|
|
/// \param CookieSize - an out parameter which will be initialized
|
|
|
|
/// with the size of the cookie, or zero if there is no cookie
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr,
|
2011-01-27 17:37:56 +08:00
|
|
|
const CXXDeleteExpr *expr,
|
2010-09-02 17:58:18 +08:00
|
|
|
QualType ElementType, llvm::Value *&NumElements,
|
|
|
|
llvm::Value *&AllocPtr, CharUnits &CookieSize);
|
|
|
|
|
2013-06-29 04:45:28 +08:00
|
|
|
/// Return whether the given global decl needs a VTT parameter.
|
|
|
|
virtual bool NeedsVTTParameter(GlobalDecl GD);
|
|
|
|
|
2012-05-01 13:23:51 +08:00
|
|
|
protected:
|
|
|
|
/// Returns the extra size required in order to store the array
|
|
|
|
/// cookie for the given type. Assumes that an array cookie is
|
|
|
|
/// required.
|
|
|
|
virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
|
|
|
|
|
|
|
|
/// Reads the array cookie for an allocation which is known to have one.
|
|
|
|
/// This is called by the standard implementation of ReadArrayCookie.
|
|
|
|
///
|
|
|
|
/// \param ptr - a pointer to the allocation made for an array, as a char*
|
|
|
|
/// \param cookieSize - the computed cookie size of an array
|
2012-06-15 15:35:42 +08:00
|
|
|
///
|
2012-05-01 13:23:51 +08:00
|
|
|
/// Other parameters are as above.
|
2012-06-15 15:35:42 +08:00
|
|
|
///
|
2012-05-01 13:23:51 +08:00
|
|
|
/// \return a size_t
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF, Address ptr,
|
2012-05-01 13:23:51 +08:00
|
|
|
CharUnits cookieSize);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-09-08 09:44:27 +08:00
|
|
|
/*************************** Static local guards ****************************/
|
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
/// Emits the guarded initializer and destructor setup for the given
|
|
|
|
/// variable, given that it couldn't be emitted as a constant.
|
2012-02-14 06:16:19 +08:00
|
|
|
/// If \p PerformInit is false, the initialization has been folded to a
|
|
|
|
/// constant and should not be performed.
|
2010-11-06 17:44:32 +08:00
|
|
|
///
|
|
|
|
/// The variable may be:
|
|
|
|
/// - a static local variable
|
|
|
|
/// - a static data member of a class template instantiation
|
|
|
|
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
|
2013-09-11 04:14:30 +08:00
|
|
|
llvm::GlobalVariable *DeclPtr,
|
|
|
|
bool PerformInit) = 0;
|
2010-09-08 09:44:27 +08:00
|
|
|
|
2012-05-01 14:13:13 +08:00
|
|
|
/// Emit code to force the execution of a destructor during global
|
|
|
|
/// teardown. The default implementation of this uses atexit.
|
|
|
|
///
|
2014-10-05 13:05:40 +08:00
|
|
|
/// \param Dtor - a function taking a single pointer argument
|
|
|
|
/// \param Addr - a pointer to pass to the destructor function.
|
2013-04-15 07:01:42 +08:00
|
|
|
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
|
2014-10-05 13:05:40 +08:00
|
|
|
llvm::Constant *Dtor,
|
|
|
|
llvm::Constant *Addr) = 0;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
|
|
|
/*************************** thread_local initialization ********************/
|
|
|
|
|
|
|
|
/// Emits ABI-required functions necessary to initialize thread_local
|
|
|
|
/// variables in this translation unit.
|
|
|
|
///
|
2014-10-05 13:05:40 +08:00
|
|
|
/// \param CXXThreadLocals - The thread_local declarations in this translation
|
|
|
|
/// unit.
|
|
|
|
/// \param CXXThreadLocalInits - If this translation unit contains any
|
|
|
|
/// non-constant initialization or non-trivial destruction for
|
|
|
|
/// thread_local variables, a list of functions to perform the
|
|
|
|
/// initialization.
|
2013-04-20 00:42:07 +08:00
|
|
|
virtual void EmitThreadLocalInitFuncs(
|
2015-12-01 09:10:48 +08:00
|
|
|
CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals,
|
2014-10-05 13:05:40 +08:00
|
|
|
ArrayRef<llvm::Function *> CXXThreadLocalInits,
|
2015-12-01 09:10:48 +08:00
|
|
|
ArrayRef<const VarDecl *> CXXThreadLocalInitVars) = 0;
|
2014-10-05 13:05:40 +08:00
|
|
|
|
|
|
|
// Determine if references to thread_local global variables can be made
|
|
|
|
// directly or require access through a thread wrapper function.
|
|
|
|
virtual bool usesThreadWrapperFunction() const = 0;
|
2013-04-20 00:42:07 +08:00
|
|
|
|
|
|
|
/// Emit a reference to a non-local thread_local variable (including
|
|
|
|
/// triggering the initialization of all thread_local variables in its
|
|
|
|
/// translation unit).
|
2014-03-27 06:48:22 +08:00
|
|
|
virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
|
|
|
|
const VarDecl *VD,
|
2014-10-05 13:05:40 +08:00
|
|
|
QualType LValType) = 0;
|
2014-09-16 03:20:10 +08:00
|
|
|
|
|
|
|
/// Emit a single constructor/destructor with the given type from a C++
|
|
|
|
/// constructor Decl.
|
|
|
|
virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
|
2017-12-14 05:53:04 +08:00
|
|
|
|
|
|
|
/// Load a vtable from This, an object of polymorphic type RD, or from one of
|
|
|
|
/// its virtual bases if it does not have its own vtable. Returns the vtable
|
|
|
|
/// and the class from which the vtable was loaded.
|
|
|
|
virtual std::pair<llvm::Value *, const CXXRecordDecl *>
|
|
|
|
LoadVTablePtr(CodeGenFunction &CGF, Address This,
|
|
|
|
const CXXRecordDecl *RD) = 0;
|
2010-05-26 03:52:27 +08:00
|
|
|
};
|
|
|
|
|
2013-01-26 07:36:14 +08:00
|
|
|
// Create an instance of a C++ ABI class:
|
|
|
|
|
|
|
|
/// Creates an Itanium-family ABI.
|
2010-08-16 11:33:14 +08:00
|
|
|
CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
|
2013-01-26 07:36:14 +08:00
|
|
|
|
|
|
|
/// Creates a Microsoft-family ABI.
|
2010-08-16 11:33:14 +08:00
|
|
|
CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
|
2010-08-22 08:05:51 +08:00
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 03:52:27 +08:00
|
|
|
|
|
|
|
#endif
|