CodeGenFunction.h revision 81407d404a3fc8d24d0e2a052d85cae183033e2b
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump// This is the internal per-function state used for llvm translation.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h"
18e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
20199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck#include "clang/AST/CharUnits.h"
21481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h"
22481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h"
23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h"
24481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h"
2569243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "CodeGenModule.h"
2696bd13ae1ab89f5a04b3ad3ec8ec1864cbba3482Mike Stump#include "CGBlocks.h"
2745d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
280dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
29b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson#include "CGCXX.h"
308f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
318f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
34f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer  class LLVMContext;
35dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall  class MDNode;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
37898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
38259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar  class Twine;
39ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
40f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class CallSite;
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
457267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  class CXXDestructorDecl;
466815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  class CXXTryStmt;
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
48c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
5072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
51c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
52679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
5329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
5429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
55391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
56fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
57af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
59492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  class TargetCodeGenInfo;
60c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
6116f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
6216f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
6316f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
6416f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
655549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
67b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
68e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
69bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
71ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall  class CGBlockInfo;
720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
73f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A branch fixup.  These are required when emitting a goto to a
74f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// label which hasn't been emitted yet.  The goto is optimistically
75f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// emitted as a branch to the basic block for the label, and (if it
76f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// occurs in a scope with non-trivial cleanups) a fixup is added to
77f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// the innermost cleanup.  When a (normal) cleanup is popped, any
78f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// unresolved fixups in that scope are threaded through the cleanup.
79f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallstruct BranchFixup {
80f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The origin of the branch.  Any switch-index stores required by
81f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// cleanup threading are added before this instruction.
82f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::Instruction *Origin;
83f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
84f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The destination of the branch.
85f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///
86f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// This can be set to null to indicate that this fixup was
87f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// successfully resolved.
88f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *Destination;
89f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
90f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The last branch of the fixup.  It is an invariant that
91f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// LatestBranch->getSuccessor(LatestBranchIndex) == Destination.
92f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///
93f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The branch is always either a BranchInst or a SwitchInst.
94f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::TerminatorInst *LatestBranch;
95f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  unsigned LatestBranchIndex;
96f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall};
97f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
98da65ea86482bc116906edfb9ba1d7124f76cc867John McCallenum CleanupKind { NormalAndEHCleanup, EHCleanup, NormalCleanup };
99da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
100f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// A stack of scopes which respond to exceptions, including cleanups
101f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall/// and catch blocks.
102f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallclass EHScopeStack {
103f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic:
104f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// A saved depth on the scope stack.  This is necessary because
105f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// pushing scopes onto the stack invalidates iterators.
106f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class stable_iterator {
107f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    friend class EHScopeStack;
108f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
109f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    /// Offset from StartOfData to EndOfBuffer.
110f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    ptrdiff_t Size;
111f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
112f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    stable_iterator(ptrdiff_t Size) : Size(Size) {}
113f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
114f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  public:
115f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    static stable_iterator invalid() { return stable_iterator(-1); }
116f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    stable_iterator() : Size(-1) {}
117f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
118f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    bool isValid() const { return Size >= 0; }
119f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1201bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall    /// \return true if this scope is (non-strictly) nested within the
1211bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall    ///   given scope, assuming they're both valid
1221bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall    bool isWithin(stable_iterator I) const { return Size <= I.Size; }
1231bda662cb37d9fe24be4b3cf8ea0f4e550e1f889John McCall
124f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    friend bool operator==(stable_iterator A, stable_iterator B) {
125f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      return A.Size == B.Size;
126f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    }
127f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    friend bool operator!=(stable_iterator A, stable_iterator B) {
128f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      return A.Size != B.Size;
129f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    }
130f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  };
131f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1323e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall  /// A lazy cleanup.  Subclasses must be POD-like:  cleanups will
1333e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall  /// not be destructed, and they will be allocated on the cleanup
1343e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall  /// stack and freely copied and moved around.
135da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  ///
136da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  /// LazyCleanup implementations should generally be declared in an
137da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  /// anonymous namespace.
138da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  class LazyCleanup {
139da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  public:
1403e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // Anchor the construction vtable.  We use the destructor because
1413e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // gcc gives an obnoxious warning if there are virtual methods
1423e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // with an accessible non-virtual destructor.  Unfortunately,
1433e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // declaring this destructor makes it non-trivial, but there
1443e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // doesn't seem to be any other way around this warning.
1453e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    //
1463e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    // This destructor will never be called.
1473e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall    virtual ~LazyCleanup();
1483e29f96988b0438e42dba3790f61fb3df42d90cbJohn McCall
149da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    /// Emit the cleanup.  For normal cleanups, this is run in the
150da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    /// same EH context as when the cleanup was pushed, i.e. the
151da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    /// immediately-enclosing context of the cleanup scope.  For
152da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    /// EH cleanups, this is run in a terminate context.
153da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    ///
154da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    // \param IsForEHCleanup true if this is for an EH cleanup, false
155da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    ///  if for a normal cleanup.
156da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    virtual void Emit(CodeGenFunction &CGF, bool IsForEHCleanup) = 0;
157da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  };
158da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
159f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallprivate:
160f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  // The implementation for this class is in CGException.h and
161f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  // CGException.cpp; the definition is here because it's used as a
162f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  // member of CodeGenFunction.
163f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
164f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The start of the scope-stack buffer, i.e. the allocated pointer
165f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// for the buffer.  All of these pointers are either simultaneously
166f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// null or simultaneously valid.
167f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  char *StartOfBuffer;
168f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
169f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The end of the buffer.
170f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  char *EndOfBuffer;
171f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
172f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The first valid entry in the buffer.
173f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  char *StartOfData;
174f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
175f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The innermost normal cleanup on the stack.
176f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator InnermostNormalCleanup;
177f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
178f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The innermost EH cleanup on the stack.
179f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator InnermostEHCleanup;
180f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
181f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The number of catches on the stack.
182f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  unsigned CatchDepth;
183f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
184f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The current set of branch fixups.  A branch fixup is a jump to
185f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// an as-yet unemitted label, i.e. a label for which we don't yet
186f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// know the EH stack depth.  Whenever we pop a cleanup, we have
187f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to thread all the current branch fixups through it.
188f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///
189f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Fixups are recorded as the Use of the respective branch or
190f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// switch statement.  The use points to the final destination.
191f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// When popping out of a cleanup, these uses are threaded through
192f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// the cleanup and adjusted to point to the new cleanup.
193f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///
194f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Note that branches are allowed to jump into protected scopes
195f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// in certain situations;  e.g. the following code is legal:
196f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///     struct A { ~A(); }; // trivial ctor, non-trivial dtor
197f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///     goto foo;
198f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///     A a;
199f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///    foo:
200f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ///     bar();
201f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::SmallVector<BranchFixup, 8> BranchFixups;
202f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
203f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  char *allocate(size_t Size);
204f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
205f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void popNullFixups();
206f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
207da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  void *pushLazyCleanup(CleanupKind K, size_t DataSize);
208da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
209f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic:
210f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  EHScopeStack() : StartOfBuffer(0), EndOfBuffer(0), StartOfData(0),
211f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   InnermostNormalCleanup(stable_end()),
212f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   InnermostEHCleanup(stable_end()),
213f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   CatchDepth(0) {}
214f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  ~EHScopeStack() { delete[] StartOfBuffer; }
215f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
216da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  // Variadic templates would make this not terrible.
217da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
218da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  /// Push a lazily-created cleanup on the stack.
2198e3f86193995c47ee0d229e4336c3382410f09f5John McCall  template <class T>
2208e3f86193995c47ee0d229e4336c3382410f09f5John McCall  void pushLazyCleanup(CleanupKind Kind) {
2218e3f86193995c47ee0d229e4336c3382410f09f5John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
2228e3f86193995c47ee0d229e4336c3382410f09f5John McCall    LazyCleanup *Obj = new(Buffer) T();
2238e3f86193995c47ee0d229e4336c3382410f09f5John McCall    (void) Obj;
2248e3f86193995c47ee0d229e4336c3382410f09f5John McCall  }
2258e3f86193995c47ee0d229e4336c3382410f09f5John McCall
2268e3f86193995c47ee0d229e4336c3382410f09f5John McCall  /// Push a lazily-created cleanup on the stack.
2278e3f86193995c47ee0d229e4336c3382410f09f5John McCall  template <class T, class A0>
2288e3f86193995c47ee0d229e4336c3382410f09f5John McCall  void pushLazyCleanup(CleanupKind Kind, A0 a0) {
2298e3f86193995c47ee0d229e4336c3382410f09f5John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
2308e3f86193995c47ee0d229e4336c3382410f09f5John McCall    LazyCleanup *Obj = new(Buffer) T(a0);
2318e3f86193995c47ee0d229e4336c3382410f09f5John McCall    (void) Obj;
2328e3f86193995c47ee0d229e4336c3382410f09f5John McCall  }
2338e3f86193995c47ee0d229e4336c3382410f09f5John McCall
2348e3f86193995c47ee0d229e4336c3382410f09f5John McCall  /// Push a lazily-created cleanup on the stack.
235da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  template <class T, class A0, class A1>
236da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  void pushLazyCleanup(CleanupKind Kind, A0 a0, A1 a1) {
237da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
238da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    LazyCleanup *Obj = new(Buffer) T(a0, a1);
239da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    (void) Obj;
240da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  }
241da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
242da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  /// Push a lazily-created cleanup on the stack.
243da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  template <class T, class A0, class A1, class A2>
244da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  void pushLazyCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2) {
245da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
246da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    LazyCleanup *Obj = new(Buffer) T(a0, a1, a2);
247da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    (void) Obj;
248da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  }
249da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
250da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  /// Push a lazily-created cleanup on the stack.
251da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  template <class T, class A0, class A1, class A2, class A3>
252da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  void pushLazyCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) {
253da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
254da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    LazyCleanup *Obj = new(Buffer) T(a0, a1, a2, a3);
255da65ea86482bc116906edfb9ba1d7124f76cc867John McCall    (void) Obj;
256da65ea86482bc116906edfb9ba1d7124f76cc867John McCall  }
257da65ea86482bc116906edfb9ba1d7124f76cc867John McCall
25877199713ab56f87ffad9a535ff2a0877704eed87John McCall  /// Push a lazily-created cleanup on the stack.
25977199713ab56f87ffad9a535ff2a0877704eed87John McCall  template <class T, class A0, class A1, class A2, class A3, class A4>
26077199713ab56f87ffad9a535ff2a0877704eed87John McCall  void pushLazyCleanup(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
26177199713ab56f87ffad9a535ff2a0877704eed87John McCall    void *Buffer = pushLazyCleanup(Kind, sizeof(T));
26277199713ab56f87ffad9a535ff2a0877704eed87John McCall    LazyCleanup *Obj = new(Buffer) T(a0, a1, a2, a3, a4);
26377199713ab56f87ffad9a535ff2a0877704eed87John McCall    (void) Obj;
26477199713ab56f87ffad9a535ff2a0877704eed87John McCall  }
26577199713ab56f87ffad9a535ff2a0877704eed87John McCall
266f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Push a cleanup on the stack.
267f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void pushCleanup(llvm::BasicBlock *NormalEntry,
268f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   llvm::BasicBlock *NormalExit,
269f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   llvm::BasicBlock *EHEntry,
270f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                   llvm::BasicBlock *EHExit);
271f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
272f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Pops a cleanup scope off the stack.  This should only be called
273f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// by CodeGenFunction::PopCleanupBlock.
274f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void popCleanup();
275f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
276f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Push a set of catch handlers on the stack.  The catch is
277f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// uninitialized and will need to have the given number of handlers
278f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// set on it.
279f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class EHCatchScope *pushCatch(unsigned NumHandlers);
280f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
281f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Pops a catch scope off the stack.
282f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void popCatch();
283f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
284f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Push an exceptions filter on the stack.
285f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class EHFilterScope *pushFilter(unsigned NumFilters);
286f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
287f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Pops an exceptions filter off the stack.
288f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void popFilter();
289f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
290f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Push a terminate handler on the stack.
291f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void pushTerminate();
292f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
293f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Pops a terminate handler off the stack.
294f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void popTerminate();
295f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
296f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Determines whether the exception-scopes stack is empty.
297f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  bool empty() const { return StartOfData == EndOfBuffer; }
298f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
299f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  bool requiresLandingPad() const {
300f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return (CatchDepth || hasEHCleanups());
301f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
302f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
303f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Determines whether there are any normal cleanups on the stack.
304f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  bool hasNormalCleanups() const {
305f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return InnermostNormalCleanup != stable_end();
306f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
307f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
308f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns the innermost normal cleanup on the stack, or
309f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// stable_end() if there are no normal cleanups.
310f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator getInnermostNormalCleanup() const {
311f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return InnermostNormalCleanup;
312f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
313f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
314f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Determines whether there are any EH cleanups on the stack.
315f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  bool hasEHCleanups() const {
316f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return InnermostEHCleanup != stable_end();
317f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
318f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
319f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns the innermost EH cleanup on the stack, or stable_end()
320f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// if there are no EH cleanups.
321f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator getInnermostEHCleanup() const {
322f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return InnermostEHCleanup;
323f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
324f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
325f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// An unstable reference to a scope-stack depth.  Invalidated by
326f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// pushes but not pops.
327f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class iterator;
328f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
329f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns an iterator pointing to the innermost EH scope.
330f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  iterator begin() const;
331f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
332f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns an iterator pointing to the outermost EH scope.
333f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  iterator end() const;
334f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
335f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Create a stable reference to the top of the EH stack.  The
336f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// returned reference is valid until that scope is popped off the
337f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// stack.
338f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator stable_begin() const {
339f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return stable_iterator(EndOfBuffer - StartOfData);
340f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
341f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
342f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Create a stable reference to the bottom of the EH stack.
343f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  static stable_iterator stable_end() {
344f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return stable_iterator(0);
345f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
346f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
347f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Translates an iterator into a stable_iterator.
348f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator stabilize(iterator it) const;
349f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
350f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Finds the nearest cleanup enclosing the given iterator.
351f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns stable_iterator::invalid() if there are no such cleanups.
352f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  stable_iterator getEnclosingEHCleanup(iterator it) const;
353f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
354f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Turn a stable reference to a scope depth into a unstable pointer
355f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to the EH stack.
356f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  iterator find(stable_iterator save) const;
357f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
358f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Removes the cleanup pointed to by the given stable_iterator.
359f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void removeCleanup(stable_iterator save);
360f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
361f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Add a branch fixup to the current cleanup scope.
362f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  BranchFixup &addBranchFixup() {
363f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    assert(hasNormalCleanups() && "adding fixup in scope without cleanups");
364f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    BranchFixups.push_back(BranchFixup());
365f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return BranchFixups.back();
366f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
367f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
368f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  unsigned getNumBranchFixups() const { return BranchFixups.size(); }
369f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  BranchFixup &getBranchFixup(unsigned I) {
370f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    assert(I < getNumBranchFixups());
371f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return BranchFixups[I];
372f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
373f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
374f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Mark any branch fixups leading to the given block as resolved.
375f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void resolveBranchFixups(llvm::BasicBlock *Dest);
376f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall};
377f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
3802a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction {
3818a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
3828a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  void operator=(const CodeGenFunction&);  // DO NOT IMPLEMENT
383bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
384f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// A jump destination is a pair of a basic block and a cleanup
385f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// depth.  They are used to implement direct jumps across cleanup
386f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// scopes, e.g. goto, break, continue, and return.
387f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  struct JumpDest {
388f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest() : Block(0), ScopeDepth() {}
389f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest(llvm::BasicBlock *Block, EHScopeStack::stable_iterator Depth)
390f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      : Block(Block), ScopeDepth(Depth) {}
391f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
392f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    llvm::BasicBlock *Block;
393f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    EHScopeStack::stable_iterator ScopeDepth;
394f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  };
395f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
397444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &Target;
3980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
39958dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
40045d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
4010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
402b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurFuncDecl - Holds the Decl for the current function or ObjC method.
403b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// This excludes BlockDecls.
4044111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
405b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
406b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
40788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
408391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4116a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  /// CurGD - The GlobalDecl for the current function being compiled.
4126a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  GlobalDecl CurGD;
4136a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump
4145ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
415f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  JumpDest ReturnBlock;
416f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
4170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
4180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
419b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman  llvm::Value *ReturnValue;
4200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
423481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
4240ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
42577b89b87c3b9220fea1bc80f6d6598d2003cc8a8Chris Lattner  // intptr_t, i32, i64
42677b89b87c3b9220fea1bc80f6d6598d2003cc8a8Chris Lattner  const llvm::IntegerType *IntPtrTy, *Int32Ty, *Int64Ty;
4277b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
42818ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
429d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  bool Exceptions;
4309c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump  bool CatchUndefined;
4313d91bbcdab155181556969cad6ec97014405acedDouglas Gregor
4323d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  /// \brief A mapping from NRVO variables to the flags used to indicate
4333d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  /// when the NRVO has been applied to this variable.
4343d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
4350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
436f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  EHScopeStack EHStack;
4370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
438f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The exception slot.  All landing pads write the current
439f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// exception pointer into this alloca.
440f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::Value *ExceptionSlot;
4410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
442f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Emits a landing pad for the current EH stack.
443f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *EmitLandingPad();
4440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
445f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getInvokeDestImpl();
44699533834ba8f3658559f334e68a518ebb6388ceaMike Stump
447f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic:
448f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// rethrows.
450f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
451bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
452f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  // A struct holding information about a finally block's IR
453f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  // generation.  For now, doesn't actually hold anything.
454f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  struct FinallyInfo {
455d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  };
456d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
457f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  FinallyInfo EnterFinallyBlock(const Stmt *Stmt,
458f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                llvm::Constant *BeginCatchFn,
459f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                llvm::Constant *EndCatchFn,
460f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                llvm::Constant *RethrowFn);
461f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void ExitFinallyBlock(FinallyInfo &FinallyInfo);
462f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
463f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// PushDestructorCleanup - Push a cleanup to call the
464f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// complete-object destructor of an object of the given type at the
465f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// given address.  Does nothing if T is not a C++ class type with a
466f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// non-trivial destructor.
467f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void PushDestructorCleanup(QualType T, llvm::Value *Addr);
468f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
46981407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// PushDestructorCleanup - Push a cleanup to call the
47081407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// complete-object variant of the given destructor on the object at
47181407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// the given address.
47281407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  void PushDestructorCleanup(const CXXDestructorDecl *Dtor,
47381407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall                             llvm::Value *Addr);
47481407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall
475f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// PopCleanupBlock - Will pop the cleanup entry on the stack and
476f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// process all branch fixups.
477f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void PopCleanupBlock();
478f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
479f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// CleanupBlock - RAII object that will create a cleanup block and
480f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// set the insert point to that block. When destructed, it sets the
481f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// insert point to the previous block and pushes a new cleanup
482f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// entry on the stack.
483f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class CleanupBlock {
484f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    CodeGenFunction &CGF;
485f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    CGBuilderTy::InsertPoint SavedIP;
486f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    llvm::BasicBlock *NormalCleanupEntryBB;
487f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    llvm::BasicBlock *NormalCleanupExitBB;
488f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    llvm::BasicBlock *EHCleanupEntryBB;
4897799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
4900d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
491f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    CleanupBlock(CodeGenFunction &CGF, CleanupKind Kind);
4920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
493f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    /// If we're currently writing a normal cleanup, tie that off and
494f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    /// start writing an EH cleanup.
495f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    void beginEHCleanup();
4967799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
497f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    ~CleanupBlock();
4980d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
4990d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
500f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// \brief Enters a new scope for capturing cleanups, all of which
501f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// will be executed once the scope is exited.
502f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class RunCleanupsScope {
50301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CodeGenFunction& CGF;
504f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    EHScopeStack::stable_iterator CleanupStackDepth;
50501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    bool OldDidCallStackSave;
5065656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool PerformCleanup;
50701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
508f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    RunCleanupsScope(const RunCleanupsScope &); // DO NOT IMPLEMENT
509f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    RunCleanupsScope &operator=(const RunCleanupsScope &); // DO NOT IMPLEMENT
51001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
51101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  public:
51201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Enter a new cleanup scope.
513f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    explicit RunCleanupsScope(CodeGenFunction &CGF)
5145656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      : CGF(CGF), PerformCleanup(true)
5155656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    {
516f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      CleanupStackDepth = CGF.EHStack.stable_begin();
51701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      OldDidCallStackSave = CGF.DidCallStackSave;
51801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
51901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
52001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Exit this cleanup scope, emitting any accumulated
52101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// cleanups.
522f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    ~RunCleanupsScope() {
5235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      if (PerformCleanup) {
5245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.DidCallStackSave = OldDidCallStackSave;
525f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall        CGF.PopCleanupBlocks(CleanupStackDepth);
5265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      }
5275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
5285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
5295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Determine whether this scope requires any cleanups.
5305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool requiresCleanups() const {
531f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      return CGF.EHStack.stable_begin() != CleanupStackDepth;
5325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
5335656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
5345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Force the emission of cleanups now, instead of waiting
5355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// until this object is destroyed.
5365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    void ForceCleanup() {
5375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      assert(PerformCleanup && "Already forced cleanup");
53801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.DidCallStackSave = OldDidCallStackSave;
539f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      CGF.PopCleanupBlocks(CleanupStackDepth);
5405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      PerformCleanup = false;
54101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
54201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  };
54301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
54444ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
545f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// PopCleanupBlocks - Takes the old cleanup stack size and emits
546f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// the cleanup blocks that have been added.
547f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize);
54844ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
549f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The given basic block lies in the current EH scope, but may be a
550f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// target of a potentially scope-crossing jump; get a stable handle
551f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to which we can perform this jump later.
552f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) const {
553f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return JumpDest(Target, EHStack.stable_begin());
554f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
555c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
556f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The given basic block lies in the current EH scope, but may be a
557f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// target of a potentially scope-crossing jump; get a stable handle
558f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to which we can perform this jump later.
559f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  JumpDest getJumpDestInCurrentScope(const char *Name = 0) {
560f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return JumpDest(createBasicBlock(Name), EHStack.stable_begin());
561f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
562f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
563f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// EmitBranchThroughCleanup - Emit a branch from the current insert
564f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// block through the normal cleanup handling code (if any) and then
565f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// on to \arg Dest.
566f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void EmitBranchThroughCleanup(JumpDest Dest);
567f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
568f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// EmitBranchThroughEHCleanup - Emit a branch from the current
569f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// insert block through the EH cleanup handling code (if any) and
570f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// then on to \arg Dest.
571f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void EmitBranchThroughEHCleanup(JumpDest Dest);
5720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
57372119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// BeginConditionalBranch - Should be called before a conditional part of an
574a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression is emitted. For example, before the RHS of the expression below
575a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// is emitted:
5761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
5771d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// b && f(T());
5781d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  ///
579a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// This is used to make sure that any temporaries created in the conditional
5801d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// branch are only destroyed if the branch is taken.
58172119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void BeginConditionalBranch() {
582a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    ++ConditionalBranchLevel;
583a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
58572119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// EndConditionalBranch - Should be called after a conditional part of an
586a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression has been emitted.
58772119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void EndConditionalBranch() {
58808e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson    assert(ConditionalBranchLevel != 0 &&
58908e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson           "Conditional branch mismatch!");
59008e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson
591a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    --ConditionalBranchLevel;
592a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5947f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
595d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  CGDebugInfo *DebugInfo;
59609429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
597f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// IndirectBranch - The first time an indirect goto is seen we create a block
598f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// with an indirect branch.  Every time we see the address of a label taken,
599f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// we add the label to the indirect goto.  Every subsequent indirect goto is
600f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// codegen'd as a jump to the IndirectBranch's basic block.
601d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::IndirectBrInst *IndirectBranch;
6020ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
6030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
6040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
6055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
608f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::DenseMap<const LabelStmt*, JumpDest> LabelMap;
6090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
611e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
612da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
613f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    BreakContinue(JumpDest Break, JumpDest Continue)
614f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      : BreakBlock(Break), ContinueBlock(Continue) {}
6150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
616f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest BreakBlock;
617f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest ContinueBlock;
6180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
619da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
62018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
6210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
6220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
62351b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
62451b09f2c528c8460b5465c676173324e44176d62Devang Patel
6250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
62680fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
627c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
628c049e4f406a7f7179eba98659044a32508e53289Devang Patel
6299834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// InvokeDest - This is the nearest exception target for calls
6309834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// which can unwind, when exceptions are being used.
6319834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *InvokeDest;
6329834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
6330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
634bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // We track this by the size expression rather than the type itself because
635bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // in certain situations, like a const qualifier applied to an VLA typedef,
636bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // multiple VLA types can share the same size expression.
6370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
6380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
639bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
6400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6414cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
6424cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
6434cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
64409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
645f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// A block containing a single 'unreachable' instruction.  Created
646f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// lazily by getUnreachableBlock().
647f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *UnreachableBlock;
6480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
649f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXThisDecl - When generating code for a C++ member function,
650f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// this will hold the implicit 'this' declaration.
6512b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  ImplicitParamDecl *CXXThisDecl;
6522504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXThisValue;
6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
654f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXVTTDecl - When generating code for a base object constructor or
655f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// base object destructor with virtual bases, this will hold the implicit
656f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// VTT parameter.
657f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  ImplicitParamDecl *CXXVTTDecl;
6582504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXVTTValue;
659f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson
660a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// ConditionalBranchLevel - Contains the nesting level of the current
661a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// conditional branch. This is used so that we know if a temporary should be
662a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// destroyed conditionally.
663a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  unsigned ConditionalBranchLevel;
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6657dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
6667dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM
6677dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// type as well as the field number that contains the actual data.
6687dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *,
6697dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson                                              unsigned> > ByRefValueInfo;
6707dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
6717dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
6727dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// number that holds the value.
6737dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
674182f383db1782af752ecaf607fdff72a8542088bMike Stump
675f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *TerminateLandingPad;
676182f383db1782af752ecaf607fdff72a8542088bMike Stump  llvm::BasicBlock *TerminateHandler;
67783252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner  llvm::BasicBlock *TrapBB;
678940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
6810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
683e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
685f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Returns a pointer to the function's exception object slot, which
686f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// is assigned in every landing pad.
687f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::Value *getExceptionSlot();
688f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
689f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getUnreachableBlock() {
690f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    if (!UnreachableBlock) {
691f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      UnreachableBlock = createBasicBlock("unreachable");
692f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
693f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    }
694f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return UnreachableBlock;
695f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
696f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
697f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getInvokeDest() {
698f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    if (!EHStack.requiresLandingPad()) return 0;
699f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return getInvokeDestImpl();
700f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
7019834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
702a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson  llvm::LLVMContext &getLLVMContext() { return VMContext; }
70369243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson
7049834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
7059834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
7069834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
7079834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
708391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
709af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
7100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
711679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
712af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
7130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
714fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
715fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
716109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian  void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
717109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian                                  ObjCMethodDecl *MD, bool ctor);
718af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
7190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
7200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
721fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
722fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
7230b2bd47151ee9205ad6c66d1ffb921918106088aFariborz Jahanian  bool IndirectObjCSetterArg(const CGFunctionInfo &FI);
72415bd58842adaa4f8cca4e58047ed18e033858d9bFariborz Jahanian  bool IvarTypeWithAggrGCObjects(QualType Ty);
725af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
7264e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
7274e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
7284e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
7294e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
7308a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump  llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
7312a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst  llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
7322a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst                                           bool BlockHasCopyDispose,
733199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck                                           CharUnits Size,
7340892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           const llvm::StructType *,
7350892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           std::vector<HelperInfo> *);
7364e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
737564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian  llvm::Function *GenerateBlockFunction(GlobalDecl GD,
738564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian                                        const BlockExpr *BExpr,
739ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall                                        CGBlockInfo &Info,
7406cc88f78fd36d3511b89412b193494b3e423cbffMike Stump                                        const Decl *OuterFuncDecl,
741ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm);
7424e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
7434e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  llvm::Value *LoadBlockStruct();
7444e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
745ea1471e0e967548c596a71469702f8846dbaf3c0John McCall  void AllocateBlockCXXThisPointer(const CXXThisExpr *E);
746ea1471e0e967548c596a71469702f8846dbaf3c0John McCall  void AllocateBlockDecl(const BlockDeclRefExpr *E);
747ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E) {
748ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall    return GetAddrOfBlockDecl(E->getDecl(), E->isByRef());
749ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall  }
750ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall  llvm::Value *GetAddrOfBlockDecl(const ValueDecl *D, bool ByRef);
7519ad5513b0f9d3999705659fb1aeb0e6c53455f43Anders Carlsson  const llvm::Type *BuildByRefType(const ValueDecl *D);
752dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
7530ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void GenerateCode(GlobalDecl GD, llvm::Function *Fn);
7540ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void StartFunction(GlobalDecl GD, QualType RetTy,
7557c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
7562284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
7572284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
758a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
7599fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitConstructorBody(FunctionArgList &Args);
7609fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitDestructorBody(FunctionArgList &Args);
7619fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitFunctionBody(FunctionArgList &Args);
762a355e07454463b19829ac92ffd115a097faff0e0John McCall
7630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
7640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
7651c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
7661c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
7670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
7680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
769af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
77017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
771519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson  /// GenerateThunk - Generate a thunk for the given method.
772519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson  void GenerateThunk(llvm::Function *Fn, GlobalDecl GD, const ThunkInfo &Thunk);
773519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson
774fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor  void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type,
775fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor                        FunctionArgList &Args);
7761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
777d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// InitializeVTablePointer - Initialize the vtable pointer of the given
778d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// subobject.
779d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  ///
780b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson  void InitializeVTablePointer(BaseSubobject Base,
781b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                               const CXXRecordDecl *NearestVBase,
7824235840554aaed11efd479df9e622dc82ab77e6dAnders Carlsson                               uint64_t OffsetFromNearestVBase,
783d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson                               llvm::Constant *VTable,
784d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson                               const CXXRecordDecl *VTableClass);
785d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
786d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
787b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson  void InitializeVTablePointers(BaseSubobject Base,
788b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                                const CXXRecordDecl *NearestVBase,
7894235840554aaed11efd479df9e622dc82ab77e6dAnders Carlsson                                uint64_t OffsetFromNearestVBase,
790603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                bool BaseIsNonVirtualPrimaryBase,
791603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                llvm::Constant *VTable,
792603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                const CXXRecordDecl *VTableClass,
793603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                VisitedVirtualBasesSetTy& VBases);
79477a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman
795603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson  void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
796d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
797d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
79850da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// EnterDtorCleanups - Enter the cleanups necessary to complete the
79950da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// given phase of destruction for a destructor.  The end result
80050da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// should call destructors on members and base classes in reverse
80150da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// order of their construction.
80250da2cadcc6da86abff6772de65280ace2cabc94John McCall  void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type);
8031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8047255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// ShouldInstrumentFunction - Return true if the current function should be
8057255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// instrumented with __cyg_profile_func_* calls
8067255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  bool ShouldInstrumentFunction();
8077255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner
8087255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// EmitFunctionInstrumentation - Emit LLVM code to call the specified
8097255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// instrumentation function with the current function and the call site, if
8107255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// function instrumentation is enabled.
8117255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  void EmitFunctionInstrumentation(const char *Fn);
8127255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner
8130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
8140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
8150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
81688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
81788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
81817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
81917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
8200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
8210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
82235b21b884e5c3447a52a74d7ffaba966b07ac81fChris Lattner  void EmitFunctionEpilog(const CGFunctionInfo &FI);
82317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
824cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitStartEHSpec - Emit the start of the exception spec.
825cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitStartEHSpec(const Decl *D);
826cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
827cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitEndEHSpec - Emit the end of the exception spec.
828cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitEndEHSpec(const Decl *D);
829cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
830f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// getTerminateLandingPad - Return a landing pad that just calls terminate.
831f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getTerminateLandingPad();
832f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
833f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// getTerminateHandler - Return a handler (not a landing pad, just
834f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// a catch handler) that just calls terminate.  This is used when
835f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// a terminate scope encloses a try.
8369b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump  llvm::BasicBlock *getTerminateHandler();
8379b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump
8388b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
840bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  const llvm::Type *ConvertType(const TypeDecl *T) {
841bff225ecf77fb891596ecb1b27196310d268365eJohn McCall    return ConvertType(getContext().getTypeDeclType(T));
842bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  }
843c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
8440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
8450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
846c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
8470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
84945012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
8504111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
85455e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
85555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
8560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
85755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
85855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
85929ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
8600032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore);
86129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
8620032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore);
86329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
86455e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
8650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
868f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  JumpDest getJumpDestForLabel(const LabelStmt *S);
8690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
870f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// SimplifyForwardingBlocks - If the given basic block is only a branch to
871f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// another basic block, simplify it. This assumes that no other code could
872f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// potentially reference the basic block.
873aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
874aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
8750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
8760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
8770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
8780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
879a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
8800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
8810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
8820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
883a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
884824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
8850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
8860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
8870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
8880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
8895e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
8900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
8910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
8920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
893d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
894d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
8950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
8960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
8970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
898a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
899a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
900a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
9010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
9020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
9030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
9040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
905a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
906a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
907a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
908a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
9090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
910488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
911dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
91290df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
91390df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers MakeQualifiers(QualType T) {
920df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers();
9210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T));
9220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
9230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
9240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
9255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
926195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// block. The caller is responsible for setting an appropriate alignment on
927195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// the alloca.
9285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
929259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar                                     const llvm::Twine &Name = "tmp");
9300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
931ac418162692a951ca3796d6830496a85a2d12493John McCall  /// InitTempAlloca - Provide an initial value for the given alloca.
932ac418162692a951ca3796d6830496a85a2d12493John McCall  void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value);
933ac418162692a951ca3796d6830496a85a2d12493John McCall
9349bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// CreateIRTemp - Create a temporary IR object of the given type, with
9359bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// appropriate alignment. This routine should only be used when an temporary
9369bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// value needs to be stored into an alloca (for example, to avoid explicit
9379bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// PHI construction), but the type is the IR type, not the type appropriate
9389bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// for storing in memory.
939121b3facb4e0585d23766f9c1e4fdf9018a4b217Chris Lattner  llvm::AllocaInst *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp");
9409bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar
941195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// CreateMemTemp - Create a temporary memory object of the given type, with
942195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// appropriate alignment.
943121b3facb4e0585d23766f9c1e4fdf9018a4b217Chris Lattner  llvm::AllocaInst *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp");
944195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar
9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9499b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
9509b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
9519b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
9529b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
95349d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
95449d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  /// \param IgnoreResult - True if the resulting value isn't used.
9550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
95614c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsAggLocVolatile = false, bool IgnoreResult = false,
95714c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsInitializer = false);
958d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
9590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
9600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
9614fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
9624fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
9630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
9640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
96514c5cbf59cffee52275230922283a247de407712Anders Carlsson  RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false,
96614c5cbf59cffee52275230922283a247de407712Anders Carlsson                           bool IsInitializer = false);
96746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
9683d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  /// EmitsAnyExprToMem - Emits the code necessary to evaluate an
9693d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  /// arbitrary expression into the given memory location.
9703d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  void EmitAnyExprToMem(const Expr *E, llvm::Value *Location,
9713d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall                        bool IsLocationVolatile = false,
9723d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall                        bool IsInitializer = false);
9733d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall
97427fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// EmitAggregateCopy - Emit an aggrate copy.
97527fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
97627fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// \param isVolatile - True iff either the source or the destination is
97727fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
9787482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
97927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump                         QualType EltTy, bool isVolatile=false);
9807482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
98151b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
98251b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
98351b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
98451b09f2c528c8460b5465c676173324e44176d62Devang Patel
985813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
986248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
9874f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
988dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
989dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
9900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9914f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
9924f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
9934f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
9944f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
995d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L);
9963d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner  llvm::BasicBlock *GetIndirectGotoBlock();
9970ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
9981884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// EmitNullInitialization - Generate code to set a value of the given type to
9991884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// null, If the type contains data member pointers, they will be initialized
10001884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// to -1 in accordance with the Itanium C++ ABI.
10011884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty);
1002ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
1003ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
1004ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
1005ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
10060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
1007ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
1008f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
1009f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitVLASize - Generate code for any VLA size expressions that might occur
1010f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// in a variably modified type. If Ty is a VLA, will return the value that
1011f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
1012d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1013d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
101460d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
10150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1016dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
1017dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
1018dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
1019dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
10205f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
10215f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
10222504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXThis() {
10232504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXThisValue && "no 'this' value for this function");
10242504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXThisValue;
10252504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
10261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1027c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
1028c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// virtual bases.
10292504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXVTT() {
10302504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXVTTValue && "no VTT value for this function");
10312504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXVTTValue;
10322504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
1033bff225ecf77fb891596ecb1b27196310d268365eJohn McCall
1034bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
10358561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  /// complete class to the given direct base.
10368561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  llvm::Value *
10378561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value,
10388561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
10398561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Base,
10408561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        bool BaseIsVirtual);
1041a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson
1042f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// GetAddressOfBaseClass - This function will add the necessary delta to the
1043f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// load of 'this' and returns address of the base class.
104434a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson  llvm::Value *GetAddressOfBaseClass(llvm::Value *Value,
10458561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                     const CXXRecordDecl *Derived,
104634a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson                                     const CXXBaseSpecifierArray &BasePath,
104734a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson                                     bool NullCheckValue);
104834a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson
1049a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson  llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
10508561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
1051a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson                                        const CXXBaseSpecifierArray &BasePath,
10525a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson                                        bool NullCheckValue);
1053a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson
1054bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson  llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This,
1055bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *ClassDecl,
1056bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *BaseClassDecl);
10572f1986b557fa671c4f8c9dd0d071398edfc073d5Anders Carlsson
1058c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall  void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,
1059c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      CXXCtorType CtorType,
1060c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      const FunctionArgList &Args);
1061155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
1062155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson                              bool ForVirtualBase, llvm::Value *This,
1063b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
1064b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
10651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1066288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
1067569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  const ConstantArrayType *ArrayTy,
10685d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
10695d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
107059174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  CallExpr::const_arg_iterator ArgEnd,
107159174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  bool ZeroInitialization = false);
10725d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson
1073569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
1074569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  llvm::Value *NumElements,
10755d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
10765d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
107759174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  CallExpr::const_arg_iterator ArgEnd,
107859174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  bool ZeroInitialization = false);
1079b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
1080f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
1081f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 const ArrayType *Array,
1082f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 llvm::Value *This);
10831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108472c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
108572c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *NumElements,
108672c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *This);
108772c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian
108802e370a02f05b4a734fe5e8c88efc4ed9dac60faAnders Carlsson  llvm::Function *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
108902e370a02f05b4a734fe5e8c88efc4ed9dac60faAnders Carlsson                                                  const ArrayType *Array,
109002e370a02f05b4a734fe5e8c88efc4ed9dac60faAnders Carlsson                                                  llvm::Value *This);
109188f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian
10927267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
10938e6404ca28d6bbb76e97ea2a53a74816c2a74665Anders Carlsson                             bool ForVirtualBase, llvm::Value *This);
1094ef66872797e46ced3ffdb428e582bc7f00474f99Fariborz Jahanian
1095ef66872797e46ced3ffdb428e582bc7f00474f99Fariborz Jahanian  void EmitNewArrayInitializer(const CXXNewExpr *E, llvm::Value *NewPtr,
1096ef66872797e46ced3ffdb428e582bc7f00474f99Fariborz Jahanian                               llvm::Value *NumElements);
10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1098f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void EmitCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1100a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson  llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
110160e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson  void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11034bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman  void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
11044bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman                      QualType DeleteTy);
11054bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman
1106c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
1107c849c052d6b4b70f2651c1969531861a5f230053Mike Stump  llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
1108c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
1109b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  void EmitCheck(llvm::Value *, unsigned Size);
1110b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
1111dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
1112dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                       bool isInc, bool isPre);
1113dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
1114dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                         bool isInc, bool isPre);
11155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1119d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitDecl - Emit a declaration.
1120d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1121d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
1123d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// EmitBlockVarDecl - Emit a block variable declaration.
1125d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1126d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
1127248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
1128d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
1129f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
1130f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                             llvm::Value *Address);
1131f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1132d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitLocalBlockVarDecl - Emit a local block variable declaration.
1133d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1134d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
1135f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void EmitLocalBlockVarDecl(const VarDecl &D, SpecialInitFn *SpecialInit = 0);
1136d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
1137f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson  void EmitStaticBlockVarDecl(const VarDecl &D,
1138f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson                              llvm::GlobalValue::LinkageTypes Linkage);
1139b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
1140b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
1141b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
11420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
11480912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
11490912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
11500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
11510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
11520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
11530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
11540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
11550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
1157a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
11580912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
11590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
11600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
11610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
11620912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
11630912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
11640912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
11650912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
11669b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
11679b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
1168a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
11690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
11700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
117191d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
1172a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
11745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
11750ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
11785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
11820912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
11830912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
118451b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
118551b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
118651b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
1187c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
1188fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
11890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11903d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
119164d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
119264d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
119310cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
11940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
119586a3a03667bdb0dcab7e6a2877dfd234b07a6d43Douglas Gregor  llvm::Constant *getUnwindResumeOrRethrowFn();
119659a7000a79118e4c140885ccbb2ac6a686a73092John McCall  void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
119759a7000a79118e4c140885ccbb2ac6a686a73092John McCall  void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
11989fc6a7774643a810c8501dae2323e863fefb623eJohn McCall
11996815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  void EmitCXXTryStmt(const CXXTryStmt &S);
12006815e941998659a55c20c147861b0f437928c3d8Anders Carlsson
12015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
120513e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
120613e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
120713e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
1208ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
1209ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
1210ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
1211ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
1212ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
1213ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
12140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
12150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
12166ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
12176ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
12186ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
12195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
12205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
12275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
12285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
12355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
12360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1237b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// EmitCheckedLValue - Same as EmitLValue but additionally we generate
1238b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// checking code to guard against undefined behavior.  This is only
1239b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// suitable when we know that the address will be used to access the
1240b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// object.
1241b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  LValue EmitCheckedLValue(const Expr *E);
1242b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
12439d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
12449d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
12459d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
124609429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
12479d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
12489d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
12499d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
12509d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
12519d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
125209429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
1253b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson                         bool Volatile, QualType Ty);
12549d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
12555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
12565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
12575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
1259213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
12603b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
126185c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
126243f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
12635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
12640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
12665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
12675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
12685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
1269213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
1270213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
127185c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
127243f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
1273ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
12740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
12750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
1276ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
12770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
12780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
12790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
1280ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
1281ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
12820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
128322c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
128480e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
12856a03e345bb3c971750920e34a0d7d1ea7c9eceb7Douglas Gregor  LValue EmitCompoundAssignOperatorLValue(const CompoundAssignOperator *E);
12865b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
128722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
12885b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
12895b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
1292eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
1293662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
1294d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
1297213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
1298b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
1299820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian  LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
130006e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
13016fcec8b58d0571866fcb162db947b029cc539ec4Anders Carlsson  LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
130275dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
1303ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor  LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E);
1304909fbf70223ea04a5ec8d449789f3683a89701ffAnders Carlsson
13052a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
130629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
1307a9976d3b192690db20f59dc44099ac4ca939bdb7John McCall  LValue EmitLValueForAnonRecordField(llvm::Value* Base,
1308a9976d3b192690db20f59dc44099ac4ca939bdb7John McCall                                      const FieldDecl* Field,
1309a9976d3b192690db20f59dc44099ac4ca939bdb7John McCall                                      unsigned CVRQualifiers);
13100ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
1311e6d2a534851a649485cb087e9dfcaf8a65886858Anders Carlsson                            unsigned CVRQualifiers);
131206a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
131306a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
131406a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// if the Field is a reference, this will return the address of the reference
131506a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// and not the address of the value stored in the reference.
131606a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  LValue EmitLValueForFieldInitialization(llvm::Value* Base,
131706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          const FieldDecl* Field,
131806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          unsigned CVRQualifiers);
131906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
132045012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
132145012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
132229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
132329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
13240ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field,
1325598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
1326fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
1327a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
1328a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump
1329b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
1330e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson  LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
1331b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson  LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E);
1332c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E);
1333b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson
13340a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
1335391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
133685c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
133709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E);
1338654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
1339654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
13408bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian  LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
134103b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian  LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
13428bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian
13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1344883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
13480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
13490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
1350c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
1351f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// \param TargetDecl - If given, the decl of the function in a direct call;
1352f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// used to set attributes on the call (noreturn, etc.).
135388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
135488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
1355f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson                  ReturnValueSlot ReturnValue,
1356c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
1357dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall                  const Decl *TargetDecl = 0,
13584b02afcb45cd1a384de7d45f440a8be091dd500bDavid Chisnall                  llvm::Instruction **callOrInvoke = 0);
13591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
136031777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  RValue EmitCall(QualType FnType, llvm::Value *Callee,
1361d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                  ReturnValueSlot ReturnValue,
1362986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgBeg,
1363986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgEnd,
1364986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  const Decl *TargetDecl = 0);
1365d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson  RValue EmitCallExpr(const CallExpr *E,
1366d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                      ReturnValueSlot ReturnValue = ReturnValueSlot());
13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1368f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee,
1369f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                  llvm::Value * const *ArgBegin,
1370f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                  llvm::Value * const *ArgEnd,
1371f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                                  const llvm::Twine &Name = "");
1372f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1373566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
1374f0070dbae9535836ad41711081465dec2259786bMike Stump                                const llvm::Type *Ty);
1375566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
1376566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson                                llvm::Value *&This, const llvm::Type *Ty);
1377566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson
1378b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
1379b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
1380a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                           ReturnValueSlot ReturnValue,
1381b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
1382c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson                           llvm::Value *VTT,
1383b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
1384b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
1385a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
1386a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                               ReturnValueSlot ReturnValue);
1387a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
1388a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                      ReturnValueSlot ReturnValue);
13895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
13900f294632f36459174199b77699e339715244b5abAnders Carlsson  RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
1391a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       const CXXMethodDecl *MD,
1392a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       ReturnValueSlot ReturnValue);
13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1394375c31c4673f83f925de221752cf801c2fbbb246Anders Carlsson
13951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  RValue EmitBuiltinExpr(const FunctionDecl *FD,
1396ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
13975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1398a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue);
139909429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
14000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
14010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
1402f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1403f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
14042752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner  llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
140530d91718a676177f0d0d0210ce4fdb4f616df6e5Nate Begeman  llvm::Value *EmitNeonCall(llvm::Function *F,
140630d91718a676177f0d0d0210ce4fdb4f616df6e5Nate Begeman                            llvm::SmallVectorImpl<llvm::Value*> &O,
140761eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman                            const char *name, bool splat = false,
140861eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman                            unsigned shift = 0, bool rightshift = false);
1409d075c01c359b9cc120c3accc7166990f9f4ac423Nate Begeman  llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
1410464ccb68f22a7e1c0a2844551c16f721540c91c3Nate Begeman  llvm::Value *EmitNeonShiftVector(llvm::Value *V, const llvm::Type *Ty,
141161eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman                                   bool negateForRightShift);
141230d91718a676177f0d0d0210ce4fdb4f616df6e5Nate Begeman
1413564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1414564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
14150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1416ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
14177f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
14188fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
1419ef072fd2f3347cfd857d6eb787b245b950771430John McCall  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E,
1420ef072fd2f3347cfd857d6eb787b245b950771430John McCall                             ReturnValueSlot Return = ReturnValueSlot());
1421ef072fd2f3347cfd857d6eb787b245b950771430John McCall  RValue EmitObjCPropertyGet(const Expr *E,
1422ef072fd2f3347cfd857d6eb787b245b950771430John McCall                             ReturnValueSlot Return = ReturnValueSlot());
1423ef072fd2f3347cfd857d6eb787b245b950771430John McCall  RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S,
1424ef072fd2f3347cfd857d6eb787b245b950771430John McCall                                  ReturnValueSlot Return = ReturnValueSlot());
142543f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
1426f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src);
14278fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
14288fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
14294029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
14304029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// expression. Will emit a temporary variable if E is not an LValue.
143132f36baa6c8d491c374af622b4e3ac28d597453cAnders Carlsson  RValue EmitReferenceBindingToExpr(const Expr* E,
143232f36baa6c8d491c374af622b4e3ac28d597453cAnders Carlsson                                    const NamedDecl *InitializedDecl);
14333aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson
1434883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1435bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
1436883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1437bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
1438bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
14390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
14400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
14410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
144214c5cbf59cffee52275230922283a247de407712Anders Carlsson  llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
14430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
14443707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
14453707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
14463707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
14473707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
14480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
14494f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
14500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
14510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
14524f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
14534f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
14540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
14550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1456883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
1457883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
1458883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
145949d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest,
146008c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool IgnoreResult = false, bool IsInitializer = false,
146108c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool RequiresGCollection = false);
14620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
146318aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// EmitAggExprToLValue - Emit the computation of the specified expression of
146418aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// aggregate type into a temporary LValue.
146518aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  LValue EmitAggExprToLValue(const Expr *E);
146618aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar
1467082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// EmitGCMemmoveCollectable - Emit special API for structs with object
1468082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// pointers.
1469082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
147008c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                                QualType Ty);
1471082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian
1472b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
147323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
14747f79f9be5916c51c35da4f126b7c12596a101607Mike Stump  ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
14757f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImag = false,
14767f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreRealAssign = false,
14777f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImagAssign = false);
14780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
147923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
148023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
1481190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
1482190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
14837f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
14847f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
14857f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
14867f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
14879b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
14889b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
14892621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
1490f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a
1491f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// static block var decl.
1492761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D,
1493761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                                 const char *Separator,
1494f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump                                       llvm::GlobalValue::LinkageTypes Linkage);
1495761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
1496761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the
1497761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// global variable that has already been created for it.  If the initializer
1498761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// has a different type than GV does, this may free GV and return a different
1499761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// one.  Otherwise it just returns GV.
1500761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *
1501761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  AddInitializerToGlobalBlockVarDecl(const VarDecl &D,
1502761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                     llvm::GlobalVariable *GV);
1503761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
15040096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
1505f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime
1506f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// initialized static block var decl.
15073b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
15083b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::GlobalVariable *GV);
1509e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
15103b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
15113b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// variable with global storage.
15123b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr);
15133b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson
15143b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr
15153b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// with the C++ runtime so that its destructor will be called at exit.
151688f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian  void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
15173b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::Constant *DeclPtr);
15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1519efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// GenerateCXXGlobalInitFunc - Generates code for initializing global
1520efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
1521efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalInitFunc(llvm::Function *Fn,
1522efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                 llvm::Constant **Decls,
1523efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                 unsigned NumDecls);
1524efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
1525efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// GenerateCXXGlobalDtorFunc - Generates code for destroying global
1526efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
1527efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
1528810112e28dc839715d17b0a786f23aaa19600ac0Chris Lattner                                 const std::vector<std::pair<llvm::WeakVH,
1529efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                   llvm::Constant*> > &DtorsAndObjects);
1530efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
1531efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D);
1532efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
153331ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson  void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E);
15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1535b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E,
15361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    llvm::Value *AggLoc = 0,
153714c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsAggLocVolatile = false,
153814c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsInitializer = false);
15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1540756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson  void EmitCXXThrowExpr(const CXXThrowExpr *E);
15411eb2e59338c4b9c0429fc39ca98662adc9e7a3f2Douglas Gregor
15420ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
15430ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
15440ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
15450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
15460946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
15470946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
15480946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
15490946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
15500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
15514bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
155231a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
155331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
155431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
155531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
15560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
155731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
155831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
155931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
15609bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
15614bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
1562be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump
156315037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// getTrapBB - Create a basic block that will call the trap intrinsic.  We'll
156415037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// generate a branch around the created basic block as necessary.
15656c552c1d5f47fbba00e6268d96a26ad026f2da2aChris Lattner  llvm::BasicBlock *getTrapBB();
15666c552c1d5f47fbba00e6268d96a26ad026f2da2aChris Lattner
156721c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson  /// EmitCallArg - Emit a single call argument.
156821c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson  RValue EmitCallArg(const Expr *E, QualType ArgType);
156921c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson
15702736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// EmitDelegateCallArg - We are performing a delegate call; that
15712736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// is, the current function is delegating to another one.  Produce
15722736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// a r-value suitable for passing the given parameter.
15732736071ea3a46f90e65c93418961611d96c10ab9John McCall  RValue EmitDelegateCallArg(const VarDecl *Param);
15742736071ea3a46f90e65c93418961611d96c10ab9John McCall
157531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
157629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
157729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
15785627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
15795627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
15805627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
15815627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
15825627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
15835627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
15840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
15855627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
15865627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
15875627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
15880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
15890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
15900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
15910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
15925627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
1593c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
15941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  llvm::Value* EmitAsmInput(const AsmStmt &S,
1595b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar                            const TargetInfo::ConstraintInfo &Info,
1596c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
15970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
15986d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman  llvm::Value* EmitAsmInputLValue(const AsmStmt &S,
15996d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman                                  const TargetInfo::ConstraintInfo &Info,
16006d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman                                  LValue InputValue, QualType InputType,
16016d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman                                  std::string &ConstraintStr);
16026d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman
16030139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The CallArgTypeInfo parameter is used for iterating over the known
1605af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
1606af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
1607af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
16080139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
1609af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                    CallExpr::const_arg_iterator ArgEnd) {
1610af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      CallExpr::const_arg_iterator Arg = ArgBeg;
1611af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1612af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
1613af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
1614af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
1615af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
161644b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman        assert(Arg != ArgEnd && "Running over edge of argument list!");
1617af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
1618af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1619af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getTypePtr() ==
16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getContext().getCanonicalType(Arg->getType()).getTypePtr() &&
1622af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1625af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                      ArgType));
1626af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Either we've emitted all the call args, or we have a call to a
1629af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
1631af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1633af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1635af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
1636af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    for (; Arg != ArgEnd; ++Arg) {
1637af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      QualType ArgType = Arg->getType();
1638af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1639af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                    ArgType));
1640af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
1641af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
1642492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall
1643492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  const TargetCodeGenInfo &getTargetHooks() const {
1644492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall    return CGM.getTargetCodeGenInfo();
1645492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  }
1646744016dde06fcffd50931e94a98c850f8b12cd87John McCall
1647744016dde06fcffd50931e94a98c850f8b12cd87John McCall  void EmitDeclMetadata();
16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1650af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
16525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
16535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1655