CodeGenFunction.h revision c8c7b187adcd989e01a9fba1ebead6c2abd770c9
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" 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; 5888a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel class CGRecordLayout; 5945d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenFunction { 63bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TargetInfo &Target; 66bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 6758dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 6845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar CGBuilderTy Builder; 695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 70c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner // Holds the Decl for the current function or method 714111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 72391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 755ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnBlock - Unified return block. 765ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar llvm::BasicBlock *ReturnBlock; 775ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnValue - The temporary alloca to hold the return value. This 785ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// is null iff the function has no return value. 795ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar llvm::Instruction *ReturnValue; 805ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Instruction *AllocaInsertPt; 840ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *LLVMIntTy; 867b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser uint32_t LLVMPointerWidth; 8718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 8818ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic: 8918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar // FIXME: The following should be private once EH code is moved out 9018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar // of NeXT runtime. 9118ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 9218ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar // ObjCEHStack - This keeps track of which object to rethrow from 9318ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar // inside @catch blocks and which @finally block exits from an EH 9418ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar // scope should be chained through. 9518ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar struct ObjCEHEntry { 96898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar ObjCEHEntry(llvm::BasicBlock *fb, llvm::BasicBlock *fne, 97898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::SwitchInst *fs, llvm::Value *dc) 98898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar : FinallyBlock(fb), FinallyNoExit(fne), FinallySwitch(fs), 99898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar DestCode(dc), Exception(0) {} 10018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 101898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// Entry point to the finally block. 102898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::BasicBlock *FinallyBlock; 103898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 104898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// Entry point to the finally block which skips execution of the 105898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// try_exit runtime function. 106898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::BasicBlock *FinallyNoExit; 107898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 108898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// Switch instruction which runs at the end of the finally block 109898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// to forward jumps through the finally block. 110898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::SwitchInst *FinallySwitch; 111898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 112898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// Variable holding the code for the destination of a jump 113898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// through the @finally block. 114898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::Value *DestCode; 115898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 116898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// The exception object being handled, during IR generation for a 117898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// @catch block. 118898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar llvm::Value *Exception; 11918ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar }; 120898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 121898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar typedef llvm::SmallVector<ObjCEHEntry*, 8> ObjCEHStackType; 122898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar ObjCEHStackType ObjCEHStack; 123898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar 124898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// EmitJumpThroughFinally - Emit a branch from the current insert 125898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// point through the finally handling code for \arg Entry and then 126a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// on to \arg Dest. It is legal to call this function even if there 127a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// is no current insertion point. 128898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// 129898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// \param ExecuteTryExit - When true, the try_exit runtime function 130898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar /// should be called prior to executing the finally code. 131898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar void EmitJumpThroughFinally(ObjCEHEntry *Entry, llvm::BasicBlock *Dest, 132898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar bool ExecuteTryExit=true); 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1347f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 1350ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// LabelIDs - Track arbitrary ids assigned to labels for use in 1360ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// implementing the GCC address-of-label extension and indirect 1370ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// goto. IDs are assigned to labels inside getIDForAddrOfLabel(). 1380ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::map<const LabelStmt*, unsigned> LabelIDs; 1390ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 1400ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// IndirectSwitches - Record the list of switches for indirect 1410ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// gotos. Emission of the actual switching code needs to be delayed 1420ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// until all AddrLabelExprs have been seen. 1430ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::vector<llvm::SwitchInst*> IndirectSwitches; 1440ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// decls. 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 151da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 152da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner // BreakContinueStack - This keeps track of where break and continue 153e21269bcb732afa70386fdd4c95d22bc2ed943b1Anders Carlsson // statements should jump to, as well as the size of the eh stack. 154da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 155e21269bcb732afa70386fdd4c95d22bc2ed943b1Anders Carlsson BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb, size_t ehss) 156e21269bcb732afa70386fdd4c95d22bc2ed943b1Anders Carlsson : BreakBlock(bb), ContinueBlock(cb), EHStackSize(ehss) {} 157da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 158da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *BreakBlock; 159da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *ContinueBlock; 160e21269bcb732afa70386fdd4c95d22bc2ed943b1Anders Carlsson size_t EHStackSize; 161da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner }; 162da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 16318ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 16480fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// SwitchInsn - This is nearest current switch instruction. It is null if 16580fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// if current context is not in a switch. 16651b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 16751b09f2c528c8460b5465c676173324e44176d62Devang Patel 16880fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// CaseRangeBlock - This block holds if condition check for last case 16980fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 170c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 171c049e4f406a7f7179eba98659044a32508e53289Devang Patel 172dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // VLASizeMap - This keeps track of the associated size for each VLA type 173dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // FIXME: Maybe this could be a stack of maps that is pushed/popped as 174dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // we enter/leave scopes. 175dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson llvm::DenseMap<const VariableArrayType*, llvm::Value*> VLASizeMap; 176dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 17717d28a3e0b0efaba14534d0e6d6a307283d96b9fAnders Carlsson /// StackSaveValues - A stack(!) of stack save values. When a new scope is 17817d28a3e0b0efaba14534d0e6d6a307283d96b9fAnders Carlsson /// entered, a null is pushed on this stack. If a VLA is emitted, then 17917d28a3e0b0efaba14534d0e6d6a307283d96b9fAnders Carlsson /// the return value of llvm.stacksave() is stored at the top of this stack. 18017d28a3e0b0efaba14534d0e6d6a307283d96b9fAnders Carlsson llvm::SmallVector<llvm::Value*, 8> StackSaveValues; 18117d28a3e0b0efaba14534d0e6d6a307283d96b9fAnders Carlsson 1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenFunction(CodeGenModule &cgm); 1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const; 1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 187391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 188af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 189679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian void StartObjCMethod(const ObjCMethodDecl *MD, 190679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian const ObjCContainerDecl *CD); 191af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 192af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// GenerateObjCGetter - Synthesize an Objective-C property getter 193af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// function. 194fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCGetter(ObjCImplementationDecl *IMP, 195fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 196af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 197af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// GenerateObjCSetter - Synthesize an Objective-C property setter 198af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// function for the given property. 199fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCSetter(ObjCImplementationDecl *IMP, 200fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 201af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 202bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void GenerateCode(const FunctionDecl *FD, 203bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar llvm::Function *Fn); 2047c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar void StartFunction(const Decl *D, QualType RetTy, 2057c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar llvm::Function *Fn, 2062284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar const FunctionArgList &Args, 2072284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar SourceLocation StartLoc); 208a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 209a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// FinishFunction - Complete IR generation of the current 210a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// function. It is legal to call this function even if there is no 211a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// current insertion point. 212af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 21317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 21417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar /// EmitFunctionProlog - Emit the target specific LLVM code to load 21517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar /// the arguments for the given function. This is also responsible 21617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar /// for naming the LLVM function arguments. 21717b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar void EmitFunctionProlog(llvm::Function *Fn, QualType RetTy, 21817b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar const FunctionArgList &Args); 21917b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 22017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar /// EmitFunctionEpilog - Emit the target specific LLVM code to 22117b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar /// return the given temporary. 22217b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar void EmitFunctionEpilog(QualType RetTy, 22317b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar llvm::Value *ReturnValue); 22417b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *ConvertType(QualType T); 226c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 227b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// LoadObjCSelf - Load the value of self. This function is only 228b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// valid while generating code for an Objective-C method. 229c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 2304111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 2314111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// isObjCPointerType - Return true if the specificed AST type will map onto 2324111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// some Objective-C pointer type. 2334111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner static bool isObjCPointerType(QualType T); 2344111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool hasAggregateLLVMType(QualType T); 23855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 23955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar /// createBasicBlock - Create an LLVM basic block. 24055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar llvm::BasicBlock *createBasicBlock(const char *Name="", 24155e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar llvm::Function *Parent=0, 24255e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar llvm::BasicBlock *InsertBefore=0) { 24329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG 24429ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar return llvm::BasicBlock::Create("", Parent, InsertBefore); 24529ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else 24655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar return llvm::BasicBlock::Create(Name, Parent, InsertBefore); 24729ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif 24855e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar } 24955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 254a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// EmitBlock - Emit the given block \arg BB and set it as the 255a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// insert point, adding a fall-through branch from the current 256a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// insert block if necessary. It is legal to call this function 257a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// even if there is no current insertion point. 258a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// 259a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// IsFinished - If true, indicates that the caller has finished 260a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// emitting branches to the given block and does not expect to emit 261a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// code into it. This means the block can be ignored if it is 262a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// unreachable. 263a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 264824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar 265d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar /// EmitBranch - Emit a branch to the specified basic block from the 266d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar /// current insert block, taking care to avoid creation of branches 267a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// from dummy blocks. It is legal to call this function even if 268a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// there is no current insertion point. 2695e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// 2705e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// This function clears the current insertion point. The caller 2715e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// should follow calls to this function with calls to Emit*Block 2725e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// prior to generation new code. 273d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar void EmitBranch(llvm::BasicBlock *Block); 274d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar 275a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// HaveInsertPoint - True if an insertion point is defined. If not, 276a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// this indicates that the current code being emitted is 277a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// unreachable. 278a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar bool HaveInsertPoint() const { 279a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar return Builder.GetInsertBlock() != 0; 280a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 281a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 282a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// EnsureInsertPoint - Ensure that an insertion point is defined so 283a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// that emitted IR has a place to go. Note that by definition, if 284a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// this function creates a block then that block is unreachable; 285a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// callers may do better to detect when no insertion point is 286a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// defined and simply skip IR generation. 287a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar void EnsureInsertPoint() { 288a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar if (!HaveInsertPoint()) 289a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar EmitBlock(createBasicBlock()); 290a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 291dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner 292488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 293dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 29490df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Stmt *S, const char *Type, 29590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// block. 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 3045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *Name = "tmp"); 3055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 3075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 3085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3109b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 3119b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 3129b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 3139b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 3149b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 3159b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isAggLocVolatile = false); 316d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 31746f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result 31846f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar /// will always be accessible even if no aggregate location is 31946f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar /// provided. 32046f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar RValue EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc = 0, 32146f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar bool isAggLocVolatile = false); 32246f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar 3237482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 3247482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar QualType EltTy); 3257482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 3267482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty); 3277482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 32851b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 32951b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 33051b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 33151b09f2c528c8460b5465c676173324e44176d62Devang Patel 33288a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel /// getCGRecordLayout - Return record layout info. 33388a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); 334813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio 335813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 336248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 3374f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 338dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson /// GetAddrOfLocalVar - Return the address of a local variable. 339dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); 340dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson 3414f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 3424f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 3434f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 3444f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 3450ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar unsigned GetIDForAddrOfLabel(const LabelStmt *L); 3460ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 3473d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson /// EmitMemSetToZero - Generate code to memset a value of the given type to 0; 3483d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty); 349ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson 350ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // EmitVAArg - Generate code to get an argument from the passed in pointer 351ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // and update it accordingly. The return value is a pointer to the argument. 352ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // FIXME: We should be able to get rid of this method and use the va_arg 353ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // instruction in LLVM instead once it works well enough. 354ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 355f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 35660d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson // EmitVLASize - Generate code for any VLA size expressions that might occur 35760d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson // in a variably modified type. If Ty is a VLA, will return the value that 35860d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson // corresponds to the size in bytes of the VLA type. Will return 0 otherwise. 35960d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson llvm::Value *EmitVLASize(QualType Ty); 360f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 361dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // GetVLASize - Returns an LLVM value that corresponds to the size in bytes 362dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // of a variable length array type. 363dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson llvm::Value *GetVLASize(const VariableArrayType *); 364dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 370248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitBlockVarDecl(const VarDecl &D); 371248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitLocalBlockVarDecl(const VarDecl &D); 372248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitStaticBlockVarDecl(const VarDecl &D); 373b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 374b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 375b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3810912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug 3820912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// info. 3830912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitStopPoint(const Stmt *S); 3840912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 385a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// EmitStmt - Emit the code for the statement \arg S. It is legal 386a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// to call this function even if there is no current insertion 387a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// point. 388a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// 389a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// This function may clear the current insertion point; callers 390a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// should use EnsureInsertPoint if they wish to subsequently 391a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// generate code without first calling EmitBlock, EmitBranch, or 392a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// EmitStmt. 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 394a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 3950912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitSimpleStmt - Try to emit a "simple" statement which does not 3960912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// necessarily require an insertion point or debug information; 3970912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// typically because the statement amounts to a jump or a container 3980912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// of other statements. 3990912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// 4000912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// \return True if the statement was handled. 4010912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar bool EmitSimpleStmt(const Stmt *S); 4020912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 4039b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 4049b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *AggLoc = 0, bool isAggVol = false); 405a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 406a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// EmitLabel - Emit the block for the given label. It is legal 407a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// to call this function even if there is no current insertion 408a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar /// point. 40991d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 410a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 4130ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 4145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 4200912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitBreakStmt(const BreakStmt &S); 4210912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitContinueStmt(const ContinueStmt &S); 42251b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 42351b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 42451b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 425c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 426fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson void EmitAsmStmt(const AsmStmt &S); 427fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson 4283d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 42964d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 43064d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 43110cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 4323d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson 4335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 437ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 438ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 439ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// provided Name). 440ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar RValue EmitUnsupportedRValue(const Expr *E, 441ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar const char *Name); 442ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar 4436ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E 4446ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 4456ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// provided Name). 4466ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 4476ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 4486ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 4495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 4505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 4515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 4585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 4595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 4615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 4625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 4635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 4665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitLoadOfLValue(LValue V, QualType LVType); 471213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 4723b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 47385c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); 47443f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 47634cdc86af5b0a54084a512a1b2643365b8f5bdd2Chris Lattner 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 481213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 482213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman QualType Ty); 48385c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); 48443f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); 485ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar 486ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// EmitStoreThroughLValue - Store Src into Dst with same 487ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// constraints as EmitStoreThroughLValue. 488ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// 489ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// \param Result [out] - If non-null, this will be set to a Value* 490ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// for the bit-field contents after the store, appropriate for use 491ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// as the result of an assignment to the bit-field. 492ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, 493ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar llvm::Value **Result=0); 49422c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb 49522c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb // Note: only availabe for agg return types 49680e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 49780e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar // Note: only availabe for agg return types 49822c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 501662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar LValue EmitPredefinedFunctionName(unsigned Type); 502d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 505213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 506b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 50706e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 508472778eb4fce241721c563280886e98389bc7219Eli Friedman 50929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar llvm::Value *EmitIvarOffset(ObjCInterfaceDecl *Interface, 51029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar const ObjCIvarDecl *Ivar); 511472778eb4fce241721c563280886e98389bc7219Eli Friedman LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, 5121e692ace08959399794363e77499b73da5494af9Eli Friedman bool isUnion, unsigned CVRQualifiers); 51329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar LValue EmitLValueForIvar(llvm::Value* Base, const ObjCIvarDecl *Ivar, 514fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian const FieldDecl *Field, 51529e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar unsigned CVRQualifiers); 51629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 517fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, 518fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian unsigned CVRQualifiers, unsigned idx); 519fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian 520e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); 521e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis 5220a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 523391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 52485c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); 52543f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian LValue EmitObjCKVCRefLValue(const ObjCKVCRefExpr *E); 526cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor LValue EmitObjCSuperExpr(const ObjCSuperExpr *E); 5270a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar 5285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 529883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5327f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// EmitCall - Generate a call of the given function, expecting the 5337f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// given result type, and using the given argument list which 5347f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// specifies both the LLVM arguments and the types they were 5357f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// derived from. 53619cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar RValue EmitCall(llvm::Value *Callee, 53719cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar QualType ResultType, 53819cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar const CallArgList &Args); 53919cd87eb5fb3c197e631ce08fd52c446c4d4e8f1Daniel Dunbar 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitCallExpr(const CallExpr *E); 5415549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 5425549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg, 5435549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 5445549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 5455193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, 5465549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgBeg, 5475549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 5485549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 5491e4d21ea5849637c49fd4222b09c4b5dedff7765Chris Lattner RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 551f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 552f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar /// if the call is unhandled by the current target. 553f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 554f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 555564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 556564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 557564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 558cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); 5594119d1aeca8016654d381ce079864058d1709571Nate Begeman llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, 5604119d1aeca8016654d381ce079864058d1709571Nate Begeman bool isSplat = false); 5616086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson 562ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 5637f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 5648fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 5658f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); 5665daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian RValue EmitObjCPropertyGet(const Expr *E); 56743f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian void EmitObjCPropertySet(const Expr *E, RValue Src); 5688fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 5698fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 570883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 571bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 572883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 573bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 574bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 575883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner 5767f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// EmitScalarExpr - Emit the computation of the specified expression of 5777f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// LLVM scalar type, returning the result. 5787f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitScalarExpr(const Expr *E); 5797f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner 5803707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 5813707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 5823707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 5833707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 5843707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 5854f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 5864f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// complex type to the specified destination type, where the destination 5874f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// type is an LLVM scalar type. 5884f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 5894f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 5904f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner 5913707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 592883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// EmitAggExpr - Emit the computation of the specified expression of 593883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// aggregate type. The result is computed into DestPtr. Note that if 594883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// DestPtr is null, the value of the aggregate expression is not needed. 595883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); 596b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner 597b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 59823b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 59958dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner ComplexPairTy EmitComplexExpr(const Expr *E); 60023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner 60123b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 60223b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// of complex type, storing into the specified Value*. 603190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 604190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner bool DestIsVolatile); 6057f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar 6067f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// StoreComplexToAddr - Store a complex number into the specified address. 6077f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, 6087f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar bool DestIsVolatile); 6099b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// LoadComplexFromAddr - Load a complex number from the specified address. 6109b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 6112621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 6122621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// GenerateStaticBlockVarDecl - return the the static 6132621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// declaration of local variable. 6142621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D, 6152621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner bool NoInit, 6162621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner const char *Separator); 6170ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 618e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson // GenerateStaticBlockVarDecl - return the static declaration of 619e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson // a local variable. Performs initialization of the variable if necessary. 620e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D); 621e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson 6220ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 6230ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 6240ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 6250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 6260946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// ContainsLabel - Return true if the statement contains a label in it. If 6270946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// this statement is not executed normally, it not containing a label means 6280946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// that we can just remove the code. 6290946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 6300946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner 6314bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 63231a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// to a constant, or if it does but contains a label, return 0. If it 63331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// constant folds to 'true' and does not contain a label, return 1, if it 63431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// constant folds to 'false' and does not contain a label, return -1. 63531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner int ConstantFoldsToSimpleInteger(const Expr *Cond); 63631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner 63731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 63831a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// if statement) to the specified blocks. Based on the condition, this might 63931a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// try to simplify the codegen of the conditional based on the branch. 64031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// 6419bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 6424bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar llvm::BasicBlock *FalseBlock); 64331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate: 6440946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner 6450ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// EmitIndirectSwitches - Emit code for all of the switch 6460ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// instructions in IndirectSwitches. 6470ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectSwitches(); 6485627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar 64929e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar void EmitReturnOfRValue(RValue RV, QualType Ty); 65029e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 6515627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 6525627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 6535627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// 6545627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \param AI - The first function argument of the expansion. 6555627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \return The argument following the last expanded function 6565627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// argument. 6575627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::Function::arg_iterator 6585627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar ExpandTypeFromArgs(QualType Ty, LValue Dst, 6595627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::Function::arg_iterator AI); 6605627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar 6615627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type 6625627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// for \arg Ty, into individual arguments on the provided vector 6635627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \arg Args. See ABIArgInfo::Expand. 6645627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar void ExpandTypeToArgs(QualType Ty, RValue Src, 6655627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::SmallVector<llvm::Value*, 16> &Args); 666c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 667c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info, 668c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson const Expr *InputExpr, std::string &ConstraintStr); 669c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 6705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 675