CodeGenFunction.h revision ddf7cac45d85b73127adbbd91a2b28fc7291c57e
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//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 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"
205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/Expr.h"
21e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h"
225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h"
235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector>
250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map>
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2745d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h"
280dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h"
298f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h"
308f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
32c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class BasicBlock;
335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Module;
34898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  class SwitchInst;
355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class ASTContext;
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class Decl;
40c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class EnumConstantDecl;
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class FunctionDecl;
42c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class FunctionTypeProto;
43c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class LabelStmt;
4429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCInterfaceDecl;
4529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  class ObjCIvarDecl;
46391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCMethodDecl;
47af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  class ObjCPropertyImplDecl;
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class TargetInfo;
49c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar  class VarDecl;
505549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  class CodeGenModule;
53b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  class CodeGenTypes;
5488a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  class CGRecordLayout;
5545d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code.
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenFunction {
59bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic:
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenModule &CGM;  // Per-module state.
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  TargetInfo &Target;
62bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
6358dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
6445d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar  CGBuilderTy Builder;
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
66c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  // Holds the Decl for the current function or method
674111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  const Decl *CurFuncDecl;
68391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  QualType FnRetTy;
695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Function *CurFn;
705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
715ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnBlock - Unified return block.
725ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::BasicBlock *ReturnBlock;
735ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// ReturnValue - The temporary alloca to hold the return value. This
745ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  /// is null iff the function has no return value.
755ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar  llvm::Instruction *ReturnValue;
765ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// AllocaInsertPoint - This is an instruction in the entry block before which
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// we prefer to insert allocas.
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Instruction *AllocaInsertPt;
800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *LLVMIntTy;
827b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser  uint32_t LLVMPointerWidth;
8318ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
8418ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic:
8518ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  // FIXME: The following should be private once EH code is moved out
8618ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  // of NeXT runtime.
8718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
8818ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  // ObjCEHStack - This keeps track of which object to rethrow from
8918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  // inside @catch blocks and which @finally block exits from an EH
9018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  // scope should be chained through.
9118ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  struct ObjCEHEntry {
92898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    ObjCEHEntry(llvm::BasicBlock *fb, llvm::BasicBlock *fne,
93898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar                llvm::SwitchInst *fs, llvm::Value *dc)
94898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar      : FinallyBlock(fb), FinallyNoExit(fne), FinallySwitch(fs),
95898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar        DestCode(dc), Exception(0) {}
9618ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
97898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// Entry point to the finally block.
98898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    llvm::BasicBlock *FinallyBlock;
99898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
100898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// Entry point to the finally block which skips execution of the
101898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// try_exit runtime function.
102898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    llvm::BasicBlock *FinallyNoExit;
103898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
104898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// Switch instruction which runs at the end of the finally block
105898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// to forward jumps through the finally block.
106898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    llvm::SwitchInst *FinallySwitch;
107898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
108898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// Variable holding the code for the destination of a jump
109898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// through the @finally block.
110898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    llvm::Value *DestCode;
111898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
112898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// The exception object being handled, during IR generation for a
113898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    /// @catch block.
114898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar    llvm::Value *Exception;
11518ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar  };
116898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
117898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  typedef llvm::SmallVector<ObjCEHEntry*, 8> ObjCEHStackType;
118898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  ObjCEHStackType ObjCEHStack;
119898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar
120898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  /// EmitJumpThroughFinally - Emit a branch from the current insert
121898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  /// point through the finally handling code for \arg Entry and then
122898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  /// on to \arg Dest.
123898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  ///
124898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  /// \param ExecuteTryExit - When true, the try_exit runtime function
125898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  /// should be called prior to executing the finally code.
126898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar  void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest,
127898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar                              bool ExecuteTryExit=true);
1285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1297f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate:
1300ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// LabelIDs - Track arbitrary ids assigned to labels for use in
1310ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// implementing the GCC address-of-label extension and indirect
1320ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// goto. IDs are assigned to labels inside getIDForAddrOfLabel().
1330ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::map<const LabelStmt*, unsigned> LabelIDs;
1340ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1350ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// IndirectSwitches - Record the list of switches for indirect
1360ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// gotos. Emission of the actual switching code needs to be delayed
1370ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// until all AddrLabelExprs have been seen.
1380ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  std::vector<llvm::SwitchInst*> IndirectSwitches;
1390ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// decls.
1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// LabelMap - This keeps track of the LLVM basic block for each C label.
1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
146da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner
147da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  // BreakContinueStack - This keeps track of where break and continue
148da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  // statements should jump to.
149da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  struct BreakContinue {
150da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb)
151da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner      : BreakBlock(bb), ContinueBlock(cb) {}
152da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner
153da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *BreakBlock;
154da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner    llvm::BasicBlock *ContinueBlock;
155da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  };
156da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  llvm::SmallVector<BreakContinue, 8> BreakContinueStack;
15718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar
15880fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// SwitchInsn - This is nearest current switch instruction. It is null if
15980fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// if current context is not in a switch.
16051b09f2c528c8460b5465c676173324e44176d62Devang Patel  llvm::SwitchInst *SwitchInsn;
16151b09f2c528c8460b5465c676173324e44176d62Devang Patel
16280fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// CaseRangeBlock - This block holds if condition check for last case
16380fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel  /// statement range in current switch instruction.
164c049e4f406a7f7179eba98659044a32508e53289Devang Patel  llvm::BasicBlock *CaseRangeBlock;
165c049e4f406a7f7179eba98659044a32508e53289Devang Patel
1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  CodeGenFunction(CodeGenModule &cgm);
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ASTContext &getContext() const;
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
171391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  void GenerateObjCMethod(const ObjCMethodDecl *OMD);
172af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
173af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void StartObjCMethod(const ObjCMethodDecl *MD);
174af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
175af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// GenerateObjCGetter - Synthesize an Objective-C property getter
176af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// function.
177af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void GenerateObjCGetter(const ObjCPropertyImplDecl *PID);
178af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
179af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// GenerateObjCSetter - Synthesize an Objective-C property setter
180af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  /// function for the given property.
181af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void GenerateObjCSetter(const ObjCPropertyImplDecl *PID);
182af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar
183bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar  void GenerateCode(const FunctionDecl *FD,
184bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar                    llvm::Function *Fn);
1857c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar  void StartFunction(const Decl *D, QualType RetTy,
1867c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar                     llvm::Function *Fn,
1872284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     const FunctionArgList &Args,
1882284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar                     SourceLocation StartLoc);
189af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar  void FinishFunction(SourceLocation EndLoc=SourceLocation());
19017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
19117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  /// EmitFunctionProlog - Emit the target specific LLVM code to load
19217b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  /// the arguments for the given function. This is also responsible
19317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  /// for naming the LLVM function arguments.
19417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  void EmitFunctionProlog(llvm::Function *Fn, QualType RetTy,
19517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          const FunctionArgList &Args);
19617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
19717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  /// EmitFunctionEpilog - Emit the target specific LLVM code to
19817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  /// return the given temporary.
19917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar  void EmitFunctionEpilog(QualType RetTy,
20017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar                          llvm::Value *ReturnValue);
20117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  const llvm::Type *ConvertType(QualType T);
203c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner
204b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// LoadObjCSelf - Load the value of self. This function is only
205b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// valid while generating code for an Objective-C method.
206c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner  llvm::Value *LoadObjCSelf();
2074111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
2084111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  /// isObjCPointerType - Return true if the specificed AST type will map onto
2094111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  /// some Objective-C pointer type.
2104111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  static bool isObjCPointerType(QualType T);
2114111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner
2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// hasAggregateLLVMType - Return true if the specified AST type will map into
2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an aggregate LLVM type or is void.
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  static bool hasAggregateLLVMType(QualType T);
2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// getBasicBlockForLabel - Return the LLVM basicblock that the specified
2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// label maps to.
2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S);
2195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitBlock(llvm::BasicBlock *BB);
222dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner
223488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar  /// ErrorUnsupported - Print out an error that codegen doesn't support the
224dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner  /// specified stmt yet.
22590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar  void ErrorUnsupported(const Stmt *S, const char *Type,
22690df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar                        bool OmitOnError=false);
2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                                  Helpers
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// CreateTempAlloca - This creates a alloca and inserts it into the entry
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// block.
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty,
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                     const char *Name = "tmp");
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EvaluateExprAsBool - Perform the usual unary conversions on the specified
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// expression and compare the result against zero, returning an Int1Ty value.
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::Value *EvaluateExprAsBool(const Expr *E);
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2419b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// EmitAnyExpr - Emit code to compute the specified expression which can have
2429b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// any type.  The result is returned as an RValue struct.  If this is an
2439b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// aggregate expression, the aggloc/agglocvolatile arguments indicate where
2449b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// the result should be returned.
2459b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0,
2469b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                     bool isAggLocVolatile = false);
247d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
24846f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result
24946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  /// will always be accessible even if no aggregate location is
25046f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  /// provided.
25146f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar  RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0,
25246f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar                           bool isAggLocVolatile = false);
25346f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar
2547482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr,
2557482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar                         QualType EltTy);
2567482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
2577482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar  void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty);
2587482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar
259d9363c3a80168283b3da518b4e17f545a6246857Devang Patel  /// isDummyBlock - Return true if BB is an empty basic block
260d9363c3a80168283b3da518b4e17f545a6246857Devang Patel  /// with no predecessors.
261d9363c3a80168283b3da518b4e17f545a6246857Devang Patel  static bool isDummyBlock(const llvm::BasicBlock *BB);
262d9363c3a80168283b3da518b4e17f545a6246857Devang Patel
26351b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// StartBlock - Start new block named N. If insert block is a dummy block
26451b09f2c528c8460b5465c676173324e44176d62Devang Patel  /// then reuse it.
26551b09f2c528c8460b5465c676173324e44176d62Devang Patel  void StartBlock(const char *N);
26651b09f2c528c8460b5465c676173324e44176d62Devang Patel
26788a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  /// getCGRecordLayout - Return record layout info.
26888a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel  const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
269813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio
270813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio  /// GetAddrOfStaticLocalVar - Return the address of a static local variable.
271248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
2724f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
273dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  /// GetAddrOfLocalVar - Return the address of a local variable.
274dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson  llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
275dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson
2764f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// getAccessedFieldNo - Given an encoded value and a result number, return
2774f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  /// the input field number being accessed.
2784f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman  static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
2794f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman
2800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  unsigned GetIDForAddrOfLabel(const LabelStmt *L);
2810ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
2823d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  /// EmitMemSetToZero - Generate code to memset a value of the given type to 0;
2833d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty);
284ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson
285ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // EmitVAArg - Generate code to get an argument from the passed in pointer
286ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // and update it accordingly. The return value is a pointer to the argument.
287ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // FIXME: We should be able to get rid of this method and use the va_arg
288ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  // instruction in LLVM instead once it works well enough.
289ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson  llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty);
2903d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                            Declaration Emission
2935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
2945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDecl(const Decl &D);
296248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitBlockVarDecl(const VarDecl &D);
297248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitLocalBlockVarDecl(const VarDecl &D);
298248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff  void EmitStaticBlockVarDecl(const VarDecl &D);
299b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar
300b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
301b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar  void EmitParmDecl(const VarDecl &D, llvm::Value *Arg);
3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                             Statement Emission
3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStmt(const Stmt *S);
3089b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false,
3099b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner                          llvm::Value *AggLoc = 0, bool isAggVol = false);
31091d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner  void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt.
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitLabelStmt(const LabelStmt &S);
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitGotoStmt(const GotoStmt &S);
3130ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectGotoStmt(const IndirectGotoStmt &S);
3145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitIfStmt(const IfStmt &S);
3155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitWhileStmt(const WhileStmt &S);
3165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDoStmt(const DoStmt &S);
3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitForStmt(const ForStmt &S);
3185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitReturnStmt(const ReturnStmt &S);
3195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitDeclStmt(const DeclStmt &S);
320da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  void EmitBreakStmt();
321da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner  void EmitContinueStmt();
32251b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitSwitchStmt(const SwitchStmt &S);
32351b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitDefaultStmt(const DefaultStmt &S);
32451b09f2c528c8460b5465c676173324e44176d62Devang Patel  void EmitCaseStmt(const CaseStmt &S);
325c049e4f406a7f7179eba98659044a32508e53289Devang Patel  void EmitCaseStmtRange(const CaseStmt &S);
326fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson  void EmitAsmStmt(const AsmStmt &S);
327fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson
3283d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson  void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
32964d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
33064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson  void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
3313d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //                         LValue Expression Emission
3345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3366ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E
3376ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  /// and issue an ErrorUnsupported style diagnostic (using the
3386ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  /// provided Name).
3396ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar  LValue EmitUnsupportedLValue(const Expr *E,
3406ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar                               const char *Name);
3416ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar
3425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLValue - Emit code to compute a designator that specifies the location
3435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// of the expression.
3445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// This can return one of two things: a simple address or a bitfield
3465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// reference.  In either case, the LLVM Value* in the LValue structure is
3475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// guaranteed to be an LLVM pointer type.
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a bitfield reference, nothing about the pointee type of
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// the LLVM value is known: For example, it may not be a pointer to an
3515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// integer.
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// If this returns a normal address, and if the lvalue's C type is fixed
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// size, this method guarantees that the returned pointer type will point to
3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// an LLVM type of the same size of the lvalue's type.  If the lvalue has a
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// variable length type, this is not possible.
3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ///
3585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitLValue(const Expr *E);
3595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitLoadOfLValue - Given an expression that represents a value lvalue,
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// this method emits the address of the lvalue, then loads the result as an
3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// rvalue, returning the rvalue.
3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitLoadOfLValue(LValue V, QualType LVType);
364213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType);
3653b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio  RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType);
36685c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType);
3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
36834cdc86af5b0a54084a512a1b2643365b8f5bdd2Chris Lattner
3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// EmitStoreThroughLValue - Store the specified rvalue into the specified
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// lvalue, where both are guaranteed to the have the same type, and that type
3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// is 'Ty'.
3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty);
373213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst,
374213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman                                                QualType Ty);
375a0c5d0eacede0f67ce46707263ddf4d8de0df706Lauro Ramos Venancio  void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty);
37685c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty);
37722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb
37822c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  // Note: only availabe for agg return types
37980e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
38080e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar  // Note: only availabe for agg return types
38122c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb  LValue EmitCallExprLValue(const CallExpr *E);
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitDeclRefLValue(const DeclRefExpr *E);
3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitStringLiteralLValue(const StringLiteral *E);
385662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar  LValue EmitPredefinedFunctionName(unsigned Type);
386d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  LValue EmitPredefinedLValue(const PredefinedExpr *E);
3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitUnaryOpLValue(const UnaryOperator *E);
3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E);
389213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E);
390b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  LValue EmitMemberExpr(const MemberExpr *E);
39106e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman  LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
392472778eb4fce241721c563280886e98389bc7219Eli Friedman
39329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface,
39429e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                              const ObjCIvarDecl *Ivar);
395472778eb4fce241721c563280886e98389bc7219Eli Friedman  LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field,
3961e692ace08959399794363e77499b73da5494af9Eli Friedman                            bool isUnion, unsigned CVRQualifiers);
39729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  LValue EmitLValueForIvar(llvm::Value* Base, const ObjCIvarDecl *Ivar,
39829e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar                           unsigned CVRQualifiers);
39929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
400e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis  LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E);
401e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis
4020a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar  LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E);
403391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E);
40485c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E);
4050a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
407883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //                         Scalar Expression Emission
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4107f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// EmitCall - Generate a call of the given function, expecting the
4117f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// given result type, and using the given argument list which
4127f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// specifies both the LLVM arguments and the types they were
4137f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// derived from.
41419cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar  RValue EmitCall(llvm::Value *Callee,
41519cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar                  QualType ResultType,
41619cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar                  const CallArgList &Args);
41719cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RValue EmitCallExpr(const CallExpr *E);
4195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
4205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg,
4215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgEnd);
4225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
4235193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman  RValue EmitCallExpr(llvm::Value *Callee, QualType FnType,
4245549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgBeg,
4255549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek                      CallExpr::const_arg_iterator ArgEnd);
4265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek
4271e4d21ea5849637c49fd4222b09c4b5dedff7765Chris Lattner  RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
429f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0
430f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  /// if the call is unhandled by the current target.
431f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar  llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
432f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar
433564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E);
434564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson  llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
435564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson
436cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson  llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...);
4374119d1aeca8016654d381ce079864058d1709571Nate Begeman  llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals,
4384119d1aeca8016654d381ce079864058d1709571Nate Begeman                          bool isSplat = false);
4396086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson
440ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar  llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
4417f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
4428fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner  llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E);
4438f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar  RValue EmitObjCMessageExpr(const ObjCMessageExpr *E);
4449c3fc703b29a31d40bcf5027dbb4784dd393804eDaniel Dunbar  RValue EmitObjCPropertyGet(const ObjCPropertyRefExpr *E);
44585c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar  void EmitObjCPropertySet(const ObjCPropertyRefExpr *E, RValue Src);
4468fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
4478fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner
448883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
449bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  //                           Expression Emission
450883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  //===--------------------------------------------------------------------===//
451bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner
452bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner  // Expressions are broken into three classes: scalar, complex, aggregate.
453883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner
4547f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  /// EmitScalarExpr - Emit the computation of the specified expression of
4557f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  /// LLVM scalar type, returning the result.
4567f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner  llvm::Value *EmitScalarExpr(const Expr *E);
4577f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner
4583707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// EmitScalarConversion - Emit a conversion from the specified type to the
4593707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  /// specified destination type, both of which are LLVM scalar types.
4603707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner  llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy,
4613707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner                                    QualType DstTy);
4623707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner
4634f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// EmitComplexToScalarConversion - Emit a conversion from the specified
4644f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// complex type to the specified destination type, where the destination
4654f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  /// type is an LLVM scalar type.
4664f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner  llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy,
4674f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner                                             QualType DstTy);
4684f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner
4693707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner
470883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// EmitAggExpr - Emit the computation of the specified expression of
471883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// aggregate type.  The result is computed into DestPtr.  Note that if
472883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  /// DestPtr is null, the value of the aggregate expression is not needed.
473883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner  void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
474b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner
475b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner  /// EmitComplexExpr - Emit the computation of the specified expression of
47623b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// complex type, returning the result.
47758dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner  ComplexPairTy EmitComplexExpr(const Expr *E);
47823b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner
47923b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
48023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner  /// of complex type, storing into the specified Value*.
481190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr,
482190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner                               bool DestIsVolatile);
4837f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar
4847f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  /// StoreComplexToAddr - Store a complex number into the specified address.
4857f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar  void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr,
4867f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar                          bool DestIsVolatile);
4879b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  /// LoadComplexFromAddr - Load a complex number from the specified address.
4889b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner  ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile);
4892621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner
4902621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner  /// GenerateStaticBlockVarDecl - return the the static
4912621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner  /// declaration of local variable.
4922621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner  llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D,
4932621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner                                                bool NoInit,
4942621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner                                                const char *Separator);
4950ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
496e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson  // GenerateStaticBlockVarDecl - return the static declaration of
497e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson  // a local variable. Performs initialization of the variable if necessary.
498e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson  llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D);
499e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson
5000ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
5010ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //                             Internal Helpers
5020ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  //===--------------------------------------------------------------------===//
5030ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar
5040ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbarprivate:
5050ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// EmitIndirectSwitches - Emit code for all of the switch
5060ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  /// instructions in IndirectSwitches.
5070ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar  void EmitIndirectSwitches();
5085627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
50929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar  void EmitReturnOfRValue(RValue RV, QualType Ty);
51029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar
5115627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty
5125627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// from function arguments into \arg Dst. See ABIArgInfo::Expand.
5135627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ///
5145627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \param AI - The first function argument of the expansion.
5155627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \return The argument following the last expanded function
5165627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument.
5175627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  llvm::Function::arg_iterator
5185627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  ExpandTypeFromArgs(QualType Ty, LValue Dst,
5195627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                     llvm::Function::arg_iterator AI);
5205627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
5215627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type
5225627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// for \arg Ty, into individual arguments on the provided vector
5235627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// \arg Args. See ABIArgInfo::Expand.
5245627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  void ExpandTypeToArgs(QualType Ty, RValue Src,
5255627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar                        llvm::SmallVector<llvm::Value*, 16> &Args);
5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
531