2008-09-09 05:33:45 +08:00
|
|
|
//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These classes wrap the information about a call or function
|
|
|
|
// definition used to handle ABI compliancy.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGCALL_H
|
2008-09-09 05:33:45 +08:00
|
|
|
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "CGValue.h"
|
2013-06-21 20:45:15 +08:00
|
|
|
#include "EHScopeStack.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/CanonicalType.h"
|
2018-02-06 07:09:13 +08:00
|
|
|
#include "clang/AST/GlobalDecl.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2008-09-09 09:06:48 +08:00
|
|
|
|
2009-02-03 13:31:23 +08:00
|
|
|
// FIXME: Restructure so we don't have to expose so much stuff.
|
|
|
|
#include "ABIInfo.h"
|
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
namespace llvm {
|
2017-03-22 00:57:30 +08:00
|
|
|
class AttributeList;
|
|
|
|
class Function;
|
|
|
|
class Type;
|
|
|
|
class Value;
|
2008-09-09 05:33:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class Decl;
|
|
|
|
class FunctionDecl;
|
|
|
|
class ObjCMethodDecl;
|
2008-09-10 07:14:03 +08:00
|
|
|
class VarDecl;
|
2008-09-09 05:33:45 +08:00
|
|
|
|
|
|
|
namespace CodeGen {
|
2017-03-22 00:57:30 +08:00
|
|
|
|
|
|
|
/// Abstract information about a function or function prototype.
|
|
|
|
class CGCalleeInfo {
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The function prototype of the callee.
|
2017-03-22 00:57:30 +08:00
|
|
|
const FunctionProtoType *CalleeProtoTy;
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The function declaration of the callee.
|
2018-11-13 23:48:08 +08:00
|
|
|
GlobalDecl CalleeDecl;
|
2017-03-22 00:57:30 +08:00
|
|
|
|
|
|
|
public:
|
2018-11-13 23:48:08 +08:00
|
|
|
explicit CGCalleeInfo() : CalleeProtoTy(nullptr), CalleeDecl() {}
|
|
|
|
CGCalleeInfo(const FunctionProtoType *calleeProtoTy, GlobalDecl calleeDecl)
|
2017-03-22 00:57:30 +08:00
|
|
|
: CalleeProtoTy(calleeProtoTy), CalleeDecl(calleeDecl) {}
|
|
|
|
CGCalleeInfo(const FunctionProtoType *calleeProtoTy)
|
2018-11-13 23:48:08 +08:00
|
|
|
: CalleeProtoTy(calleeProtoTy), CalleeDecl() {}
|
|
|
|
CGCalleeInfo(GlobalDecl calleeDecl)
|
2017-03-22 00:57:30 +08:00
|
|
|
: CalleeProtoTy(nullptr), CalleeDecl(calleeDecl) {}
|
|
|
|
|
|
|
|
const FunctionProtoType *getCalleeFunctionProtoType() const {
|
|
|
|
return CalleeProtoTy;
|
|
|
|
}
|
2018-11-13 23:48:08 +08:00
|
|
|
const GlobalDecl getCalleeDecl() const { return CalleeDecl; }
|
2016-10-27 07:46:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// All available information about a concrete callee.
|
|
|
|
class CGCallee {
|
|
|
|
enum class SpecialKind : uintptr_t {
|
|
|
|
Invalid,
|
|
|
|
Builtin,
|
|
|
|
PseudoDestructor,
|
2018-02-06 07:09:13 +08:00
|
|
|
Virtual,
|
2016-10-27 07:46:34 +08:00
|
|
|
|
2018-02-06 07:09:13 +08:00
|
|
|
Last = Virtual
|
2016-10-27 07:46:34 +08:00
|
|
|
};
|
|
|
|
|
2016-11-08 05:13:27 +08:00
|
|
|
struct BuiltinInfoStorage {
|
|
|
|
const FunctionDecl *Decl;
|
|
|
|
unsigned ID;
|
|
|
|
};
|
|
|
|
struct PseudoDestructorInfoStorage {
|
|
|
|
const CXXPseudoDestructorExpr *Expr;
|
|
|
|
};
|
2018-02-06 07:09:13 +08:00
|
|
|
struct VirtualInfoStorage {
|
|
|
|
const CallExpr *CE;
|
|
|
|
GlobalDecl MD;
|
|
|
|
Address Addr;
|
|
|
|
llvm::FunctionType *FTy;
|
|
|
|
};
|
2016-11-08 05:13:27 +08:00
|
|
|
|
2016-10-27 07:46:34 +08:00
|
|
|
SpecialKind KindOrFunctionPointer;
|
|
|
|
union {
|
|
|
|
CGCalleeInfo AbstractInfo;
|
2016-11-08 05:13:27 +08:00
|
|
|
BuiltinInfoStorage BuiltinInfo;
|
|
|
|
PseudoDestructorInfoStorage PseudoDestructorInfo;
|
2018-02-06 07:09:13 +08:00
|
|
|
VirtualInfoStorage VirtualInfo;
|
2016-10-27 07:46:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit CGCallee(SpecialKind kind) : KindOrFunctionPointer(kind) {}
|
|
|
|
|
|
|
|
CGCallee(const FunctionDecl *builtinDecl, unsigned builtinID)
|
|
|
|
: KindOrFunctionPointer(SpecialKind::Builtin) {
|
|
|
|
BuiltinInfo.Decl = builtinDecl;
|
|
|
|
BuiltinInfo.ID = builtinID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
CGCallee() : KindOrFunctionPointer(SpecialKind::Invalid) {}
|
|
|
|
|
|
|
|
/// Construct a callee. Call this constructor directly when this
|
|
|
|
/// isn't a direct call.
|
|
|
|
CGCallee(const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr)
|
|
|
|
: KindOrFunctionPointer(SpecialKind(uintptr_t(functionPtr))) {
|
|
|
|
AbstractInfo = abstractInfo;
|
|
|
|
assert(functionPtr && "configuring callee without function pointer");
|
|
|
|
assert(functionPtr->getType()->isPointerTy());
|
|
|
|
assert(functionPtr->getType()->getPointerElementType()->isFunctionTy());
|
|
|
|
}
|
|
|
|
|
|
|
|
static CGCallee forBuiltin(unsigned builtinID,
|
|
|
|
const FunctionDecl *builtinDecl) {
|
|
|
|
CGCallee result(SpecialKind::Builtin);
|
|
|
|
result.BuiltinInfo.Decl = builtinDecl;
|
|
|
|
result.BuiltinInfo.ID = builtinID;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CGCallee forPseudoDestructor(const CXXPseudoDestructorExpr *E) {
|
|
|
|
CGCallee result(SpecialKind::PseudoDestructor);
|
|
|
|
result.PseudoDestructorInfo.Expr = E;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CGCallee forDirect(llvm::Constant *functionPtr,
|
|
|
|
const CGCalleeInfo &abstractInfo = CGCalleeInfo()) {
|
|
|
|
return CGCallee(abstractInfo, functionPtr);
|
|
|
|
}
|
|
|
|
|
2018-02-06 07:09:13 +08:00
|
|
|
static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr,
|
|
|
|
llvm::FunctionType *FTy) {
|
|
|
|
CGCallee result(SpecialKind::Virtual);
|
|
|
|
result.VirtualInfo.CE = CE;
|
|
|
|
result.VirtualInfo.MD = MD;
|
|
|
|
result.VirtualInfo.Addr = Addr;
|
|
|
|
result.VirtualInfo.FTy = FTy;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-27 07:46:34 +08:00
|
|
|
bool isBuiltin() const {
|
|
|
|
return KindOrFunctionPointer == SpecialKind::Builtin;
|
|
|
|
}
|
|
|
|
const FunctionDecl *getBuiltinDecl() const {
|
|
|
|
assert(isBuiltin());
|
|
|
|
return BuiltinInfo.Decl;
|
|
|
|
}
|
|
|
|
unsigned getBuiltinID() const {
|
|
|
|
assert(isBuiltin());
|
|
|
|
return BuiltinInfo.ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPseudoDestructor() const {
|
|
|
|
return KindOrFunctionPointer == SpecialKind::PseudoDestructor;
|
|
|
|
}
|
|
|
|
const CXXPseudoDestructorExpr *getPseudoDestructorExpr() const {
|
|
|
|
assert(isPseudoDestructor());
|
|
|
|
return PseudoDestructorInfo.Expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isOrdinary() const {
|
|
|
|
return uintptr_t(KindOrFunctionPointer) > uintptr_t(SpecialKind::Last);
|
|
|
|
}
|
2018-02-06 07:09:13 +08:00
|
|
|
CGCalleeInfo getAbstractInfo() const {
|
|
|
|
if (isVirtual())
|
2018-11-13 23:48:08 +08:00
|
|
|
return VirtualInfo.MD;
|
2016-10-27 07:46:34 +08:00
|
|
|
assert(isOrdinary());
|
|
|
|
return AbstractInfo;
|
|
|
|
}
|
|
|
|
llvm::Value *getFunctionPointer() const {
|
|
|
|
assert(isOrdinary());
|
|
|
|
return reinterpret_cast<llvm::Value*>(uintptr_t(KindOrFunctionPointer));
|
|
|
|
}
|
|
|
|
void setFunctionPointer(llvm::Value *functionPtr) {
|
|
|
|
assert(isOrdinary());
|
|
|
|
KindOrFunctionPointer = SpecialKind(uintptr_t(functionPtr));
|
|
|
|
}
|
2018-02-06 07:09:13 +08:00
|
|
|
|
|
|
|
bool isVirtual() const {
|
|
|
|
return KindOrFunctionPointer == SpecialKind::Virtual;
|
|
|
|
}
|
|
|
|
const CallExpr *getVirtualCallExpr() const {
|
|
|
|
assert(isVirtual());
|
|
|
|
return VirtualInfo.CE;
|
|
|
|
}
|
|
|
|
GlobalDecl getVirtualMethodDecl() const {
|
|
|
|
assert(isVirtual());
|
|
|
|
return VirtualInfo.MD;
|
|
|
|
}
|
|
|
|
Address getThisAddress() const {
|
|
|
|
assert(isVirtual());
|
|
|
|
return VirtualInfo.Addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::FunctionType *getFunctionType() const {
|
|
|
|
if (isVirtual())
|
|
|
|
return VirtualInfo.FTy;
|
|
|
|
return cast<llvm::FunctionType>(
|
|
|
|
getFunctionPointer()->getType()->getPointerElementType());
|
|
|
|
}
|
2018-02-07 02:52:44 +08:00
|
|
|
|
|
|
|
/// If this is a delayed callee computation of some sort, prepare
|
|
|
|
/// a concrete callee.
|
|
|
|
CGCallee prepareConcreteCallee(CodeGenFunction &CGF) const;
|
2016-10-27 07:46:34 +08:00
|
|
|
};
|
|
|
|
|
2011-05-03 02:05:27 +08:00
|
|
|
struct CallArg {
|
2018-03-15 23:25:19 +08:00
|
|
|
private:
|
|
|
|
union {
|
|
|
|
RValue RV;
|
|
|
|
LValue LV; /// The argument is semantically a load from this l-value.
|
|
|
|
};
|
|
|
|
bool HasLV;
|
|
|
|
|
|
|
|
/// A data-flow flag to make sure getRValue and/or copyInto are not
|
|
|
|
/// called twice for duplicated IR emission.
|
|
|
|
mutable bool IsUsed;
|
|
|
|
|
|
|
|
public:
|
2011-05-03 02:05:27 +08:00
|
|
|
QualType Ty;
|
2018-03-15 23:25:19 +08:00
|
|
|
CallArg(RValue rv, QualType ty)
|
|
|
|
: RV(rv), HasLV(false), IsUsed(false), Ty(ty) {}
|
|
|
|
CallArg(LValue lv, QualType ty)
|
|
|
|
: LV(lv), HasLV(true), IsUsed(false), Ty(ty) {}
|
|
|
|
bool hasLValue() const { return HasLV; }
|
|
|
|
QualType getType() const { return Ty; }
|
|
|
|
|
|
|
|
/// \returns an independent RValue. If the CallArg contains an LValue,
|
|
|
|
/// a temporary copy is returned.
|
|
|
|
RValue getRValue(CodeGenFunction &CGF) const;
|
|
|
|
|
|
|
|
LValue getKnownLValue() const {
|
|
|
|
assert(HasLV && !IsUsed);
|
|
|
|
return LV;
|
|
|
|
}
|
|
|
|
RValue getKnownRValue() const {
|
|
|
|
assert(!HasLV && !IsUsed);
|
|
|
|
return RV;
|
|
|
|
}
|
|
|
|
void setRValue(RValue _RV) {
|
|
|
|
assert(!HasLV);
|
|
|
|
RV = _RV;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAggregate() const { return HasLV || RV.isAggregate(); }
|
|
|
|
|
|
|
|
void copyInto(CodeGenFunction &CGF, Address A) const;
|
2011-05-03 02:05:27 +08:00
|
|
|
};
|
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
/// CallArgList - Type for representing both the value and type of
|
|
|
|
/// arguments in a call.
|
2011-03-09 12:27:21 +08:00
|
|
|
class CallArgList :
|
2018-03-14 23:02:28 +08:00
|
|
|
public SmallVector<CallArg, 8> {
|
2011-03-12 04:59:21 +08:00
|
|
|
public:
|
2015-10-08 08:17:45 +08:00
|
|
|
CallArgList() : StackBase(nullptr) {}
|
2014-02-01 08:04:45 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
struct Writeback {
|
2013-03-23 10:35:54 +08:00
|
|
|
/// The original argument. Note that the argument l-value
|
|
|
|
/// is potentially null.
|
|
|
|
LValue Source;
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
/// The temporary alloca.
|
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 Temporary;
|
2013-03-23 10:35:54 +08:00
|
|
|
|
|
|
|
/// A value to "use" after the writeback, or null.
|
|
|
|
llvm::Value *ToUse;
|
2011-06-16 07:02:42 +08:00
|
|
|
};
|
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
struct CallArgCleanup {
|
|
|
|
EHScopeStack::stable_iterator Cleanup;
|
|
|
|
|
|
|
|
/// The "is active" insertion point. This instruction is temporary and
|
|
|
|
/// will be removed after insertion.
|
|
|
|
llvm::Instruction *IsActiveIP;
|
|
|
|
};
|
|
|
|
|
2018-03-15 23:25:19 +08:00
|
|
|
void add(RValue rvalue, QualType type) { push_back(CallArg(rvalue, type)); }
|
|
|
|
|
|
|
|
void addUncopiedAggregate(LValue LV, QualType type) {
|
|
|
|
push_back(CallArg(LV, type));
|
2011-03-12 04:59:21 +08:00
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2016-09-29 03:09:10 +08:00
|
|
|
/// Add all the arguments from another CallArgList to this one. After doing
|
|
|
|
/// this, the old CallArgList retains its list of arguments, but must not
|
|
|
|
/// be used to emit a call.
|
2011-06-16 07:02:42 +08:00
|
|
|
void addFrom(const CallArgList &other) {
|
|
|
|
insert(end(), other.begin(), other.end());
|
|
|
|
Writebacks.insert(Writebacks.end(),
|
|
|
|
other.Writebacks.begin(), other.Writebacks.end());
|
2016-09-29 03:09:10 +08:00
|
|
|
CleanupsToDeactivate.insert(CleanupsToDeactivate.end(),
|
|
|
|
other.CleanupsToDeactivate.begin(),
|
|
|
|
other.CleanupsToDeactivate.end());
|
|
|
|
assert(!(StackBase && other.StackBase) && "can't merge stackbases");
|
|
|
|
if (!StackBase)
|
|
|
|
StackBase = other.StackBase;
|
2011-06-16 07:02:42 +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
|
|
|
void addWriteback(LValue srcLV, Address temporary,
|
2013-03-23 10:35:54 +08:00
|
|
|
llvm::Value *toUse) {
|
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
|
|
|
Writeback writeback = { srcLV, temporary, toUse };
|
2011-06-16 07:02:42 +08:00
|
|
|
Writebacks.push_back(writeback);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWritebacks() const { return !Writebacks.empty(); }
|
|
|
|
|
2014-03-18 01:22:27 +08:00
|
|
|
typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator>
|
|
|
|
writeback_const_range;
|
|
|
|
|
|
|
|
writeback_const_range writebacks() const {
|
|
|
|
return writeback_const_range(Writebacks.begin(), Writebacks.end());
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2013-06-21 20:45:15 +08:00
|
|
|
void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup,
|
|
|
|
llvm::Instruction *IsActiveIP) {
|
|
|
|
CallArgCleanup ArgCleanup;
|
|
|
|
ArgCleanup.Cleanup = Cleanup;
|
|
|
|
ArgCleanup.IsActiveIP = IsActiveIP;
|
|
|
|
CleanupsToDeactivate.push_back(ArgCleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const {
|
|
|
|
return CleanupsToDeactivate;
|
|
|
|
}
|
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
void allocateArgumentMemory(CodeGenFunction &CGF);
|
|
|
|
llvm::Instruction *getStackBase() const { return StackBase; }
|
2015-08-26 02:43:32 +08:00
|
|
|
void freeArgumentMemory(CodeGenFunction &CGF) const;
|
2014-02-01 08:04:45 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Returns if we're using an inalloca struct to pass arguments in
|
2014-02-01 08:04:45 +08:00
|
|
|
/// memory.
|
|
|
|
bool isUsingInAlloca() const { return StackBase; }
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
private:
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<Writeback, 1> Writebacks;
|
2013-06-21 20:45:15 +08:00
|
|
|
|
|
|
|
/// Deactivate these cleanups immediately before making the call. This
|
|
|
|
/// is used to cleanup objects that are owned by the callee once the call
|
|
|
|
/// occurs.
|
|
|
|
SmallVector<CallArgCleanup, 1> CleanupsToDeactivate;
|
2014-02-01 08:04:45 +08:00
|
|
|
|
|
|
|
/// The stacksave call. It dominates all of the argument evaluation.
|
|
|
|
llvm::CallInst *StackBase;
|
2011-03-09 12:27:21 +08:00
|
|
|
};
|
2008-09-09 05:33:45 +08:00
|
|
|
|
2008-09-10 07:14:03 +08:00
|
|
|
/// FunctionArgList - Type for representing both the decl and type
|
|
|
|
/// of parameters to a function. The decl must be either a
|
|
|
|
/// ParmVarDecl or ImplicitParamDecl.
|
2011-07-20 14:58:45 +08:00
|
|
|
class FunctionArgList : public SmallVector<const VarDecl*, 16> {
|
2011-03-09 12:27:21 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
/// ReturnValueSlot - Contains the address where the return value of a
|
2009-12-25 04:40:36 +08:00
|
|
|
/// function can be stored, and whether the address is volatile or not.
|
2009-12-25 03:08:58 +08:00
|
|
|
class ReturnValueSlot {
|
2015-06-08 18:23:49 +08:00
|
|
|
llvm::PointerIntPair<llvm::Value *, 2, unsigned int> 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
|
|
|
CharUnits Alignment;
|
2015-06-08 18:23:49 +08:00
|
|
|
|
|
|
|
// Return value slot flags
|
|
|
|
enum Flags {
|
|
|
|
IS_VOLATILE = 0x1,
|
|
|
|
IS_UNUSED = 0x2,
|
|
|
|
};
|
2009-12-25 03:08:58 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
ReturnValueSlot() {}
|
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
|
|
|
ReturnValueSlot(Address Addr, bool IsVolatile, bool IsUnused = false)
|
|
|
|
: Value(Addr.isValid() ? Addr.getPointer() : nullptr,
|
|
|
|
(IsVolatile ? IS_VOLATILE : 0) | (IsUnused ? IS_UNUSED : 0)),
|
|
|
|
Alignment(Addr.isValid() ? Addr.getAlignment() : CharUnits::Zero()) {}
|
2009-12-25 03:08:58 +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
|
|
|
bool isNull() const { return !getValue().isValid(); }
|
2015-06-08 18:23:49 +08:00
|
|
|
|
|
|
|
bool isVolatile() const { return Value.getInt() & IS_VOLATILE; }
|
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 getValue() const { return Address(Value.getPointer(), Alignment); }
|
2015-06-08 18:23:49 +08:00
|
|
|
bool isUnused() const { return Value.getInt() & IS_UNUSED; }
|
2009-12-25 03:08:58 +08:00
|
|
|
};
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2008-09-09 05:33:45 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|