2008-07-30 07:18:29 +08:00
|
|
|
//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-02-09 07:14:22 +08:00
|
|
|
// This is the internal per-function state used for llvm translation.
|
2007-05-24 14:29:05 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-01 01:10:38 +08:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENFUNCTION_H
|
2007-05-24 14:29:05 +08:00
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2008-09-10 10:36:38 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2010-01-12 01:06:35 +08:00
|
|
|
#include "clang/AST/CharUnits.h"
|
2011-06-16 07:02:42 +08:00
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
2011-01-14 02:57:25 +08:00
|
|
|
#include "clang/Basic/ABI.h"
|
2009-04-01 06:17:44 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2011-07-15 16:37:34 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2009-04-01 06:17:44 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2011-10-19 08:43:52 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-13 12:10:07 +08:00
|
|
|
#include "CodeGenModule.h"
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGBuilder.h"
|
2011-10-19 08:43:52 +08:00
|
|
|
#include "CGDebugInfo.h"
|
2008-08-23 11:46:30 +08:00
|
|
|
#include "CGValue.h"
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace llvm {
|
2008-08-11 13:35:13 +08:00
|
|
|
class BasicBlock;
|
2009-08-12 01:46:57 +08:00
|
|
|
class LLVMContext;
|
2010-05-01 19:15:56 +08:00
|
|
|
class MDNode;
|
2007-05-24 14:29:05 +08:00
|
|
|
class Module;
|
2008-09-30 09:06:03 +08:00
|
|
|
class SwitchInst;
|
2009-10-19 09:21:05 +08:00
|
|
|
class Twine;
|
2008-11-19 17:36:46 +08:00
|
|
|
class Value;
|
2010-07-06 09:34:17 +08:00
|
|
|
class CallSite;
|
2007-06-16 07:05:46 +08:00
|
|
|
}
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
2011-11-10 16:15:53 +08:00
|
|
|
class BlockDecl;
|
2009-05-30 05:03:38 +08:00
|
|
|
class CXXDestructorDecl;
|
2011-04-15 06:09:26 +08:00
|
|
|
class CXXForRangeStmt;
|
2009-09-28 02:58:34 +08:00
|
|
|
class CXXTryStmt;
|
2007-06-02 12:16:21 +08:00
|
|
|
class Decl;
|
2011-02-17 15:39:24 +08:00
|
|
|
class LabelDecl;
|
2008-08-11 13:35:13 +08:00
|
|
|
class EnumConstantDecl;
|
2007-05-24 14:29:05 +08:00
|
|
|
class FunctionDecl;
|
2009-02-27 07:50:07 +08:00
|
|
|
class FunctionProtoType;
|
2008-08-11 13:35:13 +08:00
|
|
|
class LabelStmt;
|
2009-01-11 05:06:09 +08:00
|
|
|
class ObjCContainerDecl;
|
2008-09-24 12:00:38 +08:00
|
|
|
class ObjCInterfaceDecl;
|
|
|
|
class ObjCIvarDecl;
|
2008-03-31 07:03:07 +08:00
|
|
|
class ObjCMethodDecl;
|
2008-12-10 04:23:04 +08:00
|
|
|
class ObjCImplementationDecl;
|
2008-08-26 16:29:31 +08:00
|
|
|
class ObjCPropertyImplDecl;
|
2007-06-16 08:16:26 +08:00
|
|
|
class TargetInfo;
|
2010-03-03 12:15:11 +08:00
|
|
|
class TargetCodeGenInfo;
|
2008-08-11 13:35:13 +08:00
|
|
|
class VarDecl;
|
2009-04-26 09:32:48 +08:00
|
|
|
class ObjCForCollectionStmt;
|
|
|
|
class ObjCAtTryStmt;
|
|
|
|
class ObjCAtThrowStmt;
|
|
|
|
class ObjCAtSynchronizedStmt;
|
2011-06-16 07:02:42 +08:00
|
|
|
class ObjCAutoreleasePoolStmt;
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
namespace CodeGen {
|
2007-10-23 10:10:49 +08:00
|
|
|
class CodeGenTypes;
|
2009-02-03 05:43:58 +08:00
|
|
|
class CGFunctionInfo;
|
2009-02-09 07:14:22 +08:00
|
|
|
class CGRecordLayout;
|
2010-05-21 12:11:14 +08:00
|
|
|
class CGBlockInfo;
|
2010-08-31 15:33:07 +08:00
|
|
|
class CGCXXABI;
|
2011-02-08 16:22:06 +08:00
|
|
|
class BlockFlags;
|
|
|
|
class BlockFieldFlags;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// A branch fixup. These are required when emitting a goto to a
|
|
|
|
/// label which hasn't been emitted yet. The goto is optimistically
|
|
|
|
/// emitted as a branch to the basic block for the label, and (if it
|
|
|
|
/// occurs in a scope with non-trivial cleanups) a fixup is added to
|
|
|
|
/// the innermost cleanup. When a (normal) cleanup is popped, any
|
|
|
|
/// unresolved fixups in that scope are threaded through the cleanup.
|
|
|
|
struct BranchFixup {
|
2010-07-24 05:56:41 +08:00
|
|
|
/// The block containing the terminator which needs to be modified
|
|
|
|
/// into a switch if this fixup is resolved into the current scope.
|
|
|
|
/// If null, LatestBranch points directly to the destination.
|
|
|
|
llvm::BasicBlock *OptimisticBranchBlock;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
/// The ultimate destination of the branch.
|
2010-07-06 09:34:17 +08:00
|
|
|
///
|
|
|
|
/// This can be set to null to indicate that this fixup was
|
|
|
|
/// successfully resolved.
|
|
|
|
llvm::BasicBlock *Destination;
|
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
/// The destination index value.
|
|
|
|
unsigned DestinationIndex;
|
|
|
|
|
|
|
|
/// The initial branch of the fixup.
|
|
|
|
llvm::BranchInst *InitialBranch;
|
2010-07-06 09:34:17 +08:00
|
|
|
};
|
|
|
|
|
2011-01-28 18:53:53 +08:00
|
|
|
template <class T> struct InvariantValue {
|
2011-01-26 12:00:11 +08:00
|
|
|
typedef T type;
|
|
|
|
typedef T saved_type;
|
|
|
|
static bool needsSaving(type value) { return false; }
|
|
|
|
static saved_type save(CodeGenFunction &CGF, type value) { return value; }
|
|
|
|
static type restore(CodeGenFunction &CGF, saved_type value) { return value; }
|
|
|
|
};
|
2011-01-28 18:53:53 +08:00
|
|
|
|
|
|
|
/// A metaprogramming class for ensuring that a value will dominate an
|
|
|
|
/// arbitrary position in a function.
|
|
|
|
template <class T> struct DominatingValue : InvariantValue<T> {};
|
|
|
|
|
|
|
|
template <class T, bool mightBeInstruction =
|
|
|
|
llvm::is_base_of<llvm::Value, T>::value &&
|
|
|
|
!llvm::is_base_of<llvm::Constant, T>::value &&
|
|
|
|
!llvm::is_base_of<llvm::BasicBlock, T>::value>
|
|
|
|
struct DominatingPointer;
|
|
|
|
template <class T> struct DominatingPointer<T,false> : InvariantValue<T*> {};
|
|
|
|
// template <class T> struct DominatingPointer<T,true> at end of file
|
|
|
|
|
|
|
|
template <class T> struct DominatingValue<T*> : DominatingPointer<T> {};
|
2011-01-26 12:00:11 +08:00
|
|
|
|
2010-08-14 05:20:51 +08:00
|
|
|
enum CleanupKind {
|
|
|
|
EHCleanup = 0x1,
|
|
|
|
NormalCleanup = 0x2,
|
|
|
|
NormalAndEHCleanup = EHCleanup | NormalCleanup,
|
|
|
|
|
|
|
|
InactiveCleanup = 0x4,
|
|
|
|
InactiveEHCleanup = EHCleanup | InactiveCleanup,
|
|
|
|
InactiveNormalCleanup = NormalCleanup | InactiveCleanup,
|
|
|
|
InactiveNormalAndEHCleanup = NormalAndEHCleanup | InactiveCleanup
|
|
|
|
};
|
2010-07-14 04:32:21 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// A stack of scopes which respond to exceptions, including cleanups
|
|
|
|
/// and catch blocks.
|
|
|
|
class EHScopeStack {
|
|
|
|
public:
|
|
|
|
/// A saved depth on the scope stack. This is necessary because
|
|
|
|
/// pushing scopes onto the stack invalidates iterators.
|
|
|
|
class stable_iterator {
|
|
|
|
friend class EHScopeStack;
|
|
|
|
|
|
|
|
/// Offset from StartOfData to EndOfBuffer.
|
|
|
|
ptrdiff_t Size;
|
|
|
|
|
|
|
|
stable_iterator(ptrdiff_t Size) : Size(Size) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static stable_iterator invalid() { return stable_iterator(-1); }
|
|
|
|
stable_iterator() : Size(-1) {}
|
|
|
|
|
|
|
|
bool isValid() const { return Size >= 0; }
|
|
|
|
|
2010-08-14 15:46:19 +08:00
|
|
|
/// Returns true if this scope encloses I.
|
|
|
|
/// Returns false if I is invalid.
|
|
|
|
/// This scope must be valid.
|
2010-07-24 05:56:41 +08:00
|
|
|
bool encloses(stable_iterator I) const { return Size <= I.Size; }
|
2010-08-14 15:46:19 +08:00
|
|
|
|
|
|
|
/// Returns true if this scope strictly encloses I: that is,
|
|
|
|
/// if it encloses I and is not I.
|
|
|
|
/// Returns false is I is invalid.
|
|
|
|
/// This scope must be valid.
|
2010-07-24 05:56:41 +08:00
|
|
|
bool strictlyEncloses(stable_iterator I) const { return Size < I.Size; }
|
2010-07-21 08:40:03 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
friend bool operator==(stable_iterator A, stable_iterator B) {
|
|
|
|
return A.Size == B.Size;
|
|
|
|
}
|
|
|
|
friend bool operator!=(stable_iterator A, stable_iterator B) {
|
|
|
|
return A.Size != B.Size;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-21 15:22:38 +08:00
|
|
|
/// Information for lazily generating a cleanup. Subclasses must be
|
|
|
|
/// POD-like: cleanups will not be destructed, and they will be
|
|
|
|
/// allocated on the cleanup stack and freely copied and moved
|
|
|
|
/// around.
|
2010-07-14 04:32:21 +08:00
|
|
|
///
|
2010-07-21 15:22:38 +08:00
|
|
|
/// Cleanup implementations should generally be declared in an
|
2010-07-14 04:32:21 +08:00
|
|
|
/// anonymous namespace.
|
2010-07-21 15:22:38 +08:00
|
|
|
class Cleanup {
|
2011-07-12 08:15:30 +08:00
|
|
|
// Anchor the construction vtable.
|
|
|
|
virtual void anchor();
|
2010-07-14 04:32:21 +08:00
|
|
|
public:
|
2011-07-13 04:27:29 +08:00
|
|
|
/// Generation flags.
|
|
|
|
class Flags {
|
|
|
|
enum {
|
|
|
|
F_IsForEH = 0x1,
|
|
|
|
F_IsNormalCleanupKind = 0x2,
|
|
|
|
F_IsEHCleanupKind = 0x4
|
|
|
|
};
|
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Flags() : flags(0) {}
|
|
|
|
|
|
|
|
/// isForEH - true if the current emission is for an EH cleanup.
|
|
|
|
bool isForEHCleanup() const { return flags & F_IsForEH; }
|
|
|
|
bool isForNormalCleanup() const { return !isForEHCleanup(); }
|
|
|
|
void setIsForEHCleanup() { flags |= F_IsForEH; }
|
|
|
|
|
|
|
|
bool isNormalCleanupKind() const { return flags & F_IsNormalCleanupKind; }
|
|
|
|
void setIsNormalCleanupKind() { flags |= F_IsNormalCleanupKind; }
|
|
|
|
|
|
|
|
/// isEHCleanupKind - true if the cleanup was pushed as an EH
|
|
|
|
/// cleanup.
|
|
|
|
bool isEHCleanupKind() const { return flags & F_IsEHCleanupKind; }
|
|
|
|
void setIsEHCleanupKind() { flags |= F_IsEHCleanupKind; }
|
|
|
|
};
|
|
|
|
|
2011-07-12 08:15:30 +08:00
|
|
|
// Provide a virtual destructor to suppress a very common warning
|
|
|
|
// that unfortunately cannot be suppressed without this. Cleanups
|
|
|
|
// should not rely on this destructor ever being called.
|
|
|
|
virtual ~Cleanup() {}
|
2010-07-14 07:19:49 +08:00
|
|
|
|
2010-07-14 04:32:21 +08:00
|
|
|
/// Emit the cleanup. For normal cleanups, this is run in the
|
|
|
|
/// same EH context as when the cleanup was pushed, i.e. the
|
|
|
|
/// immediately-enclosing context of the cleanup scope. For
|
|
|
|
/// EH cleanups, this is run in a terminate context.
|
|
|
|
///
|
|
|
|
// \param IsForEHCleanup true if this is for an EH cleanup, false
|
|
|
|
/// if for a normal cleanup.
|
2011-07-13 04:27:29 +08:00
|
|
|
virtual void Emit(CodeGenFunction &CGF, Flags flags) = 0;
|
2010-07-14 04:32:21 +08:00
|
|
|
};
|
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// ConditionalCleanupN stores the saved form of its N parameters,
|
|
|
|
/// then restores them and performs the cleanup.
|
2011-01-28 16:37:24 +08:00
|
|
|
template <class T, class A0>
|
|
|
|
class ConditionalCleanup1 : public Cleanup {
|
2011-01-28 18:53:53 +08:00
|
|
|
typedef typename DominatingValue<A0>::saved_type A0_saved;
|
2011-01-28 16:37:24 +08:00
|
|
|
A0_saved a0_saved;
|
|
|
|
|
2011-07-13 04:27:29 +08:00
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) {
|
2011-01-28 18:53:53 +08:00
|
|
|
A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved);
|
2011-07-13 04:27:29 +08:00
|
|
|
T(a0).Emit(CGF, flags);
|
2011-01-28 16:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConditionalCleanup1(A0_saved a0)
|
|
|
|
: a0_saved(a0) {}
|
|
|
|
};
|
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
template <class T, class A0, class A1>
|
2011-01-28 16:37:24 +08:00
|
|
|
class ConditionalCleanup2 : public Cleanup {
|
2011-01-28 18:53:53 +08:00
|
|
|
typedef typename DominatingValue<A0>::saved_type A0_saved;
|
|
|
|
typedef typename DominatingValue<A1>::saved_type A1_saved;
|
2011-01-27 03:15:39 +08:00
|
|
|
A0_saved a0_saved;
|
|
|
|
A1_saved a1_saved;
|
2011-01-26 12:00:11 +08:00
|
|
|
|
2011-07-13 04:27:29 +08:00
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) {
|
2011-01-28 18:53:53 +08:00
|
|
|
A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved);
|
|
|
|
A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved);
|
2011-07-13 04:27:29 +08:00
|
|
|
T(a0, a1).Emit(CGF, flags);
|
2011-01-26 12:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2011-01-28 16:37:24 +08:00
|
|
|
ConditionalCleanup2(A0_saved a0, A1_saved a1)
|
|
|
|
: a0_saved(a0), a1_saved(a1) {}
|
2011-01-26 12:00:11 +08:00
|
|
|
};
|
|
|
|
|
2011-06-23 00:12:01 +08:00
|
|
|
template <class T, class A0, class A1, class A2>
|
|
|
|
class ConditionalCleanup3 : public Cleanup {
|
|
|
|
typedef typename DominatingValue<A0>::saved_type A0_saved;
|
|
|
|
typedef typename DominatingValue<A1>::saved_type A1_saved;
|
|
|
|
typedef typename DominatingValue<A2>::saved_type A2_saved;
|
|
|
|
A0_saved a0_saved;
|
|
|
|
A1_saved a1_saved;
|
|
|
|
A2_saved a2_saved;
|
|
|
|
|
2011-07-13 04:27:29 +08:00
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) {
|
2011-06-23 00:12:01 +08:00
|
|
|
A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved);
|
|
|
|
A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved);
|
|
|
|
A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved);
|
2011-07-13 04:27:29 +08:00
|
|
|
T(a0, a1, a2).Emit(CGF, flags);
|
2011-06-23 00:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConditionalCleanup3(A0_saved a0, A1_saved a1, A2_saved a2)
|
2011-07-12 08:15:30 +08:00
|
|
|
: a0_saved(a0), a1_saved(a1), a2_saved(a2) {}
|
2011-06-23 00:12:01 +08:00
|
|
|
};
|
|
|
|
|
2011-07-13 00:41:08 +08:00
|
|
|
template <class T, class A0, class A1, class A2, class A3>
|
|
|
|
class ConditionalCleanup4 : public Cleanup {
|
|
|
|
typedef typename DominatingValue<A0>::saved_type A0_saved;
|
|
|
|
typedef typename DominatingValue<A1>::saved_type A1_saved;
|
|
|
|
typedef typename DominatingValue<A2>::saved_type A2_saved;
|
|
|
|
typedef typename DominatingValue<A3>::saved_type A3_saved;
|
|
|
|
A0_saved a0_saved;
|
|
|
|
A1_saved a1_saved;
|
|
|
|
A2_saved a2_saved;
|
|
|
|
A3_saved a3_saved;
|
|
|
|
|
2011-07-13 04:27:29 +08:00
|
|
|
void Emit(CodeGenFunction &CGF, Flags flags) {
|
2011-07-13 00:41:08 +08:00
|
|
|
A0 a0 = DominatingValue<A0>::restore(CGF, a0_saved);
|
|
|
|
A1 a1 = DominatingValue<A1>::restore(CGF, a1_saved);
|
|
|
|
A2 a2 = DominatingValue<A2>::restore(CGF, a2_saved);
|
|
|
|
A3 a3 = DominatingValue<A3>::restore(CGF, a3_saved);
|
2011-07-13 04:27:29 +08:00
|
|
|
T(a0, a1, a2, a3).Emit(CGF, flags);
|
2011-07-13 00:41:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConditionalCleanup4(A0_saved a0, A1_saved a1, A2_saved a2, A3_saved a3)
|
|
|
|
: a0_saved(a0), a1_saved(a1), a2_saved(a2), a3_saved(a3) {}
|
|
|
|
};
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
private:
|
|
|
|
// The implementation for this class is in CGException.h and
|
|
|
|
// CGException.cpp; the definition is here because it's used as a
|
|
|
|
// member of CodeGenFunction.
|
|
|
|
|
|
|
|
/// The start of the scope-stack buffer, i.e. the allocated pointer
|
|
|
|
/// for the buffer. All of these pointers are either simultaneously
|
|
|
|
/// null or simultaneously valid.
|
|
|
|
char *StartOfBuffer;
|
|
|
|
|
|
|
|
/// The end of the buffer.
|
|
|
|
char *EndOfBuffer;
|
|
|
|
|
|
|
|
/// The first valid entry in the buffer.
|
|
|
|
char *StartOfData;
|
|
|
|
|
|
|
|
/// The innermost normal cleanup on the stack.
|
|
|
|
stable_iterator InnermostNormalCleanup;
|
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// The innermost EH scope on the stack.
|
|
|
|
stable_iterator InnermostEHScope;
|
2010-07-24 05:56:41 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// The current set of branch fixups. A branch fixup is a jump to
|
|
|
|
/// an as-yet unemitted label, i.e. a label for which we don't yet
|
|
|
|
/// know the EH stack depth. Whenever we pop a cleanup, we have
|
|
|
|
/// to thread all the current branch fixups through it.
|
|
|
|
///
|
|
|
|
/// Fixups are recorded as the Use of the respective branch or
|
|
|
|
/// switch statement. The use points to the final destination.
|
|
|
|
/// When popping out of a cleanup, these uses are threaded through
|
|
|
|
/// the cleanup and adjusted to point to the new cleanup.
|
|
|
|
///
|
|
|
|
/// Note that branches are allowed to jump into protected scopes
|
|
|
|
/// in certain situations; e.g. the following code is legal:
|
|
|
|
/// struct A { ~A(); }; // trivial ctor, non-trivial dtor
|
|
|
|
/// goto foo;
|
|
|
|
/// A a;
|
|
|
|
/// foo:
|
|
|
|
/// bar();
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<BranchFixup, 8> BranchFixups;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
char *allocate(size_t Size);
|
|
|
|
|
2010-07-21 15:22:38 +08:00
|
|
|
void *pushCleanup(CleanupKind K, size_t DataSize);
|
2010-07-14 04:32:21 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
public:
|
|
|
|
EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0),
|
|
|
|
InnermostNormalCleanup(stable_end()),
|
2011-08-11 10:22:43 +08:00
|
|
|
InnermostEHScope(stable_end()) {}
|
2010-07-06 09:34:17 +08:00
|
|
|
~EHScopeStack() { delete[] StartOfBuffer; }
|
|
|
|
|
2010-07-14 04:32:21 +08:00
|
|
|
// Variadic templates would make this not terrible.
|
|
|
|
|
2010-07-14 06:12:14 +08:00
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T();
|
2010-07-14 06:12:14 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T, class A0>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind, A0 a0) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T(a0);
|
2010-07-14 06:12:14 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
2010-07-14 04:32:21 +08:00
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T, class A0, class A1>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind, A0 a0, A1 a1) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T(a0, a1);
|
2010-07-14 04:32:21 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T, class A0, class A1, class A2>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T(a0, a1, a2);
|
2010-07-14 04:32:21 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T, class A0, class A1, class A2, class A3>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3);
|
2010-07-14 04:32:21 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:47:49 +08:00
|
|
|
/// Push a lazily-created cleanup on the stack.
|
|
|
|
template <class T, class A0, class A1, class A2, class A3, class A4>
|
2010-07-21 15:22:38 +08:00
|
|
|
void pushCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T));
|
|
|
|
Cleanup *Obj = new(Buffer) T(a0, a1, a2, a3, a4);
|
2010-07-21 13:47:49 +08:00
|
|
|
(void) Obj;
|
|
|
|
}
|
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
// Feel free to add more variants of the following:
|
|
|
|
|
|
|
|
/// Push a cleanup with non-constant storage requirements on the
|
|
|
|
/// stack. The cleanup type must provide an additional static method:
|
|
|
|
/// static size_t getExtraSize(size_t);
|
|
|
|
/// The argument to this method will be the value N, which will also
|
|
|
|
/// be passed as the first argument to the constructor.
|
|
|
|
///
|
|
|
|
/// The data stored in the extra storage must obey the same
|
|
|
|
/// restrictions as normal cleanup member data.
|
|
|
|
///
|
|
|
|
/// The pointer returned from this method is valid until the cleanup
|
|
|
|
/// stack is modified.
|
|
|
|
template <class T, class A0, class A1, class A2>
|
|
|
|
T *pushCleanupWithExtra(CleanupKind Kind, size_t N, A0 a0, A1 a1, A2 a2) {
|
|
|
|
void *Buffer = pushCleanup(Kind, sizeof(T) + T::getExtraSize(N));
|
|
|
|
return new (Buffer) T(N, a0, a1, a2);
|
|
|
|
}
|
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// Pops a cleanup scope off the stack. This is private to CGCleanup.cpp.
|
2010-07-06 09:34:17 +08:00
|
|
|
void popCleanup();
|
|
|
|
|
|
|
|
/// Push a set of catch handlers on the stack. The catch is
|
|
|
|
/// uninitialized and will need to have the given number of handlers
|
|
|
|
/// set on it.
|
|
|
|
class EHCatchScope *pushCatch(unsigned NumHandlers);
|
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// Pops a catch scope off the stack. This is private to CGException.cpp.
|
2010-07-06 09:34:17 +08:00
|
|
|
void popCatch();
|
|
|
|
|
|
|
|
/// Push an exceptions filter on the stack.
|
|
|
|
class EHFilterScope *pushFilter(unsigned NumFilters);
|
|
|
|
|
|
|
|
/// Pops an exceptions filter off the stack.
|
|
|
|
void popFilter();
|
|
|
|
|
|
|
|
/// Push a terminate handler on the stack.
|
|
|
|
void pushTerminate();
|
|
|
|
|
|
|
|
/// Pops a terminate handler off the stack.
|
|
|
|
void popTerminate();
|
|
|
|
|
|
|
|
/// Determines whether the exception-scopes stack is empty.
|
|
|
|
bool empty() const { return StartOfData == EndOfBuffer; }
|
|
|
|
|
|
|
|
bool requiresLandingPad() const {
|
2011-08-11 10:22:43 +08:00
|
|
|
return InnermostEHScope != stable_end();
|
2010-07-06 09:34:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Determines whether there are any normal cleanups on the stack.
|
|
|
|
bool hasNormalCleanups() const {
|
|
|
|
return InnermostNormalCleanup != stable_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the innermost normal cleanup on the stack, or
|
|
|
|
/// stable_end() if there are no normal cleanups.
|
|
|
|
stable_iterator getInnermostNormalCleanup() const {
|
|
|
|
return InnermostNormalCleanup;
|
|
|
|
}
|
2011-08-11 10:22:43 +08:00
|
|
|
stable_iterator getInnermostActiveNormalCleanup() const;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
stable_iterator getInnermostEHScope() const {
|
|
|
|
return InnermostEHScope;
|
2010-07-06 09:34:17 +08:00
|
|
|
}
|
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
stable_iterator getInnermostActiveEHScope() const;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
|
|
|
/// An unstable reference to a scope-stack depth. Invalidated by
|
|
|
|
/// pushes but not pops.
|
|
|
|
class iterator;
|
|
|
|
|
|
|
|
/// Returns an iterator pointing to the innermost EH scope.
|
|
|
|
iterator begin() const;
|
|
|
|
|
|
|
|
/// Returns an iterator pointing to the outermost EH scope.
|
|
|
|
iterator end() const;
|
|
|
|
|
|
|
|
/// Create a stable reference to the top of the EH stack. The
|
|
|
|
/// returned reference is valid until that scope is popped off the
|
|
|
|
/// stack.
|
|
|
|
stable_iterator stable_begin() const {
|
|
|
|
return stable_iterator(EndOfBuffer - StartOfData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a stable reference to the bottom of the EH stack.
|
|
|
|
static stable_iterator stable_end() {
|
|
|
|
return stable_iterator(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Translates an iterator into a stable_iterator.
|
|
|
|
stable_iterator stabilize(iterator it) const;
|
|
|
|
|
|
|
|
/// Turn a stable reference to a scope depth into a unstable pointer
|
|
|
|
/// to the EH stack.
|
|
|
|
iterator find(stable_iterator save) const;
|
|
|
|
|
|
|
|
/// Removes the cleanup pointed to by the given stable_iterator.
|
|
|
|
void removeCleanup(stable_iterator save);
|
|
|
|
|
|
|
|
/// Add a branch fixup to the current cleanup scope.
|
|
|
|
BranchFixup &addBranchFixup() {
|
|
|
|
assert(hasNormalCleanups() && "adding fixup in scope without cleanups");
|
|
|
|
BranchFixups.push_back(BranchFixup());
|
|
|
|
return BranchFixups.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumBranchFixups() const { return BranchFixups.size(); }
|
|
|
|
BranchFixup &getBranchFixup(unsigned I) {
|
|
|
|
assert(I < getNumBranchFixups());
|
|
|
|
return BranchFixups[I];
|
|
|
|
}
|
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
/// Pops lazily-removed fixups from the end of the list. This
|
|
|
|
/// should only be called by procedures which have just popped a
|
|
|
|
/// cleanup or resolved one or more fixups.
|
|
|
|
void popNullFixups();
|
|
|
|
|
|
|
|
/// Clears the branch-fixups list. This should only be called by
|
2010-09-18 10:24:39 +08:00
|
|
|
/// ResolveAllBranchFixups.
|
2010-07-24 05:56:41 +08:00
|
|
|
void clearFixups() { BranchFixups.clear(); }
|
2010-07-06 09:34:17 +08:00
|
|
|
};
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
/// CodeGenFunction - This class organizes the per-function state that is used
|
|
|
|
/// while generating LLVM code.
|
2011-02-15 17:22:45 +08:00
|
|
|
class CodeGenFunction : public CodeGenTypeCache {
|
2009-02-24 12:21:31 +08:00
|
|
|
CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT
|
2010-08-31 15:33:07 +08:00
|
|
|
|
|
|
|
friend class CGCXXABI;
|
2007-08-27 07:13:56 +08:00
|
|
|
public:
|
2010-07-24 05:56:41 +08:00
|
|
|
/// A jump destination is an abstract label, branching to which may
|
|
|
|
/// require a jump out through normal cleanups.
|
2010-07-06 09:34:17 +08:00
|
|
|
struct JumpDest {
|
2010-07-24 05:56:41 +08:00
|
|
|
JumpDest() : Block(0), ScopeDepth(), Index(0) {}
|
|
|
|
JumpDest(llvm::BasicBlock *Block,
|
|
|
|
EHScopeStack::stable_iterator Depth,
|
|
|
|
unsigned Index)
|
|
|
|
: Block(Block), ScopeDepth(Depth), Index(Index) {}
|
|
|
|
|
|
|
|
bool isValid() const { return Block != 0; }
|
|
|
|
llvm::BasicBlock *getBlock() const { return Block; }
|
|
|
|
EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
|
|
|
|
unsigned getDestIndex() const { return Index; }
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
private:
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::BasicBlock *Block;
|
|
|
|
EHScopeStack::stable_iterator ScopeDepth;
|
2010-07-24 05:56:41 +08:00
|
|
|
unsigned Index;
|
|
|
|
};
|
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
CodeGenModule &CGM; // Per-module state.
|
2009-11-13 13:51:54 +08:00
|
|
|
const TargetInfo &Target;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-22 00:57:55 +08:00
|
|
|
typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
|
2008-11-01 09:53:16 +08:00
|
|
|
CGBuilderTy Builder;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-04-23 13:30:27 +08:00
|
|
|
/// CurFuncDecl - Holds the Decl for the current function or ObjC method.
|
|
|
|
/// This excludes BlockDecls.
|
2008-06-18 02:05:57 +08:00
|
|
|
const Decl *CurFuncDecl;
|
2009-04-23 13:30:27 +08:00
|
|
|
/// CurCodeDecl - This is the inner-most code context, which includes blocks.
|
|
|
|
const Decl *CurCodeDecl;
|
2009-02-03 06:03:45 +08:00
|
|
|
const CGFunctionInfo *CurFnInfo;
|
2008-03-31 07:03:07 +08:00
|
|
|
QualType FnRetTy;
|
2007-05-30 08:13:02 +08:00
|
|
|
llvm::Function *CurFn;
|
|
|
|
|
2009-12-05 07:26:17 +08:00
|
|
|
/// CurGD - The GlobalDecl for the current function being compiled.
|
|
|
|
GlobalDecl CurGD;
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// PrologueCleanupDepth - The cleanup depth enclosing all the
|
|
|
|
/// cleanups associated with the parameters.
|
|
|
|
EHScopeStack::stable_iterator PrologueCleanupDepth;
|
|
|
|
|
2008-09-10 05:00:17 +08:00
|
|
|
/// ReturnBlock - Unified return block.
|
2010-07-06 09:34:17 +08:00
|
|
|
JumpDest ReturnBlock;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// ReturnValue - The temporary alloca to hold the return value. This is null
|
|
|
|
/// iff the function has no return value.
|
2009-12-04 10:43:40 +08:00
|
|
|
llvm::Value *ReturnValue;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-02 12:53:11 +08:00
|
|
|
/// AllocaInsertPoint - This is an instruction in the entry block before which
|
|
|
|
/// we prefer to insert allocas.
|
2009-04-01 06:17:44 +08:00
|
|
|
llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2009-12-12 09:27:46 +08:00
|
|
|
bool CatchUndefined;
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// In ARC, whether we should autorelease the return value.
|
|
|
|
bool AutoreleaseResult;
|
|
|
|
|
2011-02-08 16:22:06 +08:00
|
|
|
const CodeGen::CGBlockInfo *BlockInfo;
|
|
|
|
llvm::Value *BlockPointer;
|
|
|
|
|
2012-02-11 10:57:39 +08:00
|
|
|
llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields;
|
|
|
|
FieldDecl *LambdaThisCaptureField;
|
|
|
|
|
2010-05-17 23:52:46 +08:00
|
|
|
/// \brief A mapping from NRVO variables to the flags used to indicate
|
|
|
|
/// when the NRVO has been applied to this variable.
|
|
|
|
llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
EHScopeStack EHStack;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
/// i32s containing the indexes of the cleanup destinations.
|
|
|
|
llvm::AllocaInst *NormalCleanupDest;
|
|
|
|
|
|
|
|
unsigned NextCleanupDestIndex;
|
|
|
|
|
2011-11-10 16:15:53 +08:00
|
|
|
/// FirstBlockInfo - The head of a singly-linked-list of block layouts.
|
|
|
|
CGBlockInfo *FirstBlockInfo;
|
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// EHResumeBlock - Unified block containing a call to llvm.eh.resume.
|
|
|
|
llvm::BasicBlock *EHResumeBlock;
|
|
|
|
|
2011-09-20 04:31:14 +08:00
|
|
|
/// The exception slot. All landing pads write the current exception pointer
|
|
|
|
/// into this alloca.
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::Value *ExceptionSlot;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-09-20 04:31:14 +08:00
|
|
|
/// The selector slot. Under the MandatoryCleanup model, all landing pads
|
|
|
|
/// write the current selector value into this alloca.
|
2011-05-29 05:13:02 +08:00
|
|
|
llvm::AllocaInst *EHSelectorSlot;
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// Emits a landing pad for the current EH stack.
|
|
|
|
llvm::BasicBlock *EmitLandingPad();
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::BasicBlock *getInvokeDestImpl();
|
2009-12-02 15:41:41 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
template <class T>
|
2011-01-28 18:53:53 +08:00
|
|
|
typename DominatingValue<T>::saved_type saveValueInCond(T value) {
|
|
|
|
return DominatingValue<T>::save(*this, value);
|
2011-01-26 12:00:11 +08:00
|
|
|
}
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
public:
|
|
|
|
/// ObjCEHValueStack - Stack of Objective-C exception values, used for
|
|
|
|
/// rethrows.
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<llvm::Value*, 8> ObjCEHValueStack;
|
2009-02-08 15:46:24 +08:00
|
|
|
|
2011-06-22 10:32:12 +08:00
|
|
|
/// A class controlling the emission of a finally block.
|
|
|
|
class FinallyInfo {
|
|
|
|
/// Where the catchall's edge through the cleanup should go.
|
|
|
|
JumpDest RethrowDest;
|
|
|
|
|
|
|
|
/// A function to call to enter the catch.
|
|
|
|
llvm::Constant *BeginCatchFn;
|
|
|
|
|
|
|
|
/// An i1 variable indicating whether or not the @finally is
|
|
|
|
/// running for an exception.
|
|
|
|
llvm::AllocaInst *ForEHVar;
|
2009-12-09 11:35:49 +08:00
|
|
|
|
2011-06-22 10:32:12 +08:00
|
|
|
/// An i8* variable into which the exception pointer to rethrow
|
|
|
|
/// has been saved.
|
|
|
|
llvm::AllocaInst *SavedExnVar;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void enter(CodeGenFunction &CGF, const Stmt *Finally,
|
|
|
|
llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn,
|
|
|
|
llvm::Constant *rethrowFn);
|
|
|
|
void exit(CodeGenFunction &CGF);
|
|
|
|
};
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2011-01-28 16:37:24 +08:00
|
|
|
/// pushFullExprCleanup - Push a cleanup to be run at the end of the
|
|
|
|
/// current full-expression. Safe against the possibility that
|
|
|
|
/// we're currently inside a conditionally-evaluated expression.
|
|
|
|
template <class T, class A0>
|
|
|
|
void pushFullExprCleanup(CleanupKind kind, A0 a0) {
|
|
|
|
// If we're not in a conditional branch, or if none of the
|
|
|
|
// arguments requires saving, then use the unconditional cleanup.
|
2011-07-12 08:15:30 +08:00
|
|
|
if (!isInConditionalBranch())
|
|
|
|
return EHStack.pushCleanup<T>(kind, a0);
|
2011-01-28 16:37:24 +08:00
|
|
|
|
2011-01-28 18:53:53 +08:00
|
|
|
typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
|
2011-01-28 16:37:24 +08:00
|
|
|
|
|
|
|
typedef EHScopeStack::ConditionalCleanup1<T, A0> CleanupType;
|
|
|
|
EHStack.pushCleanup<CleanupType>(kind, a0_saved);
|
|
|
|
initFullExprCleanup();
|
|
|
|
}
|
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// pushFullExprCleanup - Push a cleanup to be run at the end of the
|
|
|
|
/// current full-expression. Safe against the possibility that
|
|
|
|
/// we're currently inside a conditionally-evaluated expression.
|
|
|
|
template <class T, class A0, class A1>
|
|
|
|
void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1) {
|
|
|
|
// If we're not in a conditional branch, or if none of the
|
|
|
|
// arguments requires saving, then use the unconditional cleanup.
|
2011-07-12 08:15:30 +08:00
|
|
|
if (!isInConditionalBranch())
|
|
|
|
return EHStack.pushCleanup<T>(kind, a0, a1);
|
2011-01-26 12:00:11 +08:00
|
|
|
|
2011-01-28 18:53:53 +08:00
|
|
|
typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
|
|
|
|
typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
|
2011-01-26 12:00:11 +08:00
|
|
|
|
|
|
|
typedef EHScopeStack::ConditionalCleanup2<T, A0, A1> CleanupType;
|
2011-01-28 16:37:24 +08:00
|
|
|
EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved);
|
|
|
|
initFullExprCleanup();
|
2011-01-26 12:00:11 +08:00
|
|
|
}
|
|
|
|
|
2011-06-23 00:12:01 +08:00
|
|
|
/// pushFullExprCleanup - Push a cleanup to be run at the end of the
|
|
|
|
/// current full-expression. Safe against the possibility that
|
|
|
|
/// we're currently inside a conditionally-evaluated expression.
|
|
|
|
template <class T, class A0, class A1, class A2>
|
|
|
|
void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2) {
|
|
|
|
// If we're not in a conditional branch, or if none of the
|
|
|
|
// arguments requires saving, then use the unconditional cleanup.
|
|
|
|
if (!isInConditionalBranch()) {
|
2011-07-12 08:15:30 +08:00
|
|
|
return EHStack.pushCleanup<T>(kind, a0, a1, a2);
|
2011-06-23 00:12:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
|
|
|
|
typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
|
|
|
|
typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2);
|
|
|
|
|
|
|
|
typedef EHScopeStack::ConditionalCleanup3<T, A0, A1, A2> CleanupType;
|
|
|
|
EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, a2_saved);
|
|
|
|
initFullExprCleanup();
|
|
|
|
}
|
|
|
|
|
2011-07-13 00:41:08 +08:00
|
|
|
/// pushFullExprCleanup - Push a cleanup to be run at the end of the
|
|
|
|
/// current full-expression. Safe against the possibility that
|
|
|
|
/// we're currently inside a conditionally-evaluated expression.
|
|
|
|
template <class T, class A0, class A1, class A2, class A3>
|
|
|
|
void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2, A3 a3) {
|
|
|
|
// If we're not in a conditional branch, or if none of the
|
|
|
|
// arguments requires saving, then use the unconditional cleanup.
|
|
|
|
if (!isInConditionalBranch()) {
|
|
|
|
return EHStack.pushCleanup<T>(kind, a0, a1, a2, a3);
|
|
|
|
}
|
|
|
|
|
|
|
|
typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
|
|
|
|
typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
|
|
|
|
typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2);
|
|
|
|
typename DominatingValue<A3>::saved_type a3_saved = saveValueInCond(a3);
|
|
|
|
|
|
|
|
typedef EHScopeStack::ConditionalCleanup4<T, A0, A1, A2, A3> CleanupType;
|
|
|
|
EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved,
|
|
|
|
a2_saved, a3_saved);
|
|
|
|
initFullExprCleanup();
|
|
|
|
}
|
|
|
|
|
2011-11-10 18:43:54 +08:00
|
|
|
/// Set up the last cleaup that was pushed as a conditional
|
|
|
|
/// full-expression cleanup.
|
|
|
|
void initFullExprCleanup();
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// PushDestructorCleanup - Push a cleanup to call the
|
|
|
|
/// complete-object destructor of an object of the given type at the
|
|
|
|
/// given address. Does nothing if T is not a C++ class type with a
|
|
|
|
/// non-trivial destructor.
|
|
|
|
void PushDestructorCleanup(QualType T, llvm::Value *Addr);
|
|
|
|
|
2010-07-21 14:29:51 +08:00
|
|
|
/// PushDestructorCleanup - Push a cleanup to call the
|
|
|
|
/// complete-object variant of the given destructor on the object at
|
|
|
|
/// the given address.
|
|
|
|
void PushDestructorCleanup(const CXXDestructorDecl *Dtor,
|
|
|
|
llvm::Value *Addr);
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// PopCleanupBlock - Will pop the cleanup entry on the stack and
|
|
|
|
/// process all branch fixups.
|
2010-07-24 05:56:41 +08:00
|
|
|
void PopCleanupBlock(bool FallThroughIsBranchThrough = false);
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2010-09-14 15:57:04 +08:00
|
|
|
/// DeactivateCleanupBlock - Deactivates the given cleanup block.
|
|
|
|
/// The block cannot be reactivated. Pops it if it's the top of the
|
|
|
|
/// stack.
|
2011-11-10 18:43:54 +08:00
|
|
|
///
|
|
|
|
/// \param DominatingIP - An instruction which is known to
|
|
|
|
/// dominate the current IP (if set) and which lies along
|
|
|
|
/// all paths of execution between the current IP and the
|
|
|
|
/// the point at which the cleanup comes into scope.
|
|
|
|
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup,
|
|
|
|
llvm::Instruction *DominatingIP);
|
2010-09-14 15:57:04 +08:00
|
|
|
|
|
|
|
/// ActivateCleanupBlock - Activates an initially-inactive cleanup.
|
|
|
|
/// Cannot be used to resurrect a deactivated cleanup.
|
2011-11-10 18:43:54 +08:00
|
|
|
///
|
|
|
|
/// \param DominatingIP - An instruction which is known to
|
|
|
|
/// dominate the current IP (if set) and which lies along
|
|
|
|
/// all paths of execution between the current IP and the
|
|
|
|
/// the point at which the cleanup comes into scope.
|
|
|
|
void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup,
|
|
|
|
llvm::Instruction *DominatingIP);
|
2010-08-14 05:20:51 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// \brief Enters a new scope for capturing cleanups, all of which
|
|
|
|
/// will be executed once the scope is exited.
|
|
|
|
class RunCleanupsScope {
|
|
|
|
EHScopeStack::stable_iterator CleanupStackDepth;
|
2009-11-25 00:43:22 +08:00
|
|
|
bool OldDidCallStackSave;
|
2009-11-25 05:15:44 +08:00
|
|
|
bool PerformCleanup;
|
2009-11-25 00:43:22 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
RunCleanupsScope(const RunCleanupsScope &); // DO NOT IMPLEMENT
|
|
|
|
RunCleanupsScope &operator=(const RunCleanupsScope &); // DO NOT IMPLEMENT
|
2009-11-25 00:43:22 +08:00
|
|
|
|
2011-10-19 08:43:52 +08:00
|
|
|
protected:
|
|
|
|
CodeGenFunction& CGF;
|
|
|
|
|
2009-11-25 00:43:22 +08:00
|
|
|
public:
|
|
|
|
/// \brief Enter a new cleanup scope.
|
2010-10-19 14:39:39 +08:00
|
|
|
explicit RunCleanupsScope(CodeGenFunction &CGF)
|
2011-10-19 08:43:52 +08:00
|
|
|
: PerformCleanup(true), CGF(CGF)
|
2009-11-25 05:15:44 +08:00
|
|
|
{
|
2010-07-06 09:34:17 +08:00
|
|
|
CleanupStackDepth = CGF.EHStack.stable_begin();
|
2009-11-25 00:43:22 +08:00
|
|
|
OldDidCallStackSave = CGF.DidCallStackSave;
|
2010-09-14 08:42:34 +08:00
|
|
|
CGF.DidCallStackSave = false;
|
2009-11-25 00:43:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Exit this cleanup scope, emitting any accumulated
|
|
|
|
/// cleanups.
|
2010-07-06 09:34:17 +08:00
|
|
|
~RunCleanupsScope() {
|
2009-11-25 05:15:44 +08:00
|
|
|
if (PerformCleanup) {
|
|
|
|
CGF.DidCallStackSave = OldDidCallStackSave;
|
2010-07-06 09:34:17 +08:00
|
|
|
CGF.PopCleanupBlocks(CleanupStackDepth);
|
2009-11-25 05:15:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine whether this scope requires any cleanups.
|
|
|
|
bool requiresCleanups() const {
|
2010-07-06 09:34:17 +08:00
|
|
|
return CGF.EHStack.stable_begin() != CleanupStackDepth;
|
2009-11-25 05:15:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Force the emission of cleanups now, instead of waiting
|
|
|
|
/// until this object is destroyed.
|
|
|
|
void ForceCleanup() {
|
|
|
|
assert(PerformCleanup && "Already forced cleanup");
|
2009-11-25 00:43:22 +08:00
|
|
|
CGF.DidCallStackSave = OldDidCallStackSave;
|
2010-07-06 09:34:17 +08:00
|
|
|
CGF.PopCleanupBlocks(CleanupStackDepth);
|
2009-11-25 05:15:44 +08:00
|
|
|
PerformCleanup = false;
|
2009-11-25 00:43:22 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-10-19 08:43:52 +08:00
|
|
|
class LexicalScope: protected RunCleanupsScope {
|
|
|
|
SourceRange Range;
|
|
|
|
bool PopDebugStack;
|
|
|
|
|
|
|
|
LexicalScope(const LexicalScope &); // DO NOT IMPLEMENT THESE
|
|
|
|
LexicalScope &operator=(const LexicalScope &);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// \brief Enter a new cleanup scope.
|
|
|
|
explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range)
|
|
|
|
: RunCleanupsScope(CGF), Range(Range), PopDebugStack(true) {
|
|
|
|
if (CGDebugInfo *DI = CGF.getDebugInfo())
|
|
|
|
DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Exit this cleanup scope, emitting any accumulated
|
|
|
|
/// cleanups.
|
|
|
|
~LexicalScope() {
|
|
|
|
if (PopDebugStack) {
|
|
|
|
CGDebugInfo *DI = CGF.getDebugInfo();
|
|
|
|
if (DI) DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Force the emission of cleanups now, instead of waiting
|
|
|
|
/// until this object is destroyed.
|
|
|
|
void ForceCleanup() {
|
|
|
|
RunCleanupsScope::ForceCleanup();
|
|
|
|
if (CGDebugInfo *DI = CGF.getDebugInfo()) {
|
|
|
|
DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
|
|
|
|
PopDebugStack = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-30 11:14:41 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// PopCleanupBlocks - Takes the old cleanup stack size and emits
|
|
|
|
/// the cleanup blocks that have been added.
|
|
|
|
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize);
|
2010-03-30 11:14:41 +08:00
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
void ResolveBranchFixups(llvm::BasicBlock *Target);
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// The given basic block lies in the current EH scope, but may be a
|
|
|
|
/// target of a potentially scope-crossing jump; get a stable handle
|
|
|
|
/// to which we can perform this jump later.
|
2010-07-24 05:56:41 +08:00
|
|
|
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) {
|
2010-07-28 09:07:35 +08:00
|
|
|
return JumpDest(Target,
|
|
|
|
EHStack.getInnermostNormalCleanup(),
|
|
|
|
NextCleanupDestIndex++);
|
2010-07-06 09:34:17 +08:00
|
|
|
}
|
2009-02-08 07:50:39 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// The given basic block lies in the current EH scope, but may be a
|
|
|
|
/// target of a potentially scope-crossing jump; get a stable handle
|
|
|
|
/// to which we can perform this jump later.
|
2011-07-20 14:58:45 +08:00
|
|
|
JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) {
|
2010-07-24 05:56:41 +08:00
|
|
|
return getJumpDestInCurrentScope(createBasicBlock(Name));
|
2010-07-06 09:34:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitBranchThroughCleanup - Emit a branch from the current insert
|
|
|
|
/// block through the normal cleanup handling code (if any) and then
|
|
|
|
/// on to \arg Dest.
|
|
|
|
void EmitBranchThroughCleanup(JumpDest Dest);
|
2011-04-17 08:54:30 +08:00
|
|
|
|
|
|
|
/// isObviouslyBranchWithoutCleanups - Return true if a branch to the
|
|
|
|
/// specified destination obviously has no cleanups to run. 'false' is always
|
|
|
|
/// a conservatively correct answer for this method.
|
|
|
|
bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const;
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// popCatchScope - Pops the catch scope at the top of the EHScope
|
|
|
|
/// stack, emitting any required code (other than the catch handlers
|
|
|
|
/// themselves).
|
|
|
|
void popCatchScope();
|
2010-07-24 05:56:41 +08:00
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
llvm::BasicBlock *getEHResumeBlock();
|
|
|
|
llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// An object to manage conditionally-evaluated expressions.
|
|
|
|
class ConditionalEvaluation {
|
|
|
|
llvm::BasicBlock *StartBB;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
public:
|
|
|
|
ConditionalEvaluation(CodeGenFunction &CGF)
|
|
|
|
: StartBB(CGF.Builder.GetInsertBlock()) {}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
void begin(CodeGenFunction &CGF) {
|
|
|
|
assert(CGF.OutermostConditional != this);
|
|
|
|
if (!CGF.OutermostConditional)
|
|
|
|
CGF.OutermostConditional = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void end(CodeGenFunction &CGF) {
|
|
|
|
assert(CGF.OutermostConditional != 0);
|
|
|
|
if (CGF.OutermostConditional == this)
|
|
|
|
CGF.OutermostConditional = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a block which will be executed prior to each
|
|
|
|
/// evaluation of the conditional code.
|
|
|
|
llvm::BasicBlock *getStartingBlock() const {
|
|
|
|
return StartBB;
|
|
|
|
}
|
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-09-17 08:50:28 +08:00
|
|
|
/// isInConditionalBranch - Return true if we're currently emitting
|
|
|
|
/// one branch or the other of a conditional expression.
|
2011-01-26 12:00:11 +08:00
|
|
|
bool isInConditionalBranch() const { return OutermostConditional != 0; }
|
|
|
|
|
2011-11-10 18:43:54 +08:00
|
|
|
void setBeforeOutermostConditional(llvm::Value *value, llvm::Value *addr) {
|
|
|
|
assert(isInConditionalBranch());
|
|
|
|
llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
|
|
|
|
new llvm::StoreInst(value, addr, &block->back());
|
|
|
|
}
|
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// An RAII object to record that we're evaluating a statement
|
|
|
|
/// expression.
|
|
|
|
class StmtExprEvaluation {
|
|
|
|
CodeGenFunction &CGF;
|
|
|
|
|
|
|
|
/// We have to save the outermost conditional: cleanups in a
|
|
|
|
/// statement expression aren't conditional just because the
|
|
|
|
/// StmtExpr is.
|
|
|
|
ConditionalEvaluation *SavedOutermostConditional;
|
|
|
|
|
|
|
|
public:
|
|
|
|
StmtExprEvaluation(CodeGenFunction &CGF)
|
|
|
|
: CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) {
|
|
|
|
CGF.OutermostConditional = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~StmtExprEvaluation() {
|
|
|
|
CGF.OutermostConditional = SavedOutermostConditional;
|
|
|
|
CGF.EnsureInsertPoint();
|
|
|
|
}
|
|
|
|
};
|
2011-02-16 16:02:54 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
/// An object which temporarily prevents a value from being
|
|
|
|
/// destroyed by aggressive peephole optimizations that assume that
|
|
|
|
/// all uses of a value have been realized in the IR.
|
|
|
|
class PeepholeProtection {
|
|
|
|
llvm::Instruction *Inst;
|
|
|
|
friend class CodeGenFunction;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PeepholeProtection() : Inst(0) {}
|
2011-11-06 17:01:30 +08:00
|
|
|
};
|
2011-02-17 18:25:35 +08:00
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
/// A non-RAII class containing all the information about a bound
|
|
|
|
/// opaque value. OpaqueValueMapping, below, is a RAII wrapper for
|
|
|
|
/// this which makes individual mappings very simple; using this
|
|
|
|
/// class directly is useful when you have a variable number of
|
|
|
|
/// opaque values or don't want the RAII functionality for some
|
|
|
|
/// reason.
|
|
|
|
class OpaqueValueMappingData {
|
2011-02-16 16:02:54 +08:00
|
|
|
const OpaqueValueExpr *OpaqueValue;
|
2011-02-17 18:25:35 +08:00
|
|
|
bool BoundLValue;
|
|
|
|
CodeGenFunction::PeepholeProtection Protection;
|
2011-02-16 16:02:54 +08:00
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
OpaqueValueMappingData(const OpaqueValueExpr *ov,
|
|
|
|
bool boundLValue)
|
|
|
|
: OpaqueValue(ov), BoundLValue(boundLValue) {}
|
2011-02-16 16:02:54 +08:00
|
|
|
public:
|
2011-11-06 17:01:30 +08:00
|
|
|
OpaqueValueMappingData() : OpaqueValue(0) {}
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
static bool shouldBindAsLValue(const Expr *expr) {
|
2011-11-09 06:54:08 +08:00
|
|
|
// gl-values should be bound as l-values for obvious reasons.
|
|
|
|
// Records should be bound as l-values because IR generation
|
|
|
|
// always keeps them in memory. Expressions of function type
|
|
|
|
// act exactly like l-values but are formally required to be
|
|
|
|
// r-values in C.
|
|
|
|
return expr->isGLValue() ||
|
|
|
|
expr->getType()->isRecordType() ||
|
|
|
|
expr->getType()->isFunctionType();
|
2011-02-17 18:25:35 +08:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
static OpaqueValueMappingData bind(CodeGenFunction &CGF,
|
|
|
|
const OpaqueValueExpr *ov,
|
|
|
|
const Expr *e) {
|
|
|
|
if (shouldBindAsLValue(ov))
|
|
|
|
return bind(CGF, ov, CGF.EmitLValue(e));
|
|
|
|
return bind(CGF, ov, CGF.EmitAnyExpr(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
static OpaqueValueMappingData bind(CodeGenFunction &CGF,
|
|
|
|
const OpaqueValueExpr *ov,
|
|
|
|
const LValue &lv) {
|
|
|
|
assert(shouldBindAsLValue(ov));
|
|
|
|
CGF.OpaqueLValues.insert(std::make_pair(ov, lv));
|
|
|
|
return OpaqueValueMappingData(ov, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static OpaqueValueMappingData bind(CodeGenFunction &CGF,
|
|
|
|
const OpaqueValueExpr *ov,
|
|
|
|
const RValue &rv) {
|
|
|
|
assert(!shouldBindAsLValue(ov));
|
|
|
|
CGF.OpaqueRValues.insert(std::make_pair(ov, rv));
|
|
|
|
|
|
|
|
OpaqueValueMappingData data(ov, false);
|
|
|
|
|
|
|
|
// Work around an extremely aggressive peephole optimization in
|
|
|
|
// EmitScalarConversion which assumes that all other uses of a
|
|
|
|
// value are extant.
|
|
|
|
data.Protection = CGF.protectFromPeepholes(rv);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValid() const { return OpaqueValue != 0; }
|
|
|
|
void clear() { OpaqueValue = 0; }
|
|
|
|
|
|
|
|
void unbind(CodeGenFunction &CGF) {
|
|
|
|
assert(OpaqueValue && "no data to unbind!");
|
|
|
|
|
|
|
|
if (BoundLValue) {
|
|
|
|
CGF.OpaqueLValues.erase(OpaqueValue);
|
|
|
|
} else {
|
|
|
|
CGF.OpaqueRValues.erase(OpaqueValue);
|
|
|
|
CGF.unprotectFromPeepholes(Protection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
|
|
|
|
class OpaqueValueMapping {
|
|
|
|
CodeGenFunction &CGF;
|
|
|
|
OpaqueValueMappingData Data;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool shouldBindAsLValue(const Expr *expr) {
|
|
|
|
return OpaqueValueMappingData::shouldBindAsLValue(expr);
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
/// Build the opaque value mapping for the given conditional
|
|
|
|
/// operator if it's the GNU ?: extension. This is a common
|
|
|
|
/// enough pattern that the convenience operator is really
|
|
|
|
/// helpful.
|
|
|
|
///
|
|
|
|
OpaqueValueMapping(CodeGenFunction &CGF,
|
|
|
|
const AbstractConditionalOperator *op) : CGF(CGF) {
|
2011-11-06 17:01:30 +08:00
|
|
|
if (isa<ConditionalOperator>(op))
|
|
|
|
// Leave Data empty.
|
2011-02-17 18:25:35 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op);
|
2011-11-06 17:01:30 +08:00
|
|
|
Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(),
|
|
|
|
e->getCommon());
|
2011-02-17 18:25:35 +08:00
|
|
|
}
|
|
|
|
|
2011-02-16 16:02:54 +08:00
|
|
|
OpaqueValueMapping(CodeGenFunction &CGF,
|
|
|
|
const OpaqueValueExpr *opaqueValue,
|
2011-02-17 18:25:35 +08:00
|
|
|
LValue lvalue)
|
2011-11-06 17:01:30 +08:00
|
|
|
: CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {
|
2011-02-17 18:25:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OpaqueValueMapping(CodeGenFunction &CGF,
|
|
|
|
const OpaqueValueExpr *opaqueValue,
|
|
|
|
RValue rvalue)
|
2011-11-06 17:01:30 +08:00
|
|
|
: CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {
|
2011-02-16 16:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void pop() {
|
2011-11-06 17:01:30 +08:00
|
|
|
Data.unbind(CGF);
|
|
|
|
Data.clear();
|
2011-02-16 16:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~OpaqueValueMapping() {
|
2011-11-06 17:01:30 +08:00
|
|
|
if (Data.isValid()) Data.unbind(CGF);
|
2011-02-16 16:02:54 +08:00
|
|
|
}
|
|
|
|
};
|
2010-11-17 03:29:39 +08:00
|
|
|
|
|
|
|
/// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
|
|
|
|
/// number that holds the value.
|
|
|
|
unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
|
2011-01-27 07:08:27 +08:00
|
|
|
|
|
|
|
/// BuildBlockByrefAddress - Computes address location of the
|
|
|
|
/// variable which is declared as __block.
|
|
|
|
llvm::Value *BuildBlockByrefAddress(llvm::Value *BaseAddr,
|
|
|
|
const VarDecl *V);
|
2007-08-24 13:35:26 +08:00
|
|
|
private:
|
2009-10-29 07:59:40 +08:00
|
|
|
CGDebugInfo *DebugInfo;
|
2011-03-08 02:45:56 +08:00
|
|
|
bool DisableDebugInfo;
|
2009-02-18 01:00:02 +08:00
|
|
|
|
2011-05-29 05:13:02 +08:00
|
|
|
/// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
|
|
|
|
/// calling llvm.stacksave for multiple VLAs in the same scope.
|
|
|
|
bool DidCallStackSave;
|
|
|
|
|
2009-12-01 04:08:49 +08:00
|
|
|
/// IndirectBranch - The first time an indirect goto is seen we create a block
|
|
|
|
/// with an indirect branch. Every time we see the address of a label taken,
|
|
|
|
/// we add the label to the indirect goto. Every subsequent indirect goto is
|
|
|
|
/// codegen'd as a jump to the IndirectBranch's basic block.
|
2009-10-29 07:59:40 +08:00
|
|
|
llvm::IndirectBrInst *IndirectBranch;
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
|
|
|
|
/// decls.
|
2011-02-07 18:33:21 +08:00
|
|
|
typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy;
|
|
|
|
DeclMapTy LocalDeclMap;
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
/// LabelMap - This keeps track of the LLVM basic block for each C label.
|
2011-02-17 15:39:24 +08:00
|
|
|
llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
// BreakContinueStack - This keeps track of where break and continue
|
2009-02-10 13:52:02 +08:00
|
|
|
// statements should jump to.
|
2007-07-17 05:28:45 +08:00
|
|
|
struct BreakContinue {
|
2010-07-06 09:34:17 +08:00
|
|
|
BreakContinue(JumpDest Break, JumpDest Continue)
|
|
|
|
: BreakBlock(Break), ContinueBlock(Continue) {}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
JumpDest BreakBlock;
|
|
|
|
JumpDest ContinueBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
};
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<BreakContinue, 8> BreakContinueStack;
|
2008-09-28 09:03:14 +08:00
|
|
|
|
2012-01-14 17:08:15 +08:00
|
|
|
/// SwitchInsn - This is nearest current switch instruction. It is null if
|
2009-02-09 07:14:22 +08:00
|
|
|
/// current context is not in a switch.
|
2007-10-05 07:45:31 +08:00
|
|
|
llvm::SwitchInst *SwitchInsn;
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// CaseRangeBlock - This block holds if condition check for last case
|
2007-10-10 01:08:50 +08:00
|
|
|
/// statement range in current switch instruction.
|
2007-10-09 04:57:48 +08:00
|
|
|
llvm::BasicBlock *CaseRangeBlock;
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
/// OpaqueLValues - Keeps track of the current set of opaque value
|
2011-02-16 16:02:54 +08:00
|
|
|
/// expressions.
|
2011-02-17 18:25:35 +08:00
|
|
|
llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
|
|
|
|
llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;
|
2011-02-16 16:02:54 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// VLASizeMap - This keeps track of the associated size for each VLA type.
|
2009-08-15 10:50:32 +08:00
|
|
|
// We track this by the size expression rather than the type itself because
|
|
|
|
// in certain situations, like a const qualifier applied to an VLA typedef,
|
|
|
|
// multiple VLA types can share the same size expression.
|
2009-02-09 07:14:22 +08:00
|
|
|
// FIXME: Maybe this could be a stack of maps that is pushed/popped as we
|
|
|
|
// enter/leave scopes.
|
2009-08-15 10:50:32 +08:00
|
|
|
llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// A block containing a single 'unreachable' instruction. Created
|
|
|
|
/// lazily by getUnreachableBlock().
|
|
|
|
llvm::BasicBlock *UnreachableBlock;
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-11-25 11:15:49 +08:00
|
|
|
/// CXXThisDecl - When generating code for a C++ member function,
|
|
|
|
/// this will hold the implicit 'this' declaration.
|
2012-02-11 10:57:39 +08:00
|
|
|
ImplicitParamDecl *CXXABIThisDecl;
|
|
|
|
llvm::Value *CXXABIThisValue;
|
2010-02-17 06:04:33 +08:00
|
|
|
llvm::Value *CXXThisValue;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-25 11:15:49 +08:00
|
|
|
/// CXXVTTDecl - When generating code for a base object constructor or
|
|
|
|
/// base object destructor with virtual bases, this will hold the implicit
|
|
|
|
/// VTT parameter.
|
|
|
|
ImplicitParamDecl *CXXVTTDecl;
|
2010-02-17 06:04:33 +08:00
|
|
|
llvm::Value *CXXVTTValue;
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// OutermostConditional - Points to the outermost active
|
|
|
|
/// conditional control. This is used so that we know if a
|
|
|
|
/// temporary should be destroyed conditionally.
|
|
|
|
ConditionalEvaluation *OutermostConditional;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-09-12 10:14:24 +08:00
|
|
|
|
|
|
|
/// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM
|
|
|
|
/// type as well as the field number that contains the actual data.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::DenseMap<const ValueDecl *, std::pair<llvm::Type *,
|
2009-09-12 10:14:24 +08:00
|
|
|
unsigned> > ByRefValueInfo;
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::BasicBlock *TerminateLandingPad;
|
2009-12-10 08:02:42 +08:00
|
|
|
llvm::BasicBlock *TerminateHandler;
|
2010-07-21 05:07:09 +08:00
|
|
|
llvm::BasicBlock *TrapBB;
|
2009-12-10 10:21:21 +08:00
|
|
|
|
2007-05-28 09:07:47 +08:00
|
|
|
public:
|
2007-05-30 07:17:50 +08:00
|
|
|
CodeGenFunction(CodeGenModule &cgm);
|
2011-11-10 16:15:53 +08:00
|
|
|
~CodeGenFunction();
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-09-02 17:58:18 +08:00
|
|
|
CodeGenTypes &getTypes() const { return CGM.getTypes(); }
|
2011-05-15 10:34:36 +08:00
|
|
|
ASTContext &getContext() const { return CGM.getContext(); }
|
2011-03-08 02:45:56 +08:00
|
|
|
CGDebugInfo *getDebugInfo() {
|
|
|
|
if (DisableDebugInfo)
|
|
|
|
return NULL;
|
|
|
|
return DebugInfo;
|
|
|
|
}
|
|
|
|
void disableDebugInfo() { DisableDebugInfo = true; }
|
|
|
|
void enableDebugInfo() { DisableDebugInfo = false; }
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
bool shouldUseFusedARCCalls() {
|
|
|
|
return CGM.getCodeGenOpts().OptimizationLevel == 0;
|
|
|
|
}
|
2007-06-03 06:49:07 +08:00
|
|
|
|
2011-02-08 16:22:06 +08:00
|
|
|
const LangOptions &getLangOptions() const { return CGM.getLangOptions(); }
|
|
|
|
|
2011-09-20 04:31:14 +08:00
|
|
|
/// Returns a pointer to the function's exception object and selector slot,
|
|
|
|
/// which is assigned in every landing pad.
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::Value *getExceptionSlot();
|
2011-05-29 05:13:02 +08:00
|
|
|
llvm::Value *getEHSelectorSlot();
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2011-09-16 02:57:19 +08:00
|
|
|
/// Returns the contents of the function's exception object and selector
|
|
|
|
/// slots.
|
|
|
|
llvm::Value *getExceptionFromSlot();
|
|
|
|
llvm::Value *getSelectorFromSlot();
|
|
|
|
|
2010-07-24 05:56:41 +08:00
|
|
|
llvm::Value *getNormalCleanupDestSlot();
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::BasicBlock *getUnreachableBlock() {
|
|
|
|
if (!UnreachableBlock) {
|
|
|
|
UnreachableBlock = createBasicBlock("unreachable");
|
|
|
|
new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
|
|
|
|
}
|
|
|
|
return UnreachableBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::BasicBlock *getInvokeDest() {
|
|
|
|
if (!EHStack.requiresLandingPad()) return 0;
|
|
|
|
return getInvokeDestImpl();
|
|
|
|
}
|
2009-02-24 01:26:39 +08:00
|
|
|
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); }
|
2009-07-13 12:10:07 +08:00
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Cleanups
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
typedef void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty);
|
|
|
|
|
2011-07-11 16:38:19 +08:00
|
|
|
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin,
|
|
|
|
llvm::Value *arrayEndPointer,
|
|
|
|
QualType elementType,
|
2012-01-26 11:33:36 +08:00
|
|
|
Destroyer *destroyer);
|
2011-07-11 16:38:19 +08:00
|
|
|
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
|
|
|
|
llvm::Value *arrayEnd,
|
|
|
|
QualType elementType,
|
2012-01-26 11:33:36 +08:00
|
|
|
Destroyer *destroyer);
|
2011-07-09 09:37:26 +08:00
|
|
|
|
2011-07-13 00:41:08 +08:00
|
|
|
void pushDestroy(QualType::DestructionKind dtorKind,
|
|
|
|
llvm::Value *addr, QualType type);
|
2011-07-09 09:37:26 +08:00
|
|
|
void pushDestroy(CleanupKind kind, llvm::Value *addr, QualType type,
|
2012-01-26 11:33:36 +08:00
|
|
|
Destroyer *destroyer, bool useEHCleanupForArray);
|
|
|
|
void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer,
|
2011-07-11 16:38:19 +08:00
|
|
|
bool useEHCleanupForArray);
|
2011-07-13 11:01:35 +08:00
|
|
|
llvm::Function *generateDestroyHelper(llvm::Constant *addr,
|
|
|
|
QualType type,
|
2012-01-26 11:33:36 +08:00
|
|
|
Destroyer *destroyer,
|
2011-07-13 11:01:35 +08:00
|
|
|
bool useEHCleanupForArray);
|
2011-07-09 09:37:26 +08:00
|
|
|
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end,
|
2012-01-26 11:33:36 +08:00
|
|
|
QualType type, Destroyer *destroyer,
|
2011-07-13 16:09:46 +08:00
|
|
|
bool checkZeroLength, bool useEHCleanup);
|
2011-07-09 09:37:26 +08:00
|
|
|
|
2012-01-26 11:33:36 +08:00
|
|
|
Destroyer *getDestroyer(QualType::DestructionKind destructionKind);
|
2011-07-13 00:41:08 +08:00
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
/// Determines whether an EH cleanup is required to destroy a type
|
|
|
|
/// with the given destruction kind.
|
|
|
|
bool needsEHCleanup(QualType::DestructionKind kind) {
|
|
|
|
switch (kind) {
|
|
|
|
case QualType::DK_none:
|
|
|
|
return false;
|
|
|
|
case QualType::DK_cxx_destructor:
|
|
|
|
case QualType::DK_objc_weak_lifetime:
|
|
|
|
return getLangOptions().Exceptions;
|
|
|
|
case QualType::DK_objc_strong_lifetime:
|
|
|
|
return getLangOptions().Exceptions &&
|
|
|
|
CGM.getCodeGenOpts().ObjCAutoRefCountExceptions;
|
|
|
|
}
|
|
|
|
llvm_unreachable("bad destruction kind");
|
|
|
|
}
|
|
|
|
|
2011-07-13 00:41:08 +08:00
|
|
|
CleanupKind getCleanupKind(QualType::DestructionKind kind) {
|
|
|
|
return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup);
|
|
|
|
}
|
|
|
|
|
2009-02-24 01:26:39 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Objective-C
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
void GenerateObjCMethod(const ObjCMethodDecl *OMD);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
void StartObjCMethod(const ObjCMethodDecl *MD,
|
2011-05-20 07:37:41 +08:00
|
|
|
const ObjCContainerDecl *CD,
|
|
|
|
SourceLocation StartLoc);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// GenerateObjCGetter - Synthesize an Objective-C property getter function.
|
2008-12-10 04:23:04 +08:00
|
|
|
void GenerateObjCGetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
2011-09-13 11:34:09 +08:00
|
|
|
void generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
|
2012-01-08 02:56:22 +08:00
|
|
|
const ObjCPropertyImplDecl *propImpl,
|
|
|
|
llvm::Constant *AtomicHelperFn);
|
2011-02-19 03:15:13 +08:00
|
|
|
|
2010-04-29 05:28:56 +08:00
|
|
|
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
|
|
|
|
ObjCMethodDecl *MD, bool ctor);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// GenerateObjCSetter - Synthesize an Objective-C property setter function
|
|
|
|
/// for the given property.
|
2008-12-10 04:23:04 +08:00
|
|
|
void GenerateObjCSetter(ObjCImplementationDecl *IMP,
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
2011-09-10 17:17:20 +08:00
|
|
|
void generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
|
2012-01-07 06:33:54 +08:00
|
|
|
const ObjCPropertyImplDecl *propImpl,
|
|
|
|
llvm::Constant *AtomicHelperFn);
|
2010-04-13 08:38:05 +08:00
|
|
|
bool IndirectObjCSetterArg(const CGFunctionInfo &FI);
|
2010-04-14 02:32:24 +08:00
|
|
|
bool IvarTypeWithAggrGCObjects(QualType Ty);
|
2008-08-26 16:29:31 +08:00
|
|
|
|
2009-02-22 04:00:35 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Block Bits
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2011-02-07 18:33:21 +08:00
|
|
|
llvm::Value *EmitBlockLiteral(const BlockExpr *);
|
2011-11-10 16:15:53 +08:00
|
|
|
llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info);
|
|
|
|
static void destroyBlockInfos(CGBlockInfo *info);
|
2010-02-24 05:51:17 +08:00
|
|
|
llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
|
2010-08-05 00:57:49 +08:00
|
|
|
const CGBlockInfo &Info,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::StructType *,
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::Constant *BlockVarLayout);
|
2009-02-22 04:00:35 +08:00
|
|
|
|
2010-06-24 08:08:06 +08:00
|
|
|
llvm::Function *GenerateBlockFunction(GlobalDecl GD,
|
2011-02-07 18:33:21 +08:00
|
|
|
const CGBlockInfo &Info,
|
2009-03-21 05:53:12 +08:00
|
|
|
const Decl *OuterFuncDecl,
|
2012-02-25 10:48:22 +08:00
|
|
|
const DeclMapTy &ldm,
|
|
|
|
bool IsLambdaConversionToBlock);
|
2009-02-22 04:00:35 +08:00
|
|
|
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo);
|
|
|
|
llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo);
|
2012-01-10 08:37:01 +08:00
|
|
|
llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction(
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
|
|
|
llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction(
|
|
|
|
const ObjCPropertyImplDecl *PID);
|
2012-02-28 09:08:45 +08:00
|
|
|
llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
|
2011-02-08 16:22:06 +08:00
|
|
|
|
|
|
|
void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags);
|
|
|
|
|
2011-03-31 09:59:53 +08:00
|
|
|
class AutoVarEmission;
|
|
|
|
|
|
|
|
void emitByrefStructureInit(const AutoVarEmission &emission);
|
|
|
|
void enterByrefCleanup(const AutoVarEmission &emission);
|
|
|
|
|
2011-02-07 18:33:21 +08:00
|
|
|
llvm::Value *LoadBlockStruct() {
|
|
|
|
assert(BlockPointer && "no block pointer set!");
|
|
|
|
return BlockPointer;
|
|
|
|
}
|
2009-02-22 04:00:35 +08:00
|
|
|
|
2010-05-20 09:18:31 +08:00
|
|
|
void AllocateBlockCXXThisPointer(const CXXThisExpr *E);
|
|
|
|
void AllocateBlockDecl(const BlockDeclRefExpr *E);
|
2010-05-21 12:11:14 +08:00
|
|
|
llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) {
|
|
|
|
return GetAddrOfBlockDecl(E->getDecl(), E->isByRef());
|
|
|
|
}
|
2011-02-07 18:33:21 +08:00
|
|
|
llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef);
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *BuildByRefType(const VarDecl *var);
|
2009-03-04 11:23:46 +08:00
|
|
|
|
2011-03-09 12:27:21 +08:00
|
|
|
void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
|
|
|
|
const CGFunctionInfo &FnInfo);
|
2009-09-11 08:07:24 +08:00
|
|
|
void StartFunction(GlobalDecl GD, QualType RetTy,
|
2008-09-10 07:14:03 +08:00
|
|
|
llvm::Function *Fn,
|
2011-03-09 12:27:21 +08:00
|
|
|
const CGFunctionInfo &FnInfo,
|
2008-10-19 02:22:23 +08:00
|
|
|
const FunctionArgList &Args,
|
2011-03-03 05:36:49 +08:00
|
|
|
SourceLocation StartLoc);
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2010-02-19 17:25:03 +08:00
|
|
|
void EmitConstructorBody(FunctionArgList &Args);
|
|
|
|
void EmitDestructorBody(FunctionArgList &Args);
|
|
|
|
void EmitFunctionBody(FunctionArgList &Args);
|
2010-02-18 11:17:58 +08:00
|
|
|
|
2012-02-25 10:48:22 +08:00
|
|
|
void EmitForwardingCallToLambda(const CXXRecordDecl *Lambda,
|
|
|
|
CallArgList &CallArgs);
|
2012-02-16 09:37:33 +08:00
|
|
|
void EmitLambdaToBlockPointerBody(FunctionArgList &Args);
|
2012-02-25 10:48:22 +08:00
|
|
|
void EmitLambdaBlockInvokeBody();
|
2012-02-17 11:02:34 +08:00
|
|
|
void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD);
|
|
|
|
void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD);
|
2012-02-16 09:37:33 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitReturnBlock - Emit the unified return block, trying to avoid its
|
|
|
|
/// emission when possible.
|
2009-01-27 07:27:52 +08:00
|
|
|
void EmitReturnBlock();
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// FinishFunction - Complete IR generation of the current function. It is
|
|
|
|
/// legal to call this function even if there is no current insertion point.
|
2008-08-26 16:29:31 +08:00
|
|
|
void FinishFunction(SourceLocation EndLoc=SourceLocation());
|
2008-09-10 07:27:19 +08:00
|
|
|
|
2010-03-24 08:39:18 +08:00
|
|
|
/// GenerateThunk - Generate a thunk for the given method.
|
2011-03-09 12:27:21 +08:00
|
|
|
void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
|
|
|
|
GlobalDecl GD, const ThunkInfo &Thunk);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-05-07 01:27:27 +08:00
|
|
|
void GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
|
|
|
|
GlobalDecl GD, const ThunkInfo &Thunk);
|
|
|
|
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type,
|
|
|
|
FunctionArgList &Args);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2012-02-14 10:31:03 +08:00
|
|
|
void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init,
|
|
|
|
ArrayRef<VarDecl *> ArrayIndexes);
|
|
|
|
|
2010-03-29 03:40:00 +08:00
|
|
|
/// InitializeVTablePointer - Initialize the vtable pointer of the given
|
|
|
|
/// subobject.
|
|
|
|
///
|
2010-10-19 14:39:39 +08:00
|
|
|
void InitializeVTablePointer(BaseSubobject Base,
|
2010-04-20 13:22:15 +08:00
|
|
|
const CXXRecordDecl *NearestVBase,
|
2011-03-23 09:04:18 +08:00
|
|
|
CharUnits OffsetFromNearestVBase,
|
2010-03-29 03:40:00 +08:00
|
|
|
llvm::Constant *VTable,
|
|
|
|
const CXXRecordDecl *VTableClass);
|
|
|
|
|
|
|
|
typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
|
2010-10-19 14:39:39 +08:00
|
|
|
void InitializeVTablePointers(BaseSubobject Base,
|
2010-04-20 13:22:15 +08:00
|
|
|
const CXXRecordDecl *NearestVBase,
|
2011-03-23 09:04:18 +08:00
|
|
|
CharUnits OffsetFromNearestVBase,
|
2010-03-29 05:07:49 +08:00
|
|
|
bool BaseIsNonVirtualPrimaryBase,
|
|
|
|
llvm::Constant *VTable,
|
|
|
|
const CXXRecordDecl *VTableClass,
|
|
|
|
VisitedVirtualBasesSetTy& VBases);
|
2009-12-08 14:46:18 +08:00
|
|
|
|
2010-03-29 05:07:49 +08:00
|
|
|
void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
|
2010-03-29 03:40:00 +08:00
|
|
|
|
2010-10-27 02:44:08 +08:00
|
|
|
/// GetVTablePtr - Return the Value of the vtable pointer member pointed
|
|
|
|
/// to by This.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Value *GetVTablePtr(llvm::Value *This, llvm::Type *Ty);
|
2010-03-29 03:40:00 +08:00
|
|
|
|
2010-07-21 13:30:47 +08:00
|
|
|
/// EnterDtorCleanups - Enter the cleanups necessary to complete the
|
|
|
|
/// given phase of destruction for a destructor. The end result
|
|
|
|
/// should call destructors on members and base classes in reverse
|
|
|
|
/// order of their construction.
|
|
|
|
void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-06-22 08:03:40 +08:00
|
|
|
/// ShouldInstrumentFunction - Return true if the current function should be
|
|
|
|
/// instrumented with __cyg_profile_func_* calls
|
|
|
|
bool ShouldInstrumentFunction();
|
|
|
|
|
|
|
|
/// EmitFunctionInstrumentation - Emit LLVM code to call the specified
|
|
|
|
/// instrumentation function with the current function and the call site, if
|
|
|
|
/// function instrumentation is enabled.
|
|
|
|
void EmitFunctionInstrumentation(const char *Fn);
|
|
|
|
|
2011-02-11 00:52:03 +08:00
|
|
|
/// EmitMCountInstrumentation - Emit call to .mcount.
|
|
|
|
void EmitMCountInstrumentation();
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitFunctionProlog - Emit the target specific LLVM code to load the
|
|
|
|
/// arguments for the given function. This is also responsible for naming the
|
|
|
|
/// LLVM function arguments.
|
2009-02-03 06:03:45 +08:00
|
|
|
void EmitFunctionProlog(const CGFunctionInfo &FI,
|
|
|
|
llvm::Function *Fn,
|
2008-09-10 07:27:19 +08:00
|
|
|
const FunctionArgList &Args);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitFunctionEpilog - Emit the target specific LLVM code to return the
|
|
|
|
/// given temporary.
|
Change IR generation for return (in the simple case) to avoid doing silly
load/store nonsense in the epilog. For example, for:
int foo(int X) {
int A[100];
return A[X];
}
we used to generate:
%arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
%tmp1 = load i32* %arrayidx ; <i32> [#uses=1]
store i32 %tmp1, i32* %retval
%0 = load i32* %retval ; <i32> [#uses=1]
ret i32 %0
}
which codegen'd to this code:
_foo: ## @foo
## BB#0: ## %entry
subq $408, %rsp ## imm = 0x198
movl %edi, 400(%rsp)
movl 400(%rsp), %edi
movslq %edi, %rax
movl (%rsp,%rax,4), %edi
movl %edi, 404(%rsp)
movl 404(%rsp), %eax
addq $408, %rsp ## imm = 0x198
ret
Now we generate:
%arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
%tmp1 = load i32* %arrayidx ; <i32> [#uses=1]
ret i32 %tmp1
}
and:
_foo: ## @foo
## BB#0: ## %entry
subq $408, %rsp ## imm = 0x198
movl %edi, 404(%rsp)
movl 404(%rsp), %edi
movslq %edi, %rax
movl (%rsp,%rax,4), %eax
addq $408, %rsp ## imm = 0x198
ret
This actually does matter, cutting out 2000 lines of IR from CGStmt.ll
for example.
Another interesting effect is that altivec.h functions which are dead
now get dce'd by the inliner. Hence all the changes to
builtins-ppc-altivec.c to ensure the calls aren't dead.
llvm-svn: 106970
2010-06-27 09:06:27 +08:00
|
|
|
void EmitFunctionEpilog(const CGFunctionInfo &FI);
|
2008-09-10 07:27:19 +08:00
|
|
|
|
2009-12-08 07:38:24 +08:00
|
|
|
/// EmitStartEHSpec - Emit the start of the exception spec.
|
|
|
|
void EmitStartEHSpec(const Decl *D);
|
|
|
|
|
|
|
|
/// EmitEndEHSpec - Emit the end of the exception spec.
|
|
|
|
void EmitEndEHSpec(const Decl *D);
|
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
/// getTerminateLandingPad - Return a landing pad that just calls terminate.
|
|
|
|
llvm::BasicBlock *getTerminateLandingPad();
|
|
|
|
|
|
|
|
/// getTerminateHandler - Return a handler (not a landing pad, just
|
|
|
|
/// a catch handler) that just calls terminate. This is used when
|
|
|
|
/// a terminate scope encloses a try.
|
2009-12-10 06:59:31 +08:00
|
|
|
llvm::BasicBlock *getTerminateHandler();
|
|
|
|
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *ConvertTypeForMem(QualType T);
|
|
|
|
llvm::Type *ConvertType(QualType T);
|
|
|
|
llvm::Type *ConvertType(const TypeDecl *T) {
|
2010-02-16 12:15:37 +08:00
|
|
|
return ConvertType(getContext().getTypeDeclType(T));
|
|
|
|
}
|
2008-04-04 12:07:35 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// LoadObjCSelf - Load the value of self. This function is only valid while
|
|
|
|
/// generating code for an Objective-C method.
|
2008-04-04 12:07:35 +08:00
|
|
|
llvm::Value *LoadObjCSelf();
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// TypeOfSelfObject - Return type of object that this self represents.
|
2009-02-03 08:09:52 +08:00
|
|
|
QualType TypeOfSelfObject();
|
2008-06-18 02:05:57 +08:00
|
|
|
|
2007-06-23 06:02:34 +08:00
|
|
|
/// hasAggregateLLVMType - Return true if the specified AST type will map into
|
|
|
|
/// an aggregate LLVM type or is void.
|
|
|
|
static bool hasAggregateLLVMType(QualType T);
|
2008-11-11 10:29:29 +08:00
|
|
|
|
|
|
|
/// createBasicBlock - Create an LLVM basic block.
|
2011-07-20 14:58:45 +08:00
|
|
|
llvm::BasicBlock *createBasicBlock(StringRef name = "",
|
2011-02-08 16:22:06 +08:00
|
|
|
llvm::Function *parent = 0,
|
|
|
|
llvm::BasicBlock *before = 0) {
|
2008-11-12 08:01:12 +08:00
|
|
|
#ifdef NDEBUG
|
2011-02-08 16:22:06 +08:00
|
|
|
return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before);
|
2008-11-12 08:01:12 +08:00
|
|
|
#else
|
2011-02-08 16:22:06 +08:00
|
|
|
return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before);
|
2008-11-12 08:01:12 +08:00
|
|
|
#endif
|
2008-11-11 10:29:29 +08:00
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
/// getBasicBlockForLabel - Return the LLVM basicblock that the specified
|
|
|
|
/// label maps to.
|
2011-02-17 15:39:24 +08:00
|
|
|
JumpDest getJumpDestForLabel(const LabelDecl *S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-12-01 04:08:49 +08:00
|
|
|
/// SimplifyForwardingBlocks - If the given basic block is only a branch to
|
|
|
|
/// another basic block, simplify it. This assumes that no other code could
|
|
|
|
/// potentially reference the basic block.
|
2009-04-01 12:37:47 +08:00
|
|
|
void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitBlock - Emit the given block \arg BB and set it as the insert point,
|
|
|
|
/// adding a fall-through branch from the current insert block if
|
|
|
|
/// necessary. It is legal to call this function even if there is no current
|
|
|
|
/// insertion point.
|
2008-11-13 09:24:05 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// IsFinished - If true, indicates that the caller has finished emitting
|
|
|
|
/// branches to the given block and does not expect to emit code into it. This
|
|
|
|
/// means the block can be ignored if it is unreachable.
|
2008-11-13 09:24:05 +08:00
|
|
|
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
|
2008-11-11 12:34:23 +08:00
|
|
|
|
2011-08-11 10:22:43 +08:00
|
|
|
/// EmitBlockAfterUses - Emit the given block somewhere hopefully
|
|
|
|
/// near its uses, and leave the insertion point in it.
|
|
|
|
void EmitBlockAfterUses(llvm::BasicBlock *BB);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitBranch - Emit a branch to the specified basic block from the current
|
|
|
|
/// insert block, taking care to avoid creation of branches from dummy
|
|
|
|
/// blocks. It is legal to call this function even if there is no current
|
|
|
|
/// insertion point.
|
2008-11-12 06:06:59 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// This function clears the current insertion point. The caller should follow
|
|
|
|
/// calls to this function with calls to Emit*Block prior to generation new
|
|
|
|
/// code.
|
2008-11-11 17:41:28 +08:00
|
|
|
void EmitBranch(llvm::BasicBlock *Block);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// HaveInsertPoint - True if an insertion point is defined. If not, this
|
|
|
|
/// indicates that the current code being emitted is unreachable.
|
|
|
|
bool HaveInsertPoint() const {
|
2008-11-12 07:11:34 +08:00
|
|
|
return Builder.GetInsertBlock() != 0;
|
|
|
|
}
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EnsureInsertPoint - Ensure that an insertion point is defined so that
|
|
|
|
/// emitted IR has a place to go. Note that by definition, if this function
|
|
|
|
/// creates a block then that block is unreachable; callers may do better to
|
|
|
|
/// detect when no insertion point is defined and simply skip IR generation.
|
2008-11-12 07:11:34 +08:00
|
|
|
void EnsureInsertPoint() {
|
|
|
|
if (!HaveInsertPoint())
|
|
|
|
EmitBlock(createBasicBlock());
|
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-16 08:56:44 +08:00
|
|
|
/// ErrorUnsupported - Print out an error that codegen doesn't support the
|
2007-12-02 09:43:38 +08:00
|
|
|
/// specified stmt yet.
|
2008-09-04 11:43:08 +08:00
|
|
|
void ErrorUnsupported(const Stmt *S, const char *Type,
|
|
|
|
bool OmitOnError=false);
|
2007-06-02 12:16:21 +08:00
|
|
|
|
2007-06-23 05:44:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-12-03 12:14:32 +08:00
|
|
|
LValue MakeAddrLValue(llvm::Value *V, QualType T,
|
|
|
|
CharUnits Alignment = CharUnits()) {
|
2010-10-15 07:06:10 +08:00
|
|
|
return LValue::MakeAddr(V, T, Alignment, getContext(),
|
|
|
|
CGM.getTBAAInfo(T));
|
2011-11-16 08:42:57 +08:00
|
|
|
}
|
|
|
|
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
|
2011-12-03 12:14:32 +08:00
|
|
|
CharUnits Alignment;
|
|
|
|
if (!T->isIncompleteType())
|
|
|
|
Alignment = getContext().getTypeAlignInChars(T);
|
2011-11-16 08:42:57 +08:00
|
|
|
return LValue::MakeAddr(V, T, Alignment, getContext(),
|
|
|
|
CGM.getTBAAInfo(T));
|
2010-08-21 10:53:44 +08:00
|
|
|
}
|
|
|
|
|
2007-06-23 05:44:33 +08:00
|
|
|
/// CreateTempAlloca - This creates a alloca and inserts it into the entry
|
2010-02-09 10:48:28 +08:00
|
|
|
/// block. The caller is responsible for setting an appropriate alignment on
|
|
|
|
/// the alloca.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty,
|
2011-07-20 15:06:53 +08:00
|
|
|
const Twine &Name = "tmp");
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-04-22 09:10:34 +08:00
|
|
|
/// InitTempAlloca - Provide an initial value for the given alloca.
|
|
|
|
void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value);
|
|
|
|
|
2010-02-17 03:44:13 +08:00
|
|
|
/// CreateIRTemp - Create a temporary IR object of the given type, with
|
|
|
|
/// appropriate alignment. This routine should only be used when an temporary
|
|
|
|
/// value needs to be stored into an alloca (for example, to avoid explicit
|
|
|
|
/// PHI construction), but the type is the IR type, not the type appropriate
|
|
|
|
/// for storing in memory.
|
2011-07-20 15:06:53 +08:00
|
|
|
llvm::AllocaInst *CreateIRTemp(QualType T, const Twine &Name = "tmp");
|
2010-02-17 03:44:13 +08:00
|
|
|
|
2010-02-09 10:48:28 +08:00
|
|
|
/// CreateMemTemp - Create a temporary memory object of the given type, with
|
|
|
|
/// appropriate alignment.
|
2011-07-20 15:06:53 +08:00
|
|
|
llvm::AllocaInst *CreateMemTemp(QualType T, const Twine &Name = "tmp");
|
2010-02-09 10:48:28 +08:00
|
|
|
|
2010-09-15 18:14:12 +08:00
|
|
|
/// CreateAggTemp - Create a temporary memory object for the given
|
|
|
|
/// aggregate type.
|
2011-07-20 15:06:53 +08:00
|
|
|
AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") {
|
2011-12-03 10:13:40 +08:00
|
|
|
CharUnits Alignment = getContext().getTypeAlignInChars(T);
|
2011-12-03 08:54:26 +08:00
|
|
|
return AggValueSlot::forAddr(CreateMemTemp(T, Name), Alignment,
|
|
|
|
T.getQualifiers(),
|
2011-08-26 04:40:09 +08:00
|
|
|
AggValueSlot::IsNotDestructed,
|
2011-08-26 07:04:34 +08:00
|
|
|
AggValueSlot::DoesNotNeedGCBarriers,
|
|
|
|
AggValueSlot::IsNotAliased);
|
2010-09-15 18:14:12 +08:00
|
|
|
}
|
|
|
|
|
2011-02-08 16:22:06 +08:00
|
|
|
/// Emit a cast to void* in the appropriate address space.
|
|
|
|
llvm::Value *EmitCastToVoidPtr(llvm::Value *value);
|
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EvaluateExprAsBool - Perform the usual unary conversions on the specified
|
|
|
|
/// expression and compare the result against zero, returning an Int1Ty value.
|
2007-06-16 07:05:46 +08:00
|
|
|
llvm::Value *EvaluateExprAsBool(const Expr *E);
|
2007-06-23 05:44:33 +08:00
|
|
|
|
2010-12-05 10:00:02 +08:00
|
|
|
/// EmitIgnoredExpr - Emit an expression in a context which ignores the result.
|
|
|
|
void EmitIgnoredExpr(const Expr *E);
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
/// EmitAnyExpr - Emit code to compute the specified expression which can have
|
|
|
|
/// any type. The result is returned as an RValue struct. If this is an
|
|
|
|
/// aggregate expression, the aggloc/agglocvolatile arguments indicate where
|
|
|
|
/// the result should be returned.
|
2009-05-27 06:03:21 +08:00
|
|
|
///
|
|
|
|
/// \param IgnoreResult - True if the resulting value isn't used.
|
2010-09-15 18:14:12 +08:00
|
|
|
RValue EmitAnyExpr(const Expr *E,
|
|
|
|
AggValueSlot AggSlot = AggValueSlot::ignored(),
|
|
|
|
bool IgnoreResult = false);
|
2007-09-29 05:49:18 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
// EmitVAListRef - Emit a "reference" to a va_list; this is either the address
|
|
|
|
// or the value of the expression, depending on how va_list is defined.
|
2009-01-21 01:46:04 +08:00
|
|
|
llvm::Value *EmitVAListRef(const Expr *E);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
|
|
|
|
/// always be accessible even if no aggregate location is provided.
|
2010-09-15 18:14:12 +08:00
|
|
|
RValue EmitAnyExprToTemp(const Expr *E);
|
2008-09-09 09:06:48 +08:00
|
|
|
|
2011-03-08 17:11:50 +08:00
|
|
|
/// EmitAnyExprToMem - Emits the code necessary to evaluate an
|
2010-04-21 18:05:39 +08:00
|
|
|
/// arbitrary expression into the given memory location.
|
|
|
|
void EmitAnyExprToMem(const Expr *E, llvm::Value *Location,
|
2011-06-16 07:02:42 +08:00
|
|
|
Qualifiers Quals, bool IsInitializer);
|
2010-04-21 18:05:39 +08:00
|
|
|
|
2011-03-08 17:11:50 +08:00
|
|
|
/// EmitExprAsInit - Emits the code necessary to initialize a
|
|
|
|
/// location in memory with the given initializer.
|
2011-06-16 07:02:42 +08:00
|
|
|
void EmitExprAsInit(const Expr *init, const ValueDecl *D,
|
2011-06-16 12:16:24 +08:00
|
|
|
LValue lvalue, bool capturedByInit);
|
2011-03-08 17:11:50 +08:00
|
|
|
|
2009-05-24 06:29:41 +08:00
|
|
|
/// EmitAggregateCopy - Emit an aggrate copy.
|
|
|
|
///
|
|
|
|
/// \param isVolatile - True iff either the source or the destination is
|
|
|
|
/// volatile.
|
2008-09-10 04:49:46 +08:00
|
|
|
void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
|
2011-12-06 06:23:28 +08:00
|
|
|
QualType EltTy, bool isVolatile=false,
|
|
|
|
unsigned Alignment = 0);
|
2008-09-10 04:49:46 +08:00
|
|
|
|
2007-10-05 07:45:31 +08:00
|
|
|
/// StartBlock - Start new block named N. If insert block is a dummy block
|
|
|
|
/// then reuse it.
|
|
|
|
void StartBlock(const char *N);
|
|
|
|
|
2008-02-27 05:41:45 +08:00
|
|
|
/// GetAddrOfStaticLocalVar - Return the address of a static local variable.
|
2010-08-31 15:33:07 +08:00
|
|
|
llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD) {
|
|
|
|
return cast<llvm::Constant>(GetAddrOfLocalVar(BVD));
|
|
|
|
}
|
2008-05-22 08:50:06 +08:00
|
|
|
|
2008-09-11 17:15:33 +08:00
|
|
|
/// GetAddrOfLocalVar - Return the address of a local variable.
|
2010-08-31 15:33:07 +08:00
|
|
|
llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) {
|
|
|
|
llvm::Value *Res = LocalDeclMap[VD];
|
|
|
|
assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!");
|
|
|
|
return Res;
|
|
|
|
}
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
/// getOpaqueLValueMapping - Given an opaque value expression (which
|
|
|
|
/// must be mapped to an l-value), return its mapping.
|
|
|
|
const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) {
|
|
|
|
assert(OpaqueValueMapping::shouldBindAsLValue(e));
|
|
|
|
|
|
|
|
llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
|
|
|
|
it = OpaqueLValues.find(e);
|
|
|
|
assert(it != OpaqueLValues.end() && "no mapping for opaque value!");
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOpaqueRValueMapping - Given an opaque value expression (which
|
|
|
|
/// must be mapped to an r-value), return its mapping.
|
|
|
|
const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) {
|
|
|
|
assert(!OpaqueValueMapping::shouldBindAsLValue(e));
|
|
|
|
|
|
|
|
llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
|
|
|
|
it = OpaqueRValues.find(e);
|
|
|
|
assert(it != OpaqueRValues.end() && "no mapping for opaque value!");
|
2011-02-16 16:02:54 +08:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
2008-05-22 08:50:06 +08:00
|
|
|
/// getAccessedFieldNo - Given an encoded value and a result number, return
|
|
|
|
/// the input field number being accessed.
|
|
|
|
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
|
|
|
|
|
2011-02-17 15:39:24 +08:00
|
|
|
llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
|
2009-10-13 14:55:33 +08:00
|
|
|
llvm::BasicBlock *GetIndirectGotoBlock();
|
2008-08-05 00:51:22 +08:00
|
|
|
|
2010-05-23 01:35:42 +08:00
|
|
|
/// EmitNullInitialization - Generate code to set a value of the given type to
|
|
|
|
/// null, If the type contains data member pointers, they will be initialized
|
|
|
|
/// to -1 in accordance with the Itanium C++ ABI.
|
|
|
|
void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty);
|
2008-11-04 13:30:00 +08:00
|
|
|
|
|
|
|
// EmitVAArg - Generate code to get an argument from the passed in pointer
|
|
|
|
// and update it accordingly. The return value is a pointer to the argument.
|
|
|
|
// FIXME: We should be able to get rid of this method and use the va_arg
|
2009-02-09 07:14:22 +08:00
|
|
|
// instruction in LLVM instead once it works well enough.
|
2008-11-04 13:30:00 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
|
2008-12-21 04:27:15 +08:00
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
/// emitArrayLength - Compute the length of an array, even if it's a
|
|
|
|
/// VLA, and drill down to the base element type.
|
|
|
|
llvm::Value *emitArrayLength(const ArrayType *arrayType,
|
|
|
|
QualType &baseType,
|
|
|
|
llvm::Value *&addr);
|
|
|
|
|
2011-06-25 05:55:10 +08:00
|
|
|
/// EmitVLASize - Capture all the sizes for the VLA expressions in
|
|
|
|
/// the given variably-modified type and store them in the VLASizeMap.
|
2009-07-19 14:58:07 +08:00
|
|
|
///
|
|
|
|
/// This function can be called with a null (unreachable) insert point.
|
2011-06-25 05:55:10 +08:00
|
|
|
void EmitVariablyModifiedType(QualType Ty);
|
|
|
|
|
|
|
|
/// getVLASize - Returns an LLVM value that corresponds to the size,
|
|
|
|
/// in non-variably-sized elements, of a variable length array type,
|
|
|
|
/// plus that largest non-variably-sized element type. Assumes that
|
|
|
|
/// the type has already been emitted with EmitVariablyModifiedType.
|
|
|
|
std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla);
|
|
|
|
std::pair<llvm::Value*,QualType> getVLASize(QualType vla);
|
2008-12-12 15:19:02 +08:00
|
|
|
|
2009-04-15 00:58:56 +08:00
|
|
|
/// LoadCXXThis - Load the value of 'this'. This function is only valid while
|
|
|
|
/// generating code for an C++ member function.
|
2010-02-17 06:04:33 +08:00
|
|
|
llvm::Value *LoadCXXThis() {
|
|
|
|
assert(CXXThisValue && "no 'this' value for this function");
|
|
|
|
return CXXThisValue;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-02 09:01:18 +08:00
|
|
|
/// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
|
|
|
|
/// virtual bases.
|
2010-02-17 06:04:33 +08:00
|
|
|
llvm::Value *LoadCXXVTT() {
|
|
|
|
assert(CXXVTTValue && "no VTT value for this function");
|
|
|
|
return CXXVTTValue;
|
|
|
|
}
|
2010-02-16 12:15:37 +08:00
|
|
|
|
|
|
|
/// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
|
2010-04-25 07:01:49 +08:00
|
|
|
/// complete class to the given direct base.
|
|
|
|
llvm::Value *
|
|
|
|
GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value,
|
|
|
|
const CXXRecordDecl *Derived,
|
|
|
|
const CXXRecordDecl *Base,
|
|
|
|
bool BaseIsVirtual);
|
2010-04-25 05:51:08 +08:00
|
|
|
|
2009-12-01 04:08:49 +08:00
|
|
|
/// GetAddressOfBaseClass - This function will add the necessary delta to the
|
|
|
|
/// load of 'this' and returns address of the base class.
|
2010-10-19 14:39:39 +08:00
|
|
|
llvm::Value *GetAddressOfBaseClass(llvm::Value *Value,
|
2010-04-25 07:01:49 +08:00
|
|
|
const CXXRecordDecl *Derived,
|
2010-08-07 14:22:56 +08:00
|
|
|
CastExpr::path_const_iterator PathBegin,
|
|
|
|
CastExpr::path_const_iterator PathEnd,
|
2010-04-25 05:06:20 +08:00
|
|
|
bool NullCheckValue);
|
|
|
|
|
2009-11-24 01:57:54 +08:00
|
|
|
llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
|
2010-04-25 07:01:49 +08:00
|
|
|
const CXXRecordDecl *Derived,
|
2010-08-07 14:22:56 +08:00
|
|
|
CastExpr::path_const_iterator PathBegin,
|
|
|
|
CastExpr::path_const_iterator PathEnd,
|
2009-09-12 12:26:35 +08:00
|
|
|
bool NullCheckValue);
|
2009-11-24 01:57:54 +08:00
|
|
|
|
2010-01-31 09:36:53 +08:00
|
|
|
llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This,
|
|
|
|
const CXXRecordDecl *ClassDecl,
|
|
|
|
const CXXRecordDecl *BaseClassDecl);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-02-23 08:48:20 +08:00
|
|
|
void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,
|
|
|
|
CXXCtorType CtorType,
|
|
|
|
const FunctionArgList &Args);
|
2011-05-01 15:04:31 +08:00
|
|
|
// It's important not to confuse this and the previous function. Delegating
|
|
|
|
// constructors are the C++0x feature. The constructor delegate optimization
|
|
|
|
// is used to reduce duplication in the base and complete consturctors where
|
|
|
|
// they are substantially the same.
|
|
|
|
void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor,
|
|
|
|
const FunctionArgList &Args);
|
2010-05-03 07:20:53 +08:00
|
|
|
void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
|
|
|
|
bool ForVirtualBase, llvm::Value *This,
|
2009-04-17 08:06:03 +08:00
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd);
|
2010-11-14 05:53:34 +08:00
|
|
|
|
|
|
|
void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D,
|
|
|
|
llvm::Value *This, llvm::Value *Src,
|
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-20 04:55:16 +08:00
|
|
|
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
|
2009-09-23 10:45:36 +08:00
|
|
|
const ConstantArrayType *ArrayTy,
|
2009-11-25 02:43:52 +08:00
|
|
|
llvm::Value *ArrayPtr,
|
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
2010-07-21 09:10:17 +08:00
|
|
|
CallExpr::const_arg_iterator ArgEnd,
|
|
|
|
bool ZeroInitialization = false);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-09-23 10:45:36 +08:00
|
|
|
void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
|
|
|
|
llvm::Value *NumElements,
|
2009-11-25 02:43:52 +08:00
|
|
|
llvm::Value *ArrayPtr,
|
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
2010-07-21 09:10:17 +08:00
|
|
|
CallExpr::const_arg_iterator ArgEnd,
|
|
|
|
bool ZeroInitialization = false);
|
2009-04-17 08:06:03 +08:00
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
static Destroyer destroyCXXObject;
|
|
|
|
|
2009-05-30 05:03:38 +08:00
|
|
|
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
|
2010-05-03 07:29:11 +08:00
|
|
|
bool ForVirtualBase, llvm::Value *This);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-09-15 14:49:18 +08:00
|
|
|
void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
|
|
|
|
llvm::Value *NewPtr, llvm::Value *NumElements);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-28 06:09:22 +08:00
|
|
|
void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
|
|
|
|
llvm::Value *Ptr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-31 09:40:14 +08:00
|
|
|
llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
|
2009-08-17 05:13:42 +08:00
|
|
|
void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-18 08:57:03 +08:00
|
|
|
void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
|
|
|
|
QualType DeleteTy);
|
|
|
|
|
2009-11-15 16:09:41 +08:00
|
|
|
llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
|
2009-11-16 14:50:58 +08:00
|
|
|
llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
|
2009-11-15 16:09:41 +08:00
|
|
|
|
2012-02-20 00:03:09 +08:00
|
|
|
void MaybeEmitStdInitializerListCleanup(llvm::Value *loc, const Expr *init);
|
2012-02-19 20:28:02 +08:00
|
|
|
void EmitStdInitializerListCleanup(llvm::Value *loc,
|
|
|
|
const InitListExpr *init);
|
2012-02-17 16:42:25 +08:00
|
|
|
|
2009-12-16 10:57:00 +08:00
|
|
|
void EmitCheck(llvm::Value *, unsigned Size);
|
|
|
|
|
2010-01-10 05:40:03 +08:00
|
|
|
llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
|
|
|
bool isInc, bool isPre);
|
|
|
|
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
|
|
|
|
bool isInc, bool isPre);
|
2007-06-02 12:16:21 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-06-14 04:44:40 +08:00
|
|
|
// Declaration Emission
|
2007-06-02 12:16:21 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-07-19 14:58:07 +08:00
|
|
|
/// EmitDecl - Emit a declaration.
|
|
|
|
///
|
|
|
|
/// This function can be called with a null (unreachable) insert point.
|
2007-06-09 09:20:56 +08:00
|
|
|
void EmitDecl(const Decl &D);
|
2009-07-19 14:58:07 +08:00
|
|
|
|
2010-10-15 12:57:14 +08:00
|
|
|
/// EmitVarDecl - Emit a local variable declaration.
|
2009-07-19 14:58:07 +08:00
|
|
|
///
|
|
|
|
/// This function can be called with a null (unreachable) insert point.
|
2010-10-15 12:57:14 +08:00
|
|
|
void EmitVarDecl(const VarDecl &D);
|
2009-07-19 14:58:07 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
void EmitScalarInit(const Expr *init, const ValueDecl *D,
|
2011-06-16 12:16:24 +08:00
|
|
|
LValue lvalue, bool capturedByInit);
|
2011-06-17 14:42:21 +08:00
|
|
|
void EmitScalarInit(llvm::Value *init, LValue lvalue);
|
2011-06-16 07:02:42 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
|
|
|
|
llvm::Value *Address);
|
|
|
|
|
2010-10-15 12:57:14 +08:00
|
|
|
/// EmitAutoVarDecl - Emit an auto variable declaration.
|
2009-07-19 14:58:07 +08:00
|
|
|
///
|
|
|
|
/// This function can be called with a null (unreachable) insert point.
|
2011-02-22 14:44:22 +08:00
|
|
|
void EmitAutoVarDecl(const VarDecl &D);
|
|
|
|
|
|
|
|
class AutoVarEmission {
|
|
|
|
friend class CodeGenFunction;
|
|
|
|
|
2011-02-22 15:16:58 +08:00
|
|
|
const VarDecl *Variable;
|
2011-02-22 14:44:22 +08:00
|
|
|
|
|
|
|
/// The alignment of the variable.
|
|
|
|
CharUnits Alignment;
|
|
|
|
|
|
|
|
/// The address of the alloca. Null if the variable was emitted
|
|
|
|
/// as a global constant.
|
|
|
|
llvm::Value *Address;
|
|
|
|
|
|
|
|
llvm::Value *NRVOFlag;
|
|
|
|
|
|
|
|
/// True if the variable is a __block variable.
|
|
|
|
bool IsByRef;
|
|
|
|
|
|
|
|
/// True if the variable is of aggregate type and has a constant
|
|
|
|
/// initializer.
|
|
|
|
bool IsConstantAggregate;
|
|
|
|
|
2011-02-22 15:16:58 +08:00
|
|
|
struct Invalid {};
|
|
|
|
AutoVarEmission(Invalid) : Variable(0) {}
|
|
|
|
|
2011-02-22 14:44:22 +08:00
|
|
|
AutoVarEmission(const VarDecl &variable)
|
2011-02-22 15:16:58 +08:00
|
|
|
: Variable(&variable), Address(0), NRVOFlag(0),
|
2011-02-22 14:44:22 +08:00
|
|
|
IsByRef(false), IsConstantAggregate(false) {}
|
|
|
|
|
|
|
|
bool wasEmittedAsGlobal() const { return Address == 0; }
|
|
|
|
|
|
|
|
public:
|
2011-02-22 15:16:58 +08:00
|
|
|
static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
|
|
|
|
|
2011-02-22 14:44:22 +08:00
|
|
|
/// Returns the address of the object within this declaration.
|
|
|
|
/// Note that this does not chase the forwarding pointer for
|
|
|
|
/// __block decls.
|
|
|
|
llvm::Value *getObjectAddress(CodeGenFunction &CGF) const {
|
|
|
|
if (!IsByRef) return Address;
|
|
|
|
|
|
|
|
return CGF.Builder.CreateStructGEP(Address,
|
2011-02-22 15:16:58 +08:00
|
|
|
CGF.getByRefValueLLVMField(Variable),
|
|
|
|
Variable->getNameAsString());
|
2011-02-22 14:44:22 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var);
|
|
|
|
void EmitAutoVarInit(const AutoVarEmission &emission);
|
|
|
|
void EmitAutoVarCleanups(const AutoVarEmission &emission);
|
2011-07-09 09:37:26 +08:00
|
|
|
void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
|
|
|
|
QualType::DestructionKind dtorKind);
|
2009-07-19 14:58:07 +08:00
|
|
|
|
2010-10-15 12:57:14 +08:00
|
|
|
void EmitStaticVarDecl(const VarDecl &D,
|
|
|
|
llvm::GlobalValue::LinkageTypes Linkage);
|
2008-08-16 11:19:19 +08:00
|
|
|
|
|
|
|
/// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
|
2011-03-04 04:13:15 +08:00
|
|
|
void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, unsigned ArgNo);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
/// protectFromPeepholes - Protect a value that we're intending to
|
|
|
|
/// store to the side, but which will probably be used later, from
|
|
|
|
/// aggressive peepholing optimizations that might delete it.
|
|
|
|
///
|
|
|
|
/// Pass the result to unprotectFromPeepholes to declare that
|
|
|
|
/// protection is no longer required.
|
|
|
|
///
|
|
|
|
/// There's no particular reason why this shouldn't apply to
|
|
|
|
/// l-values, it's just that no existing peepholes work on pointers.
|
|
|
|
PeepholeProtection protectFromPeepholes(RValue rvalue);
|
|
|
|
void unprotectFromPeepholes(PeepholeProtection protection);
|
|
|
|
|
2007-05-30 07:50:05 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Statement Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
|
2008-11-12 16:21:33 +08:00
|
|
|
void EmitStopPoint(const Stmt *S);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStmt - Emit the code for the statement \arg S. It is legal to call
|
|
|
|
/// this function even if there is no current insertion point.
|
|
|
|
///
|
|
|
|
/// This function may clear the current insertion point; callers should use
|
|
|
|
/// EnsureInsertPoint if they wish to subsequently generate code without first
|
|
|
|
/// calling EmitBlock, EmitBranch, or EmitStmt.
|
2007-05-30 07:50:05 +08:00
|
|
|
void EmitStmt(const Stmt *S);
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2008-11-12 16:21:33 +08:00
|
|
|
/// EmitSimpleStmt - Try to emit a "simple" statement which does not
|
2009-02-09 07:14:22 +08:00
|
|
|
/// necessarily require an insertion point or debug information; typically
|
|
|
|
/// because the statement amounts to a jump or a container of other
|
|
|
|
/// statements.
|
2008-11-12 16:21:33 +08:00
|
|
|
///
|
|
|
|
/// \return True if the statement was handled.
|
|
|
|
bool EmitSimpleStmt(const Stmt *S);
|
|
|
|
|
2007-09-01 06:49:20 +08:00
|
|
|
RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
|
2010-09-15 18:14:12 +08:00
|
|
|
AggValueSlot AVS = AggValueSlot::ignored());
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitLabel - Emit the block for the given label. It is legal to call this
|
|
|
|
/// function even if there is no current insertion point.
|
2011-02-17 15:39:24 +08:00
|
|
|
void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt.
|
2008-11-12 07:11:34 +08:00
|
|
|
|
2007-05-30 08:13:02 +08:00
|
|
|
void EmitLabelStmt(const LabelStmt &S);
|
|
|
|
void EmitGotoStmt(const GotoStmt &S);
|
2008-08-05 00:51:22 +08:00
|
|
|
void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
|
2007-05-31 05:03:58 +08:00
|
|
|
void EmitIfStmt(const IfStmt &S);
|
2007-06-05 11:59:43 +08:00
|
|
|
void EmitWhileStmt(const WhileStmt &S);
|
2007-06-06 04:53:16 +08:00
|
|
|
void EmitDoStmt(const DoStmt &S);
|
|
|
|
void EmitForStmt(const ForStmt &S);
|
2007-06-02 11:19:07 +08:00
|
|
|
void EmitReturnStmt(const ReturnStmt &S);
|
2007-06-09 09:20:56 +08:00
|
|
|
void EmitDeclStmt(const DeclStmt &S);
|
2008-11-12 16:21:33 +08:00
|
|
|
void EmitBreakStmt(const BreakStmt &S);
|
|
|
|
void EmitContinueStmt(const ContinueStmt &S);
|
2007-10-05 07:45:31 +08:00
|
|
|
void EmitSwitchStmt(const SwitchStmt &S);
|
|
|
|
void EmitDefaultStmt(const DefaultStmt &S);
|
|
|
|
void EmitCaseStmt(const CaseStmt &S);
|
2007-10-09 04:57:48 +08:00
|
|
|
void EmitCaseStmtRange(const CaseStmt &S);
|
2008-02-06 00:35:33 +08:00
|
|
|
void EmitAsmStmt(const AsmStmt &S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-31 03:51:14 +08:00
|
|
|
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
|
2008-09-09 18:04:29 +08:00
|
|
|
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
|
|
|
|
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
|
2008-11-16 05:26:17 +08:00
|
|
|
void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
|
2011-06-16 07:02:42 +08:00
|
|
|
void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-05-29 05:13:02 +08:00
|
|
|
llvm::Constant *getUnwindResumeFn();
|
2010-05-16 09:24:12 +08:00
|
|
|
llvm::Constant *getUnwindResumeOrRethrowFn();
|
2010-07-07 14:56:46 +08:00
|
|
|
void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
|
|
|
|
void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
|
2010-02-19 17:25:03 +08:00
|
|
|
|
2009-09-28 02:58:34 +08:00
|
|
|
void EmitCXXTryStmt(const CXXTryStmt &S);
|
2011-04-15 06:09:26 +08:00
|
|
|
void EmitCXXForRangeStmt(const CXXForRangeStmt &S);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2007-06-02 13:24:33 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// LValue Expression Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2009-02-05 15:09:07 +08:00
|
|
|
/// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
|
|
|
|
RValue GetUndefRValue(QualType Ty);
|
|
|
|
|
2009-01-10 00:50:52 +08:00
|
|
|
/// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
|
|
|
|
/// and issue an ErrorUnsupported style diagnostic (using the
|
|
|
|
/// provided Name).
|
|
|
|
RValue EmitUnsupportedRValue(const Expr *E,
|
|
|
|
const char *Name);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
|
|
|
|
/// an ErrorUnsupported style diagnostic (using the provided Name).
|
2008-08-26 04:45:57 +08:00
|
|
|
LValue EmitUnsupportedLValue(const Expr *E,
|
|
|
|
const char *Name);
|
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLValue - Emit code to compute a designator that specifies the location
|
|
|
|
/// of the expression.
|
|
|
|
///
|
|
|
|
/// This can return one of two things: a simple address or a bitfield
|
|
|
|
/// reference. In either case, the LLVM Value* in the LValue structure is
|
|
|
|
/// guaranteed to be an LLVM pointer type.
|
|
|
|
///
|
|
|
|
/// If this returns a bitfield reference, nothing about the pointee type of
|
|
|
|
/// the LLVM value is known: For example, it may not be a pointer to an
|
|
|
|
/// integer.
|
|
|
|
///
|
|
|
|
/// If this returns a normal address, and if the lvalue's C type is fixed
|
|
|
|
/// size, this method guarantees that the returned pointer type will point to
|
|
|
|
/// an LLVM type of the same size of the lvalue's type. If the lvalue has a
|
|
|
|
/// variable length type, this is not possible.
|
|
|
|
///
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue EmitLValue(const Expr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2009-12-16 10:57:00 +08:00
|
|
|
/// EmitCheckedLValue - Same as EmitLValue but additionally we generate
|
|
|
|
/// checking code to guard against undefined behavior. This is only
|
|
|
|
/// suitable when we know that the address will be used to access the
|
|
|
|
/// object.
|
|
|
|
LValue EmitCheckedLValue(const Expr *E);
|
|
|
|
|
2010-10-28 04:58:56 +08:00
|
|
|
/// EmitToMemory - Change a scalar value from its value
|
|
|
|
/// representation to its in-memory representation.
|
|
|
|
llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty);
|
|
|
|
|
|
|
|
/// EmitFromMemory - Change a scalar value from its memory
|
|
|
|
/// representation to its value representation.
|
|
|
|
llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty);
|
|
|
|
|
2009-02-10 08:57:50 +08:00
|
|
|
/// EmitLoadOfScalar - Load a scalar value from an address, taking
|
|
|
|
/// care to appropriately convert from the memory representation to
|
|
|
|
/// the LLVM value representation.
|
2009-02-18 01:00:02 +08:00
|
|
|
llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
|
2010-10-15 07:06:10 +08:00
|
|
|
unsigned Alignment, QualType Ty,
|
|
|
|
llvm::MDNode *TBAAInfo = 0);
|
2011-06-25 10:11:03 +08:00
|
|
|
|
|
|
|
/// EmitLoadOfScalar - Load a scalar value from an address, taking
|
|
|
|
/// care to appropriately convert from the memory representation to
|
|
|
|
/// the LLVM value representation. The l-value must be a simple
|
|
|
|
/// l-value.
|
2011-06-16 12:16:24 +08:00
|
|
|
llvm::Value *EmitLoadOfScalar(LValue lvalue);
|
2009-02-10 08:57:50 +08:00
|
|
|
|
|
|
|
/// EmitStoreOfScalar - Store a scalar value to an address, taking
|
|
|
|
/// care to appropriately convert from the memory representation to
|
|
|
|
/// the LLVM value representation.
|
2009-02-18 01:00:02 +08:00
|
|
|
void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
|
2010-10-15 07:06:10 +08:00
|
|
|
bool Volatile, unsigned Alignment, QualType Ty,
|
2012-01-17 01:27:18 +08:00
|
|
|
llvm::MDNode *TBAAInfo = 0, bool isInit=false);
|
2011-06-25 10:11:03 +08:00
|
|
|
|
|
|
|
/// EmitStoreOfScalar - Store a scalar value to an address, taking
|
|
|
|
/// care to appropriately convert from the memory representation to
|
|
|
|
/// the LLVM value representation. The l-value must be a simple
|
2012-01-17 01:27:18 +08:00
|
|
|
/// l-value. The isInit flag indicates whether this is an initialization.
|
|
|
|
/// If so, atomic qualifiers are ignored and the store is always non-atomic.
|
|
|
|
void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false);
|
2009-02-10 08:57:50 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitLoadOfLValue - Given an expression that represents a value lvalue,
|
|
|
|
/// this method emits the address of the lvalue, then loads the result as an
|
|
|
|
/// rvalue, returning the rvalue.
|
2011-06-25 10:11:03 +08:00
|
|
|
RValue EmitLoadOfLValue(LValue V);
|
|
|
|
RValue EmitLoadOfExtVectorElementLValue(LValue V);
|
|
|
|
RValue EmitLoadOfBitfieldLValue(LValue LV);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-06-06 04:53:16 +08:00
|
|
|
/// EmitStoreThroughLValue - Store the specified rvalue into the specified
|
|
|
|
/// lvalue, where both are guaranteed to the have the same type, and that type
|
|
|
|
/// is 'Ty'.
|
2012-01-17 01:27:18 +08:00
|
|
|
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false);
|
2011-06-25 10:11:03 +08:00
|
|
|
void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);
|
2008-11-19 17:36:46 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitStoreThroughLValue - Store Src into Dst with same constraints as
|
|
|
|
/// EmitStoreThroughLValue.
|
2008-11-19 17:36:46 +08:00
|
|
|
///
|
2009-02-09 07:14:22 +08:00
|
|
|
/// \param Result [out] - If non-null, this will be set to a Value* for the
|
|
|
|
/// bit-field contents after the store, appropriate for use as the result of
|
|
|
|
/// an assignment to the bit-field.
|
2011-06-25 10:11:03 +08:00
|
|
|
void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
|
2008-11-19 17:36:46 +08:00
|
|
|
llvm::Value **Result=0);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-11-17 07:07:28 +08:00
|
|
|
/// Emit an l-value for an assignment (simple or compound) of complex type.
|
|
|
|
LValue EmitComplexAssignmentLValue(const BinaryOperator *E);
|
2010-12-05 10:00:02 +08:00
|
|
|
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E);
|
2010-11-17 07:07:28 +08:00
|
|
|
|
2011-04-15 13:22:18 +08:00
|
|
|
// Note: only available for agg return types
|
2008-09-04 11:20:13 +08:00
|
|
|
LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
|
2010-12-05 10:00:02 +08:00
|
|
|
LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E);
|
2009-02-12 04:59:32 +08:00
|
|
|
// Note: only available for agg return types
|
2007-12-29 13:02:41 +08:00
|
|
|
LValue EmitCallExprLValue(const CallExpr *E);
|
2009-02-12 04:59:32 +08:00
|
|
|
// Note: only available for agg return types
|
|
|
|
LValue EmitVAArgExprLValue(const VAArgExpr *E);
|
2007-06-02 13:24:33 +08:00
|
|
|
LValue EmitDeclRefLValue(const DeclRefExpr *E);
|
2007-06-06 12:54:52 +08:00
|
|
|
LValue EmitStringLiteralLValue(const StringLiteral *E);
|
2009-02-25 06:18:39 +08:00
|
|
|
LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
|
2008-08-10 09:53:14 +08:00
|
|
|
LValue EmitPredefinedLValue(const PredefinedExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
LValue EmitUnaryOpLValue(const UnaryOperator *E);
|
2007-06-09 07:31:14 +08:00
|
|
|
LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
|
2008-04-19 07:10:10 +08:00
|
|
|
LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
|
2007-10-23 10:10:49 +08:00
|
|
|
LValue EmitMemberExpr(const MemberExpr *E);
|
2009-12-10 07:35:29 +08:00
|
|
|
LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
|
2008-05-14 07:18:27 +08:00
|
|
|
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
|
2011-02-17 18:25:35 +08:00
|
|
|
LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E);
|
2009-03-19 02:28:57 +08:00
|
|
|
LValue EmitCastLValue(const CastExpr *E);
|
2010-07-08 14:14:04 +08:00
|
|
|
LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E);
|
2011-06-22 01:03:29 +08:00
|
|
|
LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
|
2011-02-16 16:02:54 +08:00
|
|
|
LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2011-11-06 17:01:30 +08:00
|
|
|
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e,
|
|
|
|
AggValueSlot slot = AggValueSlot::ignored());
|
|
|
|
LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e);
|
|
|
|
|
2009-04-22 13:08:15 +08:00
|
|
|
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
|
2008-09-24 12:00:38 +08:00
|
|
|
const ObjCIvarDecl *Ivar);
|
2010-05-21 09:18:57 +08:00
|
|
|
LValue EmitLValueForAnonRecordField(llvm::Value* Base,
|
2010-12-04 17:14:42 +08:00
|
|
|
const IndirectFieldDecl* Field,
|
2010-05-21 09:18:57 +08:00
|
|
|
unsigned CVRQualifiers);
|
2009-11-17 11:57:07 +08:00
|
|
|
LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
|
2010-01-29 13:05:36 +08:00
|
|
|
unsigned CVRQualifiers);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-01-29 13:24:29 +08:00
|
|
|
/// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
|
|
|
|
/// if the Field is a reference, this will return the address of the reference
|
|
|
|
/// and not the address of the value stored in the reference.
|
2010-10-19 14:39:39 +08:00
|
|
|
LValue EmitLValueForFieldInitialization(llvm::Value* Base,
|
2010-01-29 13:24:29 +08:00
|
|
|
const FieldDecl* Field,
|
|
|
|
unsigned CVRQualifiers);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-02-03 08:09:52 +08:00
|
|
|
LValue EmitLValueForIvar(QualType ObjectTy,
|
|
|
|
llvm::Value* Base, const ObjCIvarDecl *Ivar,
|
2008-09-24 12:00:38 +08:00
|
|
|
unsigned CVRQualifiers);
|
|
|
|
|
2009-11-17 11:57:07 +08:00
|
|
|
LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field,
|
2009-02-04 03:03:09 +08:00
|
|
|
unsigned CVRQualifiers);
|
2008-12-16 04:35:07 +08:00
|
|
|
|
2009-02-28 17:07:16 +08:00
|
|
|
LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
|
|
|
|
|
2009-05-31 07:23:33 +08:00
|
|
|
LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
|
2009-05-31 07:30:54 +08:00
|
|
|
LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
|
2012-02-08 13:34:55 +08:00
|
|
|
LValue EmitLambdaLValue(const LambdaExpr *E);
|
2009-11-15 16:09:41 +08:00
|
|
|
LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2008-08-23 18:51:21 +08:00
|
|
|
LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
|
2008-03-31 07:03:07 +08:00
|
|
|
LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
|
2009-04-26 03:35:26 +08:00
|
|
|
LValue EmitStmtExprLValue(const StmtExpr *E);
|
2009-10-23 06:57:31 +08:00
|
|
|
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
|
2010-06-18 03:56:20 +08:00
|
|
|
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
|
2010-10-09 09:34:31 +08:00
|
|
|
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init);
|
2011-02-17 18:25:35 +08:00
|
|
|
|
2007-05-31 01:57:17 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-11 08:04:45 +08:00
|
|
|
// Scalar Expression Emission
|
2007-05-31 01:57:17 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitCall - Generate a call of the given function, expecting the given
|
|
|
|
/// result type, and using the given argument list which specifies both the
|
|
|
|
/// LLVM arguments and the types they were derived from.
|
2009-02-21 02:06:48 +08:00
|
|
|
///
|
2009-12-01 04:08:49 +08:00
|
|
|
/// \param TargetDecl - If given, the decl of the function in a direct call;
|
|
|
|
/// used to set attributes on the call (noreturn, etc.).
|
2009-02-03 06:03:45 +08:00
|
|
|
RValue EmitCall(const CGFunctionInfo &FnInfo,
|
|
|
|
llvm::Value *Callee,
|
2009-12-25 03:25:24 +08:00
|
|
|
ReturnValueSlot ReturnValue,
|
2009-02-21 02:06:48 +08:00
|
|
|
const CallArgList &Args,
|
2010-05-01 19:15:56 +08:00
|
|
|
const Decl *TargetDecl = 0,
|
2010-05-02 21:41:58 +08:00
|
|
|
llvm::Instruction **callOrInvoke = 0);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-12-25 03:08:58 +08:00
|
|
|
RValue EmitCall(QualType FnType, llvm::Value *Callee,
|
2009-12-25 04:40:36 +08:00
|
|
|
ReturnValueSlot ReturnValue,
|
2009-05-27 09:22:39 +08:00
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd,
|
|
|
|
const Decl *TargetDecl = 0);
|
2010-10-19 14:39:39 +08:00
|
|
|
RValue EmitCallExpr(const CallExpr *E,
|
2009-12-25 04:40:36 +08:00
|
|
|
ReturnValueSlot ReturnValue = ReturnValueSlot());
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-06 09:34:17 +08:00
|
|
|
llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee,
|
2011-07-24 01:14:25 +08:00
|
|
|
ArrayRef<llvm::Value *> Args,
|
2011-07-20 15:06:53 +08:00
|
|
|
const Twine &Name = "");
|
2011-07-15 16:37:34 +08:00
|
|
|
llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee,
|
2011-07-20 15:06:53 +08:00
|
|
|
const Twine &Name = "");
|
2010-07-06 09:34:17 +08:00
|
|
|
|
2009-11-13 12:45:41 +08:00
|
|
|
llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *Ty);
|
2010-10-19 14:39:39 +08:00
|
|
|
llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Value *This, llvm::Type *Ty);
|
2011-01-21 01:19:02 +08:00
|
|
|
llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD,
|
|
|
|
NestedNameSpecifier *Qual,
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *Ty);
|
2011-02-02 07:22:34 +08:00
|
|
|
|
|
|
|
llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD,
|
|
|
|
CXXDtorType Type,
|
2011-02-04 03:27:17 +08:00
|
|
|
const CXXRecordDecl *RD);
|
2009-11-13 12:45:41 +08:00
|
|
|
|
2009-05-12 07:37:08 +08:00
|
|
|
RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
|
|
|
|
llvm::Value *Callee,
|
2009-12-25 05:13:40 +08:00
|
|
|
ReturnValueSlot ReturnValue,
|
2009-05-12 07:37:08 +08:00
|
|
|
llvm::Value *This,
|
2010-01-02 09:01:18 +08:00
|
|
|
llvm::Value *VTT,
|
2009-05-12 07:37:08 +08:00
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
|
|
|
CallExpr::const_arg_iterator ArgEnd);
|
2009-12-25 05:13:40 +08:00
|
|
|
RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
|
|
|
|
ReturnValueSlot ReturnValue);
|
|
|
|
RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
|
|
|
|
ReturnValueSlot ReturnValue);
|
This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.
The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.
For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.
A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).
This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.
llvm-svn: 52378
2008-06-17 10:43:46 +08:00
|
|
|
|
2011-05-09 04:32:23 +08:00
|
|
|
llvm::Value *EmitCXXOperatorMemberCallee(const CXXOperatorCallExpr *E,
|
|
|
|
const CXXMethodDecl *MD,
|
|
|
|
llvm::Value *This);
|
2009-05-27 12:18:27 +08:00
|
|
|
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
|
2009-12-25 05:13:40 +08:00
|
|
|
const CXXMethodDecl *MD,
|
|
|
|
ReturnValueSlot ReturnValue);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-10-07 02:29:37 +08:00
|
|
|
RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
|
|
|
|
ReturnValueSlot ReturnValue);
|
|
|
|
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
RValue EmitBuiltinExpr(const FunctionDecl *FD,
|
2009-02-17 06:43:43 +08:00
|
|
|
unsigned BuiltinID, const CallExpr *E);
|
2007-06-06 04:53:16 +08:00
|
|
|
|
2009-12-25 05:13:40 +08:00
|
|
|
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue);
|
2009-02-18 01:00:02 +08:00
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
|
|
|
|
/// is unhandled by the current target.
|
2008-10-10 08:24:54 +08:00
|
|
|
llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
|
|
|
|
2010-03-04 03:03:45 +08:00
|
|
|
llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2010-10-19 14:39:39 +08:00
|
|
|
llvm::Value *EmitNeonCall(llvm::Function *F,
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVectorImpl<llvm::Value*> &O,
|
2010-12-09 06:37:56 +08:00
|
|
|
const char *name,
|
2010-06-14 13:21:25 +08:00
|
|
|
unsigned shift = 0, bool rightshift = false);
|
2010-12-08 06:40:02 +08:00
|
|
|
llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty,
|
2010-06-14 13:21:25 +08:00
|
|
|
bool negateForRightShift);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2012-02-22 17:30:11 +08:00
|
|
|
llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops);
|
2007-12-10 07:17:02 +08:00
|
|
|
llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2011-12-13 05:14:55 +08:00
|
|
|
llvm::Value *EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2007-12-10 07:17:02 +08:00
|
|
|
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-08-20 08:28:19 +08:00
|
|
|
llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
|
2007-08-24 13:35:26 +08:00
|
|
|
llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
|
2008-06-25 01:04:18 +08:00
|
|
|
llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
|
2010-05-22 09:48:05 +08:00
|
|
|
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E,
|
|
|
|
ReturnValueSlot Return = ReturnValueSlot());
|
2008-06-25 01:04:18 +08:00
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
/// Retrieves the default cleanup kind for an ARC cleanup.
|
|
|
|
/// Except under -fobjc-arc-eh, ARC cleanups are normal-only.
|
|
|
|
CleanupKind getARCCleanupKind() {
|
|
|
|
return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions
|
|
|
|
? NormalAndEHCleanup : NormalCleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ARC primitives.
|
|
|
|
void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr);
|
|
|
|
void EmitARCDestroyWeak(llvm::Value *addr);
|
|
|
|
llvm::Value *EmitARCLoadWeak(llvm::Value *addr);
|
|
|
|
llvm::Value *EmitARCLoadWeakRetained(llvm::Value *addr);
|
|
|
|
llvm::Value *EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr,
|
|
|
|
bool ignored);
|
|
|
|
void EmitARCCopyWeak(llvm::Value *dst, llvm::Value *src);
|
|
|
|
void EmitARCMoveWeak(llvm::Value *dst, llvm::Value *src);
|
|
|
|
llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);
|
|
|
|
llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value);
|
2011-06-25 10:11:03 +08:00
|
|
|
llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value,
|
|
|
|
bool ignored);
|
2011-06-16 07:02:42 +08:00
|
|
|
llvm::Value *EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value,
|
|
|
|
bool ignored);
|
|
|
|
llvm::Value *EmitARCRetain(QualType type, llvm::Value *value);
|
|
|
|
llvm::Value *EmitARCRetainNonBlock(llvm::Value *value);
|
2011-10-04 14:23:45 +08:00
|
|
|
llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory);
|
2011-06-16 07:02:42 +08:00
|
|
|
void EmitARCRelease(llvm::Value *value, bool precise);
|
|
|
|
llvm::Value *EmitARCAutorelease(llvm::Value *value);
|
|
|
|
llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value);
|
|
|
|
llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value);
|
|
|
|
llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
|
|
|
|
|
|
|
|
std::pair<LValue,llvm::Value*>
|
|
|
|
EmitARCStoreAutoreleasing(const BinaryOperator *e);
|
|
|
|
std::pair<LValue,llvm::Value*>
|
|
|
|
EmitARCStoreStrong(const BinaryOperator *e, bool ignored);
|
|
|
|
|
2011-10-01 18:32:24 +08:00
|
|
|
llvm::Value *EmitObjCThrowOperand(const Expr *expr);
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
llvm::Value *EmitObjCProduceObject(QualType T, llvm::Value *Ptr);
|
|
|
|
llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr);
|
|
|
|
llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr);
|
|
|
|
|
2011-10-04 14:23:45 +08:00
|
|
|
llvm::Value *EmitARCExtendBlockObject(const Expr *expr);
|
2011-06-16 07:02:42 +08:00
|
|
|
llvm::Value *EmitARCRetainScalarExpr(const Expr *expr);
|
|
|
|
llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr);
|
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
static Destroyer destroyARCStrongImprecise;
|
|
|
|
static Destroyer destroyARCStrongPrecise;
|
|
|
|
static Destroyer destroyARCWeak;
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr);
|
|
|
|
llvm::Value *EmitObjCAutoreleasePoolPush();
|
|
|
|
llvm::Value *EmitObjCMRRAutoreleasePoolPush();
|
|
|
|
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
|
|
|
|
void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr);
|
|
|
|
|
2009-05-20 08:24:07 +08:00
|
|
|
/// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
|
|
|
|
/// expression. Will emit a temporary variable if E is not an LValue.
|
2010-10-19 14:39:39 +08:00
|
|
|
RValue EmitReferenceBindingToExpr(const Expr* E,
|
2010-06-27 00:35:32 +08:00
|
|
|
const NamedDecl *InitializedDecl);
|
2010-02-01 02:34:51 +08:00
|
|
|
|
2007-08-11 08:04:45 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-27 07:13:56 +08:00
|
|
|
// Expression Emission
|
2007-08-11 08:04:45 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
2007-08-27 07:13:56 +08:00
|
|
|
|
|
|
|
// Expressions are broken into three classes: scalar, complex, aggregate.
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
/// EmitScalarExpr - Emit the computation of the specified expression of LLVM
|
|
|
|
/// scalar type, returning the result.
|
2009-08-16 15:36:22 +08:00
|
|
|
llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-26 14:48:56 +08:00
|
|
|
/// EmitScalarConversion - Emit a conversion from the specified type to the
|
|
|
|
/// specified destination type, both of which are LLVM scalar types.
|
|
|
|
llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
|
|
|
|
QualType DstTy);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-27 00:34:22 +08:00
|
|
|
/// EmitComplexToScalarConversion - Emit a conversion from the specified
|
2009-02-09 07:14:22 +08:00
|
|
|
/// complex type to the specified destination type, where the destination type
|
|
|
|
/// is an LLVM scalar type.
|
2007-08-27 00:34:22 +08:00
|
|
|
llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
|
|
|
|
QualType DstTy);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
|
|
|
|
2010-09-15 18:14:12 +08:00
|
|
|
/// EmitAggExpr - Emit the computation of the specified expression
|
|
|
|
/// of aggregate type. The result is computed into the given slot,
|
|
|
|
/// which may be null to indicate that the value is not needed.
|
2010-09-16 08:20:07 +08:00
|
|
|
void EmitAggExpr(const Expr *E, AggValueSlot AS, bool IgnoreResult = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-02-06 03:38:31 +08:00
|
|
|
/// EmitAggExprToLValue - Emit the computation of the specified expression of
|
|
|
|
/// aggregate type into a temporary LValue.
|
|
|
|
LValue EmitAggExprToLValue(const Expr *E);
|
|
|
|
|
2009-07-08 09:18:33 +08:00
|
|
|
/// EmitGCMemmoveCollectable - Emit special API for structs with object
|
|
|
|
/// pointers.
|
|
|
|
void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
|
2009-09-01 03:33:16 +08:00
|
|
|
QualType Ty);
|
2009-07-08 09:18:33 +08:00
|
|
|
|
2011-06-25 07:21:27 +08:00
|
|
|
/// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
|
|
|
|
/// make sure it survives garbage collection until this point.
|
|
|
|
void EmitExtendGCLifetime(llvm::Value *object);
|
|
|
|
|
2007-08-21 13:54:00 +08:00
|
|
|
/// EmitComplexExpr - Emit the computation of the specified expression of
|
2007-08-24 07:43:33 +08:00
|
|
|
/// complex type, returning the result.
|
2010-11-16 18:08:07 +08:00
|
|
|
ComplexPairTy EmitComplexExpr(const Expr *E,
|
|
|
|
bool IgnoreReal = false,
|
|
|
|
bool IgnoreImag = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2007-08-24 07:43:33 +08:00
|
|
|
/// EmitComplexExprIntoAddr - Emit the computation of the specified expression
|
|
|
|
/// of complex type, storing into the specified Value*.
|
2007-08-27 00:22:13 +08:00
|
|
|
void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
|
|
|
|
bool DestIsVolatile);
|
2008-08-30 13:35:15 +08:00
|
|
|
|
|
|
|
/// StoreComplexToAddr - Store a complex number into the specified address.
|
|
|
|
void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
|
|
|
|
bool DestIsVolatile);
|
2007-09-01 06:49:20 +08:00
|
|
|
/// LoadComplexFromAddr - Load a complex number from the specified address.
|
|
|
|
ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
|
2008-05-08 13:58:21 +08:00
|
|
|
|
2010-10-15 12:57:14 +08:00
|
|
|
/// CreateStaticVarDecl - Create a zero-initialized LLVM global for
|
|
|
|
/// a static local variable.
|
|
|
|
llvm::GlobalVariable *CreateStaticVarDecl(const VarDecl &D,
|
|
|
|
const char *Separator,
|
2009-12-01 04:08:49 +08:00
|
|
|
llvm::GlobalValue::LinkageTypes Linkage);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-10-15 12:57:14 +08:00
|
|
|
/// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the
|
2009-12-05 16:22:11 +08:00
|
|
|
/// global variable that has already been created for it. If the initializer
|
|
|
|
/// has a different type than GV does, this may free GV and return a different
|
|
|
|
/// one. Otherwise it just returns GV.
|
|
|
|
llvm::GlobalVariable *
|
2010-10-15 12:57:14 +08:00
|
|
|
AddInitializerToStaticVarDecl(const VarDecl &D,
|
|
|
|
llvm::GlobalVariable *GV);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2009-02-26 03:24:29 +08:00
|
|
|
|
2009-08-09 05:45:14 +08:00
|
|
|
/// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
|
|
|
|
/// variable with global storage.
|
2012-02-14 06:16:19 +08:00
|
|
|
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr,
|
|
|
|
bool PerformInit);
|
2009-08-09 05:45:14 +08:00
|
|
|
|
|
|
|
/// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr
|
|
|
|
/// with the C++ runtime so that its destructor will be called at exit.
|
2009-11-11 03:24:06 +08:00
|
|
|
void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
|
2009-08-09 05:45:14 +08:00
|
|
|
llvm::Constant *DeclPtr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-11-06 17:44:32 +08:00
|
|
|
/// Emit code in this function to perform a guarded variable
|
|
|
|
/// initialization. Guarded initializations are used when it's not
|
|
|
|
/// possible to prove that an initialization will be done exactly
|
|
|
|
/// once, e.g. with a static local variable or a static data member
|
|
|
|
/// of a class template.
|
2012-02-14 06:16:19 +08:00
|
|
|
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr,
|
|
|
|
bool PerformInit);
|
2010-09-08 09:44:27 +08:00
|
|
|
|
2010-03-20 12:15:41 +08:00
|
|
|
/// GenerateCXXGlobalInitFunc - Generates code for initializing global
|
|
|
|
/// variables.
|
|
|
|
void GenerateCXXGlobalInitFunc(llvm::Function *Fn,
|
|
|
|
llvm::Constant **Decls,
|
|
|
|
unsigned NumDecls);
|
|
|
|
|
|
|
|
/// GenerateCXXGlobalDtorFunc - Generates code for destroying global
|
|
|
|
/// variables.
|
|
|
|
void GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
|
2010-06-19 13:52:45 +08:00
|
|
|
const std::vector<std::pair<llvm::WeakVH,
|
2010-03-20 12:15:41 +08:00
|
|
|
llvm::Constant*> > &DtorsAndObjects);
|
|
|
|
|
2011-03-09 12:27:21 +08:00
|
|
|
void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
|
|
|
|
const VarDecl *D,
|
2012-02-14 06:16:19 +08:00
|
|
|
llvm::GlobalVariable *Addr,
|
|
|
|
bool PerformInit);
|
2010-03-20 12:15:41 +08:00
|
|
|
|
2010-09-15 18:14:12 +08:00
|
|
|
void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest);
|
2010-11-14 05:53:34 +08:00
|
|
|
|
|
|
|
void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src,
|
2010-12-03 01:02:11 +08:00
|
|
|
const Expr *Exp);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-11-10 16:15:53 +08:00
|
|
|
void enterFullExpression(const ExprWithCleanups *E) {
|
|
|
|
if (E->getNumObjects() == 0) return;
|
|
|
|
enterNonTrivialFullExpression(E);
|
|
|
|
}
|
|
|
|
void enterNonTrivialFullExpression(const ExprWithCleanups *E);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-10-30 09:42:31 +08:00
|
|
|
void EmitCXXThrowExpr(const CXXThrowExpr *E);
|
2010-05-16 08:44:00 +08:00
|
|
|
|
2012-02-09 11:32:31 +08:00
|
|
|
void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest);
|
|
|
|
|
2011-10-11 10:20:01 +08:00
|
|
|
RValue EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest = 0);
|
|
|
|
|
2011-09-10 06:41:49 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Annotations Emission
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Emit an annotation call (intrinsic or builtin).
|
|
|
|
llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn,
|
|
|
|
llvm::Value *AnnotatedVal,
|
|
|
|
llvm::StringRef AnnotationStr,
|
|
|
|
SourceLocation Location);
|
|
|
|
|
|
|
|
/// Emit local annotations for the local variable V, declared by D.
|
|
|
|
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V);
|
|
|
|
|
|
|
|
/// Emit field annotations for the given field & value. Returns the
|
|
|
|
/// annotation result.
|
|
|
|
llvm::Value *EmitFieldAnnotations(const FieldDecl *D, llvm::Value *V);
|
|
|
|
|
2008-08-05 00:51:22 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Internal Helpers
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2008-11-11 15:41:27 +08:00
|
|
|
/// ContainsLabel - Return true if the statement contains a label in it. If
|
|
|
|
/// this statement is not executed normally, it not containing a label means
|
|
|
|
/// that we can just remove the code.
|
|
|
|
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-02-28 08:18:40 +08:00
|
|
|
/// containsBreak - Return true if the statement contains a break out of it.
|
|
|
|
/// If the statement (recursively) contains a switch or loop with a break
|
|
|
|
/// inside of it, this is fine.
|
|
|
|
static bool containsBreak(const Stmt *S);
|
|
|
|
|
2008-11-12 18:12:14 +08:00
|
|
|
/// ConstantFoldsToSimpleInteger - If the specified expression does not fold
|
2011-02-28 07:02:32 +08:00
|
|
|
/// to a constant, or if it does but contains a label, return false. If it
|
|
|
|
/// constant folds return true and set the boolean result in Result.
|
|
|
|
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2011-02-28 08:18:40 +08:00
|
|
|
/// ConstantFoldsToSimpleInteger - If the specified expression does not fold
|
|
|
|
/// to a constant, or if it does but contains a label, return false. If it
|
|
|
|
/// constant folds return true and set the folded value.
|
|
|
|
bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APInt &Result);
|
|
|
|
|
2008-11-12 16:04:58 +08:00
|
|
|
/// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
|
|
|
|
/// if statement) to the specified blocks. Based on the condition, this might
|
|
|
|
/// try to simplify the codegen of the conditional based on the branch.
|
Make emission of 'if' conditions much more sophisticated when we
have a condition that is an &&/||. Before we used to compile things like this:
int test() {
if (x && y) foo(); else bar();
}
into:
%0 = load i32* @x ; <i32> [#uses=1]
%1 = icmp ne i32 %0, 0 ; <i1> [#uses=1]
br i1 %1, label %land_rhs, label %land_cont
land_rhs: ; preds = %entry
%2 = load i32* @y ; <i32> [#uses=1]
%3 = icmp ne i32 %2, 0 ; <i1> [#uses=1]
br label %land_cont
land_cont: ; preds = %land_rhs, %entry
%4 = phi i1 [ false, %entry ], [ %3, %land_rhs ] ; <i1> [#uses=1]
br i1 %4, label %ifthen, label %ifelse
ifthen: ; preds = %land_cont
%call = call i32 (...)* @foo() ; <i32> [#uses=0]
br label %ifend
ifelse: ; preds = %land_cont
%call1 = call i32 (...)* @bar() ; <i32> [#uses=0]
br label %ifend
ifend: ; preds = %ifelse, %ifthen
Now we turn it into the much more svelte code:
%0 = load i32* @x ; <i32> [#uses=1]
%1 = icmp ne i32 %0, 0 ; <i1> [#uses=1]
br i1 %1, label %land_lhs_true, label %ifelse
land_lhs_true: ; preds = %entry
%2 = load i32* @y ; <i32> [#uses=1]
%3 = icmp ne i32 %2, 0 ; <i1> [#uses=1]
br i1 %3, label %ifthen, label %ifelse
ifthen: ; preds = %land_lhs_true
%call = call i32 (...)* @foo() ; <i32> [#uses=0]
br label %ifend
ifelse: ; preds = %land_lhs_true, %entry
%call1 = call i32 (...)* @bar() ; <i32> [#uses=0]
br label %ifend
ifend: ; preds = %ifelse, %ifthen
Note the lack of a phi node.
This shrinks the -O0 .ll file for 176.gcc/expr.c from 43176 to 40267 lines.
llvm-svn: 59111
2008-11-12 15:46:33 +08:00
|
|
|
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
|
2008-11-12 18:12:14 +08:00
|
|
|
llvm::BasicBlock *FalseBlock);
|
2009-12-15 05:58:14 +08:00
|
|
|
|
2009-12-15 08:35:12 +08:00
|
|
|
/// getTrapBB - Create a basic block that will call the trap intrinsic. We'll
|
|
|
|
/// generate a branch around the created basic block as necessary.
|
2010-07-21 04:19:24 +08:00
|
|
|
llvm::BasicBlock *getTrapBB();
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-03-30 11:27:09 +08:00
|
|
|
/// EmitCallArg - Emit a single call argument.
|
2011-03-12 04:59:21 +08:00
|
|
|
void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType);
|
2010-03-30 11:27:09 +08:00
|
|
|
|
2010-05-27 06:34:26 +08:00
|
|
|
/// EmitDelegateCallArg - We are performing a delegate call; that
|
|
|
|
/// is, the current function is delegating to another one. Produce
|
|
|
|
/// a r-value suitable for passing the given parameter.
|
2011-03-12 04:59:21 +08:00
|
|
|
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param);
|
2010-05-27 06:34:26 +08:00
|
|
|
|
2011-10-28 03:19:51 +08:00
|
|
|
/// SetFPAccuracy - Set the minimum required accuracy of the given floating
|
|
|
|
/// point operation, expressed as the maximum relative error in ulp.
|
|
|
|
void SetFPAccuracy(llvm::Value *Val, unsigned AccuracyN,
|
|
|
|
unsigned AccuracyD = 1);
|
|
|
|
|
2008-11-12 16:04:58 +08:00
|
|
|
private:
|
2008-09-24 12:00:38 +08:00
|
|
|
void EmitReturnOfRValue(RValue RV, QualType Ty);
|
|
|
|
|
2008-09-17 08:51:38 +08:00
|
|
|
/// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
|
|
|
|
/// from function arguments into \arg Dst. See ABIArgInfo::Expand.
|
|
|
|
///
|
|
|
|
/// \param AI - The first function argument of the expansion.
|
|
|
|
/// \return The argument following the last expanded function
|
|
|
|
/// argument.
|
2009-02-09 07:14:22 +08:00
|
|
|
llvm::Function::arg_iterator
|
2008-09-17 08:51:38 +08:00
|
|
|
ExpandTypeFromArgs(QualType Ty, LValue Dst,
|
|
|
|
llvm::Function::arg_iterator AI);
|
|
|
|
|
2009-02-09 07:14:22 +08:00
|
|
|
/// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
|
|
|
|
/// Ty, into individual arguments on the provided vector \arg Args. See
|
|
|
|
/// ABIArgInfo::Expand.
|
|
|
|
void ExpandTypeToArgs(QualType Ty, RValue Src,
|
2011-07-20 14:58:45 +08:00
|
|
|
SmallVector<llvm::Value*, 16> &Args,
|
2011-07-12 14:29:11 +08:00
|
|
|
llvm::FunctionType *IRFuncTy);
|
2009-01-12 03:40:10 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value* EmitAsmInput(const AsmStmt &S,
|
2009-05-04 14:56:16 +08:00
|
|
|
const TargetInfo::ConstraintInfo &Info,
|
2009-01-12 03:40:10 +08:00
|
|
|
const Expr *InputExpr, std::string &ConstraintStr);
|
2009-02-09 07:14:22 +08:00
|
|
|
|
2010-07-16 08:55:21 +08:00
|
|
|
llvm::Value* EmitAsmInputLValue(const AsmStmt &S,
|
|
|
|
const TargetInfo::ConstraintInfo &Info,
|
|
|
|
LValue InputValue, QualType InputType,
|
|
|
|
std::string &ConstraintStr);
|
|
|
|
|
2009-04-09 04:47:54 +08:00
|
|
|
/// EmitCallArgs - Emit call arguments for a function.
|
2009-09-09 23:08:12 +08:00
|
|
|
/// The CallArgTypeInfo parameter is used for iterating over the known
|
2009-04-19 04:20:22 +08:00
|
|
|
/// argument types of the function being called.
|
|
|
|
template<typename T>
|
|
|
|
void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
|
2009-04-09 04:47:54 +08:00
|
|
|
CallExpr::const_arg_iterator ArgBeg,
|
2009-04-19 04:20:22 +08:00
|
|
|
CallExpr::const_arg_iterator ArgEnd) {
|
|
|
|
CallExpr::const_arg_iterator Arg = ArgBeg;
|
|
|
|
|
|
|
|
// First, use the argument types that the type info knows about
|
|
|
|
if (CallArgTypeInfo) {
|
|
|
|
for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
|
|
|
|
E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
|
2009-11-18 11:42:04 +08:00
|
|
|
assert(Arg != ArgEnd && "Running over edge of argument list!");
|
2009-04-19 04:20:22 +08:00
|
|
|
QualType ArgType = *I;
|
2010-09-25 01:30:16 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
QualType ActualArgType = Arg->getType();
|
|
|
|
if (ArgType->isPointerType() && ActualArgType->isPointerType()) {
|
2010-10-19 14:39:39 +08:00
|
|
|
QualType ActualBaseType =
|
2010-09-25 01:30:16 +08:00
|
|
|
ActualArgType->getAs<PointerType>()->getPointeeType();
|
2010-10-19 14:39:39 +08:00
|
|
|
QualType ArgBaseType =
|
2010-09-25 01:30:16 +08:00
|
|
|
ArgType->getAs<PointerType>()->getPointeeType();
|
|
|
|
if (ArgBaseType->isVariableArrayType()) {
|
|
|
|
if (const VariableArrayType *VAT =
|
|
|
|
getContext().getAsVariableArrayType(ActualBaseType)) {
|
|
|
|
if (!VAT->getSizeExpr())
|
|
|
|
ActualArgType = ArgType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 04:20:22 +08:00
|
|
|
assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
|
2009-09-09 23:08:12 +08:00
|
|
|
getTypePtr() ==
|
2010-09-25 01:30:16 +08:00
|
|
|
getContext().getCanonicalType(ActualArgType).getTypePtr() &&
|
2009-04-19 04:20:22 +08:00
|
|
|
"type mismatch in call argument!");
|
2010-09-25 01:30:16 +08:00
|
|
|
#endif
|
2011-03-12 04:59:21 +08:00
|
|
|
EmitCallArg(Args, *Arg, ArgType);
|
2009-04-19 04:20:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
// Either we've emitted all the call args, or we have a call to a
|
2009-04-19 04:20:22 +08:00
|
|
|
// variadic function.
|
2009-09-09 23:08:12 +08:00
|
|
|
assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
|
2009-04-19 04:20:22 +08:00
|
|
|
"Extra arguments in non-variadic function!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-19 04:20:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-19 04:20:22 +08:00
|
|
|
// If we still have any arguments, emit them using the type of the argument.
|
2011-03-12 04:59:21 +08:00
|
|
|
for (; Arg != ArgEnd; ++Arg)
|
|
|
|
EmitCallArg(Args, *Arg, Arg->getType());
|
2009-04-19 04:20:22 +08:00
|
|
|
}
|
2010-03-03 12:15:11 +08:00
|
|
|
|
|
|
|
const TargetCodeGenInfo &getTargetHooks() const {
|
|
|
|
return CGM.getTargetCodeGenInfo();
|
|
|
|
}
|
2010-07-07 07:57:41 +08:00
|
|
|
|
|
|
|
void EmitDeclMetadata();
|
2011-03-31 16:03:29 +08:00
|
|
|
|
|
|
|
CodeGenModule::ByrefHelpers *
|
2011-07-18 12:24:23 +08:00
|
|
|
buildByrefHelpers(llvm::StructType &byrefType,
|
2011-03-31 16:03:29 +08:00
|
|
|
const AutoVarEmission &emission);
|
2012-02-16 08:57:37 +08:00
|
|
|
|
|
|
|
void AddObjCARCExceptionMetadata(llvm::Instruction *Inst);
|
2007-05-24 14:29:05 +08:00
|
|
|
};
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-26 12:00:11 +08:00
|
|
|
/// Helper class with most of the code for saving a value for a
|
|
|
|
/// conditional expression cleanup.
|
2011-01-28 18:53:53 +08:00
|
|
|
struct DominatingLLVMValue {
|
2011-01-26 12:00:11 +08:00
|
|
|
typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type;
|
|
|
|
|
|
|
|
/// Answer whether the given value needs extra work to be saved.
|
|
|
|
static bool needsSaving(llvm::Value *value) {
|
|
|
|
// If it's not an instruction, we don't need to save.
|
|
|
|
if (!isa<llvm::Instruction>(value)) return false;
|
|
|
|
|
|
|
|
// If it's an instruction in the entry block, we don't need to save.
|
|
|
|
llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent();
|
|
|
|
return (block != &block->getParent()->getEntryBlock());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Try to save the given value.
|
|
|
|
static saved_type save(CodeGenFunction &CGF, llvm::Value *value) {
|
|
|
|
if (!needsSaving(value)) return saved_type(value, false);
|
|
|
|
|
|
|
|
// Otherwise we need an alloca.
|
|
|
|
llvm::Value *alloca =
|
|
|
|
CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save");
|
|
|
|
CGF.Builder.CreateStore(value, alloca);
|
|
|
|
|
|
|
|
return saved_type(alloca, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) {
|
|
|
|
if (!value.getInt()) return value.getPointer();
|
|
|
|
return CGF.Builder.CreateLoad(value.getPointer());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-01-28 18:53:53 +08:00
|
|
|
/// A partial specialization of DominatingValue for llvm::Values that
|
|
|
|
/// might be llvm::Instructions.
|
|
|
|
template <class T> struct DominatingPointer<T,true> : DominatingLLVMValue {
|
|
|
|
typedef T *type;
|
|
|
|
static type restore(CodeGenFunction &CGF, saved_type value) {
|
|
|
|
return static_cast<T*>(DominatingLLVMValue::restore(CGF, value));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A specialization of DominatingValue for RValue.
|
|
|
|
template <> struct DominatingValue<RValue> {
|
|
|
|
typedef RValue type;
|
|
|
|
class saved_type {
|
|
|
|
enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral,
|
|
|
|
AggregateAddress, ComplexAddress };
|
|
|
|
|
|
|
|
llvm::Value *Value;
|
|
|
|
Kind K;
|
|
|
|
saved_type(llvm::Value *v, Kind k) : Value(v), K(k) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static bool needsSaving(RValue value);
|
|
|
|
static saved_type save(CodeGenFunction &CGF, RValue value);
|
|
|
|
RValue restore(CodeGenFunction &CGF);
|
|
|
|
|
|
|
|
// implementations in CGExprCXX.cpp
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool needsSaving(type value) {
|
|
|
|
return saved_type::needsSaving(value);
|
|
|
|
}
|
|
|
|
static saved_type save(CodeGenFunction &CGF, type value) {
|
|
|
|
return saved_type::save(CGF, value);
|
|
|
|
}
|
2011-01-26 12:00:11 +08:00
|
|
|
static type restore(CodeGenFunction &CGF, saved_type value) {
|
2011-01-28 18:53:53 +08:00
|
|
|
return value.restore(CGF);
|
2011-01-26 12:00:11 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
2012-01-30 04:27:13 +08:00
|
|
|
|
2007-05-24 14:29:05 +08:00
|
|
|
#endif
|