CodeGenFunction.h revision c7971a9efdf9880448a69aabb5182c3c27eecf6d
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
1755fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGBuilder.h"
1855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGDebugInfo.h"
1955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CGValue.h"
2043a75fcbe4b592d7bea1fe262117114bcebc003cReid Kleckner#include "EHScopeStack.h"
2155fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "CodeGenModule.h"
2255fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/CharUnits.h"
23e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
2555fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/AST/Type.h"
2614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/Basic/ABI.h"
27524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir#include "clang/Basic/CapturedStmt.h"
28481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h"
2955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Frontend/CodeGenOptions.h"
304c7d9f1507d0f102bd4133bba63348636facd469Jay Foad#include "llvm/ADT/ArrayRef.h"
31481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h"
32481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h"
33c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher#include "llvm/Support/Debug.h"
3455fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "llvm/Support/ValueHandle.h"
358f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
38f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer  class LLVMContext;
39dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall  class MDNode;
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
41898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
42259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar  class Twine;
43ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
44f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class CallSite;
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
491a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  class BlockDecl;
507267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  class CXXDestructorDecl;
51ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  class CXXForRangeStmt;
526815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  class CXXTryStmt;
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
54ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  class LabelDecl;
55c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
5772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
58c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
59679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
6029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
6129e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
62391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
63fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
64af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
66492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  class TargetCodeGenInfo;
67c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
6816f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
6916f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
7016f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
7116f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
72f85e193739c953358c865005855253af4f68a497John McCall  class ObjCAutoreleasePoolStmt;
735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
75b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
76bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
78ee5042903d53fa7b0fbc1902d0ea07d57c7775b1John McCall  class CGBlockInfo;
794c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  class CGCXXABI;
80d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  class BlockFlags;
81d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  class BlockFieldFlags;
820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
839d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// The kind of evaluation to perform on values of a particular
849d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// type.  Basically, is the code in CGExprScalar, CGExprComplex, or
859d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// CGExprAgg?
869d232c884ea9872d6555df0fd7359699819bc1f1John McCall///
879d232c884ea9872d6555df0fd7359699819bc1f1John McCall/// TODO: should vectors maybe be split out into their own thing?
889d232c884ea9872d6555df0fd7359699819bc1f1John McCallenum TypeEvaluationKind {
899d232c884ea9872d6555df0fd7359699819bc1f1John McCall  TEK_Scalar,
909d232c884ea9872d6555df0fd7359699819bc1f1John McCall  TEK_Complex,
919d232c884ea9872d6555df0fd7359699819bc1f1John McCall  TEK_Aggregate
929d232c884ea9872d6555df0fd7359699819bc1f1John McCall};
939d232c884ea9872d6555df0fd7359699819bc1f1John McCall
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
965936e33bf74dd6bf126ceee0f6169a2593d03a69John McCallclass CodeGenFunction : public CodeGenTypeCache {
97f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  CodeGenFunction(const CodeGenFunction &) LLVM_DELETED_FUNCTION;
98f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko  void operator=(const CodeGenFunction &) LLVM_DELETED_FUNCTION;
994c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1004c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  friend class CGCXXABI;
101bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
102ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  /// A jump destination is an abstract label, branching to which may
103ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  /// require a jump out through normal cleanups.
104f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  struct JumpDest {
105ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    JumpDest() : Block(0), ScopeDepth(), Index(0) {}
106ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    JumpDest(llvm::BasicBlock *Block,
107ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall             EHScopeStack::stable_iterator Depth,
108ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall             unsigned Index)
109ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall      : Block(Block), ScopeDepth(Depth), Index(Index) {}
110ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
111ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    bool isValid() const { return Block != 0; }
112ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    llvm::BasicBlock *getBlock() const { return Block; }
113ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; }
114ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    unsigned getDestIndex() const { return Index; }
1159cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
116495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    // This should be used cautiously.
117495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    void setScopeDepth(EHScopeStack::stable_iterator depth) {
118495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      ScopeDepth = depth;
119495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    }
120495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
121ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  private:
122f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    llvm::BasicBlock *Block;
123f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    EHScopeStack::stable_iterator ScopeDepth;
124ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    unsigned Index;
125ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  };
126ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
1275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
128444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &Target;
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13058dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
13145d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
1320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
133f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall  /// CurFuncDecl - Holds the Decl for the current outermost
134f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall  /// non-closure context.
1354111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
136b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
137b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
13888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
139391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1426a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  /// CurGD - The GlobalDecl for the current function being compiled.
1436a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  GlobalDecl CurGD;
1446a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump
145f85e193739c953358c865005855253af4f68a497John McCall  /// PrologueCleanupDepth - The cleanup depth enclosing all the
146f85e193739c953358c865005855253af4f68a497John McCall  /// cleanups associated with the parameters.
147f85e193739c953358c865005855253af4f68a497John McCall  EHScopeStack::stable_iterator PrologueCleanupDepth;
148f85e193739c953358c865005855253af4f68a497John McCall
1495ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
150f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  JumpDest ReturnBlock;
151f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
153f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// iff the function has no return value.
154b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman  llvm::Value *ReturnValue;
1550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
158481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
1590ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
160524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  /// \brief API for captured statement code generation.
161524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  class CGCapturedStmtInfo {
162524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  public:
163524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    explicit CGCapturedStmtInfo(const CapturedStmt &S,
164524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir                                CapturedRegionKind K = CR_Default)
165524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      : Kind(K), ThisValue(0), CXXThisFieldDecl(0) {
166524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
167524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      RecordDecl::field_iterator Field =
168524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir        S.getCapturedRecordDecl()->field_begin();
169524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      for (CapturedStmt::const_capture_iterator I = S.capture_begin(),
170524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir                                                E = S.capture_end();
171524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir           I != E; ++I, ++Field) {
172524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir        if (I->capturesThis())
173524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir          CXXThisFieldDecl = *Field;
174524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir        else
175524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir          CaptureFields[I->getCapturedVar()] = *Field;
176524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      }
177524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    }
178524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
179524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    virtual ~CGCapturedStmtInfo();
180524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
181524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    CapturedRegionKind getKind() const { return Kind; }
182524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
183524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    void setContextValue(llvm::Value *V) { ThisValue = V; }
184524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    // \brief Retrieve the value of the context parameter.
185524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    llvm::Value *getContextValue() const { return ThisValue; }
186524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
187524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief Lookup the captured field decl for a variable.
188524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    const FieldDecl *lookup(const VarDecl *VD) const {
189524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      return CaptureFields.lookup(VD);
190524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    }
191524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
192524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    bool isCXXThisExprCaptured() const { return CXXThisFieldDecl != 0; }
193524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; }
194524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
195524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief Emit the captured statement body.
196524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    virtual void EmitBody(CodeGenFunction &CGF, Stmt *S) {
197524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir      CGF.EmitStmt(S);
198524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    }
199524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
200524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief Get the name of the capture helper.
201524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    virtual StringRef getHelperName() const { return "__captured_stmt"; }
202524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
203524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  private:
204524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief The kind of captured statement being generated.
205524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    CapturedRegionKind Kind;
206524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
207524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief Keep the map between VarDecl and FieldDecl.
208524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields;
209524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
210524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief The base address of the captured record, passed in as the first
211524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// argument of the parallel region function.
212524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    llvm::Value *ThisValue;
213524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
214524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    /// \brief Captured 'this' type.
215524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir    FieldDecl *CXXThisFieldDecl;
216524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  };
217524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  CGCapturedStmtInfo *CapturedStmtInfo;
218524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
219b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes  /// BoundsChecking - Emit run-time bounds checks. Higher values mean
220b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes  /// potentially higher performance penalties.
221b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes  unsigned char BoundsChecking;
222b3198a841e7f356f171f1e11faff014b2deb1eb8Nuno Lopes
223d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith  /// \brief Whether any type-checking sanitizers are enabled. If \c false,
224d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith  /// calls to EmitTypeCheck can be skipped.
225d6396a681c9acbe56bc41bbc2bed2db45755bcd7Richard Smith  bool SanitizePerformTypeCheck;
2269cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
2274f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz  /// \brief Sanitizer options to use for this function.
2284f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz  const SanitizerOptions *SanOpts;
2294f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
230f85e193739c953358c865005855253af4f68a497John McCall  /// In ARC, whether we should autorelease the return value.
231f85e193739c953358c865005855253af4f68a497John McCall  bool AutoreleaseResult;
232f85e193739c953358c865005855253af4f68a497John McCall
233d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  const CodeGen::CGBlockInfo *BlockInfo;
234d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::Value *BlockPointer;
235d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
236cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman  llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields;
237cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman  FieldDecl *LambdaThisCaptureField;
238cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman
2393d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  /// \brief A mapping from NRVO variables to the flags used to indicate
2403d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  /// when the NRVO has been applied to this variable.
2413d91bbcdab155181556969cad6ec97014405acedDouglas Gregor  llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags;
2429cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
243f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  EHScopeStack EHStack;
2448a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  llvm::SmallVector<char, 256> LifetimeExtendedCleanupStack;
2458a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
2468a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// Header for data within LifetimeExtendedCleanupStack.
2478a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  struct LifetimeExtendedCleanupHeader {
2488a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    /// The size of the following cleanup object.
2498a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    size_t Size : 29;
2508a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    /// The kind of cleanup to push: a value from the CleanupKind enumeration.
2518a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    unsigned Kind : 3;
2528a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
2538a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    size_t getSize() const { return Size; }
2548a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    CleanupKind getKind() const { return static_cast<CleanupKind>(Kind); }
2558a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  };
2560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
257ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  /// i32s containing the indexes of the cleanup destinations.
258ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  llvm::AllocaInst *NormalCleanupDest;
259ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
260ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  unsigned NextCleanupDestIndex;
261ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
2621a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  /// FirstBlockInfo - The head of a singly-linked-list of block layouts.
2631a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  CGBlockInfo *FirstBlockInfo;
2641a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall
265777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// EHResumeBlock - Unified block containing a call to llvm.eh.resume.
266777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  llvm::BasicBlock *EHResumeBlock;
267777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall
268285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// The exception slot.  All landing pads write the current exception pointer
269285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// into this alloca.
270f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::Value *ExceptionSlot;
2710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
272285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// The selector slot.  Under the MandatoryCleanup model, all landing pads
273285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// write the current selector value into this alloca.
27493c332a8ba2c193c435b293966d343dab15f555bJohn McCall  llvm::AllocaInst *EHSelectorSlot;
27593c332a8ba2c193c435b293966d343dab15f555bJohn McCall
276f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// Emits a landing pad for the current EH stack.
277f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *EmitLandingPad();
2780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
279f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getInvokeDestImpl();
28099533834ba8f3658559f334e68a518ebb6388ceaMike Stump
281150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  template <class T>
282804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  typename DominatingValue<T>::saved_type saveValueInCond(T value) {
283804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    return DominatingValue<T>::save(*this, value);
284150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
285150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
286f1549f66a8216a78112286e3978cea2c29d6334cJohn McCallpublic:
287f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
288f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// rethrows.
289686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<llvm::Value*, 8> ObjCEHValueStack;
290bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
291d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall  /// A class controlling the emission of a finally block.
292d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall  class FinallyInfo {
293d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// Where the catchall's edge through the cleanup should go.
294d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    JumpDest RethrowDest;
295d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall
296d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// A function to call to enter the catch.
297d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    llvm::Constant *BeginCatchFn;
298d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall
299d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// An i1 variable indicating whether or not the @finally is
300d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// running for an exception.
301d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    llvm::AllocaInst *ForEHVar;
302d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
303d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// An i8* variable into which the exception pointer to rethrow
304d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    /// has been saved.
305d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    llvm::AllocaInst *SavedExnVar;
306d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall
307d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall  public:
308d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    void enter(CodeGenFunction &CGF, const Stmt *Finally,
309d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall               llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn,
310d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall               llvm::Constant *rethrowFn);
311d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall    void exit(CodeGenFunction &CGF);
312d768e9d29abe1ac1ccc3ed63f2dce835d9bab342John McCall  };
313f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
314150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// pushFullExprCleanup - Push a cleanup to be run at the end of the
315150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// current full-expression.  Safe against the possibility that
316150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// we're currently inside a conditionally-evaluated expression.
3173ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  template <class T, class A0>
3183ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  void pushFullExprCleanup(CleanupKind kind, A0 a0) {
3193ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    // If we're not in a conditional branch, or if none of the
3203ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    // arguments requires saving, then use the unconditional cleanup.
321c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall    if (!isInConditionalBranch())
322c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall      return EHStack.pushCleanup<T>(kind, a0);
3233ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall
324804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
3253ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall
3263ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    typedef EHScopeStack::ConditionalCleanup1<T, A0> CleanupType;
3273ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    EHStack.pushCleanup<CleanupType>(kind, a0_saved);
3283ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    initFullExprCleanup();
3293ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  }
3303ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall
3313ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  /// pushFullExprCleanup - Push a cleanup to be run at the end of the
3323ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  /// current full-expression.  Safe against the possibility that
3333ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall  /// we're currently inside a conditionally-evaluated expression.
334150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  template <class T, class A0, class A1>
335150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1) {
336150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    // If we're not in a conditional branch, or if none of the
337150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    // arguments requires saving, then use the unconditional cleanup.
338c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall    if (!isInConditionalBranch())
339c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall      return EHStack.pushCleanup<T>(kind, a0, a1);
340150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
341804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
342804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
343150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
344150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    typedef EHScopeStack::ConditionalCleanup2<T, A0, A1> CleanupType;
3453ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved);
3463ad32c8d93eb65d1d4943d7df567fc9b4f55d137John McCall    initFullExprCleanup();
347150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
348150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
349d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  /// pushFullExprCleanup - Push a cleanup to be run at the end of the
350d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  /// current full-expression.  Safe against the possibility that
351d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  /// we're currently inside a conditionally-evaluated expression.
352d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  template <class T, class A0, class A1, class A2>
353d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2) {
354d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    // If we're not in a conditional branch, or if none of the
355d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    // arguments requires saving, then use the unconditional cleanup.
356d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    if (!isInConditionalBranch()) {
357c4a1a8450a3613ef256a71b9d8305b41f79eef50John McCall      return EHStack.pushCleanup<T>(kind, a0, a1, a2);
358d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    }
359d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor
360d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
361d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
362d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2);
363d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor
364d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    typedef EHScopeStack::ConditionalCleanup3<T, A0, A1, A2> CleanupType;
365d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, a2_saved);
366d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor    initFullExprCleanup();
367d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor  }
368d7b23167763f43d3e76b0de26141b1e52613ee3cDouglas Gregor
3699928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  /// pushFullExprCleanup - Push a cleanup to be run at the end of the
3709928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  /// current full-expression.  Safe against the possibility that
3719928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  /// we're currently inside a conditionally-evaluated expression.
3729928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  template <class T, class A0, class A1, class A2, class A3>
3739928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2, A3 a3) {
3749928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    // If we're not in a conditional branch, or if none of the
3759928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    // arguments requires saving, then use the unconditional cleanup.
3769928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    if (!isInConditionalBranch()) {
3779928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall      return EHStack.pushCleanup<T>(kind, a0, a1, a2, a3);
3789928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    }
3799928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall
3809928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0);
3819928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1);
3829928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2);
3839928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    typename DominatingValue<A3>::saved_type a3_saved = saveValueInCond(a3);
3849928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall
3859928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    typedef EHScopeStack::ConditionalCleanup4<T, A0, A1, A2, A3> CleanupType;
3869928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved,
3879928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall                                     a2_saved, a3_saved);
3889928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    initFullExprCleanup();
3899928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  }
3909928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall
3918a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// \brief Queue a cleanup to be pushed after finishing the current
3928a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// full-expression.
3938a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  template <class T, class A0, class A1, class A2, class A3>
3948a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  void pushCleanupAfterFullExpr(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) {
3958a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    assert(!isInConditionalBranch() && "can't defer conditional cleanup");
3968a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
3978a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    LifetimeExtendedCleanupHeader Header = { sizeof(T), Kind };
3988a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
3998a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    size_t OldSize = LifetimeExtendedCleanupStack.size();
4008a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    LifetimeExtendedCleanupStack.resize(
4018a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith        LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size);
4028a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
4038a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
4048a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    new (Buffer) LifetimeExtendedCleanupHeader(Header);
4058a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    new (Buffer + sizeof(Header)) T(a0, a1, a2, a3);
4068a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  }
4078a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
4086f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  /// Set up the last cleaup that was pushed as a conditional
4096f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  /// full-expression cleanup.
4106f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  void initFullExprCleanup();
4116f103ba42cb69d50005a977c5ea583984ab63fc4John McCall
412f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// PushDestructorCleanup - Push a cleanup to call the
413f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// complete-object destructor of an object of the given type at the
414f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// given address.  Does nothing if T is not a C++ class type with a
415f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// non-trivial destructor.
416f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void PushDestructorCleanup(QualType T, llvm::Value *Addr);
417f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
41881407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// PushDestructorCleanup - Push a cleanup to call the
41981407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// complete-object variant of the given destructor on the object at
42081407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  /// the given address.
42181407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall  void PushDestructorCleanup(const CXXDestructorDecl *Dtor,
42281407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall                             llvm::Value *Addr);
42381407d404a3fc8d24d0e2a052d85cae183033e2bJohn McCall
424f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// PopCleanupBlock - Will pop the cleanup entry on the stack and
425f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// process all branch fixups.
4261c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl  void PopCleanupBlock(bool FallThroughIsBranchThrough = false);
427f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
4287d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall  /// DeactivateCleanupBlock - Deactivates the given cleanup block.
4297d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall  /// The block cannot be reactivated.  Pops it if it's the top of the
4307d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall  /// stack.
4316f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///
4326f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  /// \param DominatingIP - An instruction which is known to
4336f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   dominate the current IP (if set) and which lies along
4346f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   all paths of execution between the current IP and the
4356f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   the point at which the cleanup comes into scope.
4366f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup,
4376f103ba42cb69d50005a977c5ea583984ab63fc4John McCall                              llvm::Instruction *DominatingIP);
4387d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall
4397d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall  /// ActivateCleanupBlock - Activates an initially-inactive cleanup.
4407d8647f194ae4f2499e5bcd40dcfea34cd21ebc6John McCall  /// Cannot be used to resurrect a deactivated cleanup.
4416f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///
4426f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  /// \param DominatingIP - An instruction which is known to
4436f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   dominate the current IP (if set) and which lies along
4446f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   all paths of execution between the current IP and the
4456f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  ///   the point at which the cleanup comes into scope.
4466f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup,
4476f103ba42cb69d50005a977c5ea583984ab63fc4John McCall                            llvm::Instruction *DominatingIP);
448cd2d2b7814e0104ed41a8da159a06a8ca77b70d8John McCall
449f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// \brief Enters a new scope for capturing cleanups, all of which
450f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// will be executed once the scope is exited.
451f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  class RunCleanupsScope {
452f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    EHScopeStack::stable_iterator CleanupStackDepth;
4538a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith    size_t LifetimeExtendedCleanupStackSize;
45401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    bool OldDidCallStackSave;
455ed383135bcffdb8849418896b742fbca7fa2b787John McCall  protected:
4565656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool PerformCleanup;
457ed383135bcffdb8849418896b742fbca7fa2b787John McCall  private:
45801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
459f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    RunCleanupsScope(const RunCleanupsScope &) LLVM_DELETED_FUNCTION;
460f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    void operator=(const RunCleanupsScope &) LLVM_DELETED_FUNCTION;
46101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
462c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher  protected:
463c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    CodeGenFunction& CGF;
4644f45bc099f2665bc6e4bcbb169aa452390dbf3feWill Dietz
46501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  public:
46601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Enter a new cleanup scope.
4679cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer    explicit RunCleanupsScope(CodeGenFunction &CGF)
468c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher      : PerformCleanup(true), CGF(CGF)
4695656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    {
470f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      CleanupStackDepth = CGF.EHStack.stable_begin();
4718a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith      LifetimeExtendedCleanupStackSize =
4728a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith          CGF.LifetimeExtendedCleanupStack.size();
47301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      OldDidCallStackSave = CGF.DidCallStackSave;
4744ada2ca7d82dab68d3646f3eb6dcdfee072e8ea4Argyrios Kyrtzidis      CGF.DidCallStackSave = false;
47501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
47601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
47701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Exit this cleanup scope, emitting any accumulated
47801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// cleanups.
479f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    ~RunCleanupsScope() {
4805656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      if (PerformCleanup) {
4815656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.DidCallStackSave = OldDidCallStackSave;
4828a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith        CGF.PopCleanupBlocks(CleanupStackDepth,
4838a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith                             LifetimeExtendedCleanupStackSize);
4845656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      }
4855656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
4865656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
4875656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Determine whether this scope requires any cleanups.
4885656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool requiresCleanups() const {
489f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      return CGF.EHStack.stable_begin() != CleanupStackDepth;
4905656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
4915656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
4925656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Force the emission of cleanups now, instead of waiting
4935656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// until this object is destroyed.
4945656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    void ForceCleanup() {
4955656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      assert(PerformCleanup && "Already forced cleanup");
49601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.DidCallStackSave = OldDidCallStackSave;
4978a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith      CGF.PopCleanupBlocks(CleanupStackDepth,
4988a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith                           LifetimeExtendedCleanupStackSize);
4995656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      PerformCleanup = false;
50001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
50101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  };
50201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
503c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher  class LexicalScope: protected RunCleanupsScope {
504c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    SourceRange Range;
505495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    SmallVector<const LabelDecl*, 4> Labels;
506495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    LexicalScope *ParentScope;
507c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher
508f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    LexicalScope(const LexicalScope &) LLVM_DELETED_FUNCTION;
509f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko    void operator=(const LexicalScope &) LLVM_DELETED_FUNCTION;
510c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher
511c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher  public:
512c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    /// \brief Enter a new cleanup scope.
513c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range)
514495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) {
515495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      CGF.CurLexicalScope = this;
516c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher      if (CGDebugInfo *DI = CGF.getDebugInfo())
517c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher        DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin());
518c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    }
519c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher
520495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    void addLabel(const LabelDecl *label) {
521495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      assert(PerformCleanup && "adding label to dead scope?");
522495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      Labels.push_back(label);
523495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    }
524495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
525c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    /// \brief Exit this cleanup scope, emitting any accumulated
526c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    /// cleanups.
527c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    ~LexicalScope() {
528efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl      if (CGDebugInfo *DI = CGF.getDebugInfo())
529efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl        DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd());
530efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl
531495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      // If we should perform a cleanup, force them now.  Note that
532495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      // this ends the cleanup scope before rescoping any labels.
533495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      if (PerformCleanup) ForceCleanup();
534c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    }
535c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher
536c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    /// \brief Force the emission of cleanups now, instead of waiting
537c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    /// until this object is destroyed.
538c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    void ForceCleanup() {
539efb72adbae0c253fc2fd9127fb3e1c36cb1b8d93Adrian Prantl      CGF.CurLexicalScope = ParentScope;
540c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher      RunCleanupsScope::ForceCleanup();
541ed383135bcffdb8849418896b742fbca7fa2b787John McCall
542495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      if (!Labels.empty())
543495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem        rescopeLabels();
544c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher    }
545495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
546495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    void rescopeLabels();
547c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher  };
548c3287793626a778178a4dbadcc7b64e392c6e26fEric Christopher
54944ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
5508a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// \brief Takes the old cleanup stack size and emits the cleanup blocks
5518a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// that have been added.
5521c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl  void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize);
55344ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
5548a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// \brief Takes the old cleanup stack size and emits the cleanup blocks
5558a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// that have been added, then adds all lifetime-extended cleanups from
5568a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  /// the given position to the stack.
5578a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize,
5588a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith                        size_t OldLifetimeExtendedStackSize);
5598a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith
560ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  void ResolveBranchFixups(llvm::BasicBlock *Target);
561ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
562f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The given basic block lies in the current EH scope, but may be a
563f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// target of a potentially scope-crossing jump; get a stable handle
564f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to which we can perform this jump later.
565ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) {
566413e67778d593215d2f2161a4e712c8568f1ddd0John McCall    return JumpDest(Target,
567413e67778d593215d2f2161a4e712c8568f1ddd0John McCall                    EHStack.getInnermostNormalCleanup(),
568413e67778d593215d2f2161a4e712c8568f1ddd0John McCall                    NextCleanupDestIndex++);
569f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
570c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
571f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// The given basic block lies in the current EH scope, but may be a
572f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// target of a potentially scope-crossing jump; get a stable handle
573f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// to which we can perform this jump later.
574686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) {
575ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall    return getJumpDestInCurrentScope(createBasicBlock(Name));
576f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
577f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
578f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// EmitBranchThroughCleanup - Emit a branch from the current insert
579f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// block through the normal cleanup handling code (if any) and then
580f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// on to \arg Dest.
581f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  void EmitBranchThroughCleanup(JumpDest Dest);
582b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner
583b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner  /// isObviouslyBranchWithoutCleanups - Return true if a branch to the
584b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner  /// specified destination obviously has no cleanups to run.  'false' is always
585b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner  /// a conservatively correct answer for this method.
586b11f9198111796ada02b57f62cdea92134fde9f7Chris Lattner  bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const;
587f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
588777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// popCatchScope - Pops the catch scope at the top of the EHScope
589777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// stack, emitting any required code (other than the catch handlers
590777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// themselves).
591777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  void popCatchScope();
592ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
593c686004145b1f4dbeb38173a0886ba7040ae0089David Chisnall  llvm::BasicBlock *getEHResumeBlock(bool isCleanup);
594777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope);
5950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
596150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// An object to manage conditionally-evaluated expressions.
597150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  class ConditionalEvaluation {
598150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    llvm::BasicBlock *StartBB;
5991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
600150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  public:
601150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    ConditionalEvaluation(CodeGenFunction &CGF)
602150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      : StartBB(CGF.Builder.GetInsertBlock()) {}
6039cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
604150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    void begin(CodeGenFunction &CGF) {
605150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      assert(CGF.OutermostConditional != this);
606150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      if (!CGF.OutermostConditional)
607150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall        CGF.OutermostConditional = this;
608150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    }
609150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
610150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    void end(CodeGenFunction &CGF) {
611150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      assert(CGF.OutermostConditional != 0);
612150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      if (CGF.OutermostConditional == this)
613150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall        CGF.OutermostConditional = 0;
614150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    }
615150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
616150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    /// Returns a block which will be executed prior to each
617150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    /// evaluation of the conditional code.
618150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    llvm::BasicBlock *getStartingBlock() const {
619150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      return StartBB;
620150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    }
621150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  };
6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6233019c444c672938c57f5573840071ecd73425ee7John McCall  /// isInConditionalBranch - Return true if we're currently emitting
6243019c444c672938c57f5573840071ecd73425ee7John McCall  /// one branch or the other of a conditional expression.
625150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  bool isInConditionalBranch() const { return OutermostConditional != 0; }
626150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
6276f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  void setBeforeOutermostConditional(llvm::Value *value, llvm::Value *addr) {
6286f103ba42cb69d50005a977c5ea583984ab63fc4John McCall    assert(isInConditionalBranch());
6296f103ba42cb69d50005a977c5ea583984ab63fc4John McCall    llvm::BasicBlock *block = OutermostConditional->getStartingBlock();
6306f103ba42cb69d50005a977c5ea583984ab63fc4John McCall    new llvm::StoreInst(value, addr, &block->back());
6316f103ba42cb69d50005a977c5ea583984ab63fc4John McCall  }
6326f103ba42cb69d50005a977c5ea583984ab63fc4John McCall
633150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// An RAII object to record that we're evaluating a statement
634150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// expression.
635150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  class StmtExprEvaluation {
636150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    CodeGenFunction &CGF;
637150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
638150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    /// We have to save the outermost conditional: cleanups in a
639150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    /// statement expression aren't conditional just because the
640150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    /// StmtExpr is.
641150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    ConditionalEvaluation *SavedOutermostConditional;
642150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
643150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  public:
644150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    StmtExprEvaluation(CodeGenFunction &CGF)
645150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) {
646150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      CGF.OutermostConditional = 0;
647150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    }
648150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
649150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    ~StmtExprEvaluation() {
650150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      CGF.OutermostConditional = SavedOutermostConditional;
651150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      CGF.EnsureInsertPoint();
652150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    }
653150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  };
654e996ffd240f20a1048179d7727a6ee3227261921John McCall
65556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// An object which temporarily prevents a value from being
65656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// destroyed by aggressive peephole optimizations that assume that
65756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// all uses of a value have been realized in the IR.
65856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  class PeepholeProtection {
65956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    llvm::Instruction *Inst;
66056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    friend class CodeGenFunction;
66156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
66256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  public:
66356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    PeepholeProtection() : Inst(0) {}
6644b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
66556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
6664b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// A non-RAII class containing all the information about a bound
6674b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// opaque value.  OpaqueValueMapping, below, is a RAII wrapper for
6684b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// this which makes individual mappings very simple; using this
6694b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// class directly is useful when you have a variable number of
6704b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// opaque values or don't want the RAII functionality for some
6714b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// reason.
6724b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class OpaqueValueMappingData {
673e996ffd240f20a1048179d7727a6ee3227261921John McCall    const OpaqueValueExpr *OpaqueValue;
67456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    bool BoundLValue;
67556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    CodeGenFunction::PeepholeProtection Protection;
676e996ffd240f20a1048179d7727a6ee3227261921John McCall
6774b9c2d235fb9449e249d74f48ecfec601650de93John McCall    OpaqueValueMappingData(const OpaqueValueExpr *ov,
6784b9c2d235fb9449e249d74f48ecfec601650de93John McCall                           bool boundLValue)
6794b9c2d235fb9449e249d74f48ecfec601650de93John McCall      : OpaqueValue(ov), BoundLValue(boundLValue) {}
680e996ffd240f20a1048179d7727a6ee3227261921John McCall  public:
6814b9c2d235fb9449e249d74f48ecfec601650de93John McCall    OpaqueValueMappingData() : OpaqueValue(0) {}
6824b9c2d235fb9449e249d74f48ecfec601650de93John McCall
68356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    static bool shouldBindAsLValue(const Expr *expr) {
684a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      // gl-values should be bound as l-values for obvious reasons.
685a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      // Records should be bound as l-values because IR generation
686a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      // always keeps them in memory.  Expressions of function type
687a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      // act exactly like l-values but are formally required to be
688a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      // r-values in C.
689a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall      return expr->isGLValue() ||
690a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall             expr->getType()->isRecordType() ||
691a5493f885095bd63d525a7035ad1c224de3ae5f2John McCall             expr->getType()->isFunctionType();
69256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    }
69356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
6944b9c2d235fb9449e249d74f48ecfec601650de93John McCall    static OpaqueValueMappingData bind(CodeGenFunction &CGF,
6954b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const OpaqueValueExpr *ov,
6964b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const Expr *e) {
6974b9c2d235fb9449e249d74f48ecfec601650de93John McCall      if (shouldBindAsLValue(ov))
6984b9c2d235fb9449e249d74f48ecfec601650de93John McCall        return bind(CGF, ov, CGF.EmitLValue(e));
6994b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return bind(CGF, ov, CGF.EmitAnyExpr(e));
7004b9c2d235fb9449e249d74f48ecfec601650de93John McCall    }
7014b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7024b9c2d235fb9449e249d74f48ecfec601650de93John McCall    static OpaqueValueMappingData bind(CodeGenFunction &CGF,
7034b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const OpaqueValueExpr *ov,
7044b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const LValue &lv) {
7054b9c2d235fb9449e249d74f48ecfec601650de93John McCall      assert(shouldBindAsLValue(ov));
7064b9c2d235fb9449e249d74f48ecfec601650de93John McCall      CGF.OpaqueLValues.insert(std::make_pair(ov, lv));
7074b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return OpaqueValueMappingData(ov, true);
7084b9c2d235fb9449e249d74f48ecfec601650de93John McCall    }
7094b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7104b9c2d235fb9449e249d74f48ecfec601650de93John McCall    static OpaqueValueMappingData bind(CodeGenFunction &CGF,
7114b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const OpaqueValueExpr *ov,
7124b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                       const RValue &rv) {
7134b9c2d235fb9449e249d74f48ecfec601650de93John McCall      assert(!shouldBindAsLValue(ov));
7144b9c2d235fb9449e249d74f48ecfec601650de93John McCall      CGF.OpaqueRValues.insert(std::make_pair(ov, rv));
7154b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7164b9c2d235fb9449e249d74f48ecfec601650de93John McCall      OpaqueValueMappingData data(ov, false);
7174b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7184b9c2d235fb9449e249d74f48ecfec601650de93John McCall      // Work around an extremely aggressive peephole optimization in
7194b9c2d235fb9449e249d74f48ecfec601650de93John McCall      // EmitScalarConversion which assumes that all other uses of a
7204b9c2d235fb9449e249d74f48ecfec601650de93John McCall      // value are extant.
7214b9c2d235fb9449e249d74f48ecfec601650de93John McCall      data.Protection = CGF.protectFromPeepholes(rv);
7224b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7234b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return data;
7244b9c2d235fb9449e249d74f48ecfec601650de93John McCall    }
7254b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7264b9c2d235fb9449e249d74f48ecfec601650de93John McCall    bool isValid() const { return OpaqueValue != 0; }
7274b9c2d235fb9449e249d74f48ecfec601650de93John McCall    void clear() { OpaqueValue = 0; }
7284b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7294b9c2d235fb9449e249d74f48ecfec601650de93John McCall    void unbind(CodeGenFunction &CGF) {
7304b9c2d235fb9449e249d74f48ecfec601650de93John McCall      assert(OpaqueValue && "no data to unbind!");
7314b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7324b9c2d235fb9449e249d74f48ecfec601650de93John McCall      if (BoundLValue) {
7334b9c2d235fb9449e249d74f48ecfec601650de93John McCall        CGF.OpaqueLValues.erase(OpaqueValue);
7344b9c2d235fb9449e249d74f48ecfec601650de93John McCall      } else {
7354b9c2d235fb9449e249d74f48ecfec601650de93John McCall        CGF.OpaqueRValues.erase(OpaqueValue);
7364b9c2d235fb9449e249d74f48ecfec601650de93John McCall        CGF.unprotectFromPeepholes(Protection);
7374b9c2d235fb9449e249d74f48ecfec601650de93John McCall      }
7384b9c2d235fb9449e249d74f48ecfec601650de93John McCall    }
7394b9c2d235fb9449e249d74f48ecfec601650de93John McCall  };
7404b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7414b9c2d235fb9449e249d74f48ecfec601650de93John McCall  /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
7424b9c2d235fb9449e249d74f48ecfec601650de93John McCall  class OpaqueValueMapping {
7434b9c2d235fb9449e249d74f48ecfec601650de93John McCall    CodeGenFunction &CGF;
7444b9c2d235fb9449e249d74f48ecfec601650de93John McCall    OpaqueValueMappingData Data;
7454b9c2d235fb9449e249d74f48ecfec601650de93John McCall
7464b9c2d235fb9449e249d74f48ecfec601650de93John McCall  public:
7474b9c2d235fb9449e249d74f48ecfec601650de93John McCall    static bool shouldBindAsLValue(const Expr *expr) {
7484b9c2d235fb9449e249d74f48ecfec601650de93John McCall      return OpaqueValueMappingData::shouldBindAsLValue(expr);
7494b9c2d235fb9449e249d74f48ecfec601650de93John McCall    }
7504b9c2d235fb9449e249d74f48ecfec601650de93John McCall
75156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    /// Build the opaque value mapping for the given conditional
75256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    /// operator if it's the GNU ?: extension.  This is a common
75356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    /// enough pattern that the convenience operator is really
75456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    /// helpful.
75556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    ///
75656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    OpaqueValueMapping(CodeGenFunction &CGF,
75756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                       const AbstractConditionalOperator *op) : CGF(CGF) {
7584b9c2d235fb9449e249d74f48ecfec601650de93John McCall      if (isa<ConditionalOperator>(op))
7594b9c2d235fb9449e249d74f48ecfec601650de93John McCall        // Leave Data empty.
76056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall        return;
76156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
76256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op);
7634b9c2d235fb9449e249d74f48ecfec601650de93John McCall      Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(),
7644b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                          e->getCommon());
76556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    }
76656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
767e996ffd240f20a1048179d7727a6ee3227261921John McCall    OpaqueValueMapping(CodeGenFunction &CGF,
768e996ffd240f20a1048179d7727a6ee3227261921John McCall                       const OpaqueValueExpr *opaqueValue,
76956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                       LValue lvalue)
7704b9c2d235fb9449e249d74f48ecfec601650de93John McCall      : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {
77156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    }
77256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
77356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    OpaqueValueMapping(CodeGenFunction &CGF,
77456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                       const OpaqueValueExpr *opaqueValue,
77556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall                       RValue rvalue)
7764b9c2d235fb9449e249d74f48ecfec601650de93John McCall      : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {
777e996ffd240f20a1048179d7727a6ee3227261921John McCall    }
778e996ffd240f20a1048179d7727a6ee3227261921John McCall
779e996ffd240f20a1048179d7727a6ee3227261921John McCall    void pop() {
7804b9c2d235fb9449e249d74f48ecfec601650de93John McCall      Data.unbind(CGF);
7814b9c2d235fb9449e249d74f48ecfec601650de93John McCall      Data.clear();
782e996ffd240f20a1048179d7727a6ee3227261921John McCall    }
783e996ffd240f20a1048179d7727a6ee3227261921John McCall
784e996ffd240f20a1048179d7727a6ee3227261921John McCall    ~OpaqueValueMapping() {
7854b9c2d235fb9449e249d74f48ecfec601650de93John McCall      if (Data.isValid()) Data.unbind(CGF);
786e996ffd240f20a1048179d7727a6ee3227261921John McCall    }
787e996ffd240f20a1048179d7727a6ee3227261921John McCall  };
788e220455a059d926953befe72857b9525273717efFariborz Jahanian
789e220455a059d926953befe72857b9525273717efFariborz Jahanian  /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
790e220455a059d926953befe72857b9525273717efFariborz Jahanian  /// number that holds the value.
791e220455a059d926953befe72857b9525273717efFariborz Jahanian  unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
79252a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian
79352a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian  /// BuildBlockByrefAddress - Computes address location of the
79452a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian  /// variable which is declared as __block.
79552a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian  llvm::Value *BuildBlockByrefAddress(llvm::Value *BaseAddr,
79652a80e19ad688091723a52ad53337767bb0ac684Fariborz Jahanian                                      const VarDecl *V);
7977f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
798d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  CGDebugInfo *DebugInfo;
799aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  bool DisableDebugInfo;
80009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
80193c332a8ba2c193c435b293966d343dab15f555bJohn McCall  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
80293c332a8ba2c193c435b293966d343dab15f555bJohn McCall  /// calling llvm.stacksave for multiple VLAs in the same scope.
80393c332a8ba2c193c435b293966d343dab15f555bJohn McCall  bool DidCallStackSave;
80493c332a8ba2c193c435b293966d343dab15f555bJohn McCall
805f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// IndirectBranch - The first time an indirect goto is seen we create a block
806f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// with an indirect branch.  Every time we see the address of a label taken,
807f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// we add the label to the indirect goto.  Every subsequent indirect goto is
808f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// codegen'd as a jump to the IndirectBranch's basic block.
809d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::IndirectBrInst *IndirectBranch;
8100ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
8110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
8120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
8136b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy;
8146b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  DeclMapTy LocalDeclMap;
8155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
817ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap;
8180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
820e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
821da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
822f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    BreakContinue(JumpDest Break, JumpDest Continue)
823f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      : BreakBlock(Break), ContinueBlock(Continue) {}
8240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
825f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest BreakBlock;
826f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    JumpDest ContinueBlock;
8270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
828686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<BreakContinue, 8> BreakContinueStack;
82918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
830170fd49294b85ab10f820721d99ff9d109c7230dZhongxing Xu  /// SwitchInsn - This is nearest current switch instruction. It is null if
8310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
83251b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
83351b09f2c528c8460b5465c676173324e44176d62Devang Patel
8340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
83580fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
836c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
837c049e4f406a7f7179eba98659044a32508e53289Devang Patel
83856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// OpaqueLValues - Keeps track of the current set of opaque value
839e996ffd240f20a1048179d7727a6ee3227261921John McCall  /// expressions.
84056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues;
84156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues;
842e996ffd240f20a1048179d7727a6ee3227261921John McCall
8430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
844bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // We track this by the size expression rather than the type itself because
845bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // in certain situations, like a const qualifier applied to an VLA typedef,
846bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // multiple VLA types can share the same size expression.
8470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
8480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
849bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
8500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
851f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// A block containing a single 'unreachable' instruction.  Created
852f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// lazily by getUnreachableBlock().
853f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *UnreachableBlock;
8540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
855d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl  /// Counts of the number return expressions in the function.
856d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl  unsigned NumReturnExprs;
857fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl
858fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl  /// Count the number of simple (constant) return expressions in the function.
859fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl  unsigned NumSimpleReturnExprs;
860fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl
861d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl  /// The last regular (non-return) debug location (breakpoint) in the function.
862d072e59eb6b5e32f93be25f08f212b0ec21d6c5dAdrian Prantl  SourceLocation LastStopPoint;
863fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl
864c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithpublic:
865c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// A scope within which we are constructing the fields of an object which
866c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use
867c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// if we need to evaluate a CXXDefaultInitExpr within the evaluation.
868c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  class FieldConstructionScope {
869c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  public:
870c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    FieldConstructionScope(CodeGenFunction &CGF, llvm::Value *This)
871c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith        : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) {
872c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith      CGF.CXXDefaultInitExprThis = This;
873c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    }
874c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    ~FieldConstructionScope() {
875c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith      CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis;
876c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    }
877c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
878c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  private:
879c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    CodeGenFunction &CGF;
880c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    llvm::Value *OldCXXDefaultInitExprThis;
881c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  };
882c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
883c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this'
884c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// is overridden to be the object under construction.
885c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  class CXXDefaultInitExprScope {
886c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  public:
887c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    CXXDefaultInitExprScope(CodeGenFunction &CGF)
888c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith        : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue) {
889c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith      CGF.CXXThisValue = CGF.CXXDefaultInitExprThis;
890c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    }
891c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    ~CXXDefaultInitExprScope() {
892c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith      CGF.CXXThisValue = OldCXXThisValue;
893c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    }
894c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
895c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  public:
896c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    CodeGenFunction &CGF;
897c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith    llvm::Value *OldCXXThisValue;
898c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  };
899c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
900c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smithprivate:
901f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXThisDecl - When generating code for a C++ member function,
902f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// this will hold the implicit 'this' declaration.
903cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman  ImplicitParamDecl *CXXABIThisDecl;
904cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman  llvm::Value *CXXABIThisValue;
9052504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXThisValue;
9061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
907c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// The value of 'this' to use when evaluating CXXDefaultInitExprs within
908c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  /// this expression.
909c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith  llvm::Value *CXXDefaultInitExprThis;
910c3bf52ced9652f555aa0767bb822ec4c64546212Richard Smith
91159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  /// CXXStructorImplicitParamDecl - When generating code for a constructor or
91259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  /// destructor, this will hold the implicit argument (e.g. VTT).
91359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  ImplicitParamDecl *CXXStructorImplicitParamDecl;
91459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  llvm::Value *CXXStructorImplicitParamValue;
9159cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
916150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// OutermostConditional - Points to the outermost active
917150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// conditional control.  This is used so that we know if a
918150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// temporary should be destroyed conditionally.
919150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  ConditionalEvaluation *OutermostConditional;
9201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
921495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  /// The current lexical scope.
922495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem  LexicalScope *CurLexicalScope;
9237dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
9241c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl  /// The current source location that should be used for exception
9251c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl  /// handling code.
9261c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl  SourceLocation CurEHLocation;
9271c3db769249a633108dc320da87c48a432e2bcc1Adrian Prantl
9287dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM
9297dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// type as well as the field number that contains the actual data.
9302acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::DenseMap<const ValueDecl *, std::pair<llvm::Type *,
9317dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson                                              unsigned> > ByRefValueInfo;
9329cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
933f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *TerminateLandingPad;
934182f383db1782af752ecaf607fdff72a8542088bMike Stump  llvm::BasicBlock *TerminateHandler;
93583252dcfe61aaebcb6bc117e71dc12968729513fChris Lattner  llvm::BasicBlock *TrapBB;
936940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman
9370df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  /// Add a kernel metadata node to the named metadata node 'opencl.kernels'.
9380df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  /// In the kernel metadata node, reference the kernel function and metadata
9390df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  /// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2):
94037453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly  /// - A node for the vec_type_hint(<type>) qualifier contains string
94137453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly  ///   "vec_type_hint", an undefined value of the <type> data type,
94237453b9580e293eef3bd60bd36047a93ac4515b1Joey Gouly  ///   and a Boolean that is true if the <type> is integer and signed.
9430df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  /// - A node for the work_group_size_hint(X,Y,Z) qualifier contains string
9440df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  ///   "work_group_size_hint", and three 32-bit integers X, Y and Z.
9450df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  /// - A node for the reqd_work_group_size(X,Y,Z) qualifier contains string
9460df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  ///   "reqd_work_group_size", and three 32-bit integers X, Y and Z.
9470df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner  void EmitOpenCLKernelMetadata(const FunctionDecl *FD,
9480df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner                                llvm::Function *Fn);
9490df579ec000ffe52e0cddf1e7ee5e50a55256835Tanya Lattner
9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
9514904bf4e84cfb48080270ebaa9005327f18ab0e5Fariborz Jahanian  CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false);
9521a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  ~CodeGenFunction();
9530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  CodeGenTypes &getTypes() const { return CGM.getTypes(); }
955f2aac84709c418189e476ad591848dad50291885John McCall  ASTContext &getContext() const { return CGM.getContext(); }
956aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  CGDebugInfo *getDebugInfo() {
957aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel    if (DisableDebugInfo)
958aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel      return NULL;
959aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel    return DebugInfo;
960aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  }
961aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  void disableDebugInfo() { DisableDebugInfo = true; }
962aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel  void enableDebugInfo() { DisableDebugInfo = false; }
963aa11289f754d220c9c155b68a4f84cdcfcefef6aDevang Patel
964f85e193739c953358c865005855253af4f68a497John McCall  bool shouldUseFusedARCCalls() {
965f85e193739c953358c865005855253af4f68a497John McCall    return CGM.getCodeGenOpts().OptimizationLevel == 0;
966f85e193739c953358c865005855253af4f68a497John McCall  }
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9684e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie  const LangOptions &getLangOpts() const { return CGM.getLangOpts(); }
969d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
970285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// Returns a pointer to the function's exception object and selector slot,
971285cfd8953d4ca4da613a47a0d691f7234068f8cBill Wendling  /// which is assigned in every landing pad.
972f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::Value *getExceptionSlot();
97393c332a8ba2c193c435b293966d343dab15f555bJohn McCall  llvm::Value *getEHSelectorSlot();
974f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
975ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling  /// Returns the contents of the function's exception object and selector
976ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling  /// slots.
977ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling  llvm::Value *getExceptionFromSlot();
978ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling  llvm::Value *getSelectorFromSlot();
979ae270598d5c7a9a283d4b3ddce53b151c6e2b182Bill Wendling
980ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall  llvm::Value *getNormalCleanupDestSlot();
981ff8e11579fc904aa4032d90d2be6ce1ac5fc9fe1John McCall
982f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getUnreachableBlock() {
983f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    if (!UnreachableBlock) {
984f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      UnreachableBlock = createBasicBlock("unreachable");
985f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall      new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock);
986f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    }
987f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return UnreachableBlock;
988f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
989f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
990f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getInvokeDest() {
991f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    if (!EHStack.requiresLandingPad()) return 0;
992f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall    return getInvokeDestImpl();
993f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  }
9949834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
99564aa4b3ec7e62288e2e66c1935487ece995ca94bJohn McCall  const TargetInfo &getTarget() const { return Target; }
996d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); }
99769243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson
9989834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
999bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  //                                  Cleanups
1000bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  //===--------------------------------------------------------------------===//
1001bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
1002bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  typedef void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty);
1003bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
10042673c68aa58e277ebc755b71d81aca618cdedbf9John McCall  void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin,
10052673c68aa58e277ebc755b71d81aca618cdedbf9John McCall                                        llvm::Value *arrayEndPointer,
10062673c68aa58e277ebc755b71d81aca618cdedbf9John McCall                                        QualType elementType,
1007516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne                                        Destroyer *destroyer);
10082673c68aa58e277ebc755b71d81aca618cdedbf9John McCall  void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
10092673c68aa58e277ebc755b71d81aca618cdedbf9John McCall                                      llvm::Value *arrayEnd,
10102673c68aa58e277ebc755b71d81aca618cdedbf9John McCall                                      QualType elementType,
1011516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne                                      Destroyer *destroyer);
1012bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
10139928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  void pushDestroy(QualType::DestructionKind dtorKind,
10149928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall                   llvm::Value *addr, QualType type);
1015074cae0861a87bf96d8ea56d02e34839d9ccbd0aJohn McCall  void pushEHDestroy(QualType::DestructionKind dtorKind,
1016074cae0861a87bf96d8ea56d02e34839d9ccbd0aJohn McCall                     llvm::Value *addr, QualType type);
1017bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  void pushDestroy(CleanupKind kind, llvm::Value *addr, QualType type,
1018516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne                   Destroyer *destroyer, bool useEHCleanupForArray);
10198a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith  void pushLifetimeExtendedDestroy(CleanupKind kind, llvm::Value *addr,
10208a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith                                   QualType type, Destroyer *destroyer,
10218a07cd3f59a0ede54906bdc8ed21724815db27adRichard Smith                                   bool useEHCleanupForArray);
1022516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne  void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer,
10232673c68aa58e277ebc755b71d81aca618cdedbf9John McCall                   bool useEHCleanupForArray);
1024c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie  llvm::Function *generateDestroyHelper(llvm::Constant *addr, QualType type,
1025516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne                                        Destroyer *destroyer,
1026c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie                                        bool useEHCleanupForArray,
1027c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie                                        const VarDecl *VD);
1028bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  void emitArrayDestroy(llvm::Value *begin, llvm::Value *end,
1029516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne                        QualType type, Destroyer *destroyer,
1030fbf780a9d1dbb191fc40c8af967c590e08724b74John McCall                        bool checkZeroLength, bool useEHCleanup);
1031bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
1032516bbd42e62d709013824d6fb8445a0cfda3129aPeter Collingbourne  Destroyer *getDestroyer(QualType::DestructionKind destructionKind);
10339928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall
1034bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  /// Determines whether an EH cleanup is required to destroy a type
1035bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  /// with the given destruction kind.
1036bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  bool needsEHCleanup(QualType::DestructionKind kind) {
1037bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    switch (kind) {
1038bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    case QualType::DK_none:
1039bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall      return false;
1040bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    case QualType::DK_cxx_destructor:
1041bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    case QualType::DK_objc_weak_lifetime:
10424e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie      return getLangOpts().Exceptions;
1043bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    case QualType::DK_objc_strong_lifetime:
10444e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie      return getLangOpts().Exceptions &&
1045bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall             CGM.getCodeGenOpts().ObjCAutoRefCountExceptions;
1046bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    }
1047bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall    llvm_unreachable("bad destruction kind");
1048bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  }
1049bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
10509928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  CleanupKind getCleanupKind(QualType::DestructionKind kind) {
10519928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall    return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup);
10529928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall  }
10539928c4805aa8d5fabd488d0d0c5aeb64fd50f0e3John McCall
1054bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  //===--------------------------------------------------------------------===//
10559834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
10569834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
10579834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
1058391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
1059af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
10600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
10618d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel                       const ObjCContainerDecl *CD,
10628d3f8979e46f9d0b8735566eabe471db0e1e0e53Devang Patel                       SourceLocation StartLoc);
1063af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
10640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
1065fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
1066fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
10671e1f4871535f2cadcbf8c9af8cc48a2213192320John McCall  void generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1068b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian                              const ObjCPropertyImplDecl *propImpl,
1069490a52b4947381879a47b4251db5fb81cdf5d02bFariborz Jahanian                              const ObjCMethodDecl *GetterMothodDecl,
1070b6e5fe3cae9bf456f084c555c3ecc256f4181cc5Fariborz Jahanian                              llvm::Constant *AtomicHelperFn);
10712846b97965e980ad2e7c8d444b82cc21d733a699Fariborz Jahanian
1072109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian  void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
1073109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian                                  ObjCMethodDecl *MD, bool ctor);
1074af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
10750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
10760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
1077fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
1078fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
107971c758d3f4ecc8b511e6ae4a7210486aa994c182John McCall  void generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
1080cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian                              const ObjCPropertyImplDecl *propImpl,
1081cd93b96bc51c255d104095bc6a6d8eac74a84b1eFariborz Jahanian                              llvm::Constant *AtomicHelperFn);
10820b2bd47151ee9205ad6c66d1ffb921918106088aFariborz Jahanian  bool IndirectObjCSetterArg(const CGFunctionInfo &FI);
108315bd58842adaa4f8cca4e58047ed18e033858d9bFariborz Jahanian  bool IvarTypeWithAggrGCObjects(QualType Ty);
1084af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
10854e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
10864e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
10874e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
10884e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
10896b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  llvm::Value *EmitBlockLiteral(const BlockExpr *);
10901a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info);
10911a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  static void destroyBlockInfos(CGBlockInfo *info);
10922a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst  llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
109389ecd41e0a6bfb3b0913dbe41c3c666340b308c7Fariborz Jahanian                                           const CGBlockInfo &Info,
10942acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                           llvm::StructType *,
1095d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall                                           llvm::Constant *BlockVarLayout);
10964e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
1097564360be450b319aeafc26698be9811837bfb826Fariborz Jahanian  llvm::Function *GenerateBlockFunction(GlobalDecl GD,
10986b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall                                        const CGBlockInfo &Info,
109964bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman                                        const DeclMapTy &ldm,
110064bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman                                        bool IsLambdaConversionToBlock);
11014e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
1102d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo);
1103d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo);
110420abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian  llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction(
110520abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian                                             const ObjCPropertyImplDecl *PID);
110620abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian  llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction(
110720abee6b95c4f5a61e471b4b616439280ca4a81bFariborz Jahanian                                             const ObjCPropertyImplDecl *PID);
1108cae40c4d448529fe65de3d87bdbe97d3b54b4d98Eli Friedman  llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty);
1109d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
1110d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags);
1111d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
11125af02db5a48476e0748f135369663080eae87c64John McCall  class AutoVarEmission;
11135af02db5a48476e0748f135369663080eae87c64John McCall
11145af02db5a48476e0748f135369663080eae87c64John McCall  void emitByrefStructureInit(const AutoVarEmission &emission);
11155af02db5a48476e0748f135369663080eae87c64John McCall  void enterByrefCleanup(const AutoVarEmission &emission);
11165af02db5a48476e0748f135369663080eae87c64John McCall
11176b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  llvm::Value *LoadBlockStruct() {
11186b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    assert(BlockPointer && "no block pointer set!");
11196b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall    return BlockPointer;
11206b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  }
11214e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
1122ea1471e0e967548c596a71469702f8846dbaf3c0John McCall  void AllocateBlockCXXThisPointer(const CXXThisExpr *E);
1123f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  void AllocateBlockDecl(const DeclRefExpr *E);
11246b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall  llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef);
11252acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Type *BuildByRefType(const VarDecl *var);
1126dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
1127d26bc76c98006609002d9930f8840490e88ac5b5John McCall  void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
1128d26bc76c98006609002d9930f8840490e88ac5b5John McCall                    const CGFunctionInfo &FnInfo);
1129f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall  void StartFunction(GlobalDecl GD,
1130f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall                     QualType RetTy,
11317c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
1132d26bc76c98006609002d9930f8840490e88ac5b5John McCall                     const CGFunctionInfo &FnInfo,
11332284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
11349c6082fe89c61af697f017aa80937581cc2128d8Tilmann Scheller                     SourceLocation StartLoc);
1135a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
11369fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitConstructorBody(FunctionArgList &Args);
11379fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitDestructorBody(FunctionArgList &Args);
113856c00c4868831c9a137ca7b0e16d063cf986d110Lang Hames  void emitImplicitAssignmentOperatorBody(FunctionArgList &Args);
11399fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitFunctionBody(FunctionArgList &Args);
1140a355e07454463b19829ac92ffd115a097faff0e0John McCall
114164bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman  void EmitForwardingCallToLambda(const CXXRecordDecl *Lambda,
114264bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman                                  CallArgList &CallArgs);
1143bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman  void EmitLambdaToBlockPointerBody(FunctionArgList &Args);
114464bee65a3436e3f0c352fcfe2130676f3502cffeEli Friedman  void EmitLambdaBlockInvokeBody();
114527dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor  void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD);
114627dd7d962bbf774988bc5e59d04a7743ed503514Douglas Gregor  void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD);
1147bd89f8c2caa9550e41daa1aa9bf30f0f1e0dfaf7Eli Friedman
11480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
11490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
11500a0f93c90fd397a1aa9f97283c55f8ba0062bf55David Blaikie  void EmitReturnBlock();
11511c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
11520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
11530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
1154af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
115517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
1156519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson  /// GenerateThunk - Generate a thunk for the given method.
1157d26bc76c98006609002d9930f8840490e88ac5b5John McCall  void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
1158d26bc76c98006609002d9930f8840490e88ac5b5John McCall                     GlobalDecl GD, const ThunkInfo &Thunk);
11599cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
11607dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman  void GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
11617dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman                            GlobalDecl GD, const ThunkInfo &Thunk);
11627dcdf5ba9324a9577461eae302e88fdd52e310c5Eli Friedman
1163fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor  void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type,
1164fb8cc253420e93cee33d29df5a2bdae6aaf16e39Douglas Gregor                        FunctionArgList &Args);
11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1166b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman  void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init,
1167b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman                               ArrayRef<VarDecl *> ArrayIndexes);
1168b74ed087469db042325bad76fdf3ff6ed67dec09Eli Friedman
1169d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// InitializeVTablePointer - Initialize the vtable pointer of the given
1170d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// subobject.
1171d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  ///
11729cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  void InitializeVTablePointer(BaseSubobject Base,
1173b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                               const CXXRecordDecl *NearestVBase,
1174d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck                               CharUnits OffsetFromNearestVBase,
1175d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson                               const CXXRecordDecl *VTableClass);
1176d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
1177d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
11789cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  void InitializeVTablePointers(BaseSubobject Base,
1179b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                                const CXXRecordDecl *NearestVBase,
1180d6fb21fa1053e5d616af55b181bb03c50d4b0d24Ken Dyck                                CharUnits OffsetFromNearestVBase,
1181603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                bool BaseIsNonVirtualPrimaryBase,
1182603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                const CXXRecordDecl *VTableClass,
1183603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                VisitedVirtualBasesSetTy& VBases);
118477a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman
1185603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson  void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
1186d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
1187043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman  /// GetVTablePtr - Return the Value of the vtable pointer member pointed
1188043fb9a1fc0609285f60f0f87e5a18195408f34cDan Gohman  /// to by This.
11892acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Value *GetVTablePtr(llvm::Value *This, llvm::Type *Ty);
1190d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
11919581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer
11929581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer  /// CanDevirtualizeMemberFunctionCalls - Checks whether virtual calls on given
11939581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer  /// expr can be devirtualized.
11949581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer  bool CanDevirtualizeMemberFunctionCall(const Expr *Base,
11959581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer                                         const CXXMethodDecl *MD);
11969581ed07dee5376002620a0cfb363c6b9e5bdd3eBenjamin Kramer
119750da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// EnterDtorCleanups - Enter the cleanups necessary to complete the
119850da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// given phase of destruction for a destructor.  The end result
119950da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// should call destructors on members and base classes in reverse
120050da2cadcc6da86abff6772de65280ace2cabc94John McCall  /// order of their construction.
120150da2cadcc6da86abff6772de65280ace2cabc94John McCall  void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type);
12021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12037255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// ShouldInstrumentFunction - Return true if the current function should be
12047255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// instrumented with __cyg_profile_func_* calls
12057255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  bool ShouldInstrumentFunction();
12067255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner
12077255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// EmitFunctionInstrumentation - Emit LLVM code to call the specified
12087255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// instrumentation function with the current function and the call site, if
12097255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  /// function instrumentation is enabled.
12107255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner  void EmitFunctionInstrumentation(const char *Fn);
12117255a2d997b15beae82e627052fdb1b2474495c2Chris Lattner
1212be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky  /// EmitMCountInstrumentation - Emit call to .mcount.
1213be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky  void EmitMCountInstrumentation();
1214be4c8705e499b55548467eb7adaa23cbc6edfef9Roman Divacky
12150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
12160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
12170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
121888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
121988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
122017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
122117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
12220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
12230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
1224fa6b079b1231366696f6a497c6a084c73a35c85dAdrian Prantl  void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc);
122517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
1226cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitStartEHSpec - Emit the start of the exception spec.
1227cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitStartEHSpec(const Decl *D);
1228cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
1229cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitEndEHSpec - Emit the end of the exception spec.
1230cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitEndEHSpec(const Decl *D);
1231cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
1232f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// getTerminateLandingPad - Return a landing pad that just calls terminate.
1233f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::BasicBlock *getTerminateLandingPad();
1234f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1235f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// getTerminateHandler - Return a handler (not a landing pad, just
1236f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// a catch handler) that just calls terminate.  This is used when
1237f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  /// a terminate scope encloses a try.
12389b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump  llvm::BasicBlock *getTerminateHandler();
12399b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump
12409cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *ConvertTypeForMem(QualType T);
12419cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *ConvertType(QualType T);
12429cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *ConvertType(const TypeDecl *T) {
1243bff225ecf77fb891596ecb1b27196310d268365eJohn McCall    return ConvertType(getContext().getTypeDeclType(T));
1244bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  }
1245c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
12460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
12470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
1248c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
12490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
125145012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
12524111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
12535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
12545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
12559d232c884ea9872d6555df0fd7359699819bc1f1John McCall  static TypeEvaluationKind getEvaluationKind(QualType T);
12569d232c884ea9872d6555df0fd7359699819bc1f1John McCall
12579d232c884ea9872d6555df0fd7359699819bc1f1John McCall  static bool hasScalarEvaluationKind(QualType T) {
12589d232c884ea9872d6555df0fd7359699819bc1f1John McCall    return getEvaluationKind(T) == TEK_Scalar;
12599d232c884ea9872d6555df0fd7359699819bc1f1John McCall  }
12609d232c884ea9872d6555df0fd7359699819bc1f1John McCall
12619d232c884ea9872d6555df0fd7359699819bc1f1John McCall  static bool hasAggregateEvaluationKind(QualType T) {
12629d232c884ea9872d6555df0fd7359699819bc1f1John McCall    return getEvaluationKind(T) == TEK_Aggregate;
12639d232c884ea9872d6555df0fd7359699819bc1f1John McCall  }
126455e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
126555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
12664def70d3040e73707c738f7c366737a986135edfRichard Smith  llvm::BasicBlock *createBasicBlock(const Twine &name = "",
1267d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall                                     llvm::Function *parent = 0,
1268d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall                                     llvm::BasicBlock *before = 0) {
126929ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
1270d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall    return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before);
127129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
1272d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall    return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before);
127329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
127455e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
12750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
1278ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  JumpDest getJumpDestForLabel(const LabelDecl *S);
12790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1280f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// SimplifyForwardingBlocks - If the given basic block is only a branch to
1281f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// another basic block, simplify it. This assumes that no other code could
1282f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// potentially reference the basic block.
1283aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
1284aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
12850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
12860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
12870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
12880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
1289a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
12900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
12910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
12920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
1293a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
1294824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
1295777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// EmitBlockAfterUses - Emit the given block somewhere hopefully
1296777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  /// near its uses, and leave the insertion point in it.
1297777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall  void EmitBlockAfterUses(llvm::BasicBlock *BB);
1298777d6e56ad9b1fed9866daf3ee6486d85c5b7d32John McCall
12990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
13000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
13010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
13020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
13035e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
13040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
13050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
13060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
1307d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
1308d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
13090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
13100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
13110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
1312a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
1313a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
1314a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
13150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
13160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
13170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
13180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
1319a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
1320a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
1321a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
1322a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
13230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1324488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
1325dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
13260a1c862914664029e3b6693e134cf3ccbf423844David Blaikie  void ErrorUnsupported(const Stmt *S, const char *Type);
13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
13295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
13310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13326da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman  LValue MakeAddrLValue(llvm::Value *V, QualType T,
13336da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman                        CharUnits Alignment = CharUnits()) {
13343d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman    return LValue::MakeAddr(V, T, Alignment, getContext(),
13353d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman                            CGM.getTBAAInfo(T));
13362f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman  }
1337e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall
13382f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman  LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
13396da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman    CharUnits Alignment;
13406da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman    if (!T->isIncompleteType())
13416da2c716017d5c8530ec99779524491ebc5dadb8Eli Friedman      Alignment = getContext().getTypeAlignInChars(T);
13422f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman    return LValue::MakeAddr(V, T, Alignment, getContext(),
13432f77b3d57031ded0de2b7b977fb63b4660f82624Eli Friedman                            CGM.getTBAAInfo(T));
13445cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar  }
13455cf8bfec711116b3c4acc70a00717b2e119e7550Daniel Dunbar
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
1347195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// block. The caller is responsible for setting an appropriate alignment on
1348195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// the alloca.
13492acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty,
13508cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner                                     const Twine &Name = "tmp");
13510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1352ac418162692a951ca3796d6830496a85a2d12493John McCall  /// InitTempAlloca - Provide an initial value for the given alloca.
1353ac418162692a951ca3796d6830496a85a2d12493John McCall  void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value);
1354ac418162692a951ca3796d6830496a85a2d12493John McCall
13559bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// CreateIRTemp - Create a temporary IR object of the given type, with
13569bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// appropriate alignment. This routine should only be used when an temporary
13579bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// value needs to be stored into an alloca (for example, to avoid explicit
13589bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// PHI construction), but the type is the IR type, not the type appropriate
13599bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// for storing in memory.
13608cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  llvm::AllocaInst *CreateIRTemp(QualType T, const Twine &Name = "tmp");
13619bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar
1362195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// CreateMemTemp - Create a temporary memory object of the given type, with
1363195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// appropriate alignment.
13648cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  llvm::AllocaInst *CreateMemTemp(QualType T, const Twine &Name = "tmp");
1365195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar
1366558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// CreateAggTemp - Create a temporary memory object for the given
1367558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// aggregate type.
13688cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner  AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") {
1369d7722d9d76a851e7897f4127626616d3b1b8e530Eli Friedman    CharUnits Alignment = getContext().getTypeAlignInChars(T);
1370f394078fde147dcf27e9b6a7965517388d64dcb6Eli Friedman    return AggValueSlot::forAddr(CreateMemTemp(T, Name), Alignment,
1371f394078fde147dcf27e9b6a7965517388d64dcb6Eli Friedman                                 T.getQualifiers(),
13727c2349be2d11143a2e59a167fd43362a3bf4585eJohn McCall                                 AggValueSlot::IsNotDestructed,
1373410ffb2bc5f072d58a73c14560345bcf77dec1ccJohn McCall                                 AggValueSlot::DoesNotNeedGCBarriers,
1374649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier                                 AggValueSlot::IsNotAliased);
1375558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  }
1376558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall
1377d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  /// Emit a cast to void* in the appropriate address space.
1378d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall  llvm::Value *EmitCastToVoidPtr(llvm::Value *value);
1379d16c2cf1cafa413709aa487cbbd5dc392f1ba1ffJohn McCall
13805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
13815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
13825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
13835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13842a41637a995affa1563f4d82a8b026e326a2faa0John McCall  /// EmitIgnoredExpr - Emit an expression in a context which ignores the result.
13852a41637a995affa1563f4d82a8b026e326a2faa0John McCall  void EmitIgnoredExpr(const Expr *E);
13862a41637a995affa1563f4d82a8b026e326a2faa0John McCall
13879b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
13889b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
13899b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
13909b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
139149d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
139270517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko  /// \param ignoreResult True if the resulting value isn't used.
1393558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  RValue EmitAnyExpr(const Expr *E,
1394e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall                     AggValueSlot aggSlot = AggValueSlot::ignored(),
1395e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall                     bool ignoreResult = false);
1396d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
13970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
13980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
13994fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
14004fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
14010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
14020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
1403558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  RValue EmitAnyExprToTemp(const Expr *E);
140446f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
140560d3365b46eb826fba44483583c0051ac5c41fe3John McCall  /// EmitAnyExprToMem - Emits the code necessary to evaluate an
1406649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier  /// arbitrary expression into the given memory location.
14073d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  void EmitAnyExprToMem(const Expr *E, llvm::Value *Location,
1408649b4a1a9b5e6f768ca0cb84bd97b00f51083e15Chad Rosier                        Qualifiers Quals, bool IsInitializer);
14093d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall
141060d3365b46eb826fba44483583c0051ac5c41fe3John McCall  /// EmitExprAsInit - Emits the code necessary to initialize a
141160d3365b46eb826fba44483583c0051ac5c41fe3John McCall  /// location in memory with the given initializer.
1412f85e193739c953358c865005855253af4f68a497John McCall  void EmitExprAsInit(const Expr *init, const ValueDecl *D,
1413a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall                      LValue lvalue, bool capturedByInit);
141460d3365b46eb826fba44483583c0051ac5c41fe3John McCall
14153ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian  /// hasVolatileMember - returns true if aggregate type has a volatile
14163ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian  /// member.
14173ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian  bool hasVolatileMember(QualType T) {
14183ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian    if (const RecordType *RT = T->getAs<RecordType>()) {
14193ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian      const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
14203ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian      return RD->hasVolatileMember();
14213ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian    }
14223ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian    return false;
14233ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian  }
14248fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison  /// EmitAggregateCopy - Emit an aggregate assignment.
14256cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  ///
14266cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  /// The difference to EmitAggregateCopy is that tail padding is not copied.
14276cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  /// This is required for correctness when assigning non-POD structures in C++.
14286cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  void EmitAggregateAssign(llvm::Value *DestPtr, llvm::Value *SrcPtr,
14293ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian                           QualType EltTy) {
14303ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian    bool IsVolatile = hasVolatileMember(EltTy);
14313ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian    EmitAggregateCopy(DestPtr, SrcPtr, EltTy, IsVolatile, CharUnits::Zero(),
14323ac83d69c61238cd0d38e90fcdd03390530ab2fbFariborz Jahanian                      true);
14336cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  }
14346cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer
14358fcbb8dfbc28b6279d22144e10ade401a6c03e9eArnaud A. de Grandmaison  /// EmitAggregateCopy - Emit an aggregate copy.
143627fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
1437f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru  /// \param isVolatile - True iff either the source or the destination is
143827fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
14396cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  /// \param isAssignment - If false, allow padding to be copied.  This often
14406cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer  /// yields more efficient.
14417482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
1442bd7d82878c1588afccbee6c68fa6e17bbbab7f2cEli Friedman                         QualType EltTy, bool isVolatile=false,
14436cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer                         CharUnits Alignment = CharUnits::Zero(),
14446cacae8bf9597b8124cd40aedc189c04484e1990Benjamin Kramer                         bool isAssignment = false);
14457482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
144651b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
144751b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
144851b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
144951b09f2c528c8460b5465c676173324e44176d62Devang Patel
1450dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
14514c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) {
14524c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall    llvm::Value *Res = LocalDeclMap[VD];
14534c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall    assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!");
14544c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall    return Res;
14554c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
14560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
145756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// getOpaqueLValueMapping - Given an opaque value expression (which
145856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// must be mapped to an l-value), return its mapping.
145956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) {
146056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    assert(OpaqueValueMapping::shouldBindAsLValue(e));
146156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
146256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator
146356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      it = OpaqueLValues.find(e);
146456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    assert(it != OpaqueLValues.end() && "no mapping for opaque value!");
146556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    return it->second;
146656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  }
146756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
146856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// getOpaqueRValueMapping - Given an opaque value expression (which
146956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// must be mapped to an r-value), return its mapping.
147056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) {
147156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    assert(!OpaqueValueMapping::shouldBindAsLValue(e));
147256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
147356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator
147456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall      it = OpaqueRValues.find(e);
147556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall    assert(it != OpaqueRValues.end() && "no mapping for opaque value!");
1476e996ffd240f20a1048179d7727a6ee3227261921John McCall    return it->second;
1477e996ffd240f20a1048179d7727a6ee3227261921John McCall  }
1478e996ffd240f20a1048179d7727a6ee3227261921John McCall
14794f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
14804f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
14814f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
14824f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
1483ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L);
14843d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner  llvm::BasicBlock *GetIndirectGotoBlock();
14850ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
14861884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// EmitNullInitialization - Generate code to set a value of the given type to
14871884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// null, If the type contains data member pointers, they will be initialized
14881884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  /// to -1 in accordance with the Itanium C++ ABI.
14891884eb0b5c55edda4893ddec45e7dbad79758782Anders Carlsson  void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty);
1490ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
1491ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
1492ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
1493ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
14940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
1495ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
1496f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
1497bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  /// emitArrayLength - Compute the length of an array, even if it's a
1498bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  /// VLA, and drill down to the base element type.
1499bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  llvm::Value *emitArrayLength(const ArrayType *arrayType,
1500bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall                               QualType &baseType,
1501bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall                               llvm::Value *&addr);
1502bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
1503bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// EmitVLASize - Capture all the sizes for the VLA expressions in
1504bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// the given variably-modified type and store them in the VLASizeMap.
1505d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1506d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
1507bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  void EmitVariablyModifiedType(QualType Ty);
1508bc8d40d85f3fa1e34569834916f18fecaa635152John McCall
1509bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// getVLASize - Returns an LLVM value that corresponds to the size,
1510bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// in non-variably-sized elements, of a variable length array type,
1511bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// plus that largest non-variably-sized element type.  Assumes that
1512bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  /// the type has already been emitted with EmitVariablyModifiedType.
1513bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla);
1514bc8d40d85f3fa1e34569834916f18fecaa635152John McCall  std::pair<llvm::Value*,QualType> getVLASize(QualType vla);
1515dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
15165f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
15175f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
15182504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXThis() {
15192504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXThisValue && "no 'this' value for this function");
15202504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXThisValue;
15212504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1523c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
1524c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// virtual bases.
152559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // FIXME: Every place that calls LoadCXXVTT is something
152659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // that needs to be abstracted properly.
15272504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXVTT() {
152859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    assert(CXXStructorImplicitParamValue && "no VTT value for this function");
152959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CXXStructorImplicitParamValue;
153059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
153159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov
153259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  /// LoadCXXStructorImplicitParam - Load the implicit parameter
153359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  /// for a constructor/destructor.
153459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  llvm::Value *LoadCXXStructorImplicitParam() {
153559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    assert(CXXStructorImplicitParamValue &&
153659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov           "no implicit argument value for this function");
153759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CXXStructorImplicitParamValue;
15382504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
1539bff225ecf77fb891596ecb1b27196310d268365eJohn McCall
1540bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
15418561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  /// complete class to the given direct base.
15428561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  llvm::Value *
15438561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value,
15448561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
15458561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Base,
15468561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        bool BaseIsVirtual);
1547a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson
1548f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// GetAddressOfBaseClass - This function will add the necessary delta to the
1549f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// load of 'this' and returns address of the base class.
15509cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  llvm::Value *GetAddressOfBaseClass(llvm::Value *Value,
15518561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                     const CXXRecordDecl *Derived,
1552f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                     CastExpr::path_const_iterator PathBegin,
1553f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                     CastExpr::path_const_iterator PathEnd,
155434a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson                                     bool NullCheckValue);
155534a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson
1556a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson  llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
15578561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
1558f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        CastExpr::path_const_iterator PathBegin,
1559f871d0cc377a1367b519a6cce26be74607566ebaJohn McCall                                        CastExpr::path_const_iterator PathEnd,
15605a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson                                        bool NullCheckValue);
1561a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson
15621d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  /// GetVTTParameter - Return the VTT parameter that should be passed to a
15631d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  /// base constructor/destructor with virtual bases.
15641d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  /// FIXME: VTTs are Itanium ABI-specific, so the definition should move
15651d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  /// to ItaniumCXXABI.cpp together with all the references to VTT.
15661d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase,
15671d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                               bool Delegating);
15681d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
1569c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall  void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,
1570c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      CXXCtorType CtorType,
1571c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      const FunctionArgList &Args);
1572059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt  // It's important not to confuse this and the previous function. Delegating
1573059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt  // constructors are the C++0x feature. The constructor delegate optimization
1574059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt  // is used to reduce duplication in the base and complete consturctors where
1575059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt  // they are substantially the same.
1576059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt  void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor,
1577059ce0d92eb5a7da900ae735dc0a2ea3d64f4b0bSean Hunt                                        const FunctionArgList &Args);
1578155ed4a23366f4514befb1c9f5f89d16f8b8b6dbAnders Carlsson  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
1579378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor                              bool ForVirtualBase, bool Delegating,
1580378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor                              llvm::Value *This,
1581b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
1582b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
158334999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian
158434999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian  void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D,
158534999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian                              llvm::Value *This, llvm::Value *Src,
158634999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian                              CallExpr::const_arg_iterator ArgBeg,
158734999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian                              CallExpr::const_arg_iterator ArgEnd);
15881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1589288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
1590569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  const ConstantArrayType *ArrayTy,
15915d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
15925d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
159359174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  CallExpr::const_arg_iterator ArgEnd,
159459174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  bool ZeroInitialization = false);
15959cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
1596569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
1597569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  llvm::Value *NumElements,
15985d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
15995d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
160059174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  CallExpr::const_arg_iterator ArgEnd,
160159174c0633fb5cde41735cfbff5744bdf837e8d9Douglas Gregor                                  bool ZeroInitialization = false);
1602b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
1603bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  static Destroyer destroyCXXObject;
1604bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
16057267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
1606378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor                             bool ForVirtualBase, bool Delegating,
1607378e1e739aed97e9b278beeb20e9f5bbe34c0232Douglas Gregor                             llvm::Value *This);
16089cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
1609197056726ed6412501130c2ef2ff69009772aa65John McCall  void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType,
1610197056726ed6412501130c2ef2ff69009772aa65John McCall                               llvm::Value *NewPtr, llvm::Value *NumElements);
16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
161286811609d9353e3aed198045d56e790eb3b6118cPeter Collingbourne  void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType,
161386811609d9353e3aed198045d56e790eb3b6118cPeter Collingbourne                        llvm::Value *Ptr);
16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1615a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson  llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
161660e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson  void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
16184bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman  void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
16194bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman                      QualType DeleteTy);
16204bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman
1621c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
1622c849c052d6b4b70f2651c1969531861a5f230053Mike Stump  llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
1623c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  llvm::Value* EmitCXXUuidofExpr(const CXXUuidofExpr *E);
1624c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
16252c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith  /// \brief Situations in which we might emit a check for the suitability of a
16262c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith  ///        pointer or glvalue.
16277ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  enum TypeCheckKind {
16282c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Checking the operand of a load. Must be suitably sized and aligned.
16297ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith    TCK_Load,
16302c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Checking the destination of a store. Must be suitably sized and aligned.
16317ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith    TCK_Store,
16322c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Checking the bound value in a reference binding. Must be suitably sized
16332c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// and aligned, but is not required to refer to an object (until the
16342c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// reference is used), per core issue 453.
16357ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith    TCK_ReferenceBinding,
16362c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Checking the object expression in a non-static data member access. Must
16372c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// be an object within its lifetime.
16387ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith    TCK_MemberAccess,
16392c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Checking the 'this' pointer for a call to a non-static member function.
16402c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith    /// Must be an object within its lifetime.
16418e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith    TCK_MemberCall,
16428e1cee6f23e2552b96b81e5ef419ab3f69c5b5c2Richard Smith    /// Checking the 'this' pointer for a constructor call.
1643c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    TCK_ConstructorCall,
1644c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    /// Checking the operand of a static_cast to a derived pointer type. Must be
1645c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    /// null or an object within its lifetime.
1646c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    TCK_DowncastPointer,
1647c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    /// Checking the operand of a static_cast to a derived reference type. Must
1648c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    /// be an object within its lifetime.
1649c764830bdb6de82baed068889096bd3e52d4cbdaRichard Smith    TCK_DowncastReference
16502c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith  };
16512c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith
16527ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  /// \brief Emit a check that \p V is the address of storage of the
16532c9f87ca5cccbfdaad82762368af5b2323320653Richard Smith  /// appropriate size and alignment for an object of type \p Type.
16544def70d3040e73707c738f7c366737a986135edfRichard Smith  void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V,
16557ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith                     QualType Type, CharUnits Alignment = CharUnits::Zero());
1656b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
1657a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith  /// \brief Emit a check that \p Base points into an array object, which
1658a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith  /// we can access at index \p Index. \p Accessed should be \c false if we
1659a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith  /// this expression is used as an lvalue, for instance in "&Arr[Idx]".
1660a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith  void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index,
1661a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith                       QualType IndexType, bool Accessed);
1662a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith
1663dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
1664dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                       bool isInc, bool isPre);
1665dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
1666dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                         bool isInc, bool isPre);
16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
16685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
16695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
16700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1671d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitDecl - Emit a declaration.
1672d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1673d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
16745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
1675d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
1676b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  /// EmitVarDecl - Emit a local variable declaration.
1677d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1678d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
1679b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  void EmitVarDecl(const VarDecl &D);
1680d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
1681f85e193739c953358c865005855253af4f68a497John McCall  void EmitScalarInit(const Expr *init, const ValueDecl *D,
1682a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall                      LValue lvalue, bool capturedByInit);
16837acddacc921cd0b3f813443a8641eeddb82dfbd4John McCall  void EmitScalarInit(llvm::Value *init, LValue lvalue);
1684f85e193739c953358c865005855253af4f68a497John McCall
1685f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D,
1686f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall                             llvm::Value *Address);
1687f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
1688b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  /// EmitAutoVarDecl - Emit an auto variable declaration.
1689d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
1690d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
169134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  void EmitAutoVarDecl(const VarDecl &D);
169234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
169334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  class AutoVarEmission {
169434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    friend class CodeGenFunction;
169534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
169657b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall    const VarDecl *Variable;
169734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
169834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// The alignment of the variable.
169934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    CharUnits Alignment;
170034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
170134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// The address of the alloca.  Null if the variable was emitted
170234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// as a global constant.
170334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    llvm::Value *Address;
170434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
170534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    llvm::Value *NRVOFlag;
170634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
170734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// True if the variable is a __block variable.
170834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    bool IsByRef;
170934695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
171034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// True if the variable is of aggregate type and has a constant
171134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// initializer.
171234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    bool IsConstantAggregate;
171334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
1714495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    /// Non-null if we should use lifetime annotations.
1715495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    llvm::Value *SizeForLifetimeMarkers;
1716495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
171757b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall    struct Invalid {};
171857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall    AutoVarEmission(Invalid) : Variable(0) {}
171957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall
172034695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    AutoVarEmission(const VarDecl &variable)
172157b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall      : Variable(&variable), Address(0), NRVOFlag(0),
1722495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem        IsByRef(false), IsConstantAggregate(false),
1723495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem        SizeForLifetimeMarkers(0) {}
172434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
172534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    bool wasEmittedAsGlobal() const { return Address == 0; }
172634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
172734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  public:
172857b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall    static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
1729495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
1730495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    bool useLifetimeMarkers() const { return SizeForLifetimeMarkers != 0; }
1731495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    llvm::Value *getSizeForLifetimeMarkers() const {
1732495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      assert(useLifetimeMarkers());
1733495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      return SizeForLifetimeMarkers;
1734495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    }
1735495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem
1736495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    /// Returns the raw, allocated address, which is not necessarily
1737495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    /// the address of the object itself.
1738495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    llvm::Value *getAllocatedAddress() const {
1739495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem      return Address;
1740495cfa46300979642acde8d93a1f21c9291dac98Nadav Rotem    }
174157b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall
174234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// Returns the address of the object within this declaration.
174334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// Note that this does not chase the forwarding pointer for
174434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    /// __block decls.
174534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    llvm::Value *getObjectAddress(CodeGenFunction &CGF) const {
174634695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall      if (!IsByRef) return Address;
174734695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall
174834695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall      return CGF.Builder.CreateStructGEP(Address,
174957b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall                                         CGF.getByRefValueLLVMField(Variable),
175057b3b6a60856eaec30fd876a8a3face8f7e3ad7bJohn McCall                                         Variable->getNameAsString());
175134695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall    }
175234695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  };
175334695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  AutoVarEmission EmitAutoVarAlloca(const VarDecl &var);
175434695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  void EmitAutoVarInit(const AutoVarEmission &emission);
175534695856c0e67b3765b46304cc71b5d2cd5b71c7John McCall  void EmitAutoVarCleanups(const AutoVarEmission &emission);
1756bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
1757bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall                              QualType::DestructionKind dtorKind);
1758d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
1759b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  void EmitStaticVarDecl(const VarDecl &D,
1760b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall                         llvm::GlobalValue::LinkageTypes Linkage);
1761b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
1762b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
1763093ac461b37a573dcf226fa55faed96f318169b9Devang Patel  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, unsigned ArgNo);
17640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
176556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// protectFromPeepholes - Protect a value that we're intending to
176656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// store to the side, but which will probably be used later, from
176756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// aggressive peepholing optimizations that might delete it.
176856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///
176956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// Pass the result to unprotectFromPeepholes to declare that
177056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// protection is no longer required.
177156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  ///
177256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// There's no particular reason why this shouldn't apply to
177356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  /// l-values, it's just that no existing peepholes work on pointers.
177456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  PeepholeProtection protectFromPeepholes(RValue rvalue);
177556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  void unprotectFromPeepholes(PeepholeProtection protection);
177656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
17775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
17785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
17795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
17805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
17820912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
17830912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
17840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
17850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
17860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
17870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
17880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
17890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
17905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
1791a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
17920912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
17930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
17940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
17950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
17960912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
17970912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
17980912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
17990912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
18002ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman  llvm::Value *EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
18012ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman                                AggValueSlot AVS = AggValueSlot::ignored());
18022ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman  llvm::Value *EmitCompoundStmtWithoutScope(const CompoundStmt &S,
18032ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman                                            bool GetLast = false,
18042ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman                                            AggValueSlot AVS =
18052ac2fa7726eb2f6fe445e098489e92931c31f7caEli Friedman                                                AggValueSlot::ignored());
1806a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
18070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
18080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
1809ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner  void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt.
1810a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
18115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
1812534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith  void EmitAttributedStmt(const AttributedStmt &S);
18135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
18140ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
18155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
18165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
18175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
18185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
18195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
18205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
18210912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
18220912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
182351b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
182451b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
182551b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
1826c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
1827a23b91d542e336be5051ac54f394e860fb756911Chad Rosier  void EmitAsmStmt(const AsmStmt &S);
18280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
18293d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
183064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
183164d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
183210cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
1833f85e193739c953358c865005855253af4f68a497John McCall  void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S);
18340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
183593c332a8ba2c193c435b293966d343dab15f555bJohn McCall  llvm::Constant *getUnwindResumeFn();
183686a3a03667bdb0dcab7e6a2877dfd234b07a6d43Douglas Gregor  llvm::Constant *getUnwindResumeOrRethrowFn();
183759a7000a79118e4c140885ccbb2ac6a686a73092John McCall  void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
183859a7000a79118e4c140885ccbb2ac6a686a73092John McCall  void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false);
18399fc6a7774643a810c8501dae2323e863fefb623eJohn McCall
18406815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  void EmitCXXTryStmt(const CXXTryStmt &S);
1841ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith  void EmitCXXForRangeStmt(const CXXForRangeStmt &S);
18429cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
1843524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K);
1844524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir  llvm::Function *GenerateCapturedStmtFunction(const CapturedDecl *CD,
1845524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir                                               const RecordDecl *RD);
1846524387ae3dfc0c4cf2b095f83f9e47aa549b7e55Ben Langmuir
18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
18485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
185113e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
185213e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
185313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
1854ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
1855ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
1856ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
1857ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
1858ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
1859ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
18600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
18610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
18626ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
18636ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
18646ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
18675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
18725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
18765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
18805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
18815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
18820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
18837ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  /// \brief Same as EmitLValue but additionally we generate checking code to
18847ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  /// guard against undefined behavior.  This is only suitable when we know
18857ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  /// that the address will be used to access the object.
18867ac9ef1c82c779a5348ed11b3d10e01c58803b35Richard Smith  LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK);
1887b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
18889d232c884ea9872d6555df0fd7359699819bc1f1John McCall  RValue convertTempToRValue(llvm::Value *addr, QualType type);
18899d232c884ea9872d6555df0fd7359699819bc1f1John McCall
18909eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall  void EmitAtomicInit(Expr *E, LValue lvalue);
18919eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall
18929eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall  RValue EmitAtomicLoad(LValue lvalue,
18939eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall                        AggValueSlot slot = AggValueSlot::ignored());
18949eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall
18959eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall  void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit);
18969eda3abe7e183b05834947391c0cdc291f4ee0d8John McCall
189726815d97c5743481e317f17a8d53a6819d061862John McCall  /// EmitToMemory - Change a scalar value from its value
189826815d97c5743481e317f17a8d53a6819d061862John McCall  /// representation to its in-memory representation.
189926815d97c5743481e317f17a8d53a6819d061862John McCall  llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty);
190026815d97c5743481e317f17a8d53a6819d061862John McCall
190126815d97c5743481e317f17a8d53a6819d061862John McCall  /// EmitFromMemory - Change a scalar value from its memory
190226815d97c5743481e317f17a8d53a6819d061862John McCall  /// representation to its value representation.
190326815d97c5743481e317f17a8d53a6819d061862John McCall  llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty);
190426815d97c5743481e317f17a8d53a6819d061862John McCall
19059d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
19069d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
19079d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
190809429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
19093d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman                                unsigned Alignment, QualType Ty,
1910b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                                llvm::MDNode *TBAAInfo = 0,
1911b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                                QualType TBAABaseTy = QualType(),
1912b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                                uint64_t TBAAOffset = 0);
1913545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall
1914545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// EmitLoadOfScalar - Load a scalar value from an address, taking
1915545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// care to appropriately convert from the memory representation to
1916545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// the LLVM value representation.  The l-value must be a simple
1917545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// l-value.
1918a07398ed98ea2b55ad7a505a3aab18aed93b149fJohn McCall  llvm::Value *EmitLoadOfScalar(LValue lvalue);
19199d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
19209d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
19219d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
19229d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
192309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
19243d5aff5d3036b0ff09d114857cd2276134b3d8c9Dan Gohman                         bool Volatile, unsigned Alignment, QualType Ty,
1925b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                         llvm::MDNode *TBAAInfo = 0, bool isInit = false,
1926b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                         QualType TBAABaseTy = QualType(),
1927b37a73d5c6a0c8bb1f6e363d3b53980e4fa0ceadManman Ren                         uint64_t TBAAOffset = 0);
1928545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall
1929545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// EmitStoreOfScalar - Store a scalar value to an address, taking
1930545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// care to appropriately convert from the memory representation to
1931545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  /// the LLVM value representation.  The l-value must be a simple
19327a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall  /// l-value.  The isInit flag indicates whether this is an initialization.
19337a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall  /// If so, atomic qualifiers are ignored and the store is always non-atomic.
19347a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall  void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false);
19359d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
19385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
1939545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  RValue EmitLoadOfLValue(LValue V);
1940545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  RValue EmitLoadOfExtVectorElementLValue(LValue V);
1941545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  RValue EmitLoadOfBitfieldLValue(LValue LV);
19420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
19435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
19467a7ee3033e44b45630981355460ef89efa0bdcc4David Chisnall  void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false);
1947545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst);
1948ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
19490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
19500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
1951ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
19520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
19530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
19540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
1955545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
1956ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
19570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
195883ce9d4a552987d34cbd500e983db8d770232379John McCall  /// Emit an l-value for an assignment (simple or compound) of complex type.
195983ce9d4a552987d34cbd500e983db8d770232379John McCall  LValue EmitComplexAssignmentLValue(const BinaryOperator *E);
19602a41637a995affa1563f4d82a8b026e326a2faa0John McCall  LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E);
19610934e18b620ecaa6c7ec18ba5c4286b6122d6fb8Eli Friedman  LValue EmitScalarCompooundAssignWithComplex(const CompoundAssignOperator *E,
19620934e18b620ecaa6c7ec18ba5c4286b6122d6fb8Eli Friedman                                              llvm::Value *&Result);
196383ce9d4a552987d34cbd500e983db8d770232379John McCall
1964fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  // Note: only available for agg return types
196580e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
19662a41637a995affa1563f4d82a8b026e326a2faa0John McCall  LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E);
19675b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
196822c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
19695b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
19705b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
19715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
19725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
1973eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
1974d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
19755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
1976a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
1977a0a628f839cf50844cc0f226bd9cb72485f98f91Richard Smith                                bool Accessed = false);
1978213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
1979b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
1980820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian  LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
198106e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
198213ec9100ca6bc03b5ce8832e4a0fcb724d47bcb1Richard Smith  LValue EmitInitListLValue(const InitListExpr *E);
198356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall  LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E);
198475dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
198503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor  LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
1986e996ffd240f20a1048179d7727a6ee3227261921John McCall  LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e);
19879cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
1988377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman  RValue EmitRValueForField(LValue LV, const FieldDecl *FD);
1989eaf856db5d1a272dc7188937206ef4572836f82aAnton Korobeynikov
1990dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall  class ConstantEmission {
1991dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference;
1992dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    ConstantEmission(llvm::Constant *C, bool isReference)
1993dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      : ValueAndIsReference(C, isReference) {}
1994dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall  public:
1995dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    ConstantEmission() {}
1996dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    static ConstantEmission forReference(llvm::Constant *C) {
1997dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      return ConstantEmission(C, true);
1998dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    }
1999dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    static ConstantEmission forValue(llvm::Constant *C) {
2000dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      return ConstantEmission(C, false);
2001dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    }
2002dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall
20037247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie    LLVM_EXPLICIT operator bool() const { return ValueAndIsReference.getOpaqueValue() != 0; }
2004dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall
2005dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    bool isReference() const { return ValueAndIsReference.getInt(); }
2006dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const {
2007dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      assert(isReference());
2008dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(),
2009dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall                                            refExpr->getType());
2010dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    }
2011dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall
2012dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    llvm::Constant *getValue() const {
2013dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      assert(!isReference());
2014dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall      return ValueAndIsReference.getPointer();
2015dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall    }
2016dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall  };
2017dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall
2018f4b88a45902af1802a1cb42ba48b1c474474f228John McCall  ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr);
2019dd2ecee313b558a9b621ec003b45e0fbc83508d7John McCall
20204b9c2d235fb9449e249d74f48ecfec601650de93John McCall  RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e,
20214b9c2d235fb9449e249d74f48ecfec601650de93John McCall                                AggValueSlot slot = AggValueSlot::ignored());
20224b9c2d235fb9449e249d74f48ecfec601650de93John McCall  LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e);
20234b9c2d235fb9449e249d74f48ecfec601650de93John McCall
20242a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
202529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
2026377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman  LValue EmitLValueForField(LValue Base, const FieldDecl* Field);
2027f5ebf9bf1df10ac15ba32a4b24dfe171b7848c58John McCall  LValue EmitLValueForLambdaField(const FieldDecl *Field);
20289cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
202906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
203006a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// if the Field is a reference, this will return the address of the reference
203106a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// and not the address of the value stored in the reference.
2032377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman  LValue EmitLValueForFieldInitialization(LValue Base,
2033377ecc7996dce6803f7b7b6208cab5e197c9c5b8Eli Friedman                                          const FieldDecl* Field);
20349cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
203545012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
203645012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
203729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
2038fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
2039b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
2040e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson  LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
204131a3702618ab49578542cffee20ba0c8859b9d1eEli Friedman  LValue EmitLambdaLValue(const LambdaExpr *E);
2042c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E);
2043c5f804636e367ef744fd24cf88f7c956a5af0434Nico Weber  LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E);
20449cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
20450a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
2046391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
2047654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
20488bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian  LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
204903b2960c14aede6ac82bdef32247094ebb72fa69Fariborz Jahanian  LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
2050189d6ef40eff11b83b2cda941d5ed89a5cef09b2John McCall  void   EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init);
205156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall
20525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2053883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
20555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
20570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
20580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
2059c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
2060f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// \param TargetDecl - If given, the decl of the function in a direct call;
2061f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// used to set attributes on the call (noreturn, etc.).
206288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
206388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
2064f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson                  ReturnValueSlot ReturnValue,
2065c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
2066dd5c98f709837e5dd3da08d44d1ce407975df2cfDavid Chisnall                  const Decl *TargetDecl = 0,
20674b02afcb45cd1a384de7d45f440a8be091dd500bDavid Chisnall                  llvm::Instruction **callOrInvoke = 0);
20681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
206931777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  RValue EmitCall(QualType FnType, llvm::Value *Callee,
2070d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                  ReturnValueSlot ReturnValue,
2071986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgBeg,
2072986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgEnd,
2073986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  const Decl *TargetDecl = 0);
20749cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  RValue EmitCallExpr(const CallExpr *E,
2075d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                      ReturnValueSlot ReturnValue = ReturnValueSlot());
20761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2077bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallInst *EmitRuntimeCall(llvm::Value *callee,
2078bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                  const Twine &name = "");
2079bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallInst *EmitRuntimeCall(llvm::Value *callee,
2080bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                  ArrayRef<llvm::Value*> args,
2081bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                  const Twine &name = "");
2082bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee,
2083bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                          const Twine &name = "");
2084bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee,
2085bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                          ArrayRef<llvm::Value*> args,
2086bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                          const Twine &name = "");
2087bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall
2088f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall  llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee,
20892d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner                                  ArrayRef<llvm::Value *> Args,
20908cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner                                  const Twine &Name = "");
20914c7d9f1507d0f102bd4133bba63348636facd469Jay Foad  llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee,
20928cc488fefb2fb04bc8d5398da29f0182f97934cfChris Lattner                                  const Twine &Name = "");
2093bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee,
2094bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                         ArrayRef<llvm::Value*> args,
2095bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                         const Twine &name = "");
2096bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee,
2097bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                         const Twine &name = "");
2098bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall  void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee,
2099bd7370a78604e9a20d698bfe328c1e43f12a0613John McCall                                       ArrayRef<llvm::Value*> args);
2100f1549f66a8216a78112286e3978cea2c29d6334cJohn McCall
21012726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian  llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD,
21022726267f094a0c1f5ac5b501ec5a9898c58876bfFariborz Jahanian                                         NestedNameSpecifier *Qual,
21032acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner                                         llvm::Type *Ty);
2104ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian
2105ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian  llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD,
2106ccd5259d33cbbdd6f5fbf7ccab4cb4a2702309eaFariborz Jahanian                                                   CXXDtorType Type,
2107771c678c04f5f685b4f188ec6c2fd88ad0f7457fFariborz Jahanian                                                   const CXXRecordDecl *RD);
2108566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson
2109b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
21104def70d3040e73707c738f7c366737a986135edfRichard Smith                           SourceLocation CallLoc,
2111b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
2112a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                           ReturnValueSlot ReturnValue,
2113b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
211459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov                           llvm::Value *ImplicitParam,
211559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov                           QualType ImplicitParamTy,
2116b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
2117b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
2118a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
2119a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                               ReturnValueSlot ReturnValue);
2120a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
2121a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                      ReturnValueSlot ReturnValue);
21225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
2123a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson  llvm::Value *EmitCXXOperatorMemberCallee(const CXXOperatorCallExpr *E,
2124a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson                                           const CXXMethodDecl *MD,
2125a2447e0d1e28669cd637204a871f15b1215277fdAnders Carlsson                                           llvm::Value *This);
21260f294632f36459174199b77699e339715244b5abAnders Carlsson  RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
2127a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       const CXXMethodDecl *MD,
2128a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       ReturnValueSlot ReturnValue);
21291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
21306c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne  RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
21316c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne                                ReturnValueSlot ReturnValue);
21326c0aa5ff6e6253db0f993053599e2a52b5b93b2dPeter Collingbourne
21339cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
21341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  RValue EmitBuiltinExpr(const FunctionDecl *FD,
2135ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
21365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2137a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue);
213809429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
21390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
21400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
2141f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
2142f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
2143ff920eec4d449bee560d8d99636ad0eb50cd9d8dTim Northover  llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
21442752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner  llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
21459cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  llvm::Value *EmitNeonCall(llvm::Function *F,
2146686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                            SmallVectorImpl<llvm::Value*> &O,
2147db3d4d036037f379f12643e067b229862d61e932Bob Wilson                            const char *name,
214861eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman                            unsigned shift = 0, bool rightshift = false);
2149cf55652cf668c1402eee0b12edd2e5a1bc34d7a1Bob Wilson  llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx);
21502acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty,
215161eecf5aea018ea65c9ab0bccacd2996b15c632dNate Begeman                                   bool negateForRightShift);
21529cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
2153795b10062c2eaffae9e04241fb1a73cdbcb24a37Bill Wendling  llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops);
2154564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
2155564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
21560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2157ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
21587f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
2159eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard  llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E);
2160ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E);
2161ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E);
2162ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek  llvm::Value *EmitObjCCollectionLiteral(const Expr *E,
2163ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek                                const ObjCMethodDecl *MethodWithObjects);
21648fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
2165ef072fd2f3347cfd857d6eb787b245b950771430John McCall  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E,
2166ef072fd2f3347cfd857d6eb787b245b950771430John McCall                             ReturnValueSlot Return = ReturnValueSlot());
21678fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
2168f85e193739c953358c865005855253af4f68a497John McCall  /// Retrieves the default cleanup kind for an ARC cleanup.
2169f85e193739c953358c865005855253af4f68a497John McCall  /// Except under -fobjc-arc-eh, ARC cleanups are normal-only.
2170f85e193739c953358c865005855253af4f68a497John McCall  CleanupKind getARCCleanupKind() {
2171f85e193739c953358c865005855253af4f68a497John McCall    return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions
2172f85e193739c953358c865005855253af4f68a497John McCall             ? NormalAndEHCleanup : NormalCleanup;
2173f85e193739c953358c865005855253af4f68a497John McCall  }
2174f85e193739c953358c865005855253af4f68a497John McCall
2175f85e193739c953358c865005855253af4f68a497John McCall  // ARC primitives.
2176f85e193739c953358c865005855253af4f68a497John McCall  void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr);
2177f85e193739c953358c865005855253af4f68a497John McCall  void EmitARCDestroyWeak(llvm::Value *addr);
2178f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCLoadWeak(llvm::Value *addr);
2179f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCLoadWeakRetained(llvm::Value *addr);
2180f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr,
2181f85e193739c953358c865005855253af4f68a497John McCall                                bool ignored);
2182f85e193739c953358c865005855253af4f68a497John McCall  void EmitARCCopyWeak(llvm::Value *dst, llvm::Value *src);
2183f85e193739c953358c865005855253af4f68a497John McCall  void EmitARCMoveWeak(llvm::Value *dst, llvm::Value *src);
2184f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);
2185f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value);
2186545d996ec5a3113f046944f11b27cc2d6cb055b4John McCall  llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value,
21875b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall                                  bool resultIgnored);
2188f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value,
21895b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall                                      bool resultIgnored);
2190f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetain(QualType type, llvm::Value *value);
2191f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainNonBlock(llvm::Value *value);
2192348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall  llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory);
21935b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall  void EmitARCDestroyStrong(llvm::Value *addr, ARCPreciseLifetime_t precise);
21945b07e8077a20b80fee90bd76c43c6150c676e4a8John McCall  void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
2195f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCAutorelease(llvm::Value *value);
2196f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value);
2197f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value);
2198f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
2199f85e193739c953358c865005855253af4f68a497John McCall
2200f85e193739c953358c865005855253af4f68a497John McCall  std::pair<LValue,llvm::Value*>
2201f85e193739c953358c865005855253af4f68a497John McCall  EmitARCStoreAutoreleasing(const BinaryOperator *e);
2202f85e193739c953358c865005855253af4f68a497John McCall  std::pair<LValue,llvm::Value*>
2203f85e193739c953358c865005855253af4f68a497John McCall  EmitARCStoreStrong(const BinaryOperator *e, bool ignored);
2204f85e193739c953358c865005855253af4f68a497John McCall
22052b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall  llvm::Value *EmitObjCThrowOperand(const Expr *expr);
22062b014d6c0c6b8ac94b416ac37dfc7931f20777a7John McCall
2207f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitObjCProduceObject(QualType T, llvm::Value *Ptr);
2208f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr);
2209f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr);
2210f85e193739c953358c865005855253af4f68a497John McCall
2211348f16fc7c71f0d9b651cb79fd1012843073493fJohn McCall  llvm::Value *EmitARCExtendBlockObject(const Expr *expr);
2212f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainScalarExpr(const Expr *expr);
2213f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr);
2214f85e193739c953358c865005855253af4f68a497John McCall
2215b6a6079449a5275c283982e19b0c38e165833bb2John McCall  void EmitARCIntrinsicUse(llvm::ArrayRef<llvm::Value*> values);
2216b6a6079449a5275c283982e19b0c38e165833bb2John McCall
2217bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  static Destroyer destroyARCStrongImprecise;
2218bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  static Destroyer destroyARCStrongPrecise;
2219bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall  static Destroyer destroyARCWeak;
2220bdc4d80956c83a486e58d3df6bb524a1f66ff574John McCall
2221f85e193739c953358c865005855253af4f68a497John McCall  void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr);
2222f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitObjCAutoreleasePoolPush();
2223f85e193739c953358c865005855253af4f68a497John McCall  llvm::Value *EmitObjCMRRAutoreleasePoolPush();
2224f85e193739c953358c865005855253af4f68a497John McCall  void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
2225f85e193739c953358c865005855253af4f68a497John McCall  void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr);
2226f85e193739c953358c865005855253af4f68a497John McCall
2227d4ec562b3aaf50ea9015f82c96ebfd05a35fc7efRichard Smith  /// \brief Emits a reference binding to the passed in expression.
2228d4ec562b3aaf50ea9015f82c96ebfd05a35fc7efRichard Smith  RValue EmitReferenceBindingToExpr(const Expr *E);
22293aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson
2230883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
2231bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
2232883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
2233bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
2234bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
22350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
22360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
22370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
223814c5cbf59cffee52275230922283a247de407712Anders Carlsson  llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
22390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
22403707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
22413707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
22423707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
22433707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
22440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
22454f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
22460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
22470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
22484f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
22494f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
22500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
22510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2252558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// EmitAggExpr - Emit the computation of the specified expression
2253558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// of aggregate type.  The result is computed into the given slot,
2254558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  /// which may be null to indicate that the value is not needed.
2255e0c1168ec7910a1a7ed08df4d4f0c58c2fa2ecd1John McCall  void EmitAggExpr(const Expr *E, AggValueSlot AS);
22560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
225718aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// EmitAggExprToLValue - Emit the computation of the specified expression of
225818aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// aggregate type into a temporary LValue.
225918aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  LValue EmitAggExprToLValue(const Expr *E);
226018aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar
2261082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// EmitGCMemmoveCollectable - Emit special API for structs with object
2262082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// pointers.
2263082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
226408c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                                QualType Ty);
2265082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian
22660c24c808e4dce43e88abf2d5f98546b901bd4315John McCall  /// EmitExtendGCLifetime - Given a pointer to an Objective-C object,
22670c24c808e4dce43e88abf2d5f98546b901bd4315John McCall  /// make sure it survives garbage collection until this point.
22680c24c808e4dce43e88abf2d5f98546b901bd4315John McCall  void EmitExtendGCLifetime(llvm::Value *object);
22690c24c808e4dce43e88abf2d5f98546b901bd4315John McCall
2270b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
227123b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
2272b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall  ComplexPairTy EmitComplexExpr(const Expr *E,
2273b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall                                bool IgnoreReal = false,
2274b418d74c11498b7e1044103131e2e3be4d63512eJohn McCall                                bool IgnoreImag = false);
22750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
22769d232c884ea9872d6555df0fd7359699819bc1f1John McCall  /// EmitComplexExprIntoLValue - Emit the given expression of complex
22779d232c884ea9872d6555df0fd7359699819bc1f1John McCall  /// type and place its result into the specified l-value.
22789d232c884ea9872d6555df0fd7359699819bc1f1John McCall  void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit);
22799d232c884ea9872d6555df0fd7359699819bc1f1John McCall
22809d232c884ea9872d6555df0fd7359699819bc1f1John McCall  /// EmitStoreOfComplex - Store a complex number into the specified l-value.
22819d232c884ea9872d6555df0fd7359699819bc1f1John McCall  void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit);
22827f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
22839d232c884ea9872d6555df0fd7359699819bc1f1John McCall  /// EmitLoadOfComplex - Load a complex number from the specified l-value.
22849d232c884ea9872d6555df0fd7359699819bc1f1John McCall  ComplexPairTy EmitLoadOfComplex(LValue src);
22852621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
2286b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  /// CreateStaticVarDecl - Create a zero-initialized LLVM global for
2287b6bbcc9995186799a60ce17d0c1acff31601653aJohn McCall  /// a static local variable.
22880f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  llvm::GlobalVariable *CreateStaticVarDecl(const VarDecl &D,
22890f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth                                            const char *Separator,
22900f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth                                       llvm::GlobalValue::LinkageTypes Linkage);
22919cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
22920f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the
22930f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  /// global variable that has already been created for it.  If the initializer
22940f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  /// has a different type than GV does, this may free GV and return a different
22950f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  /// one.  Otherwise it just returns GV.
22960f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  llvm::GlobalVariable *
22970f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  AddInitializerToStaticVarDecl(const VarDecl &D,
22980f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth                                llvm::GlobalVariable *GV);
22999cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
23000096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
23013b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
23023b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// variable with global storage.
23037ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr,
23047ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                                bool PerformInit);
23053b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson
230620bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// Call atexit() with a function that passes the given argument to
230720bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// the given function.
2308c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie  void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::Constant *fn,
2309c7971a9efdf9880448a69aabb5182c3c27eecf6dDavid Blaikie                                    llvm::Constant *addr);
23101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23113030eb82593097502469a8b3fc26112c79c75605John McCall  /// Emit code in this function to perform a guarded variable
23123030eb82593097502469a8b3fc26112c79c75605John McCall  /// initialization.  Guarded initializations are used when it's not
23133030eb82593097502469a8b3fc26112c79c75605John McCall  /// possible to prove that an initialization will be done exactly
23143030eb82593097502469a8b3fc26112c79c75605John McCall  /// once, e.g. with a static local variable or a static data member
23153030eb82593097502469a8b3fc26112c79c75605John McCall  /// of a class template.
23160f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth  void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr,
23177ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                          bool PerformInit);
23185cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
2319efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// GenerateCXXGlobalInitFunc - Generates code for initializing global
2320efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
2321efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalInitFunc(llvm::Function *Fn,
2322c7b5f381ed41a238aa4c243f99170909f64a3414Benjamin Kramer                                 ArrayRef<llvm::Constant *> Decls,
2323b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith                                 llvm::GlobalVariable *Guard = 0);
2324efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
23253f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall  /// GenerateCXXGlobalDtorsFunc - Generates code for destroying global
2326efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
23273f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall  void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn,
23283f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall                                  const std::vector<std::pair<llvm::WeakVH,
23293f88f686e32949ffe02ccb551f482f9cf810358bJohn McCall                                  llvm::Constant*> > &DtorsAndObjects);
2330efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
2331d26bc76c98006609002d9930f8840490e88ac5b5John McCall  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
2332d26bc76c98006609002d9930f8840490e88ac5b5John McCall                                        const VarDecl *D,
23337ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                                        llvm::GlobalVariable *Addr,
23347ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith                                        bool PerformInit);
2335efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
2336558d2abc7f9fd6801cc7677200992313ae90b5d8John McCall  void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest);
233734999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian
233834999876e215b22febc240b1a6dc054215d12f9cFariborz Jahanian  void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src,
2339830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian                                  const Expr *Exp);
23401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23411a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  void enterFullExpression(const ExprWithCleanups *E) {
23421a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall    if (E->getNumObjects() == 0) return;
23431a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall    enterNonTrivialFullExpression(E);
23441a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  }
23451a343ebbf413e8eae6b2737b2b2d79cbf5765571John McCall  void enterNonTrivialFullExpression(const ExprWithCleanups *E);
23461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
23474c71b8cded575b0cfc133c5da4502ca613982094Richard Smith  void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true);
23481eb2e59338c4b9c0429fc39ca98662adc9e7a3f2Douglas Gregor
23494c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman  void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest);
23504c5d8afd100189b6cce4fd89bfb8aec5700acb50Eli Friedman
2351276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman  RValue EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest = 0);
2352276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman
23530ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
235477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  //                         Annotations Emission
235577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  //===--------------------------------------------------------------------===//
235677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
235777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit an annotation call (intrinsic or builtin).
235877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn,
235977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge                                  llvm::Value *AnnotatedVal,
2360cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko                                  StringRef AnnotationStr,
236177f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge                                  SourceLocation Location);
236277f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
236377f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit local annotations for the local variable V, declared by D.
236477f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  void EmitVarAnnotations(const VarDecl *D, llvm::Value *V);
236577f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
236677f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// Emit field annotations for the given field & value. Returns the
236777f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  /// annotation result.
236877f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  llvm::Value *EmitFieldAnnotations(const FieldDecl *D, llvm::Value *V);
236977f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge
237077f68bb90af93b95045fb994e7cd68137adcc132Julien Lerouge  //===--------------------------------------------------------------------===//
23710ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
23720ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
23730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
23740946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
23750946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
23760946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
23770946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
23780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2379ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// containsBreak - Return true if the statement contains a break out of it.
2380ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// If the statement (recursively) contains a switch or loop with a break
2381ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// inside of it, this is fine.
2382ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  static bool containsBreak(const Stmt *S);
2383ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner
23844bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
2385c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner  /// to a constant, or if it does but contains a label, return false.  If it
2386c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner  /// constant folds return true and set the boolean result in Result.
2387c2c90011a688c04a4e980282f08c267e081c4b00Chris Lattner  bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result);
23880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2389ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
2390ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// to a constant, or if it does but contains a label, return false.  If it
2391ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner  /// constant folds return true and set the folded value.
2392e1ecdc168175719d74e112bcacd4aae5e12d4631Richard Trieu  bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result);
2393ef425a69006afaa87751ee41ccf8ff405d9ede70Chris Lattner
239431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
239531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
239631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
23979bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
23984bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
2399be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump
24004def70d3040e73707c738f7c366737a986135edfRichard Smith  /// \brief Emit a description of a type in a format suitable for passing to
24014def70d3040e73707c738f7c366737a986135edfRichard Smith  /// a runtime sanitizer handler.
24024def70d3040e73707c738f7c366737a986135edfRichard Smith  llvm::Constant *EmitCheckTypeDescriptor(QualType T);
24034def70d3040e73707c738f7c366737a986135edfRichard Smith
24044def70d3040e73707c738f7c366737a986135edfRichard Smith  /// \brief Convert a value into a format suitable for passing to a runtime
24054def70d3040e73707c738f7c366737a986135edfRichard Smith  /// sanitizer handler.
24064def70d3040e73707c738f7c366737a986135edfRichard Smith  llvm::Value *EmitCheckValue(llvm::Value *V);
24074def70d3040e73707c738f7c366737a986135edfRichard Smith
24084def70d3040e73707c738f7c366737a986135edfRichard Smith  /// \brief Emit a description of a source location in a format suitable for
24094def70d3040e73707c738f7c366737a986135edfRichard Smith  /// passing to a runtime sanitizer handler.
24104def70d3040e73707c738f7c366737a986135edfRichard Smith  llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc);
24114def70d3040e73707c738f7c366737a986135edfRichard Smith
2412ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz  /// \brief Specify under what conditions this check can be recovered
2413ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz  enum CheckRecoverableKind {
2414ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    /// Always terminate program execution if this check fails
2415ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    CRK_Unrecoverable,
2416ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    /// Check supports recovering, allows user to specify which
2417ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    CRK_Recoverable,
2418ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    /// Runtime conditionally aborts, always need to support recovery.
2419ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz    CRK_AlwaysRecoverable
2420ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz  };
2421ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz
2422cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith  /// \brief Create a basic block that will call a handler function in a
2423cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith  /// sanitizer runtime with the provided arguments, and create a conditional
2424cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith  /// branch to it.
24254def70d3040e73707c738f7c366737a986135edfRichard Smith  void EmitCheck(llvm::Value *Checked, StringRef CheckName,
2426cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko                 ArrayRef<llvm::Constant *> StaticArgs,
2427cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko                 ArrayRef<llvm::Value *> DynamicArgs,
2428ad95481b2769ad61f23afc5e2c31f11c66090657Will Dietz                 CheckRecoverableKind Recoverable);
24299cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
2430cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith  /// \brief Create a basic block that will call the trap intrinsic, and emit a
2431cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith  /// conditional branch to it, for the -ftrapv checks.
243278d85b1c5830a881c0a20a1b3fea99ee73149590Chad Rosier  void EmitTrapCheck(llvm::Value *Checked);
2433cc305617e952f8c3a06b63d9225d0dd7769341b7Richard Smith
243421c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson  /// EmitCallArg - Emit a single call argument.
2435413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall  void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType);
243621c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson
24372736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// EmitDelegateCallArg - We are performing a delegate call; that
24382736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// is, the current function is delegating to another one.  Produce
24392736071ea3a46f90e65c93418961611d96c10ab9John McCall  /// a r-value suitable for passing the given parameter.
2440413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall  void EmitDelegateCallArg(CallArgList &args, const VarDecl *param);
24412736071ea3a46f90e65c93418961611d96c10ab9John McCall
2442c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne  /// SetFPAccuracy - Set the minimum required accuracy of the given floating
2443c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne  /// point operation, expressed as the maximum relative error in ulp.
24448250016fb9491fcfde7fce05230d66e267944484Duncan Sands  void SetFPAccuracy(llvm::Value *Val, float Accuracy);
2445c5096cbf7a42e0f9012945b00d9037a5b5a88d72Peter Collingbourne
244631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
2447c3f8955d7da1019dbe16b0bdf3e49d2e08d988e9Rafael Espindola  llvm::MDNode *getRangeForLoadFromType(QualType Ty);
244829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
244929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
24505627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
24515627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
24525627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
24535627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
24545627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
24555627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
24560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
24575627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
24585627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
24595627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
24600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
24610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
24620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
24630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
24646b9240e058bf3451685df73fc8ce181b3046e92bCraig Topper                        SmallVectorImpl<llvm::Value *> &Args,
2465811bf3669f4d82c57fe3cd3c49050fdbc95d0affChris Lattner                        llvm::FunctionType *IRFuncTy);
2466c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
246742b60551eff3a424e191b293bfd606559dc96bffChad Rosier  llvm::Value* EmitAsmInput(const TargetInfo::ConstraintInfo &Info,
2468c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
24690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
247042b60551eff3a424e191b293bfd606559dc96bffChad Rosier  llvm::Value* EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info,
24716d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman                                  LValue InputValue, QualType InputType,
24726d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman                                  std::string &ConstraintStr);
24736d7cfd7ef82e42ff30ee1dafd2883fd94e9f8294Eli Friedman
24740139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
24751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The CallArgTypeInfo parameter is used for iterating over the known
2476af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
2477af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
2478af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
24790139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
2480b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl                    CallExpr::const_arg_iterator ArgEnd,
2481b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl                    bool ForceColumnInfo = false) {
2482b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    CGDebugInfo *DI = getDebugInfo();
2483b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    SourceLocation CallLoc;
2484b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    if (DI) CallLoc = DI->getLocation();
2485b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl
2486b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    CallExpr::const_arg_iterator Arg = ArgBeg;
2487af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
2488af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
2489af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
2490af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
2491af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
249244b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman        assert(Arg != ArgEnd && "Running over edge of argument list!");
2493af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
2494745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#ifndef NDEBUG
2495745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        QualType ActualArgType = Arg->getType();
2496745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        if (ArgType->isPointerType() && ActualArgType->isPointerType()) {
24979cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer          QualType ActualBaseType =
2498745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian            ActualArgType->getAs<PointerType>()->getPointeeType();
24999cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer          QualType ArgBaseType =
2500745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian            ArgType->getAs<PointerType>()->getPointeeType();
2501745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian          if (ArgBaseType->isVariableArrayType()) {
2502745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian            if (const VariableArrayType *VAT =
2503745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian                getContext().getAsVariableArrayType(ActualBaseType)) {
2504745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian              if (!VAT->getSizeExpr())
2505745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian                ActualArgType = ArgType;
2506745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian            }
2507745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian          }
2508745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian        }
2509af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
25101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getTypePtr() ==
2511745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian               getContext().getCanonicalType(ActualArgType).getTypePtr() &&
2512af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
2513745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian#endif
2514413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall        EmitCallArg(Args, *Arg, ArgType);
2515b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl
2516b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl        // Each argument expression could modify the debug
2517b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl        // location. Restore it.
2518b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl        if (DI) DI->EmitLocation(Builder, CallLoc, ForceColumnInfo);
2519af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
25201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
25211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Either we've emitted all the call args, or we have a call to a
2522af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
25231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
2524af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
25251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2526af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
25271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2528af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
2529b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    for (; Arg != ArgEnd; ++Arg) {
2530413ebdb1af6fb0d81845b61254daf02ba0449afdJohn McCall      EmitCallArg(Args, *Arg, Arg->getType());
2531b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl
2532b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl      // Restore the debug location.
2533b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl      if (DI) DI->EmitLocation(Builder, CallLoc, ForceColumnInfo);
2534b0e603c63813c8378e35a75408ab4cefe71e93e2Adrian Prantl    }
2535af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
2536492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall
2537492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  const TargetCodeGenInfo &getTargetHooks() const {
2538492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall    return CGM.getTargetCodeGenInfo();
2539492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  }
2540744016dde06fcffd50931e94a98c850f8b12cd87John McCall
2541744016dde06fcffd50931e94a98c850f8b12cd87John McCall  void EmitDeclMetadata();
2542f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall
2543f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall  CodeGenModule::ByrefHelpers *
25442acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  buildByrefHelpers(llvm::StructType &byrefType,
2545f0c11f7e6848f023ced6a5b51399ba787c7d4d0bJohn McCall                    const AutoVarEmission &emission);
2546b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman
2547b49bd27b334a6c4e3bf9d810a7d5b022578f1194Dan Gohman  void AddObjCARCExceptionMetadata(llvm::Instruction *Inst);
2548f4c3db175101cbf94dad59419c3ed7aed51bf606Jay Foad
2549ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman  /// GetPointeeAlignment - Given an expression with a pointer type, emit the
2550ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman  /// value and compute our best estimate of the alignment of the pointee.
2551ea93e40785ffeadfac66b948c95f9490ec26207aEli Friedman  std::pair<llvm::Value*, unsigned> EmitPointerWithAlignment(const Expr *Addr);
25525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
25531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2554150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// Helper class with most of the code for saving a value for a
2555150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall/// conditional expression cleanup.
2556804b807ea918184d6de63bd745e1ff75a9bfc679John McCallstruct DominatingLLVMValue {
2557150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type;
2558150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2559150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// Answer whether the given value needs extra work to be saved.
2560150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  static bool needsSaving(llvm::Value *value) {
2561150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    // If it's not an instruction, we don't need to save.
2562150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    if (!isa<llvm::Instruction>(value)) return false;
2563150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2564150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    // If it's an instruction in the entry block, we don't need to save.
2565150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent();
2566150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    return (block != &block->getParent()->getEntryBlock());
2567150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
2568150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2569150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  /// Try to save the given value.
2570150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  static saved_type save(CodeGenFunction &CGF, llvm::Value *value) {
2571150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    if (!needsSaving(value)) return saved_type(value, false);
2572150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2573150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    // Otherwise we need an alloca.
2574150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    llvm::Value *alloca =
2575150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall      CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save");
2576150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    CGF.Builder.CreateStore(value, alloca);
2577150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2578150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    return saved_type(alloca, true);
2579150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
2580150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2581150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) {
2582150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    if (!value.getInt()) return value.getPointer();
2583150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall    return CGF.Builder.CreateLoad(value.getPointer());
2584150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
2585150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall};
2586150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
2587804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A partial specialization of DominatingValue for llvm::Values that
2588804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// might be llvm::Instructions.
2589804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <class T> struct DominatingPointer<T,true> : DominatingLLVMValue {
2590804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  typedef T *type;
2591804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  static type restore(CodeGenFunction &CGF, saved_type value) {
2592804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    return static_cast<T*>(DominatingLLVMValue::restore(CGF, value));
2593804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  }
2594804b807ea918184d6de63bd745e1ff75a9bfc679John McCall};
2595804b807ea918184d6de63bd745e1ff75a9bfc679John McCall
2596804b807ea918184d6de63bd745e1ff75a9bfc679John McCall/// A specialization of DominatingValue for RValue.
2597804b807ea918184d6de63bd745e1ff75a9bfc679John McCalltemplate <> struct DominatingValue<RValue> {
2598804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  typedef RValue type;
2599804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  class saved_type {
2600804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral,
2601804b807ea918184d6de63bd745e1ff75a9bfc679John McCall                AggregateAddress, ComplexAddress };
2602804b807ea918184d6de63bd745e1ff75a9bfc679John McCall
2603804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    llvm::Value *Value;
2604804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    Kind K;
2605804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    saved_type(llvm::Value *v, Kind k) : Value(v), K(k) {}
2606804b807ea918184d6de63bd745e1ff75a9bfc679John McCall
2607804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  public:
2608804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    static bool needsSaving(RValue value);
2609804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    static saved_type save(CodeGenFunction &CGF, RValue value);
2610804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    RValue restore(CodeGenFunction &CGF);
2611804b807ea918184d6de63bd745e1ff75a9bfc679John McCall
2612804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    // implementations in CGExprCXX.cpp
2613804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  };
2614804b807ea918184d6de63bd745e1ff75a9bfc679John McCall
2615804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  static bool needsSaving(type value) {
2616804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    return saved_type::needsSaving(value);
2617804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  }
2618804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  static saved_type save(CodeGenFunction &CGF, type value) {
2619804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    return saved_type::save(CGF, value);
2620804b807ea918184d6de63bd745e1ff75a9bfc679John McCall  }
2621150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  static type restore(CodeGenFunction &CGF, saved_type value) {
2622804b807ea918184d6de63bd745e1ff75a9bfc679John McCall    return value.restore(CGF);
2623150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall  }
2624150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall};
2625150b462afc7a713edd19bcbbbb22381fe060d4f5John McCall
26265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
26275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
26284e1524babb095e70de1da882573eb6fbee98a857Fariborz Jahanian
26295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
2630