CodeGenFunction.h revision 49d1cd5a09ed3df353371fd7f206674a85e0fb45
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>
2596bd13ae1ab89f5a04b3ad3ec8ec1864cbba3482Mike Stump#include "CGBlocks.h"
2645d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
270dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
28b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson#include "CGCXX.h"
298f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
308f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
34898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
35ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
41c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
4372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
44c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
45679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
4629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
4729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
48391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
49fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
50af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
52c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
5316f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCForCollectionStmt;
5416f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtTryStmt;
5516f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtThrowStmt;
5616f0049415ec596504891259e2a83e19871c0d52Chris Lattner  class ObjCAtSynchronizedStmt;
575549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class CodeGenModule;
60b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
61e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
62bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
672a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction {
688a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT
698a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson  void operator=(const CodeGenFunction&);  // DO NOT IMPLEMENT
70bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7458dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
7545d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
77b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurFuncDecl - Holds the Decl for the current function or ObjC method.
78b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// This excludes BlockDecls.
794111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
80b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  /// CurCodeDecl - This is the inner-most code context, which includes blocks.
81b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner  const Decl *CurCodeDecl;
8288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
83391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
865ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
875ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
880dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
905ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::Instruction *ReturnValue;
910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
94481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner  llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
950ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
977b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
9818ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
9918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
100fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
101fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// rethrows.
102273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
1030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1046fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// PushCleanupBlock - Push a new cleanup entry on the stack and set the
1056fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// passed in block as the cleanup block.
1066fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  void PushCleanupBlock(llvm::BasicBlock *CleanupBlock);
107bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
1080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupBlockInfo - A struct representing a popped cleanup block.
109bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  struct CleanupBlockInfo {
110bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// CleanupBlock - the cleanup block
111bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *CleanupBlock;
1120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// SwitchBlock - the block (if any) containing the switch instruction used
1140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// for jumping to the final destination.
115bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *SwitchBlock;
1160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
117bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// EndBlock - the default destination for the switch instruction.
118bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *EndBlock;
1190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
121bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson                     llvm::BasicBlock *eb)
122bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson      : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {}
123bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  };
124bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
125bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
1260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branch fixups and return a block info struct with the switch block and end
1270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// block.
128bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  CleanupBlockInfo PopCleanupBlock();
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupScope - RAII object that will create a cleanup block and set the
1310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert point to that block. When destructed, it sets the insert point to
1320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the previous block and pushes a new cleanup entry on the stack.
1330d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  class CleanupScope {
1340d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CodeGenFunction& CGF;
1350d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    llvm::BasicBlock *CurBB;
1366fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson    llvm::BasicBlock *CleanupBB;
1370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1380d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
1390d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CleanupScope(CodeGenFunction &cgf)
1400d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) {
1416fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CleanupBB = CGF.createBasicBlock("cleanup");
1426fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.Builder.SetInsertPoint(CleanupBB);
1430d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1450d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    ~CleanupScope() {
1466fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.PushCleanupBlock(CleanupBB);
1470d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson      CGF.Builder.SetInsertPoint(CurBB);
1480d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1490d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
1500d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
151c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
152c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// blocks that have been added.
153c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlocks(size_t OldCleanupStackSize);
154c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
15587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// EmitBranchThroughCleanup - Emit a branch from the current insert block
15687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// through the cleanup handling code (if any) and then on to \arg Dest.
15787eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  ///
1580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FIXME: Maybe this should really be in EmitBranch? Don't we always want
15987eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// this behavior for branches?
16087eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
1610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1627f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
163e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo* DebugInfo;
16409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
1650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LabelIDs - Track arbitrary ids assigned to labels for use in implementing
1660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the GCC address-of-label extension and indirect goto. IDs are assigned to
1670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// labels inside getIDForAddrOfLabel().
1680ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::map<const LabelStmt*, unsigned> LabelIDs;
1690ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1700ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// IndirectSwitches - Record the list of switches for indirect
1710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// gotos. Emission of the actual switching code needs to be delayed until all
1720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// AddrLabelExprs have been seen.
1730ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::vector<llvm::SwitchInst*> IndirectSwitches;
1740ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
1810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
183e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
184da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
185e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
186e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson      : BreakBlock(bb), ContinueBlock(cb) {}
1870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
188da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
189da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
1900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
191da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
19218ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
1930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
1940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
19551b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
19651b09f2c528c8460b5465c676173324e44176d62Devang Patel
1970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
19880fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
199c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
200c049e4f406a7f7179eba98659044a32508e53289Devang Patel
2019834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// InvokeDest - This is the nearest exception target for calls
2029834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  /// which can unwind, when exceptions are being used.
2039834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *InvokeDest;
2049834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
2050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
2060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
2070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
208dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap;
2090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2104cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
2114cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
2124cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
21309429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
2146ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  struct CleanupEntry {
2156ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// CleanupBlock - The block of code that does the actual cleanup.
2166ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    llvm::BasicBlock *CleanupBlock;
2170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2186ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
219bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BasicBlock *> Blocks;
2206ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2216ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// BranchFixups - Branch instructions to basic blocks that haven't been
2226ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// inserted into the current function yet.
223bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BranchInst *> BranchFixups;
2246ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2256ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    explicit CleanupEntry(llvm::BasicBlock *cb)
2266ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson      : CleanupBlock(cb) {}
2276ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  };
2280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2296ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  /// CleanupEntries - Stack of cleanup entries.
2306ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
2316ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
232bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
233bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson
234bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
235bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  BlockScopeMap BlockScopes;
2360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2372b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  /// CXXThisDecl - When parsing an C++ function, this will hold the implicit
2382b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  /// 'this' declaration.
2392b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson  ImplicitParamDecl *CXXThisDecl;
2402b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
2430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
245e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2479834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  llvm::BasicBlock *getInvokeDest() { return InvokeDest; }
2489834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; }
2499834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
2509834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
2519834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //                                  Objective-C
2529834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar  //===--------------------------------------------------------------------===//
2539834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar
254391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
255af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
257679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
258af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
260fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
261fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
262af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
2640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
265fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
266fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
267af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2684e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
2694e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //                                  Block Bits
2704e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  //===--------------------------------------------------------------------===//
2714e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
2728a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump  llvm::Value *BuildBlockLiteralTmp(const BlockExpr *);
273a803b0e6ca0d1c71a0b3f5d7380da8bbacf2f983Mike Stump  llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose,
274a803b0e6ca0d1c71a0b3f5d7380da8bbacf2f983Mike Stump                                           uint64_t Size,
2750892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           const llvm::StructType *,
2760892099dbc640720400a1d9decd2733a09d733e5Mike Stump                                           std::vector<HelperInfo> *);
2774e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
278161d36de7ee686b09525bb919ad1b20592e499fcChris Lattner  llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
2794e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump                                        const BlockInfo& Info,
2806cc88f78fd36d3511b89412b193494b3e423cbffMike Stump                                        const Decl *OuterFuncDecl,
2817f28a9c37e67ae16396042ad9c085830969daf29Mike Stump                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
2828a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump                                        uint64_t &Size, uint64_t &Align,
28300470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                      llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
28400470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump                                        bool &subBlockHasCopyDispose);
2854e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
2866cc88f78fd36d3511b89412b193494b3e423cbffMike Stump  void BlockForwardSelf();
2874e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump  llvm::Value *LoadBlockStruct();
2884e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump
289a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);
29030395dd7b77ec1abfae9ebfcacf86f5d72b91fefMike Stump
291dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump  const llvm::Type *BuildByRefType(QualType Ty, uint64_t Align);
292dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump
293bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar  void GenerateCode(const FunctionDecl *FD,
294bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar                    llvm::Function *Fn);
2950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartFunction(const Decl *D, QualType RetTy,
2967c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
2972284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
2982284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
299a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
3000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
3010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
3021c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
3031c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
3040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
3050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
306af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
30717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
3080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
3090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
3100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
31188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
31288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
31317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
31417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
3150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
3160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
31788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
31817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
3198b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
3205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
321c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
3220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
3230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
324c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
3250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
32745012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
3284111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
33255e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
33355e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
3340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
33555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
33655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
33729ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
33829ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar    return llvm::BasicBlock::Create("", Parent, InsertBefore);
33929ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
34055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar    return llvm::BasicBlock::Create(Name, Parent, InsertBefore);
34129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
34255e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
3430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
3470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
348aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// SimplifyForwardingBlocks - If the given basic block is only a
349aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// branch to another basic block, simplify it. This assumes that no
350aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  /// other code could potentially reference the basic block.
351aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar  void SimplifyForwardingBlocks(llvm::BasicBlock *BB);
352aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar
3530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
3540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
3550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
3560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
357a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
3580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
3590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
3600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
361a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
362824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
3630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
3640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
3650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
3660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
3675e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
3680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
3690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
3700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
371d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
372d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
3730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
3740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
3750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
376a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
377a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
378a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
3790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
3800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
3810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
3820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
383a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
384a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
385a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
386a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
3870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
388488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
389dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
39090df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
39190df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
3955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
3985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// block.
3995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
4005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     const char *Name = "tmp");
4010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4069b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
4079b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
4089b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
4099b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
41049d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  ///
41149d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  /// \param IgnoreResult - True if the resulting value isn't used.
4120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
41349d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump                     bool isAggLocVolatile = false, bool IgnoreResult = false);
414d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
4150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
4160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
4174fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
4184fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
4190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
4200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
4210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
42246f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar                           bool isAggLocVolatile = false);
42346f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
42427fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// EmitAggregateCopy - Emit an aggrate copy.
42527fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  ///
42627fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// \param isVolatile - True iff either the source or the destination is
42727fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump  /// volatile.
4287482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
42927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump                         QualType EltTy, bool isVolatile=false);
4307482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
4317482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
4327482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
43351b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
43451b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
43551b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
43651b09f2c528c8460b5465c676173324e44176d62Devang Patel
43788a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getCGRecordLayout - Return record layout info.
43888a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
439813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio
440813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
441248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
4424f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
443dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
444dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
4450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4464f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
4474f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
4484f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
4494f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
4500ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  unsigned GetIDForAddrOfLabel(const LabelStmt *L);
4510ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
4520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
4533d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
454ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
455ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
456ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
457ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
4580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
459ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
460f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
46160d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // EmitVLASize - Generate code for any VLA size expressions that might occur
46260d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // in a variably modified type. If Ty is a VLA, will return the value that
46360d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
46460d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
4650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
466dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
467dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
468dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
469dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
4705f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// LoadCXXThis - Load the value of 'this'. This function is only valid while
4715f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  /// generating code for an C++ member function.
4725f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson  llvm::Value *LoadCXXThis();
4735f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson
474b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson  void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
475b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              llvm::Value *This,
476b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgBeg,
477b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson                              CallExpr::const_arg_iterator ArgEnd);
478b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
484248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
485248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
486248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitStaticBlockVarDecl(const VarDecl &D);
487b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
488b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
489b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
4900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
4935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
4960912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
4970912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
4980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
4990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
5000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
5010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
5020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
5030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
505a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
5060912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
5070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
5080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
5090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
5100912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
5110912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
5120912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
5130912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
5149b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
5159b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
516a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
5170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
5180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
51991d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
520a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
5230ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
5300912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
5310912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
53251b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
53351b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
53451b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
535c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
536fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
5370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5383d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
53964d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
54064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
54110cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
5420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
54713e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
54813e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
54913e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
550ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
551ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
552ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
553ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
554ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
555ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
5560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
5570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
5586ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
5596ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
5606ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
5635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
5665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
5675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
5695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
5705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
5765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
5780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5799d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
5809d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
5819d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
58209429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
5839d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
5849d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
5859d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
5869d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
5879d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
58809429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
589b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson                         bool Volatile, QualType Ty);
5909d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
5915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
5925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
5935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
5945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
595213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
5963b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
59785c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
59843f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
6025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
6035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
6045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
605213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
606213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
60785c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
60843f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
609ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
6100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
6110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
612ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
6130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
6140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
6150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
616ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
617ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
6180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
61922c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
62080e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
6215b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
62222c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
6235b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
6245b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
6255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
6265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
627eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner  LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E);
628662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
629d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
6315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
632213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
633b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
63406e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
6359034558f2f9ac1dc6bd2e74f4481ca62fce28718Daniel Dunbar  LValue EmitConditionalOperator(const ConditionalOperator *E);
63675dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner  LValue EmitCastLValue(const CastExpr *E);
637472778eb4fce241721c563280886e98389bc7219Eli Friedman
6382a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar  llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
63929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
640472778eb4fce241721c563280886e98389bc7219Eli Friedman  LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
6411e692ace08959399794363e77499b73da5494af9Eli Friedman                            bool isUnion, unsigned CVRQualifiers);
64245012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
64345012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
64429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
64529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
646fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian  LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
647598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
648fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
649a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump  LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E);
650a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump
651e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis  LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
652e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis
6530a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
654391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
65585c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
65643f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E);
657654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E);
658654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner  LValue EmitStmtExprLValue(const StmtExpr *E);
6590a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
661883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
6650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
6660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
667c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  ///
668c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// \param TargetDecl - If given, the decl of the function in a
669c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// direct call; used to set attributes on the call (noreturn,
670c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar  /// etc.).
67188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
67288b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
673c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const CallArgList &Args,
674c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                  const Decl *TargetDecl = 0);
67519cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitCallExpr(const CallExpr *E);
677b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson
678b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson  RValue EmitCXXMemberCall(const CXXMethodDecl *MD,
679b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *Callee,
680b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           llvm::Value *This,
681b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgBeg,
682b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson                           CallExpr::const_arg_iterator ArgEnd);
683b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson
684774e7c6881ee6cb970cd42239d700dce87ed402aAnders Carlsson  RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E);
6855549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
6865193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman  RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
6875549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgBeg,
688c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                      CallExpr::const_arg_iterator ArgEnd,
689c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar                      const Decl *TargetDecl = 0);
6900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
691ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar  RValue EmitBuiltinExpr(const FunctionDecl *FD,
692ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar                         unsigned BuiltinID, const CallExpr *E);
6935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
694acfde805d644bc71dfeac54ddbc9f12cdae0bb02Anders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E);
69509429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump
6960dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
6970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
698f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
699f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
700564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
701564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
7020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
703cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson  llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
7044119d1aeca8016654d381ce079864058d1709571Nate Begeman  llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
7054119d1aeca8016654d381ce079864058d1709571Nate Begeman                          bool isSplat = false);
7060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
707ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
7087f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
7098fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
7108f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
7115daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  RValue EmitObjCPropertyGet(const Expr *E);
712f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S);
71343f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
714f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian  void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src);
7158fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
7168fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
7174029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
7184029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  /// expression. Will emit a temporary variable if E is not an LValue.
7194029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson  RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType);
7204029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson
721883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
722bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
723883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
724bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
725bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
7260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
7280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
7297f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitScalarExpr(const Expr *E);
7300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7313707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
7323707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
7333707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
7343707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
7350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7364f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
7370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
7380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
7394f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
7404f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
7410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
743883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
744883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
745883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
74649d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest,
74749d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump                   bool IgnoreResult = false);
7480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
749b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
75023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
75158dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  ComplexPairTy EmitComplexExpr(const Expr *E);
7520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
75323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
75423b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
755190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
756190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
7577f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
7587f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
7597f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
7607f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
7619b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
7629b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
7632621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
7640096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global
7650096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// for a static block var decl.
7660096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  llvm::GlobalVariable * CreateStaticBlockVarDecl(const VarDecl &D,
7670096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  const char *Separator,
7680096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  llvm::GlobalValue::LinkageTypes
7690096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                                  Linkage);
7700096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar
7710096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// GenerateStaticCXXBlockVarDecl - Create the initializer for a C++
7720096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  /// runtime initialized static block var decl.
7730096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar  void GenerateStaticCXXBlockVarDeclInit(const VarDecl &D,
7740096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar                                         llvm::GlobalVariable *GV);
775e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
77631ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson  void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E);
777b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson
7780ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
7790ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
7800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
7810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7820946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
7830946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
7840946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
7850946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
7860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7874bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
78831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
78931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
79031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
79131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
7920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
79331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
79431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
79531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
7969bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
7974bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
79831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
7990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8000ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// EmitIndirectSwitches - Emit code for all of the switch
8010ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// instructions in IndirectSwitches.
8020ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectSwitches();
8035627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
80429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
80529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
8065627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
8075627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
8085627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
8095627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
8105627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
8115627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
8120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
8135627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
8145627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
8155627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
8160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
8170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
8180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
8190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
8205627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
821c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
822b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar  llvm::Value* EmitAsmInput(const AsmStmt &S,
823b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar                            const TargetInfo::ConstraintInfo &Info,
824c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
8250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
826c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlock - emits a single cleanup block.
827c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlock();
828c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
82987eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// AddBranchFixup - adds a branch instruction to the list of fixups for the
83087eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// current cleanup scope.
83187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void AddBranchFixup(llvm::BranchInst *BI);
8320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
8330139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArg - Emit a single call argument.
8340139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  RValue EmitCallArg(const Expr *E, QualType ArgType);
8350139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson
8360139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson  /// EmitCallArgs - Emit call arguments for a function.
837af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// The CallArgTypeInfo parameter is used for iterating over the known
838af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  /// argument types of the function being called.
839af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  template<typename T>
840af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo,
8410139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson                    CallExpr::const_arg_iterator ArgBeg,
842af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                    CallExpr::const_arg_iterator ArgEnd) {
843af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      CallExpr::const_arg_iterator Arg = ArgBeg;
844af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
845af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // First, use the argument types that the type info knows about
846af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    if (CallArgTypeInfo) {
847af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(),
848af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson           E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) {
849af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        QualType ArgType = *I;
850af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
851af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        assert(getContext().getCanonicalType(ArgType.getNonReferenceType()).
852af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               getTypePtr() ==
853af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               getContext().getCanonicalType(Arg->getType()).getTypePtr() &&
854af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson               "type mismatch in call argument!");
855af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
856af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson        Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
857af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                      ArgType));
858af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      }
859af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
860af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // Either we've emitted all the call args, or we have a call to a
861af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      // variadic function.
8621768fabfbae60202ba497b98dd9be9eb09bb2e20Eli Friedman      assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) &&
863af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson             "Extra arguments in non-variadic function!");
864af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
865af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
866af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
867af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    // If we still have any arguments, emit them using the type of the argument.
868af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    for (; Arg != ArgEnd; ++Arg) {
869af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      QualType ArgType = Arg->getType();
870af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
871af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson                                    ArgType));
872af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson    }
873af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson  }
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
875af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
876af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
8785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
881