CodeGenFunction.h revision 2752c0137d95aa2f4ee1cdff4b564bac842e041b
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump// This is the internal per-function state used for llvm translation.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h"
18e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
20199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck#include "clang/AST/CharUnits.h"
21481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h"
22481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h"
23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h"
24481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h"
250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map>
2669243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "CodeGenModule.h"
2796bd13ae1ab89f5a04b3ad3ec8ec1864cbba3482Mike Stump#include "CGBlocks.h"
2845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
290dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
30b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson#include "CGCXX.h"
318f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
328f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
35f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer  class LLVMContext;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
37898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
38259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar  class Twine;
39ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
447267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  class CXXDestructorDecl;
456815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  class CXXTryStmt;
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
47c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
4972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
50c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
51679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
5229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
5329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
54391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
55fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
56af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
58492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  class TargetCodeGenInfo;
59c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
6016f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
6116f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
6216f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
6316f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
66b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
67e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
68bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
732a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction {
748a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
758a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  void operator=(const CodeGenFunction&);  // DO NOT IMPLEMENT
76bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
78444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &Target;
790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8058dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
8145d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
83b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurFuncDecl - Holds the Decl for the current function or ObjC method.
84b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// This excludes BlockDecls.
854111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
86b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
87b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
8888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
89391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
926a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  /// CurGD - The GlobalDecl for the current function being compiled.
936a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  GlobalDecl CurGD;
946a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump
955ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
965ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
99b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman  llvm::Value *ReturnValue;
1000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
103481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
1040ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
1067b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
10718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
108d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  bool Exceptions;
1099c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump  bool CatchUndefined;
11018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
111fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
112fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// rethrows.
113273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
1140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1156fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// PushCleanupBlock - Push a new cleanup entry on the stack and set the
1166fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// passed in block as the cleanup block.
1177799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian  void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock,
118d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                        llvm::BasicBlock *CleanupExitBlock,
119d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                        llvm::BasicBlock *PreviousInvokeDest,
12099533834ba8f3658559f334e68a518ebb6388ceaMike Stump                        bool EHOnly = false);
121d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock) {
122d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    PushCleanupBlock(CleanupEntryBlock, 0, getInvokeDest(), false);
123d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  }
124bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
1250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupBlockInfo - A struct representing a popped cleanup block.
126bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  struct CleanupBlockInfo {
1277799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupEntryBlock - the cleanup entry block
128bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *CleanupBlock;
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// SwitchBlock - the block (if any) containing the switch instruction used
1310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// for jumping to the final destination.
132bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *SwitchBlock;
1330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
134bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// EndBlock - the default destination for the switch instruction.
135bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *EndBlock;
1360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13799533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// EHOnly - True iff this cleanup should only be performed on the
13899533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// exceptional edge.
13999533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
14099533834ba8f3658559f334e68a518ebb6388ceaMike Stump
1410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
14299533834ba8f3658559f334e68a518ebb6388ceaMike Stump                     llvm::BasicBlock *eb, bool ehonly = false)
14399533834ba8f3658559f334e68a518ebb6388ceaMike Stump      : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb), EHOnly(ehonly) {}
144bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  };
145bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
146d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// EHCleanupBlock - RAII object that will create a cleanup block for the
147d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// exceptional edge and set the insert point to that block.  When destroyed,
148d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// it creates the cleanup edge and sets the insert point to the previous
149d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// block.
150d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  class EHCleanupBlock {
151d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    CodeGenFunction& CGF;
152d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *Cont;
153d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *CleanupHandler;
154d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *CleanupEntryBB;
155d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *PreviousInvokeDest;
156d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  public:
157d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    EHCleanupBlock(CodeGenFunction &cgf)
158d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      : CGF(cgf), Cont(CGF.createBasicBlock("cont")),
159d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        CleanupHandler(CGF.createBasicBlock("ehcleanup")),
160d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        CleanupEntryBB(CGF.createBasicBlock("ehcleanup.rest")),
161d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        PreviousInvokeDest(CGF.getInvokeDest()) {
162d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      CGF.EmitBranch(Cont);
16320d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump      llvm::BasicBlock *TerminateHandler = CGF.getTerminateHandler();
164d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      CGF.Builder.SetInsertPoint(CleanupEntryBB);
16520d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump      CGF.setInvokeDest(TerminateHandler);
166d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    }
167d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    ~EHCleanupBlock();
168d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  };
169d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
170bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
1710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branch fixups and return a block info struct with the switch block and end
172d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// block.  This will also reset the invoke handler to the previous value
173d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// from when the cleanup block was created.
174bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  CleanupBlockInfo PopCleanupBlock();
1750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
176f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// DelayedCleanupBlock - RAII object that will create a cleanup block and set
177f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// the insert point to that block. When destructed, it sets the insert point
178f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// to the previous block and pushes a new cleanup entry on the stack.
179d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor  class DelayedCleanupBlock {
1800d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CodeGenFunction& CGF;
1810d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    llvm::BasicBlock *CurBB;
1827799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupEntryBB;
1837799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupExitBB;
184d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *CurInvokeDest;
18599533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
1867799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
1870d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
18899533834ba8f3658559f334e68a518ebb6388ceaMike Stump    DelayedCleanupBlock(CodeGenFunction &cgf, bool ehonly = false)
1897799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()),
190d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        CleanupEntryBB(CGF.createBasicBlock("cleanup")), CleanupExitBB(0),
191d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        CurInvokeDest(CGF.getInvokeDest()),
192d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        EHOnly(ehonly) {
1937799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      CGF.Builder.SetInsertPoint(CleanupEntryBB);
1940d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1967799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *getCleanupExitBlock() {
1977799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      if (!CleanupExitBB)
1987799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian        CleanupExitBB = CGF.createBasicBlock("cleanup.exit");
1997799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      return CleanupExitBB;
2007799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    }
2017799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
202d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor    ~DelayedCleanupBlock() {
203d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      CGF.PushCleanupBlock(CleanupEntryBB, CleanupExitBB, CurInvokeDest,
204d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                           EHOnly);
205d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      // FIXME: This is silly, move this into the builder.
206d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      if (CurBB)
207d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.SetInsertPoint(CurBB);
208d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      else
209d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.ClearInsertionPoint();
2100d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
2110d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
2120d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
21301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  /// \brief Enters a new scope for capturing cleanups, all of which will be
21401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  /// executed once the scope is exited.
21501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  class CleanupScope {
21601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CodeGenFunction& CGF;
21701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    size_t CleanupStackDepth;
21801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    bool OldDidCallStackSave;
2195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool PerformCleanup;
22001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
22101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CleanupScope(const CleanupScope &); // DO NOT IMPLEMENT
22201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CleanupScope &operator=(const CleanupScope &); // DO NOT IMPLEMENT
22301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
22401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  public:
22501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Enter a new cleanup scope.
2265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    explicit CleanupScope(CodeGenFunction &CGF)
2275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      : CGF(CGF), PerformCleanup(true)
2285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    {
22901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CleanupStackDepth = CGF.CleanupEntries.size();
23001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      OldDidCallStackSave = CGF.DidCallStackSave;
23101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
23201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
23301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Exit this cleanup scope, emitting any accumulated
23401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// cleanups.
23501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    ~CleanupScope() {
2365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      if (PerformCleanup) {
2375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.DidCallStackSave = OldDidCallStackSave;
2385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.EmitCleanupBlocks(CleanupStackDepth);
2395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      }
2405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
2415656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
2425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Determine whether this scope requires any cleanups.
2435656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool requiresCleanups() const {
2445656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      return CGF.CleanupEntries.size() > CleanupStackDepth;
2455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
2465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
2475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Force the emission of cleanups now, instead of waiting
2485656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// until this object is destroyed.
2495656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    void ForceCleanup() {
2505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      assert(PerformCleanup && "Already forced cleanup");
25101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.DidCallStackSave = OldDidCallStackSave;
25201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.EmitCleanupBlocks(CleanupStackDepth);
2535656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      PerformCleanup = false;
25401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
25501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  };
25601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
257c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
258c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// blocks that have been added.
259c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlocks(size_t OldCleanupStackSize);
260c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
26187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// EmitBranchThroughCleanup - Emit a branch from the current insert block
26287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// through the cleanup handling code (if any) and then on to \arg Dest.
26387eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  ///
2640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FIXME: Maybe this should really be in EmitBranch? Don't we always want
26587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// this behavior for branches?
26687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
2670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
26872119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// BeginConditionalBranch - Should be called before a conditional part of an
269a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression is emitted. For example, before the RHS of the expression below
270a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// is emitted:
2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
2721d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// b && f(T());
2731d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  ///
274a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// This is used to make sure that any temporaries created in the conditional
2751d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// branch are only destroyed if the branch is taken.
27672119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void BeginConditionalBranch() {
277a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    ++ConditionalBranchLevel;
278a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
28072119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// EndConditionalBranch - Should be called after a conditional part of an
281a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression has been emitted.
28272119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void EndConditionalBranch() {
28308e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson    assert(ConditionalBranchLevel != 0 &&
28408e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson           "Conditional branch mismatch!");
28508e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson
286a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    --ConditionalBranchLevel;
287a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
2897f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
290d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  CGDebugInfo *DebugInfo;
29109429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
292f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// IndirectBranch - The first time an indirect goto is seen we create a block
293f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// with an indirect branch.  Every time we see the address of a label taken,
294f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// we add the label to the indirect goto.  Every subsequent indirect goto is
295f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// codegen'd as a jump to the IndirectBranch's basic block.
296d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::IndirectBrInst *IndirectBranch;
2970ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
2980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
2990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
3040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
306e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
307da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
308e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
309e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson      : BreakBlock(bb), ContinueBlock(cb) {}
3100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
311da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
312da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
3130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
314da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
31518ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
3160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
3170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
31851b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
31951b09f2c528c8460b5465c676173324e44176d62Devang Patel
3200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
32180fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
322c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
323c049e4f406a7f7179eba98659044a32508e53289Devang Patel
3249834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// InvokeDest - This is the nearest exception target for calls
3259834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// which can unwind, when exceptions are being used.
3269834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *InvokeDest;
3279834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
3280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
329bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // We track this by the size expression rather than the type itself because
330bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // in certain situations, like a const qualifier applied to an VLA typedef,
331bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // multiple VLA types can share the same size expression.
3320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
3330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
334bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
3350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3364cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
3374cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
3384cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
33909429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
3406ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  struct CleanupEntry {
3417799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupEntryBlock - The block of code that does the actual cleanup.
3427799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupEntryBlock;
3430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3447799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupExitBlock - The cleanup exit block.
3457799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupExitBlock;
3467799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
3476ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
348bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BasicBlock *> Blocks;
3496ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
3506ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// BranchFixups - Branch instructions to basic blocks that haven't been
3516ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// inserted into the current function yet.
352bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BranchInst *> BranchFixups;
3536ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
354d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    /// PreviousInvokeDest - The invoke handler from the start of the cleanup
355d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    /// region.
356d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *PreviousInvokeDest;
357d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
35899533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// EHOnly - Perform this only on the exceptional edge, not the main edge.
35999533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
36099533834ba8f3658559f334e68a518ebb6388ceaMike Stump
3617799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    explicit CleanupEntry(llvm::BasicBlock *CleanupEntryBlock,
362d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          llvm::BasicBlock *CleanupExitBlock,
363d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          llvm::BasicBlock *PreviousInvokeDest,
364d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          bool ehonly)
365d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      : CleanupEntryBlock(CleanupEntryBlock),
36699533834ba8f3658559f334e68a518ebb6388ceaMike Stump        CleanupExitBlock(CleanupExitBlock),
367d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        PreviousInvokeDest(PreviousInvokeDest),
36899533834ba8f3658559f334e68a518ebb6388ceaMike Stump        EHOnly(ehonly) {}
3696ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  };
3700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3716ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  /// CleanupEntries - Stack of cleanup entries.
3726ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
3736ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
374bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
375bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson
376bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
377bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  BlockScopeMap BlockScopes;
3780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
379f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXThisDecl - When generating code for a C++ member function,
380f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// this will hold the implicit 'this' declaration.
3812b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  ImplicitParamDecl *CXXThisDecl;
3822504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXThisValue;
3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
384f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXVTTDecl - When generating code for a base object constructor or
385f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// base object destructor with virtual bases, this will hold the implicit
386f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// VTT parameter.
387f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  ImplicitParamDecl *CXXVTTDecl;
3882504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXVTTValue;
389f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson
390e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary.
391e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  struct CXXLiveTemporaryInfo {
392e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// Temporary - The live temporary.
393e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    const CXXTemporary *Temporary;
3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
395e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// ThisPtr - The pointer to the temporary.
396e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *ThisPtr;
3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
398e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// DtorBlock - The destructor block.
399e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::BasicBlock *DtorBlock;
4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
401f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// CondPtr - If this is a conditional temporary, this is the pointer to the
402f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// condition variable that states whether the destructor should be called
403f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// or not.
404e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *CondPtr;
4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
406e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    CXXLiveTemporaryInfo(const CXXTemporary *temporary,
407f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *thisptr, llvm::BasicBlock *dtorblock,
408f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *condptr)
4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock),
410e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson      CondPtr(condptr) { }
411e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  };
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
413e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries;
4141d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson
415a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// ConditionalBranchLevel - Contains the nesting level of the current
416a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// conditional branch. This is used so that we know if a temporary should be
417a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// destroyed conditionally.
418a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  unsigned ConditionalBranchLevel;
4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4207dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
4217dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM
4227dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// type as well as the field number that contains the actual data.
4237dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *,
4247dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson                                              unsigned> > ByRefValueInfo;
4257dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
4267dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
4277dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// number that holds the value.
4287dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
429182f383db1782af752ecaf607fdff72a8542088bMike Stump
430182f383db1782af752ecaf607fdff72a8542088bMike Stump  llvm::BasicBlock *TerminateHandler;
43115037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  llvm::BasicBlock *TrapBB;
432940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman
433940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman  int UniqueAggrDestructorCount;
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
4360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
438e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4409834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *getInvokeDest() { return InvokeDest; }
4419834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; }
4429834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
443a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson  llvm::LLVMContext &getLLVMContext() { return VMContext; }
44469243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson
4459834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
4469834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
4479834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
4489834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
449391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
450af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
452679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
453af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
455fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
456fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
457af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
4590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
460fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
461fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
462af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4634e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
4644e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
4654e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
4664e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
4678a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump  llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
4682a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst  llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
4692a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst                                           bool BlockHasCopyDispose,
470199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck                                           CharUnits Size,
4710892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           const llvm::StructType *,
4720892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           std::vector<HelperInfo> *);
4734e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
474161d36de7ee686b09525bb919ad1b20592e499fcChris Lattner  llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
4754e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump                                        const BlockInfo& Info,
4766cc88f78fd36d3511b89412b193494b3e423cbffMike Stump                                        const Decl *OuterFuncDecl,
4777f28a9c37e67ae16396042ad9c085830969daf29Mike Stump                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
47830a8a272f091054ce92b9daa1992bcff887c3ee4Ken Dyck                                        CharUnits &Size, CharUnits &Align,
47900470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                      llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
48000470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                                        bool &subBlockHasCopyDispose);
4814e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
4826cc88f78fd36d3511b89412b193494b3e423cbffMike Stump  void BlockForwardSelf();
4834e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  llvm::Value *LoadBlockStruct();
4844e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
485199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck  CharUnits AllocateBlockDecl(const BlockDeclRefExpr *E);
486a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
4879ad5513b0f9d3999705659fb1aeb0e6c53455f43Anders Carlsson  const llvm::Type *BuildByRefType(const ValueDecl *D);
488dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
4890ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void GenerateCode(GlobalDecl GD, llvm::Function *Fn);
4900ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void StartFunction(GlobalDecl GD, QualType RetTy,
4917c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
4922284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
4932284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
494a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
4959fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitConstructorBody(FunctionArgList &Args);
4969fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitDestructorBody(FunctionArgList &Args);
4979fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitFunctionBody(FunctionArgList &Args);
498a355e07454463b19829ac92ffd115a097faff0e0John McCall
4990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
5000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
5011c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
5021c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
5030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
5040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
505af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
50617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
507c902d22129322731607988dafb8cd7f708eb75b1Mike Stump  /// DynamicTypeAdjust - Do the non-virtual and virtual adjustments on an
508c902d22129322731607988dafb8cd7f708eb75b1Mike Stump  /// object pointer to alter the dynamic type of the pointer.  Used by
509c902d22129322731607988dafb8cd7f708eb75b1Mike Stump  /// GenerateCovariantThunk for building thunks.
5107622cd3410846d28862ecfe862117894a259a7faAnders Carlsson  llvm::Value *DynamicTypeAdjust(llvm::Value *V,
5117622cd3410846d28862ecfe862117894a259a7faAnders Carlsson                                 const ThunkAdjustment &Adjustment);
512c902d22129322731607988dafb8cd7f708eb75b1Mike Stump
513ed032eb5c18b99528cbd76415337b6056a72b911Mike Stump  /// GenerateThunk - Generate a thunk for the given method
51435c98cc4c00efcfe47ad0b716e7c50afb9c5ff75Eli Friedman  llvm::Constant *GenerateThunk(llvm::Function *Fn, GlobalDecl GD,
515a94822e8937eeb340a653b88024f805a07a2d2eeAnders Carlsson                                bool Extern,
516a94822e8937eeb340a653b88024f805a07a2d2eeAnders Carlsson                                const ThunkAdjustment &ThisAdjustment);
5177622cd3410846d28862ecfe862117894a259a7faAnders Carlsson  llvm::Constant *
51835c98cc4c00efcfe47ad0b716e7c50afb9c5ff75Eli Friedman  GenerateCovariantThunk(llvm::Function *Fn, GlobalDecl GD,
5197622cd3410846d28862ecfe862117894a259a7faAnders Carlsson                         bool Extern,
5207622cd3410846d28862ecfe862117894a259a7faAnders Carlsson                         const CovariantThunkAdjustment &Adjustment);
521ed032eb5c18b99528cbd76415337b6056a72b911Mike Stump
522de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson  void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type);
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
52477a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman  void InitializeVtablePtrs(const CXXRecordDecl *ClassDecl);
52577a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman
526e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman  void InitializeVtablePtrsRecursive(const CXXRecordDecl *ClassDecl,
527e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman                                     llvm::Constant *Vtable,
52821431c551d867962c66c92f0f96f652678f64c1cAnders Carlsson                                     CGVtableInfo::AddrSubMap_t& AddressPoints,
529e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman                                     llvm::Value *ThisPtr,
530e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman                                     uint64_t Offset);
531e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman
5329fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void SynthesizeCXXCopyConstructor(const FunctionArgList &Args);
5339fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void SynthesizeCXXCopyAssignment(const FunctionArgList &Args);
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
535426cc3828ce07a2cff15c9837f5958e6fc4b7739Fariborz Jahanian  /// EmitDtorEpilogue - Emit all code that comes at the end of class's
536f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// destructor. This is to call destructors on members and base classes in
537f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// reverse order of their construction.
538de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson  void EmitDtorEpilogue(const CXXDestructorDecl *Dtor,
539de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson                        CXXDtorType Type);
5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
5420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
5430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
54488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
54588b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
54617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
54717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
5480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
5490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
55088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
55117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
552cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitStartEHSpec - Emit the start of the exception spec.
553cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitStartEHSpec(const Decl *D);
554cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
555cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitEndEHSpec - Emit the end of the exception spec.
556cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitEndEHSpec(const Decl *D);
557cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
558182f383db1782af752ecaf607fdff72a8542088bMike Stump  /// getTerminateHandler - Return a handler that just calls terminate.
5599b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump  llvm::BasicBlock *getTerminateHandler();
5609b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump
5618b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
563bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  const llvm::Type *ConvertType(const TypeDecl *T) {
564bff225ecf77fb891596ecb1b27196310d268365eJohn McCall    return ConvertType(getContext().getTypeDeclType(T));
565bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  }
566c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
5670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
5680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
569c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
5700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
57245012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
5734111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
57755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
57855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
5790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
58055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
58155e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
58229ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
5830032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore);
58429ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
5850032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore);
58629ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
58755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
5880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
5920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
593f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// SimplifyForwardingBlocks - If the given basic block is only a branch to
594f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// another basic block, simplify it. This assumes that no other code could
595f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// potentially reference the basic block.
596aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
597aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
5980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
5990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
6000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
6010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
602a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
6030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
6040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
6050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
606a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
607824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
6080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
6090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
6100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
6110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
6125e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
6130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
6140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
6150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
616d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
617d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
6180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
6190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
6200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
621a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
622a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
623a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
6240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
6250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
6260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
6270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
628a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
629a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
630a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
631a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
6320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
633488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
634dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
63590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
63690df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers MakeQualifiers(QualType T) {
643df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers();
6440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T));
6450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
6460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
649195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// block. The caller is responsible for setting an appropriate alignment on
650195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// the alloca.
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
652259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar                                     const llvm::Twine &Name = "tmp");
6530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6549bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// CreateIRTemp - Create a temporary IR object of the given type, with
6559bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// appropriate alignment. This routine should only be used when an temporary
6569bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// value needs to be stored into an alloca (for example, to avoid explicit
6579bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// PHI construction), but the type is the IR type, not the type appropriate
6589bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// for storing in memory.
6599bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  llvm::Value *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp");
6609bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar
661195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// CreateMemTemp - Create a temporary memory object of the given type, with
662195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// appropriate alignment.
663195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  llvm::Value *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp");
664195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar
6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
6685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6699b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
6709b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
6719b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
6729b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
67349d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
67449d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  /// \param IgnoreResult - True if the resulting value isn't used.
6750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
67614c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsAggLocVolatile = false, bool IgnoreResult = false,
67714c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsInitializer = false);
678d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
6790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
6800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
6814fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
6824fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
6830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
6840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
68514c5cbf59cffee52275230922283a247de407712Anders Carlsson  RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false,
68614c5cbf59cffee52275230922283a247de407712Anders Carlsson                           bool IsInitializer = false);
68746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
68827fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// EmitAggregateCopy - Emit an aggrate copy.
68927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
69027fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// \param isVolatile - True iff either the source or the destination is
69127fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
6927482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
69327fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump                         QualType EltTy, bool isVolatile=false);
6947482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
6957482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
6967482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
69751b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
69851b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
69951b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
70051b09f2c528c8460b5465c676173324e44176d62Devang Patel
701813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
702248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
7034f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
704dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
705dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
7060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7074f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
7084f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
7094f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
7104f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
711d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L);
7123d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner  llvm::BasicBlock *GetIndirectGotoBlock();
7130ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
7140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
7153d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
716ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
717ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
718ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
719ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
7200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
721ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
722f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
723f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitVLASize - Generate code for any VLA size expressions that might occur
724f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// in a variably modified type. If Ty is a VLA, will return the value that
725f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
726d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
727d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
72860d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
7290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
730dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
731dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
732dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
733dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
7345f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
7355f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
7362504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXThis() {
7372504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXThisValue && "no 'this' value for this function");
7382504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXThisValue;
7392504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
741c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
742c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// virtual bases.
7432504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXVTT() {
7442504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXVTTValue && "no VTT value for this function");
7452504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXVTTValue;
7462504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
747bff225ecf77fb891596ecb1b27196310d268365eJohn McCall
748bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
749bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  /// complete class down to one of its virtual bases.
750bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  llvm::Value *GetAddressOfBaseOfCompleteClass(llvm::Value *Value,
751bff225ecf77fb891596ecb1b27196310d268365eJohn McCall                                               bool IsVirtual,
752bff225ecf77fb891596ecb1b27196310d268365eJohn McCall                                               const CXXRecordDecl *Derived,
753bff225ecf77fb891596ecb1b27196310d268365eJohn McCall                                               const CXXRecordDecl *Base);
754c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson
755f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// GetAddressOfBaseClass - This function will add the necessary delta to the
756f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// load of 'this' and returns address of the base class.
757a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson  llvm::Value *GetAddressOfBaseClass(llvm::Value *Value,
758a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson                                     const CXXRecordDecl *ClassDecl,
759a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson                                     const CXXRecordDecl *BaseClassDecl,
760a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson                                     bool NullCheckValue);
761a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson
762a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson  llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
7635a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson                                        const CXXRecordDecl *ClassDecl,
764a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson                                        const CXXRecordDecl *DerivedClassDecl,
7655a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson                                        bool NullCheckValue);
766a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson
767bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson  llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This,
768bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *ClassDecl,
769bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *BaseClassDecl);
7702f1986b557fa671c4f8c9dd0d071398edfc073d5Anders Carlsson
7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue,
772eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   llvm::Value *SrcValue,
773c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian                                   const ArrayType *Array,
774c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian                                   const CXXRecordDecl *BaseClassDecl,
775c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian                                   QualType Ty);
776c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian
7771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitClassAggrCopyAssignment(llvm::Value *DestValue,
778c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian                                   llvm::Value *SrcValue,
779eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   const ArrayType *Array,
780eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   const CXXRecordDecl *BaseClassDecl,
781eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   QualType Ty);
782eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian
783ca28361fb0a72c50e0a400fae2fad9520e61c0a5Fariborz Jahanian  void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue,
7841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               const CXXRecordDecl *ClassDecl,
785942f4f33d02dba823594bd2d7b3d317cb01c74f8Fariborz Jahanian                               const CXXRecordDecl *BaseClassDecl,
786942f4f33d02dba823594bd2d7b3d317cb01c74f8Fariborz Jahanian                               QualType Ty);
7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7880270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian  void EmitClassCopyAssignment(llvm::Value *DestValue, llvm::Value *SrcValue,
7891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               const CXXRecordDecl *ClassDecl,
7900270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian                               const CXXRecordDecl *BaseClassDecl,
7910270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian                               QualType Ty);
7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
793c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall  void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,
794c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      CXXCtorType CtorType,
795c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      const FunctionArgList &Args);
7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
797b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              llvm::Value *This,
798b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
799b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
8001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
801288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
802569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  const ConstantArrayType *ArrayTy,
8035d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
8045d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
8055d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgEnd);
8065d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson
807569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
808569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  llvm::Value *NumElements,
8095d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
8105d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
8115d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgEnd);
812b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
813f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
814f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 const ArrayType *Array,
815f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 llvm::Value *This);
8161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
81772c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
81872c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *NumElements,
81972c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *This);
82072c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian
821dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Constant *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
82288f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian                                                const ArrayType *Array,
82388f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian                                                llvm::Value *This);
82488f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian
8257267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
8267267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson                             llvm::Value *This);
8271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
828543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson  void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
829f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson  void PopCXXTemporary();
8301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
831a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson  llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
83260e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson  void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
8331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8344bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman  void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
8354bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman                      QualType DeleteTy);
8364bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman
837c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
838c849c052d6b4b70f2651c1969531861a5f230053Mike Stump  llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
839c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
840b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  void EmitCheck(llvm::Value *, unsigned Size);
841b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
842dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
843dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                       bool isInc, bool isPre);
844dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
845dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                         bool isInc, bool isPre);
8465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
850d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitDecl - Emit a declaration.
851d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
852d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
8535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
854d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
8551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// EmitBlockVarDecl - Emit a block variable declaration.
856d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
857d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
858248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
859d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
860d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitLocalBlockVarDecl - Emit a local block variable declaration.
861d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
862d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
863248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
864d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
865f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson  void EmitStaticBlockVarDecl(const VarDecl &D,
866f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson                              llvm::GlobalValue::LinkageTypes Linkage);
867b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
868b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
869b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
8700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
8760912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
8770912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
8780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
8790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
8800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
8810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
8820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
8830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
885a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
8860912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
8870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
8880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
8890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
8900912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
8910912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
8920912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
8930912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
8949b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
8959b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
896a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
8970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
8980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
89991d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
900a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
9030ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
9100912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
9110912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
91251b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
91351b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
91451b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
915c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
916fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
9170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9183d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
91964d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
92064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
92110cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
9220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9239fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  struct CXXTryStmtInfo {
9249fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *SavedLandingPad;
9259fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *HandlerBlock;
9269fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *FinallyBlock;
9279fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  };
9289fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  CXXTryStmtInfo EnterCXXTryStmt(const CXXTryStmt &S);
9299fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void ExitCXXTryStmt(const CXXTryStmt &S, CXXTryStmtInfo Info);
9309fc6a7774643a810c8501dae2323e863fefb623eJohn McCall
9316815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  void EmitCXXTryStmt(const CXXTryStmt &S);
9326815e941998659a55c20c147861b0f437928c3d8Anders Carlsson
9335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
93713e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
93813e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
93913e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
940ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
941ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
942ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
943ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
944ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
945ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
9460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
9470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
9486ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
9496ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
9506ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
9665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
9680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
969b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// EmitCheckedLValue - Same as EmitLValue but additionally we generate
970b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// checking code to guard against undefined behavior.  This is only
971b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// suitable when we know that the address will be used to access the
972b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// object.
973b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  LValue EmitCheckedLValue(const Expr *E);
974b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
9759d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
9769d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
9779d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
97809429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
9799d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
9809d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
9819d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
9829d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
9839d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
98409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
985b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson                         bool Volatile, QualType Ty);
9869d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
991213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
9923b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
99385c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
99443f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
1001213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
1002213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
100385c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
100443f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
1005ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
10060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
10070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
1008ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
10090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
10100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
10110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
1012ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
1013ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
10140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
101522c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
101680e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
10175b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
101822c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
10195b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
10205b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
1023eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
1024662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
1025d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
1028213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
1029b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
1030820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian  LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
103106e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
10326fcec8b58d0571866fcb162db947b029cc539ec4Anders Carlsson  LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
103375dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
103448620bafe4ba879f96c2d17caefeb79f3fae2eeaFariborz Jahanian  LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E);
1035909fbf70223ea04a5ec8d449789f3683a89701ffAnders Carlsson
10362a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
103729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
10380ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
1039e6d2a534851a649485cb087e9dfcaf8a65886858Anders Carlsson                            unsigned CVRQualifiers);
104006a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
104106a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
104206a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// if the Field is a reference, this will return the address of the reference
104306a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// and not the address of the value stored in the reference.
104406a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  LValue EmitLValueForFieldInitialization(llvm::Value* Base,
104506a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          const FieldDecl* Field,
104606a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          unsigned CVRQualifiers);
104706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
104845012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
104945012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
105029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
105129e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
10520ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field,
1053598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
1054fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
1055a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
1056a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump
1057b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
1058e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson  LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
1059b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson  LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E);
1060c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E);
1061b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson
10620a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
1063391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
106485c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
106509105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E);
1066654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
1067654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
10688bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian  LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
10698bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian
10705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1071883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
10725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
10735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
10750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
10760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
1077c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
1078f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// \param TargetDecl - If given, the decl of the function in a direct call;
1079f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// used to set attributes on the call (noreturn, etc.).
108088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
108188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
1082f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson                  ReturnValueSlot ReturnValue,
1083c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
1084c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const Decl *TargetDecl = 0);
10851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
108631777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  RValue EmitCall(QualType FnType, llvm::Value *Callee,
1087d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                  ReturnValueSlot ReturnValue,
1088986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgBeg,
1089986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgEnd,
1090986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  const Decl *TargetDecl = 0);
1091d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson  RValue EmitCallExpr(const CallExpr *E,
1092d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                      ReturnValueSlot ReturnValue = ReturnValueSlot());
10931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1094566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
1095f0070dbae9535836ad41711081465dec2259786bMike Stump                                const llvm::Type *Ty);
1096566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
1097566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson                                llvm::Value *&This, const llvm::Type *Ty);
1098566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson
1099b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
1100b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
1101a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                           ReturnValueSlot ReturnValue,
1102b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
1103c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson                           llvm::Value *VTT,
1104b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
1105b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
1106a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
1107a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                               ReturnValueSlot ReturnValue);
1108a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
1109a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                      ReturnValueSlot ReturnValue);
11105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
11110f294632f36459174199b77699e339715244b5abAnders Carlsson  RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
1112a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       const CXXMethodDecl *MD,
1113a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       ReturnValueSlot ReturnValue);
11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1115375c31c4673f83f925de221752cf801c2fbbb246Anders Carlsson
11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  RValue EmitBuiltinExpr(const FunctionDecl *FD,
1117ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1119a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue);
112009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
11210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
11220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
1123f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1124f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
11252752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner  llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1126564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1127564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
11280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1129ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
11307f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
11318fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
11328f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
11335daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  RValue EmitObjCPropertyGet(const Expr *E);
1134f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S);
113543f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
1136f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src);
11378fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
11388fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
11394029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
11404029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// expression. Will emit a temporary variable if E is not an LValue.
1141a64a869312066ff6119d1d7ae03f88ce499e3f82Anders Carlsson  RValue EmitReferenceBindingToExpr(const Expr* E, bool IsInitializer = false);
11423aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson
1143883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1144bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
1145883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1146bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
1147bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
11480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
11500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
115114c5cbf59cffee52275230922283a247de407712Anders Carlsson  llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
11520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11533707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
11543707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
11553707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
11563707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
11570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11584f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
11590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
11600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
11614f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
11624f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
11630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1165883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
1166883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
1167883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
116849d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest,
116908c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool IgnoreResult = false, bool IsInitializer = false,
117008c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool RequiresGCollection = false);
11710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
117218aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// EmitAggExprToLValue - Emit the computation of the specified expression of
117318aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// aggregate type into a temporary LValue.
117418aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  LValue EmitAggExprToLValue(const Expr *E);
117518aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar
1176082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// EmitGCMemmoveCollectable - Emit special API for structs with object
1177082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// pointers.
1178082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
117908c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                                QualType Ty);
1180082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian
1181b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
118223b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
11837f79f9be5916c51c35da4f126b7c12596a101607Mike Stump  ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
11847f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImag = false,
11857f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreRealAssign = false,
11867f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImagAssign = false);
11870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
118823b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
118923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
1190190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
1191190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
11927f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
11937f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
11947f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
11957f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
11969b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
11979b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
11982621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
1199f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a
1200f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// static block var decl.
1201761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D,
1202761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                                 const char *Separator,
1203f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump                                       llvm::GlobalValue::LinkageTypes Linkage);
1204761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
1205761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the
1206761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// global variable that has already been created for it.  If the initializer
1207761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// has a different type than GV does, this may free GV and return a different
1208761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// one.  Otherwise it just returns GV.
1209761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *
1210761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  AddInitializerToGlobalBlockVarDecl(const VarDecl &D,
1211761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                     llvm::GlobalVariable *GV);
1212761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
12130096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
1214f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime
1215f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// initialized static block var decl.
12163b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
12173b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::GlobalVariable *GV);
1218e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
12193b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
12203b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// variable with global storage.
12213b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr);
12223b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson
12233b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr
12243b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// with the C++ runtime so that its destructor will be called at exit.
122588f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian  void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
12263b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::Constant *DeclPtr);
12271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// GenerateCXXGlobalInitFunc - Generates code for initializing global
122989ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson  /// variables.
123089ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson  void GenerateCXXGlobalInitFunc(llvm::Function *Fn,
12316c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman                                 llvm::Constant **Decls,
123289ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson                                 unsigned NumDecls);
12331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12346c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D);
12356c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman
123631ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson  void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E);
12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1238b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E,
12391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    llvm::Value *AggLoc = 0,
124014c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsAggLocVolatile = false,
124114c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsInitializer = false);
12421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1243756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson  void EmitCXXThrowExpr(const CXXThrowExpr *E);
1244c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
12450ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
12460ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
12470ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
12480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12490946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
12500946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
12510946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
12520946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
12530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12544bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
125531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
125631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
125731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
125831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
12590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
126031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
126131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
126231a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
12639bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
12644bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
1265be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump
126615037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// getTrapBB - Create a basic block that will call the trap intrinsic.  We'll
126715037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// generate a branch around the created basic block as necessary.
126815037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  llvm::BasicBlock* getTrapBB();
126931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
12700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
127129e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
127229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
12735627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
12745627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
12755627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
12765627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
12775627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
12785627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
12790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
12805627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
12815627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
12825627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
12830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
12840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
12850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
12860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
12875627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
1288c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
12891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  llvm::Value* EmitAsmInput(const AsmStmt &S,
1290b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar                            const TargetInfo::ConstraintInfo &Info,
1291c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
12920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1293c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlock - emits a single cleanup block.
1294c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlock();
1295c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
129687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// AddBranchFixup - adds a branch instruction to the list of fixups for the
129787eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// current cleanup scope.
129887eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void AddBranchFixup(llvm::BranchInst *BI);
12990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13000139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArg - Emit a single call argument.
13010139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  RValue EmitCallArg(const Expr *E, QualType ArgType);
13021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13030139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
13041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The CallArgTypeInfo parameter is used for iterating over the known
1305af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
1306af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
1307af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
13080139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
1309af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                    CallExpr::const_arg_iterator ArgEnd) {
1310af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      CallExpr::const_arg_iterator Arg = ArgBeg;
1311af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1312af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
1313af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
1314af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
1315af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
131644b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman        assert(Arg != ArgEnd && "Running over edge of argument list!");
1317af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
1318af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1319af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
13201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getTypePtr() ==
13211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getContext().getCanonicalType(Arg->getType()).getTypePtr() &&
1322af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1325af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                      ArgType));
1326af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Either we've emitted all the call args, or we have a call to a
1329af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
13301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
1331af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
13321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1333af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1335af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
1336af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    for (; Arg != ArgEnd; ++Arg) {
1337af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      QualType ArgType = Arg->getType();
1338af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1339af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                    ArgType));
1340af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
1341af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
1342492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall
1343492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  const TargetCodeGenInfo &getTargetHooks() const {
1344492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall    return CGM.getTargetCodeGenInfo();
1345492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  }
13465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1348af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
13495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1353