CodeGenFunction.h revision 109dfc6ca6652f60c55ed0f2631aebf323d0200d
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump// This is the internal per-function state used for llvm translation.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H
15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h"
18e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
20199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck#include "clang/AST/CharUnits.h"
21481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h"
22481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h"
23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h"
24481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h"
2569243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "CodeGenModule.h"
2696bd13ae1ab89f5a04b3ad3ec8ec1864cbba3482Mike Stump#include "CGBlocks.h"
2745d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
280dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
29b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson#include "CGCXX.h"
308f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
318f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
34f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer  class LLVMContext;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
36898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
37259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar  class Twine;
38ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
437267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  class CXXDestructorDecl;
446815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  class CXXTryStmt;
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
46c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
4872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
49c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
50679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
5129e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
5229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
53391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
54fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
55af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
57492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  class TargetCodeGenInfo;
58c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
5916f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
6016f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
6116f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
6216f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
65b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
66e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
67bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
722a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction {
738a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
748a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  void operator=(const CodeGenFunction&);  // DO NOT IMPLEMENT
75bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
77444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &Target;
780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7958dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
8045d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
82b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurFuncDecl - Holds the Decl for the current function or ObjC method.
83b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// This excludes BlockDecls.
844111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
85b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
86b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
8788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
88391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
916a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  /// CurGD - The GlobalDecl for the current function being compiled.
926a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump  GlobalDecl CurGD;
936a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump
945ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
955ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
98b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman  llvm::Value *ReturnValue;
990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
102481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
1030ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
1057b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
10618ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
107d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  bool Exceptions;
1089c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump  bool CatchUndefined;
10918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
110fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
111fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// rethrows.
112273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
1130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1146fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// PushCleanupBlock - Push a new cleanup entry on the stack and set the
1156fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// passed in block as the cleanup block.
1167799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian  void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock,
117d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                        llvm::BasicBlock *CleanupExitBlock,
118d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                        llvm::BasicBlock *PreviousInvokeDest,
11999533834ba8f3658559f334e68a518ebb6388ceaMike Stump                        bool EHOnly = false);
120d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock) {
121d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    PushCleanupBlock(CleanupEntryBlock, 0, getInvokeDest(), false);
122d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  }
123bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
1240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupBlockInfo - A struct representing a popped cleanup block.
125bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  struct CleanupBlockInfo {
1267799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupEntryBlock - the cleanup entry block
127bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *CleanupBlock;
1280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// SwitchBlock - the block (if any) containing the switch instruction used
1300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// for jumping to the final destination.
131bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *SwitchBlock;
1320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
133bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// EndBlock - the default destination for the switch instruction.
134bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *EndBlock;
1350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13699533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// EHOnly - True iff this cleanup should only be performed on the
13799533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// exceptional edge.
13899533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
13999533834ba8f3658559f334e68a518ebb6388ceaMike Stump
1400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
14199533834ba8f3658559f334e68a518ebb6388ceaMike Stump                     llvm::BasicBlock *eb, bool ehonly = false)
14299533834ba8f3658559f334e68a518ebb6388ceaMike Stump      : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb), EHOnly(ehonly) {}
143bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  };
144bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
145d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// EHCleanupBlock - RAII object that will create a cleanup block for the
146d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// exceptional edge and set the insert point to that block.  When destroyed,
147d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// it creates the cleanup edge and sets the insert point to the previous
148d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// block.
149d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  class EHCleanupBlock {
150d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    CodeGenFunction& CGF;
1513d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall    llvm::BasicBlock *PreviousInsertionBlock;
152d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *CleanupHandler;
153d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *PreviousInvokeDest;
154d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  public:
155d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    EHCleanupBlock(CodeGenFunction &cgf)
1563d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall      : CGF(cgf),
1573d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall        PreviousInsertionBlock(CGF.Builder.GetInsertBlock()),
1583d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall        CleanupHandler(CGF.createBasicBlock("ehcleanup", CGF.CurFn)),
159d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        PreviousInvokeDest(CGF.getInvokeDest()) {
16020d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump      llvm::BasicBlock *TerminateHandler = CGF.getTerminateHandler();
1613d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall      CGF.Builder.SetInsertPoint(CleanupHandler);
16220d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump      CGF.setInvokeDest(TerminateHandler);
163d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    }
164d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    ~EHCleanupBlock();
165d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  };
166d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
167bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
1680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branch fixups and return a block info struct with the switch block and end
169d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// block.  This will also reset the invoke handler to the previous value
170d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump  /// from when the cleanup block was created.
171bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  CleanupBlockInfo PopCleanupBlock();
1720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
173f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// DelayedCleanupBlock - RAII object that will create a cleanup block and set
174f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// the insert point to that block. When destructed, it sets the insert point
175f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// to the previous block and pushes a new cleanup entry on the stack.
176d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor  class DelayedCleanupBlock {
1770d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CodeGenFunction& CGF;
1780d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    llvm::BasicBlock *CurBB;
1797799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupEntryBB;
1807799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupExitBB;
181d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *CurInvokeDest;
18299533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
1837799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
1840d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
18599533834ba8f3658559f334e68a518ebb6388ceaMike Stump    DelayedCleanupBlock(CodeGenFunction &cgf, bool ehonly = false)
1867799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()),
187548ce5e78215a34f409d597bb2c1e9f897a8eda3John McCall        CleanupEntryBB(CGF.createBasicBlock("cleanup")),
188548ce5e78215a34f409d597bb2c1e9f897a8eda3John McCall        CleanupExitBB(0),
189d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        CurInvokeDest(CGF.getInvokeDest()),
190d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        EHOnly(ehonly) {
1917799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      CGF.Builder.SetInsertPoint(CleanupEntryBB);
1920d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1947799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *getCleanupExitBlock() {
1957799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      if (!CleanupExitBB)
1967799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian        CleanupExitBB = CGF.createBasicBlock("cleanup.exit");
1977799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian      return CleanupExitBB;
1987799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    }
1997799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
200d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor    ~DelayedCleanupBlock() {
201d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      CGF.PushCleanupBlock(CleanupEntryBB, CleanupExitBB, CurInvokeDest,
202d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                           EHOnly);
203d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      // FIXME: This is silly, move this into the builder.
204d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      if (CurBB)
205d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.SetInsertPoint(CurBB);
206d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      else
207d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.ClearInsertionPoint();
2080d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
2090d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
2100d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
21101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  /// \brief Enters a new scope for capturing cleanups, all of which will be
21201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  /// executed once the scope is exited.
21301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  class CleanupScope {
21401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CodeGenFunction& CGF;
21501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    size_t CleanupStackDepth;
21601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    bool OldDidCallStackSave;
2175656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool PerformCleanup;
21801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
21901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CleanupScope(const CleanupScope &); // DO NOT IMPLEMENT
22001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    CleanupScope &operator=(const CleanupScope &); // DO NOT IMPLEMENT
22101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
22201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  public:
22301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Enter a new cleanup scope.
2245656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    explicit CleanupScope(CodeGenFunction &CGF)
2255656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      : CGF(CGF), PerformCleanup(true)
2265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    {
22701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CleanupStackDepth = CGF.CleanupEntries.size();
22801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      OldDidCallStackSave = CGF.DidCallStackSave;
22901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
23001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
23101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// \brief Exit this cleanup scope, emitting any accumulated
23201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    /// cleanups.
23301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    ~CleanupScope() {
2345656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      if (PerformCleanup) {
2355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.DidCallStackSave = OldDidCallStackSave;
2365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor        CGF.EmitCleanupBlocks(CleanupStackDepth);
2375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      }
2385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
2395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
2405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Determine whether this scope requires any cleanups.
2415656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    bool requiresCleanups() const {
2425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      return CGF.CleanupEntries.size() > CleanupStackDepth;
2435656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    }
2445656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor
2455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// \brief Force the emission of cleanups now, instead of waiting
2465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    /// until this object is destroyed.
2475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor    void ForceCleanup() {
2485656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      assert(PerformCleanup && "Already forced cleanup");
24901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.DidCallStackSave = OldDidCallStackSave;
25001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor      CGF.EmitCleanupBlocks(CleanupStackDepth);
2515656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor      PerformCleanup = false;
25201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor    }
25301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor  };
25401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor
25544ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson  /// CXXTemporariesCleanupScope - Enters a new scope for catching live
25644ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson  /// temporaries, all of which will be popped once the scope is exited.
25744ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson  class CXXTemporariesCleanupScope {
25844ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    CodeGenFunction &CGF;
25944ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    size_t NumLiveTemporaries;
26044ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
26144ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    // DO NOT IMPLEMENT
26244ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    CXXTemporariesCleanupScope(const CXXTemporariesCleanupScope &);
26344ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    CXXTemporariesCleanupScope &operator=(const CXXTemporariesCleanupScope &);
26444ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
26544ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson  public:
26644ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    explicit CXXTemporariesCleanupScope(CodeGenFunction &CGF)
26744ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson      : CGF(CGF), NumLiveTemporaries(CGF.LiveTemporaries.size()) { }
26844ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
26944ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    ~CXXTemporariesCleanupScope() {
27044ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson      while (CGF.LiveTemporaries.size() > NumLiveTemporaries)
27144ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson        CGF.PopCXXTemporary();
27244ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson    }
27344ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson  };
27444ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
27544ec82b4a1597802f5bf17721481b8c265bc8dc5Anders Carlsson
276c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
277c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// blocks that have been added.
278c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlocks(size_t OldCleanupStackSize);
279c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
28087eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// EmitBranchThroughCleanup - Emit a branch from the current insert block
28187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// through the cleanup handling code (if any) and then on to \arg Dest.
28287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  ///
2830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FIXME: Maybe this should really be in EmitBranch? Don't we always want
28487eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// this behavior for branches?
28587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
2860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
28772119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// BeginConditionalBranch - Should be called before a conditional part of an
288a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression is emitted. For example, before the RHS of the expression below
289a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// is emitted:
2901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
2911d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// b && f(T());
2921d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  ///
293a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// This is used to make sure that any temporaries created in the conditional
2941d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// branch are only destroyed if the branch is taken.
29572119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void BeginConditionalBranch() {
296a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    ++ConditionalBranchLevel;
297a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
29972119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  /// EndConditionalBranch - Should be called after a conditional part of an
300a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// expression has been emitted.
30172119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson  void EndConditionalBranch() {
30208e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson    assert(ConditionalBranchLevel != 0 &&
30308e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson           "Conditional branch mismatch!");
30408e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson
305a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson    --ConditionalBranchLevel;
306a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  }
3071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
3087f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
309d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  CGDebugInfo *DebugInfo;
31009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
311f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// IndirectBranch - The first time an indirect goto is seen we create a block
312f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// with an indirect branch.  Every time we see the address of a label taken,
313f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// we add the label to the indirect goto.  Every subsequent indirect goto is
314f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// codegen'd as a jump to the IndirectBranch's basic block.
315d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::IndirectBrInst *IndirectBranch;
3160ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
3170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
3180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
3230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
325e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
326da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
327e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
328e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson      : BreakBlock(bb), ContinueBlock(cb) {}
3290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
330da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
331da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
3320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
333da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
33418ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
3350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
3360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
33751b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
33851b09f2c528c8460b5465c676173324e44176d62Devang Patel
3390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
34080fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
341c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
342c049e4f406a7f7179eba98659044a32508e53289Devang Patel
3439834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// InvokeDest - This is the nearest exception target for calls
3449834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// which can unwind, when exceptions are being used.
3459834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *InvokeDest;
3469834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
3470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
348bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // We track this by the size expression rather than the type itself because
349bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // in certain situations, like a const qualifier applied to an VLA typedef,
350bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  // multiple VLA types can share the same size expression.
3510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
3520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
353bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman  llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap;
3540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3554cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
3564cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
3574cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
35809429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
3596ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  struct CleanupEntry {
3607799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupEntryBlock - The block of code that does the actual cleanup.
3617799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupEntryBlock;
3620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3637799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    /// CleanupExitBlock - The cleanup exit block.
3647799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    llvm::BasicBlock *CleanupExitBlock;
3657799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian
3666ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
367bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BasicBlock *> Blocks;
3686ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
3696ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// BranchFixups - Branch instructions to basic blocks that haven't been
3706ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// inserted into the current function yet.
371bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BranchInst *> BranchFixups;
3726ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
373d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    /// PreviousInvokeDest - The invoke handler from the start of the cleanup
374d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    /// region.
375d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump    llvm::BasicBlock *PreviousInvokeDest;
376d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump
37799533834ba8f3658559f334e68a518ebb6388ceaMike Stump    /// EHOnly - Perform this only on the exceptional edge, not the main edge.
37899533834ba8f3658559f334e68a518ebb6388ceaMike Stump    bool EHOnly;
37999533834ba8f3658559f334e68a518ebb6388ceaMike Stump
3807799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian    explicit CleanupEntry(llvm::BasicBlock *CleanupEntryBlock,
381d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          llvm::BasicBlock *CleanupExitBlock,
382d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          llvm::BasicBlock *PreviousInvokeDest,
383d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump                          bool ehonly)
384d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump      : CleanupEntryBlock(CleanupEntryBlock),
38599533834ba8f3658559f334e68a518ebb6388ceaMike Stump        CleanupExitBlock(CleanupExitBlock),
386d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump        PreviousInvokeDest(PreviousInvokeDest),
38799533834ba8f3658559f334e68a518ebb6388ceaMike Stump        EHOnly(ehonly) {}
3886ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  };
3890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3906ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  /// CleanupEntries - Stack of cleanup entries.
3916ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
3926ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
393bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
394bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson
395bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
396bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  BlockScopeMap BlockScopes;
3970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
398f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXThisDecl - When generating code for a C++ member function,
399f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// this will hold the implicit 'this' declaration.
4002b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  ImplicitParamDecl *CXXThisDecl;
4012504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXThisValue;
4021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
403f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// CXXVTTDecl - When generating code for a base object constructor or
404f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// base object destructor with virtual bases, this will hold the implicit
405f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  /// VTT parameter.
406f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  ImplicitParamDecl *CXXVTTDecl;
4072504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *CXXVTTValue;
408f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson
409e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary.
410e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  struct CXXLiveTemporaryInfo {
411e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// Temporary - The live temporary.
412e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    const CXXTemporary *Temporary;
4131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
414e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// ThisPtr - The pointer to the temporary.
415e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *ThisPtr;
4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
417e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// DtorBlock - The destructor block.
418e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::BasicBlock *DtorBlock;
4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
420f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// CondPtr - If this is a conditional temporary, this is the pointer to the
421f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// condition variable that states whether the destructor should be called
422f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump    /// or not.
423e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *CondPtr;
4241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
425e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    CXXLiveTemporaryInfo(const CXXTemporary *temporary,
426f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *thisptr, llvm::BasicBlock *dtorblock,
427f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *condptr)
4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock),
429e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson      CondPtr(condptr) { }
430e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  };
4311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
432e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries;
4331d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson
434a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// ConditionalBranchLevel - Contains the nesting level of the current
435a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// conditional branch. This is used so that we know if a temporary should be
436a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  /// destroyed conditionally.
437a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson  unsigned ConditionalBranchLevel;
4381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4397dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
4407dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM
4417dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// type as well as the field number that contains the actual data.
4427dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *,
4437dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson                                              unsigned> > ByRefValueInfo;
4447dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson
4457dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field
4467dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  /// number that holds the value.
4477dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson  unsigned getByRefValueLLVMField(const ValueDecl *VD) const;
448182f383db1782af752ecaf607fdff72a8542088bMike Stump
449182f383db1782af752ecaf607fdff72a8542088bMike Stump  llvm::BasicBlock *TerminateHandler;
45015037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  llvm::BasicBlock *TrapBB;
451940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman
452940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman  int UniqueAggrDestructorCount;
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
4550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
457e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4599834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *getInvokeDest() { return InvokeDest; }
4609834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; }
4619834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
462a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson  llvm::LLVMContext &getLLVMContext() { return VMContext; }
46369243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson
4649834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
4659834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
4669834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
4679834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
468391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
469af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
471679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
472af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
474fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
475fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
476109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian  void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP,
477109dfc6ca6652f60c55ed0f2631aebf323d0200dFariborz Jahanian                                  ObjCMethodDecl *MD, bool ctor);
478af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
4800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
481fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
482fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
4830b2bd47151ee9205ad6c66d1ffb921918106088aFariborz Jahanian  bool IndirectObjCSetterArg(const CGFunctionInfo &FI);
48415bd58842adaa4f8cca4e58047ed18e033858d9bFariborz Jahanian  bool IvarTypeWithAggrGCObjects(QualType Ty);
485af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
4864e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
4874e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
4884e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
4894e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
4908a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump  llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
4912a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst  llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *,
4922a7eb28397148079cbc8e54e8a3871ef01c4f4bcBlaine Garst                                           bool BlockHasCopyDispose,
493199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck                                           CharUnits Size,
4940892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           const llvm::StructType *,
4950892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           std::vector<HelperInfo> *);
4964e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
497161d36de7ee686b09525bb919ad1b20592e499fcChris Lattner  llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
4984e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump                                        const BlockInfo& Info,
4996cc88f78fd36d3511b89412b193494b3e423cbffMike Stump                                        const Decl *OuterFuncDecl,
5007f28a9c37e67ae16396042ad9c085830969daf29Mike Stump                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
50130a8a272f091054ce92b9daa1992bcff887c3ee4Ken Dyck                                        CharUnits &Size, CharUnits &Align,
50200470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                      llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
50300470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                                        bool &subBlockHasCopyDispose);
5044e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
5056cc88f78fd36d3511b89412b193494b3e423cbffMike Stump  void BlockForwardSelf();
5064e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  llvm::Value *LoadBlockStruct();
5074e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
508199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck  CharUnits AllocateBlockDecl(const BlockDeclRefExpr *E);
509a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
5109ad5513b0f9d3999705659fb1aeb0e6c53455f43Anders Carlsson  const llvm::Type *BuildByRefType(const ValueDecl *D);
511dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
5120ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void GenerateCode(GlobalDecl GD, llvm::Function *Fn);
5130ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson  void StartFunction(GlobalDecl GD, QualType RetTy,
5147c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
5152284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
5162284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
517a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
5189fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitConstructorBody(FunctionArgList &Args);
5199fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitDestructorBody(FunctionArgList &Args);
5209fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void EmitFunctionBody(FunctionArgList &Args);
521a355e07454463b19829ac92ffd115a097faff0e0John McCall
5220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
5230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
5241c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
5251c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
5260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
5270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
528af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
52917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
530519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson  /// GenerateThunk - Generate a thunk for the given method.
531519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson  void GenerateThunk(llvm::Function *Fn, GlobalDecl GD, const ThunkInfo &Thunk);
532519c32880b99396034ecaedc0cd86db2e8485003Anders Carlsson
533de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson  void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type);
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
535d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// InitializeVTablePointer - Initialize the vtable pointer of the given
536d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  /// subobject.
537d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  ///
538b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson  void InitializeVTablePointer(BaseSubobject Base,
539b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                               const CXXRecordDecl *NearestVBase,
540d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson                               llvm::Constant *VTable,
541d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson                               const CXXRecordDecl *VTableClass);
542d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
543d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson  typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
544b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson  void InitializeVTablePointers(BaseSubobject Base,
545b3b772ea15a4cd54879e244629aa685ead9548bbAnders Carlsson                                const CXXRecordDecl *NearestVBase,
546603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                bool BaseIsNonVirtualPrimaryBase,
547603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                llvm::Constant *VTable,
548603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                const CXXRecordDecl *VTableClass,
549603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson                                VisitedVirtualBasesSetTy& VBases);
55077a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman
551603d6d12cc4cba1ef219a3d55c698c7c87f87adfAnders Carlsson  void InitializeVTablePointers(const CXXRecordDecl *ClassDecl);
552d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
553d103f9f9b401b419e756f8c1849683cd77586067Anders Carlsson
5549fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void SynthesizeCXXCopyConstructor(const FunctionArgList &Args);
5559fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void SynthesizeCXXCopyAssignment(const FunctionArgList &Args);
5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
557426cc3828ce07a2cff15c9837f5958e6fc4b7739Fariborz Jahanian  /// EmitDtorEpilogue - Emit all code that comes at the end of class's
558f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// destructor. This is to call destructors on members and base classes in
559f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// reverse order of their construction.
560de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson  void EmitDtorEpilogue(const CXXDestructorDecl *Dtor,
561de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson                        CXXDtorType Type);
5621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
5640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
5650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
56688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
56788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
56817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
56917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
5700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
5710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
57288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
57317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
574cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitStartEHSpec - Emit the start of the exception spec.
575cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitStartEHSpec(const Decl *D);
576cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
577cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  /// EmitEndEHSpec - Emit the end of the exception spec.
578cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump  void EmitEndEHSpec(const Decl *D);
579cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump
580182f383db1782af752ecaf607fdff72a8542088bMike Stump  /// getTerminateHandler - Return a handler that just calls terminate.
5819b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump  llvm::BasicBlock *getTerminateHandler();
5829b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump
5838b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
5845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
585bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  const llvm::Type *ConvertType(const TypeDecl *T) {
586bff225ecf77fb891596ecb1b27196310d268365eJohn McCall    return ConvertType(getContext().getTypeDeclType(T));
587bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  }
588c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
5890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
5900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
591c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
5920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
59445012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
5954111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
5965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
5975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
5985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
59955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
60055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
6010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
60255e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
60355e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
60429ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
6050032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore);
60629ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
6070032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson    return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore);
60829ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
60955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
6100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
6140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
615f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// SimplifyForwardingBlocks - If the given basic block is only a branch to
616f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// another basic block, simplify it. This assumes that no other code could
617f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// potentially reference the basic block.
618aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
619aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
6200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
6210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
6220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
6230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
624a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
6250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
6260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
6270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
628a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
629824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
6300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
6310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
6320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
6330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
6345e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
6350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
6360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
6370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
638d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
639d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
6400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
6410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
6420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
643a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
644a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
645a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
6460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
6470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
6480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
6490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
650a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
651a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
652a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
653a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
6540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
655488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
656dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
65790df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
65890df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  Qualifiers MakeQualifiers(QualType T) {
665df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump    Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers();
6660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T));
6670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall    return Quals;
6680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  }
6690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall
6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
671195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// block. The caller is responsible for setting an appropriate alignment on
672195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// the alloca.
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
674259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar                                     const llvm::Twine &Name = "tmp");
6750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
676ac418162692a951ca3796d6830496a85a2d12493John McCall  /// InitTempAlloca - Provide an initial value for the given alloca.
677ac418162692a951ca3796d6830496a85a2d12493John McCall  void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value);
678ac418162692a951ca3796d6830496a85a2d12493John McCall
6799bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// CreateIRTemp - Create a temporary IR object of the given type, with
6809bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// appropriate alignment. This routine should only be used when an temporary
6819bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// value needs to be stored into an alloca (for example, to avoid explicit
6829bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// PHI construction), but the type is the IR type, not the type appropriate
6839bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  /// for storing in memory.
6849bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar  llvm::Value *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp");
6859bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar
686195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// CreateMemTemp - Create a temporary memory object of the given type, with
687195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  /// appropriate alignment.
688195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar  llvm::Value *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp");
689195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar
6905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
6915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
6925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6949b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
6959b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
6969b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
6979b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
69849d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
69949d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  /// \param IgnoreResult - True if the resulting value isn't used.
7000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
70114c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsAggLocVolatile = false, bool IgnoreResult = false,
70214c5cbf59cffee52275230922283a247de407712Anders Carlsson                     bool IsInitializer = false);
703d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
7040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
7050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
7064fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
7074fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
7080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
7090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
71014c5cbf59cffee52275230922283a247de407712Anders Carlsson  RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false,
71114c5cbf59cffee52275230922283a247de407712Anders Carlsson                           bool IsInitializer = false);
71246f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
7133d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  /// EmitsAnyExprToMem - Emits the code necessary to evaluate an
7143d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  /// arbitrary expression into the given memory location.
7153d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall  void EmitAnyExprToMem(const Expr *E, llvm::Value *Location,
7163d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall                        bool IsLocationVolatile = false,
7173d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall                        bool IsInitializer = false);
7183d3ec1c099ec8bfac3aa1fb0126fe515b7c7fa05John McCall
71927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// EmitAggregateCopy - Emit an aggrate copy.
72027fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
72127fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// \param isVolatile - True iff either the source or the destination is
72227fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
7237482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
72427fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump                         QualType EltTy, bool isVolatile=false);
7257482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
7267482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
7277482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
72851b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
72951b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
73051b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
73151b09f2c528c8460b5465c676173324e44176d62Devang Patel
732813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
733248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
7344f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
735dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
736dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
7370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7384f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
7394f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
7404f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
7414f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
742d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner  llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L);
7433d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner  llvm::BasicBlock *GetIndirectGotoBlock();
7440ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
7450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
7463d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
747ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
748ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
749ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
750ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
7510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
752ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
753f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
754f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitVLASize - Generate code for any VLA size expressions that might occur
755f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// in a variably modified type. If Ty is a VLA, will return the value that
756f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
757d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
758d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
75960d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
7600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
761dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
762dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
763dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
764dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
7655f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
7665f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
7672504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXThis() {
7682504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXThisValue && "no 'this' value for this function");
7692504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXThisValue;
7702504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
7711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
772c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
773c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson  /// virtual bases.
7742504941793b549323f9d29c62507cf21d865fadeJohn McCall  llvm::Value *LoadCXXVTT() {
7752504941793b549323f9d29c62507cf21d865fadeJohn McCall    assert(CXXVTTValue && "no VTT value for this function");
7762504941793b549323f9d29c62507cf21d865fadeJohn McCall    return CXXVTTValue;
7772504941793b549323f9d29c62507cf21d865fadeJohn McCall  }
778bff225ecf77fb891596ecb1b27196310d268365eJohn McCall
779bff225ecf77fb891596ecb1b27196310d268365eJohn McCall  /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
7808561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  /// complete class to the given direct base.
7818561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  llvm::Value *
7828561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson  GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value,
7838561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
7848561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Base,
7858561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        bool BaseIsVirtual);
786a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson
787a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson  llvm::Value *OldGetAddressOfBaseClass(llvm::Value *Value,
788a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson                                        const CXXRecordDecl *ClassDecl,
789a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson                                        const CXXRecordDecl *BaseClassDecl);
790a88ad5618fcb07c5374c79d6781a33234984b039Anders Carlsson
791f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// GetAddressOfBaseClass - This function will add the necessary delta to the
792f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// load of 'this' and returns address of the base class.
79334a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson  llvm::Value *GetAddressOfBaseClass(llvm::Value *Value,
7948561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                     const CXXRecordDecl *Derived,
79534a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson                                     const CXXBaseSpecifierArray &BasePath,
79634a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson                                     bool NullCheckValue);
79734a2d384c745ebc39cae45dc1c0c4a6a7012e09bAnders Carlsson
798a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson  llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value,
7998561a8666c70f924c8f0209c41b9b77bbbf90607Anders Carlsson                                        const CXXRecordDecl *Derived,
800a04efdf635d35d88e65041fad007225d8c8d64a5Anders Carlsson                                        const CXXBaseSpecifierArray &BasePath,
8015a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson                                        bool NullCheckValue);
802a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson
803bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson  llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This,
804bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *ClassDecl,
805bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson                                         const CXXRecordDecl *BaseClassDecl);
8062f1986b557fa671c4f8c9dd0d071398edfc073d5Anders Carlsson
8071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue,
808eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   llvm::Value *SrcValue,
8098e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                                   const ArrayType *Array,
8108e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                                   const CXXRecordDecl *BaseClassDecl,
8118e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                                   QualType Ty);
812c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian
8131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitClassAggrCopyAssignment(llvm::Value *DestValue,
814c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian                                   llvm::Value *SrcValue,
8158e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                                   const ArrayType *Array,
816eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   const CXXRecordDecl *BaseClassDecl,
817eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian                                   QualType Ty);
818eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian
819ca28361fb0a72c50e0a400fae2fad9520e61c0a5Fariborz Jahanian  void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue,
8208e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                               const CXXRecordDecl *ClassDecl,
8218e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                               const CXXRecordDecl *BaseClassDecl,
8228e142ccf1196c9ae31f10f9caa97670e343971e7Anders Carlsson                               QualType Ty);
8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8240270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian  void EmitClassCopyAssignment(llvm::Value *DestValue, llvm::Value *SrcValue,
8251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                               const CXXRecordDecl *ClassDecl,
8260270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian                               const CXXRecordDecl *BaseClassDecl,
8270270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian                               QualType Ty);
8281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
829c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall  void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor,
830c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      CXXCtorType CtorType,
831c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall                                      const FunctionArgList &Args);
8321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
833b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              llvm::Value *This,
834b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
835b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
8361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
837288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
838569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  const ConstantArrayType *ArrayTy,
8395d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
8405d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
8415d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgEnd);
8425d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson
843569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson  void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
844569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson                                  llvm::Value *NumElements,
8455d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  llvm::Value *ArrayPtr,
8465d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgBeg,
8475d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson                                  CallExpr::const_arg_iterator ArgEnd);
848b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
849f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
850f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 const ArrayType *Array,
851f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian                                 llvm::Value *This);
8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
85372c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian  void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D,
85472c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *NumElements,
85572c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian                                 llvm::Value *This);
85672c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian
857dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Constant *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
85888f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian                                                const ArrayType *Array,
85988f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian                                                llvm::Value *This);
86088f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian
8617267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
8627267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson                             llvm::Value *This);
8631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
864543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson  void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
865f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson  void PopCXXTemporary();
8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
867a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson  llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
86860e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson  void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
8691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8704bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman  void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr,
8714bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman                      QualType DeleteTy);
8724bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman
873c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
874c849c052d6b4b70f2651c1969531861a5f230053Mike Stump  llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
875c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
876b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  void EmitCheck(llvm::Value *, unsigned Size);
877b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
878dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
879dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                       bool isInc, bool isPre);
880dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner  ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV,
881dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner                                         bool isInc, bool isPre);
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
8845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
8850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
886d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitDecl - Emit a declaration.
887d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
888d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
890d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
8911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// EmitBlockVarDecl - Emit a block variable declaration.
892d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
893d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
894248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
895d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
896d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitLocalBlockVarDecl - Emit a local block variable declaration.
897d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
898d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
899248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
900d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
901f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson  void EmitStaticBlockVarDecl(const VarDecl &D,
902f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson                              llvm::GlobalValue::LinkageTypes Linkage);
903b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
904b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
905b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
9060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
9120912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
9130912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
9140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
9150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
9160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
9170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
9180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
9190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
921a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
9220912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
9230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
9240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
9250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
9260912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
9270912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
9280912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
9290912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
9309b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
9319b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
932a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
9330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
9340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
93591d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
936a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
9375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
9385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
9390ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
9405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
9460912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
9470912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
94851b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
94951b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
95051b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
951c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
952fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
9530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9543d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
95564d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
95664d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
95710cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
9580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9599fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  struct CXXTryStmtInfo {
9609fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *SavedLandingPad;
9619fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *HandlerBlock;
9629fc6a7774643a810c8501dae2323e863fefb623eJohn McCall    llvm::BasicBlock *FinallyBlock;
9639fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  };
9649fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  CXXTryStmtInfo EnterCXXTryStmt(const CXXTryStmt &S);
9659fc6a7774643a810c8501dae2323e863fefb623eJohn McCall  void ExitCXXTryStmt(const CXXTryStmt &S, CXXTryStmtInfo Info);
9669fc6a7774643a810c8501dae2323e863fefb623eJohn McCall
9676815e941998659a55c20c147861b0f437928c3d8Anders Carlsson  void EmitCXXTryStmt(const CXXTryStmt &S);
9686815e941998659a55c20c147861b0f437928c3d8Anders Carlsson
9695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
9715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
9725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
97313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
97413e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
97513e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
976ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
977ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
978ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
979ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
980ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
981ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
9820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
9830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
9846ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
9856ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
9866ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
9875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
9885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
10040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1005b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// EmitCheckedLValue - Same as EmitLValue but additionally we generate
1006b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// checking code to guard against undefined behavior.  This is only
1007b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// suitable when we know that the address will be used to access the
1008b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  /// object.
1009b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump  LValue EmitCheckedLValue(const Expr *E);
1010b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump
10119d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
10129d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
10139d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
101409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
10159d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
10169d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
10179d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
10189d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
10199d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
102009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
1021b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson                         bool Volatile, QualType Ty);
10229d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
10245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
10255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
10265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
1027213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
10283b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
102985c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
103043f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
10315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
10335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
10345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
10355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
10365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
1037213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
1038213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
103985c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
104043f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
1041ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
10420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
10430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
1044ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
10450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
10460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
10470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
1048ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
1049ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
10500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
105122c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
105280e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
10536a03e345bb3c971750920e34a0d7d1ea7c9eceb7Douglas Gregor  LValue EmitCompoundAssignOperatorLValue(const CompoundAssignOperator *E);
10545b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
105522c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
10565b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
10575b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
10585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
10595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
1060eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
1061662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
1062d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
10635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
10645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
1065213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
1066b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
1067820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian  LValue EmitObjCIsaExpr(const ObjCIsaExpr *E);
106806e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
10696fcec8b58d0571866fcb162db947b029cc539ec4Anders Carlsson  LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
107075dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
107148620bafe4ba879f96c2d17caefeb79f3fae2eeaFariborz Jahanian  LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E);
1072909fbf70223ea04a5ec8d449789f3683a89701ffAnders Carlsson
10732a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
107429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
10750ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
1076e6d2a534851a649485cb087e9dfcaf8a65886858Anders Carlsson                            unsigned CVRQualifiers);
107706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
107806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
107906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// if the Field is a reference, this will return the address of the reference
108006a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  /// and not the address of the value stored in the reference.
108106a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson  LValue EmitLValueForFieldInitialization(llvm::Value* Base,
108206a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          const FieldDecl* Field,
108306a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson                                          unsigned CVRQualifiers);
108406a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson
108545012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
108645012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
108729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
108829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
10890ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson  LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field,
1090598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
1091fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
1092a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
1093a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump
1094b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
1095e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson  LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
1096b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson  LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E);
1097c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump  LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E);
1098b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson
10990a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
1100391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
110185c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
110209105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E);
1103654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
1104654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
11058bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian  LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
11068bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian
11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
1108883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
11095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
11120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
11130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
1114c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
1115f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// \param TargetDecl - If given, the decl of the function in a direct call;
1116f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// used to set attributes on the call (noreturn, etc.).
111788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
111888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
1119f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson                  ReturnValueSlot ReturnValue,
1120c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
1121c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const Decl *TargetDecl = 0);
11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
112331777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson  RValue EmitCall(QualType FnType, llvm::Value *Callee,
1124d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                  ReturnValueSlot ReturnValue,
1125986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgBeg,
1126986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgEnd,
1127986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  const Decl *TargetDecl = 0);
1128d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson  RValue EmitCallExpr(const CallExpr *E,
1129d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson                      ReturnValueSlot ReturnValue = ReturnValueSlot());
11301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1131566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This,
1132f0070dbae9535836ad41711081465dec2259786bMike Stump                                const llvm::Type *Ty);
1133566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson  llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type,
1134566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson                                llvm::Value *&This, const llvm::Type *Ty);
1135566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson
1136b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
1137b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
1138a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                           ReturnValueSlot ReturnValue,
1139b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
1140c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson                           llvm::Value *VTT,
1141b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
1142b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
1143a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E,
1144a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                               ReturnValueSlot ReturnValue);
1145a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E,
1146a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                      ReturnValueSlot ReturnValue);
11475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
11480f294632f36459174199b77699e339715244b5abAnders Carlsson  RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
1149a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       const CXXMethodDecl *MD,
1150a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson                                       ReturnValueSlot ReturnValue);
11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1152375c31c4673f83f925de221752cf801c2fbbb246Anders Carlsson
11531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  RValue EmitBuiltinExpr(const FunctionDecl *FD,
1154ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1156a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue);
115709429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
11580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
11590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
1160f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1161f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
11622752c0137d95aa2f4ee1cdff4b564bac842e041bChris Lattner  llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1163564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
1164564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
11650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1166ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
11677f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
11688fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
11698f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
11705daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  RValue EmitObjCPropertyGet(const Expr *E);
1171f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S);
117243f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
1173f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src);
11748fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
11758fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
11764029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
11774029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// expression. Will emit a temporary variable if E is not an LValue.
1178a64a869312066ff6119d1d7ae03f88ce499e3f82Anders Carlsson  RValue EmitReferenceBindingToExpr(const Expr* E, bool IsInitializer = false);
11793aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson
1180883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1181bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
1182883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
1183bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
1184bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
11850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
11870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
118814c5cbf59cffee52275230922283a247de407712Anders Carlsson  llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false);
11890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11903707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
11913707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
11923707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
11933707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
11940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
11954f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
11960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
11970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
11984f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
11994f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
12000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1202883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
1203883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
1204883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
120549d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest,
120608c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool IgnoreResult = false, bool IsInitializer = false,
120708c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                   bool RequiresGCollection = false);
12080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
120918aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// EmitAggExprToLValue - Emit the computation of the specified expression of
121018aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  /// aggregate type into a temporary LValue.
121118aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar  LValue EmitAggExprToLValue(const Expr *E);
121218aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar
1213082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// EmitGCMemmoveCollectable - Emit special API for structs with object
1214082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// pointers.
1215082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
121608c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian                                QualType Ty);
1217082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian
1218b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
121923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
12207f79f9be5916c51c35da4f126b7c12596a101607Mike Stump  ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
12217f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImag = false,
12227f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreRealAssign = false,
12237f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImagAssign = false);
12240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
122523b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
122623b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
1227190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
1228190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
12297f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
12307f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
12317f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
12327f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
12339b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
12349b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
12352621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
1236f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a
1237f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// static block var decl.
1238761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D,
1239761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                                 const char *Separator,
1240f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump                                       llvm::GlobalValue::LinkageTypes Linkage);
1241761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
1242761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the
1243761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// global variable that has already been created for it.  If the initializer
1244761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// has a different type than GV does, this may free GV and return a different
1245761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  /// one.  Otherwise it just returns GV.
1246761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  llvm::GlobalVariable *
1247761acc19d966a67f2175783d09412d6ac9463400Chris Lattner  AddInitializerToGlobalBlockVarDecl(const VarDecl &D,
1248761acc19d966a67f2175783d09412d6ac9463400Chris Lattner                                     llvm::GlobalVariable *GV);
1249761acc19d966a67f2175783d09412d6ac9463400Chris Lattner
12500096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
1251f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime
1252f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump  /// initialized static block var decl.
12533b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
12543b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::GlobalVariable *GV);
1255e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
12563b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++
12573b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// variable with global storage.
12583b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr);
12593b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson
12603b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr
12613b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson  /// with the C++ runtime so that its destructor will be called at exit.
126288f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian  void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn,
12633b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson                                     llvm::Constant *DeclPtr);
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1265efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// GenerateCXXGlobalInitFunc - Generates code for initializing global
1266efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
1267efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalInitFunc(llvm::Function *Fn,
1268efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                 llvm::Constant **Decls,
1269efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                 unsigned NumDecls);
1270efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
1271efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// GenerateCXXGlobalDtorFunc - Generates code for destroying global
1272efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  /// variables.
1273efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
1274efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                 const std::vector<std::pair<llvm::Constant*,
1275efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar                                   llvm::Constant*> > &DtorsAndObjects);
1276efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
1277efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D);
1278efb0fa9e11f75af51744a6159530ef7cc8efa24aDaniel Dunbar
127931ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson  void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E);
12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1281b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E,
12821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump                                    llvm::Value *AggLoc = 0,
128314c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsAggLocVolatile = false,
128414c5cbf59cffee52275230922283a247de407712Anders Carlsson                                    bool IsInitializer = false);
12851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1286756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson  void EmitCXXThrowExpr(const CXXThrowExpr *E);
1287c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump
12880ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
12890ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
12900ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
12910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12920946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
12930946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
12940946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
12950946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
12960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
12974bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
129831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
129931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
130031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
130131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
13020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
130331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
130431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
130531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
13069bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
13074bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
1308be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump
130915037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// getTrapBB - Create a basic block that will call the trap intrinsic.  We'll
131015037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  /// generate a branch around the created basic block as necessary.
131115037caa1542bb810ad54c653aeb80f61df7b00cMike Stump  llvm::BasicBlock* getTrapBB();
131221c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson
131321c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson  /// EmitCallArg - Emit a single call argument.
131421c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson  RValue EmitCallArg(const Expr *E, QualType ArgType);
131521c9ad9d29d08a287292c670e7c52bc522c7f8bbAnders Carlsson
131631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
13170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
131829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
131929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
13205627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
13215627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
13225627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
13235627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
13245627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
13255627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
13260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
13275627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
13285627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
13295627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
13300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
13310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
13320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
13330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
13345627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
1335c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
13361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  llvm::Value* EmitAsmInput(const AsmStmt &S,
1337b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar                            const TargetInfo::ConstraintInfo &Info,
1338c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
13390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1340c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlock - emits a single cleanup block.
1341c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlock();
1342c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
134387eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// AddBranchFixup - adds a branch instruction to the list of fixups for the
134487eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// current cleanup scope.
134587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void AddBranchFixup(llvm::BranchInst *BI);
13460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
13470139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// The CallArgTypeInfo parameter is used for iterating over the known
1349af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
1350af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
1351af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
13520139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
1353af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                    CallExpr::const_arg_iterator ArgEnd) {
1354af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      CallExpr::const_arg_iterator Arg = ArgBeg;
1355af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1356af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
1357af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
1358af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
1359af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
136044b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman        assert(Arg != ArgEnd && "Running over edge of argument list!");
1361af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
1362af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
1363af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
13641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getTypePtr() ==
13651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump               getContext().getCanonicalType(Arg->getType()).getTypePtr() &&
1366af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
13671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump        Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1369af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                      ArgType));
1370af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      // Either we've emitted all the call args, or we have a call to a
1373af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
13741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
1375af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
13761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1377af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1379af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
1380af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    for (; Arg != ArgEnd; ++Arg) {
1381af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      QualType ArgType = Arg->getType();
1382af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
1383af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                    ArgType));
1384af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
1385af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
1386492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall
1387492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  const TargetCodeGenInfo &getTargetHooks() const {
1388492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall    return CGM.getTargetCodeGenInfo();
1389492c4f998d848673d3d6c9e6416115df4036a71dJohn McCall  }
13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
13911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1392af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
13935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
13945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
13955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
13965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1397