CodeGenFunction.h revision e896d98548b02223c7740d807a0aa6e20fba7079
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"
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/DenseMap.h"
19da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner#include "llvm/ADT/SmallVector.h"
20c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson#include "clang/Basic/TargetInfo.h"
215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/Expr.h"
22e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector>
260ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map>
275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
290dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
308f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
318f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
33c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
35898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
36ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  class Value;
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
42c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
44c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class FunctionTypeProto;
45c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
46679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian  class ObjCContainerDecl;
4729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
4829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
49391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
50fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  class ObjCImplementationDecl;
51af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
53c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
545549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class CodeGenModule;
57b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
58e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  class CGDebugInfo;
59bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar  class CGFunctionInfo;
600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  class CGRecordLayout;
610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenFunction {
65bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6958dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
7045d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
72c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  // Holds the Decl for the current function or method
734111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
7488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  const CGFunctionInfo *CurFnInfo;
75391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
785ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
795ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ReturnValue - The temporary alloca to hold the return value. This is null
810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// iff the function has no return value.
825ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::Instruction *ReturnValue;
830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Instruction *AllocaInsertPt;
870ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
897b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
9018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
9118ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
92fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// ObjCEHValueStack - Stack of Objective-C exception values, used for
93fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson  /// rethrows.
94273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson  llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack;
950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
966fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// PushCleanupBlock - Push a new cleanup entry on the stack and set the
976fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  /// passed in block as the cleanup block.
986fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson  void PushCleanupBlock(llvm::BasicBlock *CleanupBlock);
99bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
1000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupBlockInfo - A struct representing a popped cleanup block.
101bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  struct CleanupBlockInfo {
102bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// CleanupBlock - the cleanup block
103bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *CleanupBlock;
1040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// SwitchBlock - the block (if any) containing the switch instruction used
1060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    /// for jumping to the final destination.
107bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *SwitchBlock;
1080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
109bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    /// EndBlock - the default destination for the switch instruction.
110bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    llvm::BasicBlock *EndBlock;
1110dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump    CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb,
113bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson                     llvm::BasicBlock *eb)
114bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson      : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {}
115bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  };
116bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson
117bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all
1180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branch fixups and return a block info struct with the switch block and end
1190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// block.
120bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson  CleanupBlockInfo PopCleanupBlock();
1210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CleanupScope - RAII object that will create a cleanup block and set the
1230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert point to that block. When destructed, it sets the insert point to
1240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the previous block and pushes a new cleanup entry on the stack.
1250d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  class CleanupScope {
1260d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CodeGenFunction& CGF;
1270d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    llvm::BasicBlock *CurBB;
1286fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson    llvm::BasicBlock *CleanupBB;
1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1300d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  public:
1310d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    CleanupScope(CodeGenFunction &cgf)
1320d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson      : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()) {
1336fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CleanupBB = CGF.createBasicBlock("cleanup");
1346fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.Builder.SetInsertPoint(CleanupBB);
1350d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1370d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    ~CleanupScope() {
1386fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson      CGF.PushCleanupBlock(CleanupBB);
1390d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson      CGF.Builder.SetInsertPoint(CurBB);
1400d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson    }
1410d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson  };
1420d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson
143c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
144c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// blocks that have been added.
145c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlocks(size_t OldCleanupStackSize);
146c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
14787eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// EmitBranchThroughCleanup - Emit a branch from the current insert block
14887eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// through the cleanup handling code (if any) and then on to \arg Dest.
14987eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  ///
1500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FIXME: Maybe this should really be in EmitBranch? Don't we always want
15187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// this behavior for branches?
15287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void EmitBranchThroughCleanup(llvm::BasicBlock *Dest);
1530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1547f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
155e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo* DebugInfo;
156e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson
1570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LabelIDs - Track arbitrary ids assigned to labels for use in implementing
1580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// the GCC address-of-label extension and indirect goto. IDs are assigned to
1590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// labels inside getIDForAddrOfLabel().
1600ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::map<const LabelStmt*, unsigned> LabelIDs;
1610ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1620ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// IndirectSwitches - Record the list of switches for indirect
1630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// gotos. Emission of the actual switching code needs to be delayed until all
1640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// AddrLabelExprs have been seen.
1650ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::vector<llvm::SwitchInst*> IndirectSwitches;
1660ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// decls.
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
1730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // BreakContinueStack - This keeps track of where break and continue
175e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson  // statements should jump to.
176da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
177e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
178e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson      : BreakBlock(bb), ContinueBlock(cb) {}
1790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
180da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
181da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
1820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  };
183da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
18418ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
1850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// SwitchInsn - This is nearest current switch instruction. It is null if if
1860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// current context is not in a switch.
18751b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
18851b09f2c528c8460b5465c676173324e44176d62Devang Patel
1890dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// CaseRangeBlock - This block holds if condition check for last case
19080fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
191c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
192c049e4f406a7f7179eba98659044a32508e53289Devang Patel
1930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // VLASizeMap - This keeps track of the associated size for each VLA type.
1940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // FIXME: Maybe this could be a stack of maps that is pushed/popped as we
1950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // enter/leave scopes.
196dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap;
1970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
1984cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid
1994cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  /// calling llvm.stacksave for multiple VLAs in the same scope.
2004cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson  bool DidCallStackSave;
2014cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson
2026ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  struct CleanupEntry {
2036ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// CleanupBlock - The block of code that does the actual cleanup.
2046ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    llvm::BasicBlock *CleanupBlock;
2050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2066ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// Blocks - Basic blocks that were emitted in the current cleanup scope.
207bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BasicBlock *> Blocks;
2086ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2096ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// BranchFixups - Branch instructions to basic blocks that haven't been
2106ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    /// inserted into the current function yet.
211bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson    std::vector<llvm::BranchInst *> BranchFixups;
2126ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
2136ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson    explicit CleanupEntry(llvm::BasicBlock *cb)
2146ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson      : CleanupBlock(cb) {}
2150dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
216bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson    ~CleanupEntry() {
217bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson      assert(Blocks.empty() && "Did not empty blocks!");
218bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson      assert(BranchFixups.empty() && "Did not empty branch fixups!");
219bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson    }
2206ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  };
2210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2226ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  /// CleanupEntries - Stack of cleanup entries.
2236ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson  llvm::SmallVector<CleanupEntry, 8> CleanupEntries;
2246ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson
225bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap;
226bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson
227bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  /// BlockScopes - Map of which "cleanup scope" scope basic blocks have.
228bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson  BlockScopeMap BlockScopes;
2290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
2320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
234e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson  CGDebugInfo *getDebugInfo() { return DebugInfo; }
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
236391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
237af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartObjCMethod(const ObjCMethodDecl *MD,
239679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian                       const ObjCContainerDecl *CD);
240af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCGetter - Synthesize an Objective-C property getter function.
242fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCGetter(ObjCImplementationDecl *IMP,
243fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
244af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
2450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateObjCSetter - Synthesize an Objective-C property setter function
2460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// for the given property.
247fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian  void GenerateObjCSetter(ObjCImplementationDecl *IMP,
248fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian                          const ObjCPropertyImplDecl *PID);
249af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
250d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  struct BlockInfo {
251d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson    const llvm::Type *BlockLiteralTy;
252d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson
253d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson    const char *NameSuffix;
254d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson
255d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson    BlockInfo(const llvm::Type *blt, const char *ns)
256d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson      :  BlockLiteralTy(blt), NameSuffix(ns) {}
257d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  };
258d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson
259d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson  llvm::Function *GenerateBlockFunction(const BlockExpr *Expr,
260d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson                                        const BlockInfo& Info);
261d5cab5435371b8cc74a9e05ebd40b5995ebad149Anders Carlsson
262bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar  void GenerateCode(const FunctionDecl *FD,
263bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar                    llvm::Function *Fn);
2640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void StartFunction(const Decl *D, QualType RetTy,
2657c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
2662284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
2672284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
268a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
2690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitReturnBlock - Emit the unified return block, trying to avoid its
2700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emission when possible.
2711c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar  void EmitReturnBlock();
2721c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar
2730dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// FinishFunction - Complete IR generation of the current function. It is
2740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// legal to call this function even if there is no current insertion point.
275af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
27617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
2770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionProlog - Emit the target specific LLVM code to load the
2780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// arguments for the given function. This is also responsible for naming the
2790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM function arguments.
28088b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionProlog(const CGFunctionInfo &FI,
28188b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                          llvm::Function *Fn,
28217b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
28317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
2840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitFunctionEpilog - Emit the target specific LLVM code to return the
2850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// given temporary.
28688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
28717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
2888b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar  const llvm::Type *ConvertTypeForMem(QualType T);
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
290c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
2910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LoadObjCSelf - Load the value of self. This function is only valid while
2920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// generating code for an Objective-C method.
293c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
2940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
2950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// TypeOfSelfObject - Return type of object that this self represents.
29645012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  QualType TypeOfSelfObject();
2974111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
2984111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  /// isObjCPointerType - Return true if the specificed AST type will map onto
2994111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  /// some Objective-C pointer type.
3004111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  static bool isObjCPointerType(QualType T);
3014111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
30555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar
30655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  /// createBasicBlock - Create an LLVM basic block.
3070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::BasicBlock *createBasicBlock(const char *Name="",
30855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::Function *Parent=0,
30955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar                                     llvm::BasicBlock *InsertBefore=0) {
31029ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG
31129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar    return llvm::BasicBlock::Create("", Parent, InsertBefore);
31229ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else
31355e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar    return llvm::BasicBlock::Create(Name, Parent, InsertBefore);
31429ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif
31555e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar  }
3160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
3200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3210dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBlock - Emit the given block \arg BB and set it as the insert point,
3220dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// adding a fall-through branch from the current insert block if
3230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessary. It is legal to call this function even if there is no current
3240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
325a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  ///
3260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// IsFinished - If true, indicates that the caller has finished emitting
3270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// branches to the given block and does not expect to emit code into it. This
3280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// means the block can be ignored if it is unreachable.
329a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar  void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false);
330824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar
3310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitBranch - Emit a branch to the specified basic block from the current
3320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insert block, taking care to avoid creation of branches from dummy
3330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// blocks. It is legal to call this function even if there is no current
3340dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// insertion point.
3355e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar  ///
3360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function clears the current insertion point. The caller should follow
3370dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calls to this function with calls to Emit*Block prior to generation new
3380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// code.
339d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar  void EmitBranch(llvm::BasicBlock *Block);
340d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar
3410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// HaveInsertPoint - True if an insertion point is defined. If not, this
3420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// indicates that the current code being emitted is unreachable.
3430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  bool HaveInsertPoint() const {
344a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    return Builder.GetInsertBlock() != 0;
345a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
346a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
3470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint - Ensure that an insertion point is defined so that
3480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// emitted IR has a place to go. Note that by definition, if this function
3490dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// creates a block then that block is unreachable; callers may do better to
3500dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// detect when no insertion point is defined and simply skip IR generation.
351a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  void EnsureInsertPoint() {
352a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar    if (!HaveInsertPoint())
353a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar      EmitBlock(createBasicBlock());
354a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar  }
3550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
356488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
357dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
35890df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
35990df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// block.
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     const char *Name = "tmp");
3690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3749b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
3759b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
3769b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
3779b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
3780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
3799b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                     bool isAggLocVolatile = false);
380d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
3810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // EmitVAListRef - Emit a "reference" to a va_list; this is either the address
3820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // or the value of the expression, depending on how va_list is defined.
3834fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman  llvm::Value *EmitVAListRef(const Expr *E);
3844fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman
3850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will
3860dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// always be accessible even if no aggregate location is provided.
3870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
38846f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar                           bool isAggLocVolatile = false);
38946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
3907482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
3917482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar                         QualType EltTy);
3927482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
3937482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
3947482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
39551b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
39651b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
39751b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
39851b09f2c528c8460b5465c676173324e44176d62Devang Patel
39988a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getCGRecordLayout - Return record layout info.
40088a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
401813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio
402813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
403248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
4044f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
405dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
406dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
4070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4084f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
4094f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
4104f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
4114f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
4120ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  unsigned GetIDForAddrOfLabel(const LabelStmt *L);
4130ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
4140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0.
4153d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
416ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
417ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
418ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
419ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
4200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // instruction in LLVM instead once it works well enough.
421ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
422f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson
42360d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // EmitVLASize - Generate code for any VLA size expressions that might occur
42460d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // in a variably modified type. If Ty is a VLA, will return the value that
42560d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  // corresponds to the size in bytes of the VLA type. Will return 0 otherwise.
42660d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson  llvm::Value *EmitVLASize(QualType Ty);
4270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
428dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // GetVLASize - Returns an LLVM value that corresponds to the size in bytes
429dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  // of a variable length array type.
430dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson  llvm::Value *GetVLASize(const VariableArrayType *);
431dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
437248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
438248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
439248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitStaticBlockVarDecl(const VarDecl &D);
440b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
441b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
442b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
4430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info.
4490912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitStopPoint(const Stmt *S);
4500912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
4510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStmt - Emit the code for the statement \arg S. It is legal to call
4520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// this function even if there is no current insertion point.
4530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  ///
4540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// This function may clear the current insertion point; callers should use
4550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EnsureInsertPoint if they wish to subsequently generate code without first
4560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// calling EmitBlock, EmitBranch, or EmitStmt.
4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
458a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
4590912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// EmitSimpleStmt - Try to emit a "simple" statement which does not
4600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// necessarily require an insertion point or debug information; typically
4610dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// because the statement amounts to a jump or a container of other
4620dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// statements.
4630912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  ///
4640912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  /// \return True if the statement was handled.
4650912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  bool EmitSimpleStmt(const Stmt *S);
4660912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar
4679b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
4689b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
469a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
4700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitLabel - Emit the block for the given label. It is legal to call this
4710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// function even if there is no current insertion point.
47291d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
473a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar
4745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
4760ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
4825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
4830912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitBreakStmt(const BreakStmt &S);
4840912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar  void EmitContinueStmt(const ContinueStmt &S);
48551b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
48651b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
48751b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
488c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
489fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
4900dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4913d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
49264d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
49364d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
49410cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner  void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S);
4950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
4965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
50013e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
50113e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar  RValue GetUndefRValue(QualType Ty);
50213e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar
503ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
504ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
505ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  /// provided Name).
506ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar  RValue EmitUnsupportedRValue(const Expr *E,
507ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar                               const char *Name);
508ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar
5090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue
5100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an ErrorUnsupported style diagnostic (using the provided Name).
5116ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
5126ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
5136ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
5310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5329d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitLoadOfScalar - Load a scalar value from an address, taking
5339d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
5349d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
5359d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
5369d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                                QualType Ty);
5379d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
5389d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// EmitStoreOfScalar - Store a scalar value to an address, taking
5399d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// care to appropriately convert from the memory representation to
5409d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  /// the LLVM value representation.
5419d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar  void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
5429d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar                         bool Volatile);
5439d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar
5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
5475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
548213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
5493b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
55085c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
55143f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType);
5525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5530dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
5545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
5565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
558213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
559213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
56085c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
56143f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty);
562ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar
5630dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue - Store Src into Dst with same constraints as
5640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitStoreThroughLValue.
565ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  ///
5660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// \param Result [out] - If non-null, this will be set to a Value* for the
5670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// bit-field contents after the store, appropriate for use as the result of
5680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// an assignment to the bit-field.
569ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty,
570ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar                                      llvm::Value **Result=0);
5710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
57222c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
57380e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
5745b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
57522c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
5765b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  // Note: only available for agg return types
5775b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar  LValue EmitVAArgExprLValue(const VAArgExpr *E);
5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
5795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
580662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
581d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
5825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
5835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
584213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
585b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
58606e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
587472778eb4fce241721c563280886e98389bc7219Eli Friedman
58829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface,
58929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
590472778eb4fce241721c563280886e98389bc7219Eli Friedman  LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
5911e692ace08959399794363e77499b73da5494af9Eli Friedman                            bool isUnion, unsigned CVRQualifiers);
59245012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian  LValue EmitLValueForIvar(QualType ObjectTy,
59345012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian                           llvm::Value* Base, const ObjCIvarDecl *Ivar,
594fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian                           const FieldDecl *Field,
59529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
59629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
597fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian  LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field,
598598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian                                unsigned CVRQualifiers);
599fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian
600e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis  LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
601e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis
6020a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
603391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
60485c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
60543f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E);
606cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor  LValue EmitObjCSuperExpr(const ObjCSuperExpr *E);
6070a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar
6085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
609883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitCall - Generate a call of the given function, expecting the given
6130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// result type, and using the given argument list which specifies both the
6140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// LLVM arguments and the types they were derived from.
61588b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar  RValue EmitCall(const CGFunctionInfo &FnInfo,
61688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar                  llvm::Value *Callee,
61719cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar                  const CallArgList &Args);
61819cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar
6195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitCallExpr(const CallExpr *E);
6205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
6215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
6225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgEnd);
6235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
6245193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman  RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
6255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgBeg,
6265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgEnd);
6270dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6281e4d21ea5849637c49fd4222b09c4b5dedff7765Chris Lattner  RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
630acfde805d644bc71dfeac54ddbc9f12cdae0bb02Anders Carlsson  RValue EmitBlockCallExpr(const CallExpr *E);
631acfde805d644bc71dfeac54ddbc9f12cdae0bb02Anders Carlsson
6320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call
6330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is unhandled by the current target.
634f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
635f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
636564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
637564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
6380dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
639cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson  llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
6404119d1aeca8016654d381ce079864058d1709571Nate Begeman  llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
6414119d1aeca8016654d381ce079864058d1709571Nate Begeman                          bool isSplat = false);
6420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
643ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
6447f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
6458fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
6468f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
6475daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian  RValue EmitObjCPropertyGet(const Expr *E);
64843f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian  void EmitObjCPropertySet(const Expr *E, RValue Src);
6498fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
6508fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
651883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
652bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
653883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
654bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
655bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
6560dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6570dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// EmitScalarExpr - Emit the computation of the specified expression of LLVM
6580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// scalar type, returning the result.
6597f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitScalarExpr(const Expr *E);
6600dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6613707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
6623707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
6633707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
6643707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
6650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6664f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
6670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// complex type to the specified destination type, where the destination type
6680dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// is an LLVM scalar type.
6694f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
6704f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
6710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
6720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
673883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
674883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
675883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
676883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
6770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
678b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
67923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
68058dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  ComplexPairTy EmitComplexExpr(const Expr *E);
6810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
68223b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
68323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
684190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
685190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
6867f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
6877f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
6887f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
6897f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
6909b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
6919b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
6922621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
6930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// GenerateStaticBlockVarDecl - return the the static declaration of local
6940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// variable.
69545206ecf708bf03b04db07c2476b9f862127a8b1Sanjiv Gupta  llvm::GlobalValue * GenerateStaticBlockVarDecl(const VarDecl &D,
69645206ecf708bf03b04db07c2476b9f862127a8b1Sanjiv Gupta                                                 bool NoInit,
69745206ecf708bf03b04db07c2476b9f862127a8b1Sanjiv Gupta                                                 const char *Separator,
69845206ecf708bf03b04db07c2476b9f862127a8b1Sanjiv Gupta                                                 llvm::GlobalValue
69945206ecf708bf03b04db07c2476b9f862127a8b1Sanjiv Gupta                                                 ::LinkageTypes Linkage);
7000ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
7010dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // GenerateStaticCXXBlockVarDecl - return the static declaration of a local
7020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  // variable. Performs initialization of the variable if necessary.
703e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson  llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D);
704e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
7050ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
7060ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
7070ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
7080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7090946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// ContainsLabel - Return true if the statement contains a label in it.  If
7100946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// this statement is not executed normally, it not containing a label means
7110946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  /// that we can just remove the code.
7120946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner  static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false);
7130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7144bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar  /// ConstantFoldsToSimpleInteger - If the specified expression does not fold
71531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// to a constant, or if it does but contains a label, return 0.  If it
71631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'true' and does not contain a label, return 1, if it
71731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// constant folds to 'false' and does not contain a label, return -1.
71831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  int ConstantFoldsToSimpleInteger(const Expr *Cond);
7190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
72031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an
72131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// if statement) to the specified blocks.  Based on the condition, this might
72231a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner  /// try to simplify the codegen of the conditional based on the branch.
7239bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner  void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock,
7244bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar                            llvm::BasicBlock *FalseBlock);
72531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate:
7260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7270ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// EmitIndirectSwitches - Emit code for all of the switch
7280ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// instructions in IndirectSwitches.
7290ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectSwitches();
7305627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
73129e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
73229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
7335627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
7345627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
7355627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
7365627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
7375627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
7385627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
7390dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  llvm::Function::arg_iterator
7405627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
7415627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
7425627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
7430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg
7440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// Ty, into individual arguments on the provided vector \arg Args. See
7450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  /// ABIArgInfo::Expand.
7460dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump  void ExpandTypeToArgs(QualType Ty, RValue Src,
7475627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
748c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson
749c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson  llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info,
750c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson                            const Expr *InputExpr, std::string &ConstraintStr);
7510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
752c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  /// EmitCleanupBlock - emits a single cleanup block.
753c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson  void EmitCleanupBlock();
754c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson
75587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// AddBranchFixup - adds a branch instruction to the list of fixups for the
75687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  /// current cleanup scope.
75787eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson  void AddBranchFixup(llvm::BranchInst *BI);
7580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump
7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
764