CodeGenFunction.h revision 6d0bdaa68989bee60c85274e82a8f9c982587f26
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"
20481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h"
21481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h"
22481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h"
23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h"
240ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map>
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;
3469243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson  class LLVMContext;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
36898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
37ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
427267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  class CXXDestructorDecl;
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
44c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
4672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
47c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
48679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
4929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
5029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
51391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
52fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
53af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
55c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
5616f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
5716f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
5816f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
5916f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
605549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class CodeGenModule;
63b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
64e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
65bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
702a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction {
718a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
728a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  void operator=(const CodeGenFunction&);  // DO NOT IMPLEMENT
73bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7758dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
7845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
80b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurFuncDecl - Holds the Decl for the current function or ObjC method.
81b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// This excludes BlockDecls.
824111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
83b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
84b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
8588b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
86391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
895ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
905ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
935ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::Instruction *ReturnValue;
940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
97481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
980ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
1007b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
10118ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
10218ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
103fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
104fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// rethrows.
105273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
1060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1076fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// PushCleanupBlock - Push a new cleanup entry on the stack and set the
1086fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// passed in block as the cleanup block.
1096fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  void PushCleanupBlock(llvm::BasicBlock *CleanupBlock);
110bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
1110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupBlockInfo - A struct representing a popped cleanup block.
112bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  struct CleanupBlockInfo {
113bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// CleanupBlock - the cleanup block
114bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *CleanupBlock;
1150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// SwitchBlock - the block (if any) containing the switch instruction used
1170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// for jumping to the final destination.
118bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *SwitchBlock;
1190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
120bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// EndBlock - the default destination for the switch instruction.
121bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *EndBlock;
1220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
124bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson                     llvm::BasicBlock *eb)
125bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson      : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {}
126bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  };
127bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
128bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branch fixups and return a block info struct with the switch block and end
1300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// block.
131bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  CleanupBlockInfo PopCleanupBlock();
1320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupScope - RAII object that will create a cleanup block and set the
1340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert point to that block. When destructed, it sets the insert point to
1350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the previous block and pushes a new cleanup entry on the stack.
1360d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  class CleanupScope {
1370d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CodeGenFunction& CGF;
1380d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    llvm::BasicBlock *CurBB;
1396fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson    llvm::BasicBlock *CleanupBB;
1400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1410d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
1420d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CleanupScope(CodeGenFunction &cgf)
1430d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) {
1446fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CleanupBB = CGF.createBasicBlock("cleanup");
1456fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.Builder.SetInsertPoint(CleanupBB);
1460d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1480d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    ~CleanupScope() {
1496fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.PushCleanupBlock(CleanupBB);
150d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      // FIXME: This is silly, move this into the builder.
151d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      if (CurBB)
152d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.SetInsertPoint(CurBB);
153d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar      else
154d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar        CGF.Builder.ClearInsertionPoint();
1550d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1560d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
1570d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
158c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
159c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// blocks that have been added.
160c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlocks(size_t OldCleanupStackSize);
161c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
16287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// EmitBranchThroughCleanup - Emit a branch from the current insert block
16387eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// through the cleanup handling code (if any) and then on to \arg Dest.
16487eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  ///
1650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FIXME: Maybe this should really be in EmitBranch? Don't we always want
16687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// this behavior for branches?
16787eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
1680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1691d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// PushConditionalTempDestruction - Should be called before a conditional
1701d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// part of an expression is emitted. For example, before the RHS of the
1711d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// expression below is emitted:
1721d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  ///
1731d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// b && f(T());
1741d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  ///
1751d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// This is used to make sure that any temporaryes created in the conditional
1761d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// branch are only destroyed if the branch is taken.
1771d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  void PushConditionalTempDestruction();
1781d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson
1791d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// PopConditionalTempDestruction - Should be called after a conditional
1801d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// part of an expression has been emitted.
1811d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  void PopConditionalTempDestruction();
1821d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson
1837f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
184e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo* DebugInfo;
18509429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
1860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LabelIDs - Track arbitrary ids assigned to labels for use in implementing
1870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the GCC address-of-label extension and indirect goto. IDs are assigned to
1880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// labels inside getIDForAddrOfLabel().
1890ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::map<const LabelStmt*, unsigned> LabelIDs;
1900ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1910ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// IndirectSwitches - Record the list of switches for indirect
1920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// gotos. Emission of the actual switching code needs to be delayed until all
1930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// AddrLabelExprs have been seen.
1940ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::vector<llvm::SwitchInst*> IndirectSwitches;
1950ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
2020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
204e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
205da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
206e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
207e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson      : BreakBlock(bb), ContinueBlock(cb) {}
2080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
209da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
210da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
2110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
212da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
21318ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
2140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
2150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
21651b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
21751b09f2c528c8460b5465c676173324e44176d62Devang Patel
2180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
21980fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
220c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
221c049e4f406a7f7179eba98659044a32508e53289Devang Patel
2229834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// InvokeDest - This is the nearest exception target for calls
2239834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// which can unwind, when exceptions are being used.
2249834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *InvokeDest;
2259834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
2260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
2270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
2280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
229dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap;
2300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2314cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
2324cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
2334cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
23409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
2356ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  struct CleanupEntry {
2366ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// CleanupBlock - The block of code that does the actual cleanup.
2376ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    llvm::BasicBlock *CleanupBlock;
2380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2396ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
240bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BasicBlock *> Blocks;
2416ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2426ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// BranchFixups - Branch instructions to basic blocks that haven't been
2436ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// inserted into the current function yet.
244bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BranchInst *> BranchFixups;
2456ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2466ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    explicit CleanupEntry(llvm::BasicBlock *cb)
2476ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson      : CleanupBlock(cb) {}
2486ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  };
2490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2506ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  /// CleanupEntries - Stack of cleanup entries.
2516ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
2526ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
253bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
254bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson
255bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
256bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  BlockScopeMap BlockScopes;
2570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2582b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  /// CXXThisDecl - When parsing an C++ function, this will hold the implicit
2592b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  /// 'this' declaration.
2602b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  ImplicitParamDecl *CXXThisDecl;
2612b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson
262e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary.
263e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  struct CXXLiveTemporaryInfo {
264e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// Temporary - The live temporary.
265e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    const CXXTemporary *Temporary;
266e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson
267e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// ThisPtr - The pointer to the temporary.
268e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *ThisPtr;
269e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson
270e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// DtorBlock - The destructor block.
271e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::BasicBlock *DtorBlock;
272e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson
273e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// CondPtr - If this is a conditional temporary, this is the pointer to
274e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// the condition variable that states whether the destructor should be
275e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    /// called or not.
276e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    llvm::Value *CondPtr;
277e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson
278e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson    CXXLiveTemporaryInfo(const CXXTemporary *temporary,
279f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *thisptr, llvm::BasicBlock *dtorblock,
280f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson                         llvm::Value *condptr)
281e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson      : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock),
282e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson      CondPtr(condptr) { }
283e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  };
284e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson
285e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson  llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries;
2861d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson
2871d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// ConditionalTempDestructionStack - Contains the number of live temporaries
2881d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// when PushConditionalTempDestruction was called. This is used so that
2891d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  /// we know how many temporaries were created by a certain expression.
2901d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson  llvm::SmallVector<size_t, 4> ConditionalTempDestructionStack;
291543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
2940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
296e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2989834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *getInvokeDest() { return InvokeDest; }
2999834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; }
3009834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
301a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson  llvm::LLVMContext &getLLVMContext() { return VMContext; }
30269243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson
3039834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
3049834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
3059834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
3069834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
307391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
308af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
3090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
310679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
311af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
3120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
313fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
314fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
315af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
3160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
3170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
318fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
319fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
320af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
3214e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
3224e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
3234e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
3244e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
3258a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump  llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
326a803b0e6ca0d1c71a0b3f5d7380da8bbacf2f983Mike Stump  llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose,
327a803b0e6ca0d1c71a0b3f5d7380da8bbacf2f983Mike Stump                                           uint64_t Size,
3280892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           const llvm::StructType *,
3290892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           std::vector<HelperInfo> *);
3304e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
331161d36de7ee686b09525bb919ad1b20592e499fcChris Lattner  llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
3324e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump                                        const BlockInfo& Info,
3336cc88f78fd36d3511b89412b193494b3e423cbffMike Stump                                        const Decl *OuterFuncDecl,
3347f28a9c37e67ae16396042ad9c085830969daf29Mike Stump                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
3358a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump                                        uint64_t &Size, uint64_t &Align,
33600470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                      llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
33700470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                                        bool &subBlockHasCopyDispose);
3384e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
3396cc88f78fd36d3511b89412b193494b3e423cbffMike Stump  void BlockForwardSelf();
3404e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  llvm::Value *LoadBlockStruct();
3414e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
342a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
34330395dd7b77ec1abfae9ebfcacf86f5d72b91fefMike Stump
344dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump  const llvm::Type *BuildByRefType(QualType Ty, uint64_t Align);
345dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
346bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar  void GenerateCode(const FunctionDecl *FD,
347bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar                    llvm::Function *Fn);
3480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartFunction(const Decl *D, QualType RetTy,
3497c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
3502284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
3512284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
352a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
3530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
3540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
3551c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
3561c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
3570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
3580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
359af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
36017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
361ab3c0a2c879569bb00fa664ebaccf9442c0a9c5fFariborz Jahanian  void EmitCtorPrologue(const CXXConstructorDecl *CD);
362ab3c0a2c879569bb00fa664ebaccf9442c0a9c5fFariborz Jahanian
3630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
3640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
3650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
36688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
36788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
36817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
36917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
3700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
3710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
37288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
37317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
3748b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
376c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
3770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
3780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
379c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
3800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
38245012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
3834111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
38755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
38855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
3890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
39055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
39155e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
39229ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
39329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar    return llvm::BasicBlock::Create("", Parent, InsertBefore);
39429ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
39555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar    return llvm::BasicBlock::Create(Name, Parent, InsertBefore);
39629ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
39755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
3980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
4015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
4020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
403aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// SimplifyForwardingBlocks - If the given basic block is only a
404aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// branch to another basic block, simplify it. This assumes that no
405aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// other code could potentially reference the basic block.
406aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
407aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
4080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
4090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
4100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
4110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
412a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
4130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
4140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
4150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
416a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
417824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
4180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
4190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
4200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
4210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
4225e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
4230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
4240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
4250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
426d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
427d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
4280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
4290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
4300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
431a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
432a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
433a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
4340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
4350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
4360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
4370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
438a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
439a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
440a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
441a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
4420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
443488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
444dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
44590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
44690df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// block.
4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     const char *Name = "tmp");
4560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4619b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
4629b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
4639b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
4649b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
46549d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
46649d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  /// \param IgnoreResult - True if the resulting value isn't used.
4670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
46849d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump                     bool isAggLocVolatile = false, bool IgnoreResult = false);
469d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
4700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
4710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
4724fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
4734fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
4740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
4750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
4760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
47746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar                           bool isAggLocVolatile = false);
47846f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
47927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// EmitAggregateCopy - Emit an aggrate copy.
48027fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
48127fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// \param isVolatile - True iff either the source or the destination is
48227fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
4837482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
48427fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump                         QualType EltTy, bool isVolatile=false);
4857482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
4867482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
4877482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
48851b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
48951b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
49051b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
49151b09f2c528c8460b5465c676173324e44176d62Devang Patel
49288a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getCGRecordLayout - Return record layout info.
49388a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
494813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio
495813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
496248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
4974f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
498dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
499dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
5000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5014f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
5024f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
5034f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
5044f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
5050ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  unsigned GetIDForAddrOfLabel(const LabelStmt *L);
5060ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
5070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
5083d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
509ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
510ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
511ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
512ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
5130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
514ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
515f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
51660d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // EmitVLASize - Generate code for any VLA size expressions that might occur
51760d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // in a variably modified type. If Ty is a VLA, will return the value that
51860d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
519d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
520d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
52160d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
5220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
523dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
524dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
525dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
526dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
5275f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
5285f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
5295f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  llvm::Value *LoadCXXThis();
5305f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson
5319e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian  /// AddressCXXOfBaseClass - This function will add the necessary delta
5329e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian  /// to the load of 'this' and returns address of the base class.
5339e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian  // FIXME. This currently only does a derived to non-virtual base conversion.
5349e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian  // Other kinds of conversions will come later.
5359e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian  llvm::Value *AddressCXXOfBaseClass(llvm::Value *ThisValue,
5366d0bdaa68989bee60c85274e82a8f9c982587f26Fariborz Jahanian                                     const CXXRecordDecl *ClassDecl,
5376d0bdaa68989bee60c85274e82a8f9c982587f26Fariborz Jahanian                                     const CXXRecordDecl *BaseClassDecl);
5389e809e7da2448c08aa11f15be4680226754678ceFariborz Jahanian
539b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
540b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              llvm::Value *This,
541b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
542b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
543b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
5447267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson  void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type,
5457267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson                             llvm::Value *This);
5467267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson
547543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson  void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr);
548f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson  void PopCXXTemporary();
549543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson
550a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson  llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
551a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
556d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitDecl - Emit a declaration.
557d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
558d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
560d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
561d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitBlockVarDecl - Emit a block variable declaration.
562d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
563d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
564248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
565d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
566d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// EmitLocalBlockVarDecl - Emit a local block variable declaration.
567d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  ///
568d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar  /// This function can be called with a null (unreachable) insert point.
569248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
570d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar
571248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitStaticBlockVarDecl(const VarDecl &D);
572b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
573b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
574b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
5750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
5810912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
5820912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
5830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
5840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
5850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
5860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
5870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
5880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
590a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
5910912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
5920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
5930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
5940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
5950912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
5960912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
5970912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
5980912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
5999b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
6009b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
601a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
6020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
6030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
60491d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
605a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
6065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
6075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
6080ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
6150912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
6160912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
61751b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
61851b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
61951b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
620c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
621fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
6220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6233d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
62464d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
62564d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
62610cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
6270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
63213e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
63313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
63413e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
635ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
636ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
637ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
638ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
639ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
640ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
6410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
6420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
6436ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
6446ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
6456ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
6465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
6545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
6630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6649d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
6659d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
6669d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
66709429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
6689d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
6699d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
6709d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
6719d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
6729d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
67309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
674b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson                         bool Volatile, QualType Ty);
6759d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
6775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
680213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
6813b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
68285c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
68343f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
6845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
6875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
6885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
6895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
690213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
691213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
69285c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
69343f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
694ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
6950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
6960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
697ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
6980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
6990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
7000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
701ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
702ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
7030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
70422c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
70580e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
7065b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
70722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
7085b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
7095b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
7105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
7115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
712eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
713662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
714d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
7155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
7165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
717213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
718b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
71906e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
7209034558f2f9ac1dc6bd2e74f4481ca62fce28718Daniel Dunbar  LValue EmitConditionalOperator(const ConditionalOperator *E);
72175dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
722472778eb4fce241721c563280886e98389bc7219Eli Friedman
7232a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
72429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
725472778eb4fce241721c563280886e98389bc7219Eli Friedman  LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
7261e692ace08959399794363e77499b73da5494af9Eli Friedman                            bool isUnion, unsigned CVRQualifiers);
72745012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
72845012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
72929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
73029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
731fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian  LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
732598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
733fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
734a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
735a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump
736e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis  LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
737b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  LValue EmitCXXConstructLValue(const CXXConstructExpr *E);
738e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson  LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E);
739b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson
7400a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
741391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
74285c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
74343f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E);
744654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
745654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
7460a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
748883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
7520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
7530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
754c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
755c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// \param TargetDecl - If given, the decl of the function in a
756c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// direct call; used to set attributes on the call (noreturn,
757c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// etc.).
75888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
75988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
760c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
761c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const Decl *TargetDecl = 0);
762986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson
763986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson  RValue EmitCall(llvm::Value *Callee, QualType FnType,
764986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgBeg,
765986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  CallExpr::const_arg_iterator ArgEnd,
766986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson                  const Decl *TargetDecl = 0);
7675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitCallExpr(const CallExpr *E);
768b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson
769b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
770b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
771b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
772b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
773b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
774774e7c6881ee6cb970cd42239d700dce87ed402aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E);
7755549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
7760f294632f36459174199b77699e339715244b5abAnders Carlsson  RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
7770f294632f36459174199b77699e339715244b5abAnders Carlsson                                       const CXXMethodDecl *MD);
7780f294632f36459174199b77699e339715244b5abAnders Carlsson
779ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar  RValue EmitBuiltinExpr(const FunctionDecl *FD,
780ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
782acfde805d644bc71dfeac54ddbc9f12cdae0bb02Anders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E);
78309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
7840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
7850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
786f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
787f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
788564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
789564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
7900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
791cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson  llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
7924119d1aeca8016654d381ce079864058d1709571Nate Begeman  llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
7934119d1aeca8016654d381ce079864058d1709571Nate Begeman                          bool isSplat = false);
7940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
795ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
7967f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
7978fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
7988f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
7995daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  RValue EmitObjCPropertyGet(const Expr *E);
800f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S);
80143f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
802f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src);
8038fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
8048fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
8054029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
8064029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// expression. Will emit a temporary variable if E is not an LValue.
8074029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType);
8084029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson
809883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
810bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
811883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
812bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
813bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
8140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
8160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
8177f79f9be5916c51c35da4f126b7c12596a101607Mike Stump  llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign=false);
8180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8193707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
8203707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
8213707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
8223707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
8230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8244f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
8250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
8260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
8274f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
8284f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
8290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
831883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
832883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
833883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
83449d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest,
83549d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump                   bool IgnoreResult = false);
8360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
837082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// EmitGCMemmoveCollectable - Emit special API for structs with object
838082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  /// pointers.
839082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
840082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian                                unsigned long);
841082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian
842b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
84323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
8447f79f9be5916c51c35da4f126b7c12596a101607Mike Stump  ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false,
8457f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImag = false,
8467f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreRealAssign = false,
8477f79f9be5916c51c35da4f126b7c12596a101607Mike Stump                                bool IgnoreImagAssign = false);
8480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
84923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
85023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
851190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
852190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
8537f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
8547f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
8557f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
8567f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
8579b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
8589b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
8592621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
8600096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global
8610096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// for a static block var decl.
8620096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  llvm::GlobalVariable * CreateStaticBlockVarDecl(const VarDecl &D,
8630096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  const char *Separator,
8640096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  llvm::GlobalValue::LinkageTypes
8650096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  Linkage);
8660096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
8670096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// GenerateStaticCXXBlockVarDecl - Create the initializer for a C++
8680096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// runtime initialized static block var decl.
8690096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  void GenerateStaticCXXBlockVarDeclInit(const VarDecl &D,
8700096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                         llvm::GlobalVariable *GV);
871e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
87231ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson  void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E);
873b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
874b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson  RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E,
875b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson                                    llvm::Value *AggLoc = 0,
876b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson                                    bool isAggLocVolatile = false);
877b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson
8780ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
8790ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
8800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
8810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8820946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
8830946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
8840946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
8850946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
8860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8874bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
88831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
88931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
89031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
89131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
8920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
89331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
89431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
89531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
8969bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
8974bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
89831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
8990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9000ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// EmitIndirectSwitches - Emit code for all of the switch
9010ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// instructions in IndirectSwitches.
9020ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectSwitches();
9035627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
90429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
90529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
9065627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
9075627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
9085627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
9095627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
9105627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
9115627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
9120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
9135627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
9145627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
9155627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
9160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
9170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
9180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
9190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
9205627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
921c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
922b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar  llvm::Value* EmitAsmInput(const AsmStmt &S,
923b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar                            const TargetInfo::ConstraintInfo &Info,
924c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
9250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
926c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlock - emits a single cleanup block.
927c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlock();
928c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
92987eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// AddBranchFixup - adds a branch instruction to the list of fixups for the
93087eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// current cleanup scope.
93187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void AddBranchFixup(llvm::BranchInst *BI);
9320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
9330139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArg - Emit a single call argument.
9340139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  RValue EmitCallArg(const Expr *E, QualType ArgType);
9350139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson
9360139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
937af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// The CallArgTypeInfo parameter is used for iterating over the known
938af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
939af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
940af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
9410139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
942af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                    CallExpr::const_arg_iterator ArgEnd) {
943af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      CallExpr::const_arg_iterator Arg = ArgBeg;
944af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
945af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
946af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
947af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
948af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
949af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
950af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
951af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
952af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               getTypePtr() ==
953af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               getContext().getCanonicalType(Arg->getType()).getTypePtr() &&
954af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
955af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
956af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
957af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                      ArgType));
958af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
959af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
960af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // Either we've emitted all the call args, or we have a call to a
961af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
9621768fabfbae60202ba497b98dd9be9eb09bb2e20Eli Friedman      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
963af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
964af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
965af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
966af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
967af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
968af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    for (; Arg != ArgEnd; ++Arg) {
969af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      QualType ArgType = Arg->getType();
970af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
971af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                    ArgType));
972af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
973af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
9745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
975af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
976af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
9775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
9785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
9795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
981