CodeGenFunction.h revision 9fc6a7774643a810c8501dae2323e863fefb623e
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump// This is the internal per-function state used for llvm translation. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h" 18e3a09e6ad09f8d1387ecaa008aaf85527909da0aArgyrios Kyrtzidis#include "clang/AST/ExprCXX.h" 195549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 20199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck#include "clang/AST/CharUnits.h" 21481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "clang/Basic/TargetInfo.h" 22481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/DenseMap.h" 23481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/ADT/SmallVector.h" 24481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner#include "llvm/Support/ValueHandle.h" 250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map> 2669243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson#include "CodeGenModule.h" 2796bd13ae1ab89f5a04b3ad3ec8ec1864cbba3482Mike Stump#include "CGBlocks.h" 2845d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar#include "CGBuilder.h" 290dbe227feccf6a8dbadfff8ca3f80416b7bf2f28Daniel Dunbar#include "CGCall.h" 30b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson#include "CGCXX.h" 318f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h" 328f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 34c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class BasicBlock; 35f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer class LLVMContext; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 37898d508d4c9e9d45914952473e39196b20830a9fDaniel Dunbar class SwitchInst; 38259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar class Twine; 39ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar class Value; 405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 447267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson class CXXDestructorDecl; 456815e941998659a55c20c147861b0f437928c3d8Anders Carlsson class CXXTryStmt; 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 47c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class EnumConstantDecl; 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 4972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor class FunctionProtoType; 50c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class LabelStmt; 51679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian class ObjCContainerDecl; 5229e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCInterfaceDecl; 5329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar class ObjCIvarDecl; 54391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 55fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian class ObjCImplementationDecl; 56af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar class ObjCPropertyImplDecl; 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TargetInfo; 58c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class VarDecl; 5916f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCForCollectionStmt; 6016f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtTryStmt; 6116f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtThrowStmt; 6216f0049415ec596504891259e2a83e19871c0d52Chris Lattner class ObjCAtSynchronizedStmt; 635549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class CodeGenModule; 66b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel class CodeGenTypes; 67e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson class CGDebugInfo; 68bb36d331f439f49859efcfb4435c61762fbba6f9Daniel Dunbar class CGFunctionInfo; 690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump class CGRecordLayout; 700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 732a998148a6823c44d67da347c95eb2ea21f6b986Mike Stumpclass CodeGenFunction : public BlockFunction { 748a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT 758a219ceda2b5afd447e7199b9c53079bead31b89Anders Carlsson void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT 76bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 78444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar const TargetInfo &Target; 790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 8058dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 8145d196b8387dcefc4df26cda114fa34c6528e928Daniel Dunbar CGBuilderTy Builder; 820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 83b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurFuncDecl - Holds the Decl for the current function or ObjC method. 84b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// This excludes BlockDecls. 854111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 86b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner /// CurCodeDecl - This is the inner-most code context, which includes blocks. 87b5437d238752dc297e42410e98d38d5250fe0463Chris Lattner const Decl *CurCodeDecl; 8888b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar const CGFunctionInfo *CurFnInfo; 89391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 926a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump /// CurGD - The GlobalDecl for the current function being compiled. 936a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump GlobalDecl CurGD; 946a1e0eb557d47e85185e09bdf8721f53f4bf9c9cMike Stump 955ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar /// ReturnBlock - Unified return block. 965ca2084cf9b529563209429857f01fdae9dcdfa5Daniel Dunbar llvm::BasicBlock *ReturnBlock; 970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ReturnValue - The temporary alloca to hold the return value. This is null 980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// iff the function has no return value. 99b17daf9ab790ae71aacad2cc4aa11cd8d86c25d1Eli Friedman llvm::Value *ReturnValue; 1000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 103481769b5dc102b0256b35581e787909ad5edfab5Chris Lattner llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 1040ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *LLVMIntTy; 1067b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser uint32_t LLVMPointerWidth; 10718ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 108d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump bool Exceptions; 1099c276ae0f24d4cee8f7954069d4b8eae45d0447dMike Stump bool CatchUndefined; 11018ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbarpublic: 111fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson /// ObjCEHValueStack - Stack of Objective-C exception values, used for 112fa1f756f88f4e6f3da2673082fdc1e8f54bccd6fAnders Carlsson /// rethrows. 113273558fbd891a0872e620e0d3d109b92c1160d72Anders Carlsson llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; 1140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1156fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson /// PushCleanupBlock - Push a new cleanup entry on the stack and set the 1166fc559136b8ef98bfb824a0fd49df385405f2879Anders Carlsson /// passed in block as the cleanup block. 1177799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock, 118d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *CleanupExitBlock, 119d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *PreviousInvokeDest, 12099533834ba8f3658559f334e68a518ebb6388ceaMike Stump bool EHOnly = false); 121d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock) { 122d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump PushCleanupBlock(CleanupEntryBlock, 0, getInvokeDest(), false); 123d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump } 124bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson 1250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// CleanupBlockInfo - A struct representing a popped cleanup block. 126bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson struct CleanupBlockInfo { 1277799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian /// CleanupEntryBlock - the cleanup entry block 128bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson llvm::BasicBlock *CleanupBlock; 1290dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1300dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// SwitchBlock - the block (if any) containing the switch instruction used 1310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// for jumping to the final destination. 132bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson llvm::BasicBlock *SwitchBlock; 1330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 134bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson /// EndBlock - the default destination for the switch instruction. 135bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson llvm::BasicBlock *EndBlock; 1360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 13799533834ba8f3658559f334e68a518ebb6388ceaMike Stump /// EHOnly - True iff this cleanup should only be performed on the 13899533834ba8f3658559f334e68a518ebb6388ceaMike Stump /// exceptional edge. 13999533834ba8f3658559f334e68a518ebb6388ceaMike Stump bool EHOnly; 14099533834ba8f3658559f334e68a518ebb6388ceaMike Stump 1410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb, 14299533834ba8f3658559f334e68a518ebb6388ceaMike Stump llvm::BasicBlock *eb, bool ehonly = false) 14399533834ba8f3658559f334e68a518ebb6388ceaMike Stump : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb), EHOnly(ehonly) {} 144bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson }; 145bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson 146d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// EHCleanupBlock - RAII object that will create a cleanup block for the 147d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// exceptional edge and set the insert point to that block. When destroyed, 148d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// it creates the cleanup edge and sets the insert point to the previous 149d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// block. 150d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump class EHCleanupBlock { 151d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CodeGenFunction& CGF; 152d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *Cont; 153d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *CleanupHandler; 154d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *CleanupEntryBB; 155d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *PreviousInvokeDest; 156d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump public: 157d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump EHCleanupBlock(CodeGenFunction &cgf) 158d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump : CGF(cgf), Cont(CGF.createBasicBlock("cont")), 159d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CleanupHandler(CGF.createBasicBlock("ehcleanup")), 160d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CleanupEntryBB(CGF.createBasicBlock("ehcleanup.rest")), 161d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump PreviousInvokeDest(CGF.getInvokeDest()) { 162d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CGF.EmitBranch(Cont); 16320d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump llvm::BasicBlock *TerminateHandler = CGF.getTerminateHandler(); 164d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CGF.Builder.SetInsertPoint(CleanupEntryBB); 16520d3a53cef96ed1d42ec82a313e8453cfef6512bMike Stump CGF.setInvokeDest(TerminateHandler); 166d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump } 167d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump ~EHCleanupBlock(); 168d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump }; 169d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump 170bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all 1710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// branch fixups and return a block info struct with the switch block and end 172d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// block. This will also reset the invoke handler to the previous value 173d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// from when the cleanup block was created. 174bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson CleanupBlockInfo PopCleanupBlock(); 1750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 176f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// DelayedCleanupBlock - RAII object that will create a cleanup block and set 177f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// the insert point to that block. When destructed, it sets the insert point 178f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// to the previous block and pushes a new cleanup entry on the stack. 179d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor class DelayedCleanupBlock { 1800d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson CodeGenFunction& CGF; 1810d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson llvm::BasicBlock *CurBB; 1827799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian llvm::BasicBlock *CleanupEntryBB; 1837799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian llvm::BasicBlock *CleanupExitBB; 184d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *CurInvokeDest; 18599533834ba8f3658559f334e68a518ebb6388ceaMike Stump bool EHOnly; 1867799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian 1870d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson public: 18899533834ba8f3658559f334e68a518ebb6388ceaMike Stump DelayedCleanupBlock(CodeGenFunction &cgf, bool ehonly = false) 1897799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()), 190d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CleanupEntryBB(CGF.createBasicBlock("cleanup")), CleanupExitBB(0), 191d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CurInvokeDest(CGF.getInvokeDest()), 192d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump EHOnly(ehonly) { 1937799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian CGF.Builder.SetInsertPoint(CleanupEntryBB); 1940d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson } 1950dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1967799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian llvm::BasicBlock *getCleanupExitBlock() { 1977799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian if (!CleanupExitBB) 1987799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian CleanupExitBB = CGF.createBasicBlock("cleanup.exit"); 1997799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian return CleanupExitBB; 2007799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian } 2017799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian 202d5782d5013ef5dbe033d1c3d1334e01c5996e06bDouglas Gregor ~DelayedCleanupBlock() { 203d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump CGF.PushCleanupBlock(CleanupEntryBB, CleanupExitBB, CurInvokeDest, 204d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump EHOnly); 205d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar // FIXME: This is silly, move this into the builder. 206d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar if (CurBB) 207d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar CGF.Builder.SetInsertPoint(CurBB); 208d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar else 209d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar CGF.Builder.ClearInsertionPoint(); 2100d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson } 2110d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson }; 2120d5c6851393d260dfb5ab0420b50adc173e1c549Anders Carlsson 21301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Enters a new scope for capturing cleanups, all of which will be 21401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// executed once the scope is exited. 21501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor class CleanupScope { 21601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CodeGenFunction& CGF; 21701234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor size_t CleanupStackDepth; 21801234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor bool OldDidCallStackSave; 2195656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool PerformCleanup; 22001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 22101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CleanupScope(const CleanupScope &); // DO NOT IMPLEMENT 22201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CleanupScope &operator=(const CleanupScope &); // DO NOT IMPLEMENT 22301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 22401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor public: 22501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Enter a new cleanup scope. 2265656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor explicit CleanupScope(CodeGenFunction &CGF) 2275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor : CGF(CGF), PerformCleanup(true) 2285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor { 22901234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CleanupStackDepth = CGF.CleanupEntries.size(); 23001234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor OldDidCallStackSave = CGF.DidCallStackSave; 23101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 23201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 23301234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// \brief Exit this cleanup scope, emitting any accumulated 23401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor /// cleanups. 23501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor ~CleanupScope() { 2365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (PerformCleanup) { 2375656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 2385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor CGF.EmitCleanupBlocks(CleanupStackDepth); 2395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 2405656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 2415656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 2425656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Determine whether this scope requires any cleanups. 2435656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor bool requiresCleanups() const { 2445656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor return CGF.CleanupEntries.size() > CleanupStackDepth; 2455656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor } 2465656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor 2475656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// \brief Force the emission of cleanups now, instead of waiting 2485656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor /// until this object is destroyed. 2495656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor void ForceCleanup() { 2505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor assert(PerformCleanup && "Already forced cleanup"); 25101234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CGF.DidCallStackSave = OldDidCallStackSave; 25201234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor CGF.EmitCleanupBlocks(CleanupStackDepth); 2535656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor PerformCleanup = false; 25401234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor } 25501234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor }; 25601234bbc1cb94946df8046ad95e17537082b4f71Douglas Gregor 257c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup 258c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson /// blocks that have been added. 259c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson void EmitCleanupBlocks(size_t OldCleanupStackSize); 260c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson 26187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// EmitBranchThroughCleanup - Emit a branch from the current insert block 26287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// through the cleanup handling code (if any) and then on to \arg Dest. 26387eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// 2640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// FIXME: Maybe this should really be in EmitBranch? Don't we always want 26587eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// this behavior for branches? 26687eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson void EmitBranchThroughCleanup(llvm::BasicBlock *Dest); 2670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 26872119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson /// BeginConditionalBranch - Should be called before a conditional part of an 269a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// expression is emitted. For example, before the RHS of the expression below 270a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// is emitted: 2711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 2721d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson /// b && f(T()); 2731d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson /// 274a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// This is used to make sure that any temporaries created in the conditional 2751d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson /// branch are only destroyed if the branch is taken. 27672119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson void BeginConditionalBranch() { 277a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson ++ConditionalBranchLevel; 278a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson } 2791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28072119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson /// EndConditionalBranch - Should be called after a conditional part of an 281a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// expression has been emitted. 28272119a887c4af39c90f10b6bdc158389071f42eaAnders Carlsson void EndConditionalBranch() { 28308e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson assert(ConditionalBranchLevel != 0 && 28408e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson "Conditional branch mismatch!"); 28508e9e453f40aff95a59bd67db49b8f050765e1f0Anders Carlsson 286a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson --ConditionalBranchLevel; 287a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson } 2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2897f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 290d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner CGDebugInfo *DebugInfo; 29109429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 292f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// IndirectBranch - The first time an indirect goto is seen we create a block 293f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// with an indirect branch. Every time we see the address of a label taken, 294f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// we add the label to the indirect goto. Every subsequent indirect goto is 295f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// codegen'd as a jump to the IndirectBranch's basic block. 296d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner llvm::IndirectBrInst *IndirectBranch; 2970ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 2980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 2990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// decls. 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 3015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 3035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 3040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // BreakContinueStack - This keeps track of where break and continue 306e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson // statements should jump to. 307da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 308e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) 309e4b6d342c29d5cb9d311756100df1603810fa892Anders Carlsson : BreakBlock(bb), ContinueBlock(cb) {} 3100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 311da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *BreakBlock; 312da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *ContinueBlock; 3130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump }; 314da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 31518ccc7776ad6288c5f630dc7967fb99d099c9cd9Daniel Dunbar 3160dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// SwitchInsn - This is nearest current switch instruction. It is null if if 3170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// current context is not in a switch. 31851b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 31951b09f2c528c8460b5465c676173324e44176d62Devang Patel 3200dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// CaseRangeBlock - This block holds if condition check for last case 32180fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 322c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 323c049e4f406a7f7179eba98659044a32508e53289Devang Patel 3249834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar /// InvokeDest - This is the nearest exception target for calls 3259834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar /// which can unwind, when exceptions are being used. 3269834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar llvm::BasicBlock *InvokeDest; 3279834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 3280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // VLASizeMap - This keeps track of the associated size for each VLA type. 329bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // We track this by the size expression rather than the type itself because 330bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // in certain situations, like a const qualifier applied to an VLA typedef, 331bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman // multiple VLA types can share the same size expression. 3320dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 3330dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // enter/leave scopes. 334bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 3350dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3364cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 3374cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson /// calling llvm.stacksave for multiple VLAs in the same scope. 3384cc1a4703363ff940b6273aeef9d96a87edeb04bAnders Carlsson bool DidCallStackSave; 33909429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 3406ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson struct CleanupEntry { 3417799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian /// CleanupEntryBlock - The block of code that does the actual cleanup. 3427799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian llvm::BasicBlock *CleanupEntryBlock; 3430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3447799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian /// CleanupExitBlock - The cleanup exit block. 3457799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian llvm::BasicBlock *CleanupExitBlock; 3467799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian 3476ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson /// Blocks - Basic blocks that were emitted in the current cleanup scope. 348bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson std::vector<llvm::BasicBlock *> Blocks; 3496ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson 3506ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson /// BranchFixups - Branch instructions to basic blocks that haven't been 3516ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson /// inserted into the current function yet. 352bb66f9f2e454135b86462d121629275b6ac38e96Anders Carlsson std::vector<llvm::BranchInst *> BranchFixups; 3536ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson 354d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// PreviousInvokeDest - The invoke handler from the start of the cleanup 355d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump /// region. 356d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *PreviousInvokeDest; 357d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump 35899533834ba8f3658559f334e68a518ebb6388ceaMike Stump /// EHOnly - Perform this only on the exceptional edge, not the main edge. 35999533834ba8f3658559f334e68a518ebb6388ceaMike Stump bool EHOnly; 36099533834ba8f3658559f334e68a518ebb6388ceaMike Stump 3617799621ad7d16f3c6a1aeda024312d63ecd77777Fariborz Jahanian explicit CleanupEntry(llvm::BasicBlock *CleanupEntryBlock, 362d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *CleanupExitBlock, 363d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump llvm::BasicBlock *PreviousInvokeDest, 364d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump bool ehonly) 365d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump : CleanupEntryBlock(CleanupEntryBlock), 36699533834ba8f3658559f334e68a518ebb6388ceaMike Stump CleanupExitBlock(CleanupExitBlock), 367d88ea5687968640ada2bc5a10211cbeb68a671ecMike Stump PreviousInvokeDest(PreviousInvokeDest), 36899533834ba8f3658559f334e68a518ebb6388ceaMike Stump EHOnly(ehonly) {} 3696ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson }; 3700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 3716ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson /// CleanupEntries - Stack of cleanup entries. 3726ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson llvm::SmallVector<CleanupEntry, 8> CleanupEntries; 3736ccc47698d0311ddabf32fa0f6db8e4f09ac96f8Anders Carlsson 374bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap; 375bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson 376bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson /// BlockScopes - Map of which "cleanup scope" scope basic blocks have. 377bd6fa3d032acd7eafc6c10827c41103df45beab7Anders Carlsson BlockScopeMap BlockScopes; 3780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 379f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXThisDecl - When generating code for a C++ member function, 380f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// this will hold the implicit 'this' declaration. 3812b77ba8bc7a842829ad9193816dc1d7d5e9c5be6Anders Carlsson ImplicitParamDecl *CXXThisDecl; 3822504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXThisValue; 3831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 384f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// CXXVTTDecl - When generating code for a base object constructor or 385f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// base object destructor with virtual bases, this will hold the implicit 386f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson /// VTT parameter. 387f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson ImplicitParamDecl *CXXVTTDecl; 3882504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *CXXVTTValue; 389f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson 390e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary. 391e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson struct CXXLiveTemporaryInfo { 392e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson /// Temporary - The live temporary. 393e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson const CXXTemporary *Temporary; 3941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 395e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson /// ThisPtr - The pointer to the temporary. 396e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson llvm::Value *ThisPtr; 3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 398e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson /// DtorBlock - The destructor block. 399e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson llvm::BasicBlock *DtorBlock; 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 401f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// CondPtr - If this is a conditional temporary, this is the pointer to the 402f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// condition variable that states whether the destructor should be called 403f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// or not. 404e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson llvm::Value *CondPtr; 4051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 406e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson CXXLiveTemporaryInfo(const CXXTemporary *temporary, 407f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson llvm::Value *thisptr, llvm::BasicBlock *dtorblock, 408f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson llvm::Value *condptr) 4091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock), 410e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson CondPtr(condptr) { } 411e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson }; 4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 413e8b5578fcc2a3ffb90986f95f2c9127a9a08e34bAnders Carlsson llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries; 4141d8475067d5b62ed5a57ba93862e23f3096a8bddAnders Carlsson 415a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// ConditionalBranchLevel - Contains the nesting level of the current 416a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// conditional branch. This is used so that we know if a temporary should be 417a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson /// destroyed conditionally. 418a36bf8f74180e834c6bf2db867796fd5338495abAnders Carlsson unsigned ConditionalBranchLevel; 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4207dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson 4217dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM 4227dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// type as well as the field number that contains the actual data. 4237dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *, 4247dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson unsigned> > ByRefValueInfo; 4257dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson 4267dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field 4277dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson /// number that holds the value. 4287dfa4079f4b37507048b19bfc693d3b015d9dd11Anders Carlsson unsigned getByRefValueLLVMField(const ValueDecl *VD) const; 429182f383db1782af752ecaf607fdff72a8542088bMike Stump 430182f383db1782af752ecaf607fdff72a8542088bMike Stump llvm::BasicBlock *TerminateHandler; 43115037caa1542bb810ad54c653aeb80f61df7b00cMike Stump llvm::BasicBlock *TrapBB; 432940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman 433940670512d7c3d93389bb38a426abcb7ef44271eEli Friedman int UniqueAggrDestructorCount; 4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenFunction(CodeGenModule &cgm); 4360dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 4375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const; 438e896d98548b02223c7740d807a0aa6e20fba7079Anders Carlsson CGDebugInfo *getDebugInfo() { return DebugInfo; } 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4409834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar llvm::BasicBlock *getInvokeDest() { return InvokeDest; } 4419834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; } 4429834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 443a1cf15f4680e5cf39e72e28c5ea854fcba792e84Owen Anderson llvm::LLVMContext &getLLVMContext() { return VMContext; } 44469243825cb5c91ec7207256aa57ae327cfaf8cb2Owen Anderson 4459834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 4469834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar // Objective-C 4479834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar //===--------------------------------------------------------------------===// 4489834ffbe54788239c8361d3cfe5826fd277ddfb2Daniel Dunbar 449391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 450af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 4510dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void StartObjCMethod(const ObjCMethodDecl *MD, 452679a502d462ef819e6175b58e255ca3f3391e7cfFariborz Jahanian const ObjCContainerDecl *CD); 453af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 4540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 455fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCGetter(ObjCImplementationDecl *IMP, 456fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 457af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 4580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// GenerateObjCSetter - Synthesize an Objective-C property setter function 4590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// for the given property. 460fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian void GenerateObjCSetter(ObjCImplementationDecl *IMP, 461fef30b55230064d334a669a065a1c9acdb87cdfeFariborz Jahanian const ObjCPropertyImplDecl *PID); 462af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 4634e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 4644e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump // Block Bits 4654e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump //===--------------------------------------------------------------------===// 4664e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 4678a2b4b1c5b960710db95e9b296d9a600aee37c00Mike Stump llvm::Value *BuildBlockLiteralTmp(const BlockExpr *); 468a803b0e6ca0d1c71a0b3f5d7380da8bbacf2f983Mike Stump llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose, 469199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits Size, 4700892099dbc640720400a1d9decd2733a09d733e5Mike Stump const llvm::StructType *, 4710892099dbc640720400a1d9decd2733a09d733e5Mike Stump std::vector<HelperInfo> *); 4724e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 473161d36de7ee686b09525bb919ad1b20592e499fcChris Lattner llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr, 4744e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump const BlockInfo& Info, 4756cc88f78fd36d3511b89412b193494b3e423cbffMike Stump const Decl *OuterFuncDecl, 4767f28a9c37e67ae16396042ad9c085830969daf29Mike Stump llvm::DenseMap<const Decl*, llvm::Value*> ldm, 47730a8a272f091054ce92b9daa1992bcff887c3ee4Ken Dyck CharUnits &Size, CharUnits &Align, 47800470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls, 47900470a1c4c44c5ed26bad9a38b4d3904b02d7a28Mike Stump bool &subBlockHasCopyDispose); 4804e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 4816cc88f78fd36d3511b89412b193494b3e423cbffMike Stump void BlockForwardSelf(); 4824e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump llvm::Value *LoadBlockStruct(); 4834e7a1f7682d94811bd41fca8aefccc38f686db23Mike Stump 484199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits AllocateBlockDecl(const BlockDeclRefExpr *E); 485a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E); 4869ad5513b0f9d3999705659fb1aeb0e6c53455f43Anders Carlsson const llvm::Type *BuildByRefType(const ValueDecl *D); 487dab514fc30242c7afd6c03956e46136c400fb0d3Mike Stump 4880ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson void GenerateCode(GlobalDecl GD, llvm::Function *Fn); 4890ff8bafde95f6fa51ccea70738c1b99db870bddcAnders Carlsson void StartFunction(GlobalDecl GD, QualType RetTy, 4907c086516f3cc9fba2733b1919973206c6ba4b171Daniel Dunbar llvm::Function *Fn, 4912284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar const FunctionArgList &Args, 4922284ac9ec80299fcdefae9a2787cf85105a0f203Daniel Dunbar SourceLocation StartLoc); 493a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 4949fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitConstructorBody(FunctionArgList &Args); 4959fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitDestructorBody(FunctionArgList &Args); 4969fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void EmitFunctionBody(FunctionArgList &Args); 497a355e07454463b19829ac92ffd115a097faff0e0John McCall 4980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitReturnBlock - Emit the unified return block, trying to avoid its 4990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emission when possible. 5001c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar void EmitReturnBlock(); 5011c1d6074f5a0296dd273362655b1b8f9057289e3Daniel Dunbar 5020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// FinishFunction - Complete IR generation of the current function. It is 5030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// legal to call this function even if there is no current insertion point. 504af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 50517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 506c902d22129322731607988dafb8cd7f708eb75b1Mike Stump /// DynamicTypeAdjust - Do the non-virtual and virtual adjustments on an 507c902d22129322731607988dafb8cd7f708eb75b1Mike Stump /// object pointer to alter the dynamic type of the pointer. Used by 508c902d22129322731607988dafb8cd7f708eb75b1Mike Stump /// GenerateCovariantThunk for building thunks. 5097622cd3410846d28862ecfe862117894a259a7faAnders Carlsson llvm::Value *DynamicTypeAdjust(llvm::Value *V, 5107622cd3410846d28862ecfe862117894a259a7faAnders Carlsson const ThunkAdjustment &Adjustment); 511c902d22129322731607988dafb8cd7f708eb75b1Mike Stump 512ed032eb5c18b99528cbd76415337b6056a72b911Mike Stump /// GenerateThunk - Generate a thunk for the given method 51335c98cc4c00efcfe47ad0b716e7c50afb9c5ff75Eli Friedman llvm::Constant *GenerateThunk(llvm::Function *Fn, GlobalDecl GD, 514a94822e8937eeb340a653b88024f805a07a2d2eeAnders Carlsson bool Extern, 515a94822e8937eeb340a653b88024f805a07a2d2eeAnders Carlsson const ThunkAdjustment &ThisAdjustment); 5167622cd3410846d28862ecfe862117894a259a7faAnders Carlsson llvm::Constant * 51735c98cc4c00efcfe47ad0b716e7c50afb9c5ff75Eli Friedman GenerateCovariantThunk(llvm::Function *Fn, GlobalDecl GD, 5187622cd3410846d28862ecfe862117894a259a7faAnders Carlsson bool Extern, 5197622cd3410846d28862ecfe862117894a259a7faAnders Carlsson const CovariantThunkAdjustment &Adjustment); 520ed032eb5c18b99528cbd76415337b6056a72b911Mike Stump 521de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type); 5221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52377a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman void InitializeVtablePtrs(const CXXRecordDecl *ClassDecl); 52477a259c6dbf582949af8a243b472c0c7faa373a6Eli Friedman 525e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman void InitializeVtablePtrsRecursive(const CXXRecordDecl *ClassDecl, 526e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman llvm::Constant *Vtable, 52721431c551d867962c66c92f0f96f652678f64c1cAnders Carlsson CGVtableInfo::AddrSubMap_t& AddressPoints, 528e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman llvm::Value *ThisPtr, 529e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman uint64_t Offset); 530e12e77bed10f87bdc7305d0dbd1de89e48f280c1Eli Friedman 5319fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void SynthesizeCXXCopyConstructor(const FunctionArgList &Args); 5329fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void SynthesizeCXXCopyAssignment(const FunctionArgList &Args); 5331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534426cc3828ce07a2cff15c9837f5958e6fc4b7739Fariborz Jahanian /// EmitDtorEpilogue - Emit all code that comes at the end of class's 535f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// destructor. This is to call destructors on members and base classes in 536f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// reverse order of their construction. 537de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson void EmitDtorEpilogue(const CXXDestructorDecl *Dtor, 538de1d26b9c1d8823b173e4d77015ad88b4da70559Anders Carlsson CXXDtorType Type); 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionProlog - Emit the target specific LLVM code to load the 5410dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// arguments for the given function. This is also responsible for naming the 5420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM function arguments. 54388b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void EmitFunctionProlog(const CGFunctionInfo &FI, 54488b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Function *Fn, 54517b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar const FunctionArgList &Args); 54617b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 5470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 5480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// given temporary. 54988b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue); 55017b708d61827cd86278e9580b041dd6cbadf07d3Daniel Dunbar 551cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitStartEHSpec - Emit the start of the exception spec. 552cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitStartEHSpec(const Decl *D); 553cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 554cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump /// EmitEndEHSpec - Emit the end of the exception spec. 555cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump void EmitEndEHSpec(const Decl *D); 556cce3d4f9812182ed4e551b7cf0fc86576be8d9c5Mike Stump 557182f383db1782af752ecaf607fdff72a8542088bMike Stump /// getTerminateHandler - Return a handler that just calls terminate. 5589b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump llvm::BasicBlock *getTerminateHandler(); 5599b39c51ae3c547568ac42325f94b4197618f6b18Mike Stump 5608b1a343b6b360d63d5dc8a6beb841ce4414c1e00Daniel Dunbar const llvm::Type *ConvertTypeForMem(QualType T); 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *ConvertType(QualType T); 562bff225ecf77fb891596ecb1b27196310d268365eJohn McCall const llvm::Type *ConvertType(const TypeDecl *T) { 563bff225ecf77fb891596ecb1b27196310d268365eJohn McCall return ConvertType(getContext().getTypeDeclType(T)); 564bff225ecf77fb891596ecb1b27196310d268365eJohn McCall } 565c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 5660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LoadObjCSelf - Load the value of self. This function is only valid while 5670dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// generating code for an Objective-C method. 568c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 5690dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 5700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// TypeOfSelfObject - Return type of object that this self represents. 57145012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian QualType TypeOfSelfObject(); 5724111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 5735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 5745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 5755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool hasAggregateLLVMType(QualType T); 57655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar 57755e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar /// createBasicBlock - Create an LLVM basic block. 5780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump llvm::BasicBlock *createBasicBlock(const char *Name="", 57955e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar llvm::Function *Parent=0, 58055e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar llvm::BasicBlock *InsertBefore=0) { 58129ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#ifdef NDEBUG 5820032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore); 58329ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#else 5840032b2781b4deb131f8c9b7968f2030bf2489cddOwen Anderson return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore); 58529ea6729155c759836be4b5453bee9ef8e1e97eeDaniel Dunbar#endif 58655e874299f2ad827646a4ca9ea38c402aaeb38c9Daniel Dunbar } 5870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 5905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 5910dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 592f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// SimplifyForwardingBlocks - If the given basic block is only a branch to 593f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// another basic block, simplify it. This assumes that no other code could 594f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// potentially reference the basic block. 595aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 596aa5bd87f1fd5f9ca47924248817c89325759b30eDaniel Dunbar 5970dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 5980dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// adding a fall-through branch from the current insert block if 5990dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessary. It is legal to call this function even if there is no current 6000dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 601a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar /// 6020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// IsFinished - If true, indicates that the caller has finished emitting 6030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// branches to the given block and does not expect to emit code into it. This 6040dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// means the block can be ignored if it is unreachable. 605a0c21a8faa79e88ac432d116eca58f7a7217195dDaniel Dunbar void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 606824e3bd76b2e32db2ec6e4d2d113413e518d1c63Daniel Dunbar 6070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitBranch - Emit a branch to the specified basic block from the current 6080dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insert block, taking care to avoid creation of branches from dummy 6090dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// blocks. It is legal to call this function even if there is no current 6100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// insertion point. 6115e08ad3cc62ab94649959ae227a9a411a729bf49Daniel Dunbar /// 6120dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function clears the current insertion point. The caller should follow 6130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calls to this function with calls to Emit*Block prior to generation new 6140dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// code. 615d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar void EmitBranch(llvm::BasicBlock *Block); 616d57a871339c7c98d58d93108b806f59bdf4e13e2Daniel Dunbar 6170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// HaveInsertPoint - True if an insertion point is defined. If not, this 6180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// indicates that the current code being emitted is unreachable. 6190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump bool HaveInsertPoint() const { 620a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar return Builder.GetInsertBlock() != 0; 621a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 622a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 6230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint - Ensure that an insertion point is defined so that 6240dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// emitted IR has a place to go. Note that by definition, if this function 6250dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// creates a block then that block is unreachable; callers may do better to 6260dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// detect when no insertion point is defined and simply skip IR generation. 627a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar void EnsureInsertPoint() { 628a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar if (!HaveInsertPoint()) 629a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar EmitBlock(createBasicBlock()); 630a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar } 6310dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 632488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 633dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 63490df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar void ErrorUnsupported(const Stmt *S, const char *Type, 63590df4b6661968a84bf64baee489bb2f6d948fcc1Daniel Dunbar bool OmitOnError=false); 6365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 6400dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 6410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers MakeQualifiers(QualType T) { 642df317bf71653eeb235da8337b1e8e790f9653aa4Mike Stump Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers(); 6430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T)); 6440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Quals; 6450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 6460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 6475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 648195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// block. The caller is responsible for setting an appropriate alignment on 649195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// the alloca. 6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 651259e9ccf882d11491ad149aec5e6d7a061c9f938Daniel Dunbar const llvm::Twine &Name = "tmp"); 6520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 6539bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// CreateIRTemp - Create a temporary IR object of the given type, with 6549bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// appropriate alignment. This routine should only be used when an temporary 6559bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// value needs to be stored into an alloca (for example, to avoid explicit 6569bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// PHI construction), but the type is the IR type, not the type appropriate 6579bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar /// for storing in memory. 6589bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar llvm::Value *CreateIRTemp(QualType T, const llvm::Twine &Name = "tmp"); 6599bd4da2cfa8b956b851200db8f9a37e175edbb15Daniel Dunbar 660195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// CreateMemTemp - Create a temporary memory object of the given type, with 661195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar /// appropriate alignment. 662195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar llvm::Value *CreateMemTemp(QualType T, const llvm::Twine &Name = "tmp"); 663195337d2e5d4625ae9dc1328c7cdbc7115b0261bDaniel Dunbar 6645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 6655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 6665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 6675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6689b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 6699b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 6709b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 6719b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 67249d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// 67349d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump /// \param IgnoreResult - True if the resulting value isn't used. 6740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 67514c5cbf59cffee52275230922283a247de407712Anders Carlsson bool IsAggLocVolatile = false, bool IgnoreResult = false, 67614c5cbf59cffee52275230922283a247de407712Anders Carlsson bool IsInitializer = false); 677d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 6780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 6790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // or the value of the expression, depending on how va_list is defined. 6804fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman llvm::Value *EmitVAListRef(const Expr *E); 6814fd0aa5803357d8c72eeac2cae15e12649ea08feEli Friedman 6820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 6830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// always be accessible even if no aggregate location is provided. 68414c5cbf59cffee52275230922283a247de407712Anders Carlsson RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false, 68514c5cbf59cffee52275230922283a247de407712Anders Carlsson bool IsInitializer = false); 68646f45b9bec4a265ad8400a538e5ec3a5683617f1Daniel Dunbar 68727fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// EmitAggregateCopy - Emit an aggrate copy. 68827fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// 68927fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// \param isVolatile - True iff either the source or the destination is 69027fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump /// volatile. 6917482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 69227fe2e6c97a3782a0639d87b460741e8ba5d076dMike Stump QualType EltTy, bool isVolatile=false); 6937482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 6947482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty); 6957482d12c345c6391f8956850545e2d4aa7701ce6Daniel Dunbar 69651b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 69751b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 69851b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 69951b09f2c528c8460b5465c676173324e44176d62Devang Patel 700813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 701248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 7024f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 703dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson /// GetAddrOfLocalVar - Return the address of a local variable. 704dde0a94120915fa925d1ffcdb997c7b44dc9fa21Anders Carlsson llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); 7050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 7064f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 7074f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 7084f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 7094f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 710d9becd1846e2c72bf6ad283faa1b048f33dd3afeChris Lattner llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L); 7113d00fdc82fd550ae4bfbb2e700a1fc85bbd6d6fdChris Lattner llvm::BasicBlock *GetIndirectGotoBlock(); 7120ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 7130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitMemSetToZero - Generate code to memset a value of the given type to 0. 7143d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty); 715ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson 716ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // EmitVAArg - Generate code to get an argument from the passed in pointer 717ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // and update it accordingly. The return value is a pointer to the argument. 718ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson // FIXME: We should be able to get rid of this method and use the va_arg 7190dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump // instruction in LLVM instead once it works well enough. 720ddf7cac45d85b73127adbbd91a2b28fc7291c57eAnders Carlsson llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 721f666b7780d04186521adcaedb0e15dfa4d5e6933Anders Carlsson 722f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// EmitVLASize - Generate code for any VLA size expressions that might occur 723f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// in a variably modified type. If Ty is a VLA, will return the value that 724f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// corresponds to the size in bytes of the VLA type. Will return 0 otherwise. 725d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 726d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 72760d35413662ebdcd1d31e34a8a7c665eb6977f1eAnders Carlsson llvm::Value *EmitVLASize(QualType Ty); 7280dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 729dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // GetVLASize - Returns an LLVM value that corresponds to the size in bytes 730dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson // of a variable length array type. 731dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson llvm::Value *GetVLASize(const VariableArrayType *); 732dcc90d87e6430c643b4311ae5b0089535bca41f7Anders Carlsson 7335f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// LoadCXXThis - Load the value of 'this'. This function is only valid while 7345f4307b7ba164b03c853c8d3eb4674d33f8967a6Anders Carlsson /// generating code for an C++ member function. 7352504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXThis() { 7362504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXThisValue && "no 'this' value for this function"); 7372504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXThisValue; 7382504941793b549323f9d29c62507cf21d865fadeJohn McCall } 7391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 740c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have 741c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson /// virtual bases. 7422504941793b549323f9d29c62507cf21d865fadeJohn McCall llvm::Value *LoadCXXVTT() { 7432504941793b549323f9d29c62507cf21d865fadeJohn McCall assert(CXXVTTValue && "no VTT value for this function"); 7442504941793b549323f9d29c62507cf21d865fadeJohn McCall return CXXVTTValue; 7452504941793b549323f9d29c62507cf21d865fadeJohn McCall } 746bff225ecf77fb891596ecb1b27196310d268365eJohn McCall 747bff225ecf77fb891596ecb1b27196310d268365eJohn McCall /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a 748bff225ecf77fb891596ecb1b27196310d268365eJohn McCall /// complete class down to one of its virtual bases. 749bff225ecf77fb891596ecb1b27196310d268365eJohn McCall llvm::Value *GetAddressOfBaseOfCompleteClass(llvm::Value *Value, 750bff225ecf77fb891596ecb1b27196310d268365eJohn McCall bool IsVirtual, 751bff225ecf77fb891596ecb1b27196310d268365eJohn McCall const CXXRecordDecl *Derived, 752bff225ecf77fb891596ecb1b27196310d268365eJohn McCall const CXXRecordDecl *Base); 753c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson 754f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// GetAddressOfBaseClass - This function will add the necessary delta to the 755f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// load of 'this' and returns address of the base class. 756a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, 757a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson const CXXRecordDecl *ClassDecl, 758a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson const CXXRecordDecl *BaseClassDecl, 759a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson bool NullCheckValue); 760a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson 761a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, 7625a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson const CXXRecordDecl *ClassDecl, 763a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson const CXXRecordDecl *DerivedClassDecl, 7645a0f49ebc83e7fe0da07b9964c44b0a7fae270cbAnders Carlsson bool NullCheckValue); 765a3697c9c155bda93fd2802f37084b620f4738822Anders Carlsson 766bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson llvm::Value *GetVirtualBaseClassOffset(llvm::Value *This, 767bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *ClassDecl, 768bb7e17b52ffaa4097b4c4d7935746d23539ffe2aAnders Carlsson const CXXRecordDecl *BaseClassDecl); 7692f1986b557fa671c4f8c9dd0d071398edfc073d5Anders Carlsson 7701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue, 771eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian llvm::Value *SrcValue, 772c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian const ArrayType *Array, 773c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian const CXXRecordDecl *BaseClassDecl, 774c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian QualType Ty); 775c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian 7761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitClassAggrCopyAssignment(llvm::Value *DestValue, 777c28bbc2d2271aab6c5d79ef2758604221cd92a4bFariborz Jahanian llvm::Value *SrcValue, 778eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian const ArrayType *Array, 779eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian const CXXRecordDecl *BaseClassDecl, 780eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian QualType Ty); 781eb0b6d556ff2b4a5053e89fd084eb34e44cea14cFariborz Jahanian 782ca28361fb0a72c50e0a400fae2fad9520e61c0a5Fariborz Jahanian void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue, 7831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const CXXRecordDecl *ClassDecl, 784942f4f33d02dba823594bd2d7b3d317cb01c74f8Fariborz Jahanian const CXXRecordDecl *BaseClassDecl, 785942f4f33d02dba823594bd2d7b3d317cb01c74f8Fariborz Jahanian QualType Ty); 7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7870270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian void EmitClassCopyAssignment(llvm::Value *DestValue, llvm::Value *SrcValue, 7881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const CXXRecordDecl *ClassDecl, 7890270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian const CXXRecordDecl *BaseClassDecl, 7900270b8aa3f9b50ec3acd1abfd2b97377a3e1bb05Fariborz Jahanian QualType Ty); 7911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 793b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson llvm::Value *This, 794b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 795b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 7961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 797288dcaf329c49b01dacd5c1dd9f35609555feecdFariborz Jahanian void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 798569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson const ConstantArrayType *ArrayTy, 7995d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 8005d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 8015d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 8025d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson 803569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 804569c1f4a6c703eaa8b963bed7d5c2fd5d4569e93Anders Carlsson llvm::Value *NumElements, 8055d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson llvm::Value *ArrayPtr, 8065d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 8075d4d946ec2d88696fd8422aeb64dc29688e6a2c1Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 808b14095aa98c6fedd3625920c4ce834bcaf24d9f7Anders Carlsson 809f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, 810f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian const ArrayType *Array, 811f800f6c09ed4a71bcb593d6962e0fda2c2845a70Fariborz Jahanian llvm::Value *This); 8121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81372c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, 81472c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian llvm::Value *NumElements, 81572c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian llvm::Value *This); 81672c2153b466263a21870b2b1c817900d4981493eFariborz Jahanian 817dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner llvm::Constant *GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D, 81888f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian const ArrayType *Array, 81988f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian llvm::Value *This); 82088f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian 8217267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 8227267c1693abe7875b0c57268be05005ae013c6c9Anders Carlsson llvm::Value *This); 8231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 824543ac0c4d24a81fb2b7b6e83370aa8e4cbc93054Anders Carlsson void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); 825f4b8fea84a6b1ef74cf8fe572918439e34935e51Anders Carlsson void PopCXXTemporary(); 8261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 827a00703dccbdc6cc4a293db38477dea7db5538c7eAnders Carlsson llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 82860e282cc1e508be327b0481cecedc206873cb86aAnders Carlsson void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 8291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8304bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, 8314bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman QualType DeleteTy); 8324bf8152799ec41796f989ea1b94f6f1bac349117Eli Friedman 833c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); 834c849c052d6b4b70f2651c1969531861a5f230053Mike Stump llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); 835c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump 836b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump void EmitCheck(llvm::Value *, unsigned Size); 837b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 838dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, 839dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 840dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, 841dd36d328730d8c02915d0884541b45ec6ca0049dChris Lattner bool isInc, bool isPre); 8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 846d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// EmitDecl - Emit a declaration. 847d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 848d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 8495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 850d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 8511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// EmitBlockVarDecl - Emit a block variable declaration. 852d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 853d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 854248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitBlockVarDecl(const VarDecl &D); 855d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 856d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// EmitLocalBlockVarDecl - Emit a local block variable declaration. 857d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// 858d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar /// This function can be called with a null (unreachable) insert point. 859248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitLocalBlockVarDecl(const VarDecl &D); 860d286f05f1234bac289173f0eed88d7ecbaea0099Daniel Dunbar 861f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson void EmitStaticBlockVarDecl(const VarDecl &D, 862f6b89a173827457c28ac77b7cf091a24ef484e8aAnders Carlsson llvm::GlobalValue::LinkageTypes Linkage); 863b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 864b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 865b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); 8660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 8705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 8710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 8720912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitStopPoint(const Stmt *S); 8730912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 8740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 8750dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// this function even if there is no current insertion point. 8760dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// 8770dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// This function may clear the current insertion point; callers should use 8780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EnsureInsertPoint if they wish to subsequently generate code without first 8790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// calling EmitBlock, EmitBranch, or EmitStmt. 8805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 881a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 8820912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// EmitSimpleStmt - Try to emit a "simple" statement which does not 8830dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// necessarily require an insertion point or debug information; typically 8840dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// because the statement amounts to a jump or a container of other 8850dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// statements. 8860912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// 8870912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar /// \return True if the statement was handled. 8880912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar bool EmitSimpleStmt(const Stmt *S); 8890912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar 8909b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 8919b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *AggLoc = 0, bool isAggVol = false); 892a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 8930dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitLabel - Emit the block for the given label. It is legal to call this 8940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// function even if there is no current insertion point. 89591d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 896a448fb2da03ece39978784793eea68760e8205a1Daniel Dunbar 8975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 8985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 8990ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 9005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 9035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 9060912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitBreakStmt(const BreakStmt &S); 9070912425f79418a215c2fbd2d8fc9511244a4aa46Daniel Dunbar void EmitContinueStmt(const ContinueStmt &S); 90851b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 90951b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 91051b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 911c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 912fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson void EmitAsmStmt(const AsmStmt &S); 9130dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 9143d8400d9a61aa4b63ff35e5cede405b32a41425eAnders Carlsson void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 91564d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 91664d5d6c5903157c521af496479d06dc26032d718Anders Carlsson void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 91710cac6f7115b59a466bb8d2d51cdddeb38aadc37Chris Lattner void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 9180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 9199fc6a7774643a810c8501dae2323e863fefb623eJohn McCall struct CXXTryStmtInfo { 9209fc6a7774643a810c8501dae2323e863fefb623eJohn McCall llvm::BasicBlock *SavedLandingPad; 9219fc6a7774643a810c8501dae2323e863fefb623eJohn McCall llvm::BasicBlock *HandlerBlock; 9229fc6a7774643a810c8501dae2323e863fefb623eJohn McCall llvm::BasicBlock *FinallyBlock; 9239fc6a7774643a810c8501dae2323e863fefb623eJohn McCall }; 9249fc6a7774643a810c8501dae2323e863fefb623eJohn McCall CXXTryStmtInfo EnterCXXTryStmt(const CXXTryStmt &S); 9259fc6a7774643a810c8501dae2323e863fefb623eJohn McCall void ExitCXXTryStmt(const CXXTryStmt &S, CXXTryStmtInfo Info); 9269fc6a7774643a810c8501dae2323e863fefb623eJohn McCall 9276815e941998659a55c20c147861b0f437928c3d8Anders Carlsson void EmitCXXTryStmt(const CXXTryStmt &S); 9286815e941998659a55c20c147861b0f437928c3d8Anders Carlsson 9295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 9315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 9325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 93313e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 93413e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar RValue GetUndefRValue(QualType Ty); 93513e81737a433b23f8c662d10d1d57356122a8caaDaniel Dunbar 936ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 937ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 938ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar /// provided Name). 939ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar RValue EmitUnsupportedRValue(const Expr *E, 940ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar const char *Name); 941ce1d38b8163650e473d7084e0686ed5a7956057bDaniel Dunbar 9420dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 9430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an ErrorUnsupported style diagnostic (using the provided Name). 9446ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 9456ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 9466ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 9525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 9535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 9595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 9625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 9635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 9640dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 965b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// EmitCheckedLValue - Same as EmitLValue but additionally we generate 966b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// checking code to guard against undefined behavior. This is only 967b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// suitable when we know that the address will be used to access the 968b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump /// object. 969b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump LValue EmitCheckedLValue(const Expr *E); 970b14e62d5aee7522b98c410ee65bd750c2cfe6f01Mike Stump 9719d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitLoadOfScalar - Load a scalar value from an address, taking 9729d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 9739d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 97409429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, 9759d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar QualType Ty); 9769d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 9779d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// EmitStoreOfScalar - Store a scalar value to an address, taking 9789d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// care to appropriately convert from the memory representation to 9799d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar /// the LLVM value representation. 98009429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 981b4aa4664ec851573624a7a29c6c750fc1d5cc268Anders Carlsson bool Volatile, QualType Ty); 9829d9cc874bcc168474757a8f90476684b4a93ed76Daniel Dunbar 9835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 9845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 9855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 9865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitLoadOfLValue(LValue V, QualType LVType); 987213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 9883b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 98985c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); 99043f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); 9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9920dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 9935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 997213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 998213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman QualType Ty); 99985c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); 100043f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); 1001ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar 10020dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue - Store Src into Dst with same constraints as 10030dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitStoreThroughLValue. 1004ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar /// 10050dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// \param Result [out] - If non-null, this will be set to a Value* for the 10060dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// bit-field contents after the store, appropriate for use as the result of 10070dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// an assignment to the bit-field. 1008ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, 1009ed3849b456d64d124bddc7ac044f3ce590bd9d69Daniel Dunbar llvm::Value **Result=0); 10100dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 101122c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb // Note: only availabe for agg return types 101280e62c29fe21cd06c93eba6e72b7e32dca06fcf9Daniel Dunbar LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 10135b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 101422c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 10155b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar // Note: only available for agg return types 10165b5c9ef865607e179413462dcd71bcebb5b7daaeDaniel Dunbar LValue EmitVAArgExprLValue(const VAArgExpr *E); 10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 1019eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 1020662b71ee82339c67f2c3689196e716c6560cf925Daniel Dunbar LValue EmitPredefinedFunctionName(unsigned Type); 1021d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 10225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 10235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 1024213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 1025b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 1026820bca41c3899374775d2a1dfc2ef2e22aaf1c7bFariborz Jahanian LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); 102706e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 10286fcec8b58d0571866fcb162db947b029cc539ec4Anders Carlsson LValue EmitConditionalOperatorLValue(const ConditionalOperator *E); 102975dfedaf702822c9e51a4f3c5d3ecf2d2ad99272Chris Lattner LValue EmitCastLValue(const CastExpr *E); 103048620bafe4ba879f96c2d17caefeb79f3fae2eeaFariborz Jahanian LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E); 1031909fbf70223ea04a5ec8d449789f3683a89701ffAnders Carlsson 10322a03192a02dbf4fdff438d1e658356bde871aba4Daniel Dunbar llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 103329e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar const ObjCIvarDecl *Ivar); 10340ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field, 1035e6d2a534851a649485cb087e9dfcaf8a65886858Anders Carlsson unsigned CVRQualifiers); 103606a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson 103706a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that 103806a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// if the Field is a reference, this will return the address of the reference 103906a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson /// and not the address of the value stored in the reference. 104006a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson LValue EmitLValueForFieldInitialization(llvm::Value* Base, 104106a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson const FieldDecl* Field, 104206a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson unsigned CVRQualifiers); 104306a2970e9480c6d02b367b2f970baff29b9f9721Anders Carlsson 104445012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian LValue EmitLValueForIvar(QualType ObjectTy, 104545012a7ef5abf1042c893f3f2fa5c23cb5485ea9Fariborz Jahanian llvm::Value* Base, const ObjCIvarDecl *Ivar, 104629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar unsigned CVRQualifiers); 104729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 10480ed303c918915cbe2c611cddbfabd00404664831Anders Carlsson LValue EmitLValueForBitfield(llvm::Value* Base, const FieldDecl* Field, 1049598d3f61b6ca854e9d3c2f3359e24468502a61aaFariborz Jahanian unsigned CVRQualifiers); 1050fd64bb635dc221baa19f81d5d2a084f7eb269f7fFariborz Jahanian 1051a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); 1052a99038c0757a836c6faeeddaa5dfd249b32f6e9eMike Stump 1053b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 1054e61c9e80a108b5db7e5f0e702f0e455d737c6390Anders Carlsson LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 1055b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E); 1056c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); 1057b9ea0b53d323cdca2b8284ff986a878e195cb97fAnders Carlsson 10580a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 1059391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 106085c59edda02df48fae8dc85049743319bc6e7e89Daniel Dunbar LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); 106109105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E); 1062654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E); 1063654599454c8e6cc83b1b9b3af43c49c2f66a26cbChris Lattner LValue EmitStmtExprLValue(const StmtExpr *E); 10648bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); 10658bfd31f9dad09cd52225d868bbd92a9bebe87775Fariborz Jahanian 10665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1067883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 10685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 10695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10700dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitCall - Generate a call of the given function, expecting the given 10710dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// result type, and using the given argument list which specifies both the 10720dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// LLVM arguments and the types they were derived from. 1073c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar /// 1074f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// \param TargetDecl - If given, the decl of the function in a direct call; 1075f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// used to set attributes on the call (noreturn, etc.). 107688b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar RValue EmitCall(const CGFunctionInfo &FnInfo, 107788b5396b0897f28d22ae3debf4a0d97b33b6c362Daniel Dunbar llvm::Value *Callee, 1078f3c47c9525153aea2de0ec4bd615b9cf2d81c103Anders Carlsson ReturnValueSlot ReturnValue, 1079c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar const CallArgList &Args, 1080c0ef9f59937c3971c48b6fed37cf5bd8985c024bDaniel Dunbar const Decl *TargetDecl = 0); 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108231777a2540879051a3c643b90e02c3fd3d315243Anders Carlsson RValue EmitCall(QualType FnType, llvm::Value *Callee, 1083d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue, 1084986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgBeg, 1085986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson CallExpr::const_arg_iterator ArgEnd, 1086986477149db76e6d9f8d3c9859c9880c11b680aeAnders Carlsson const Decl *TargetDecl = 0); 1087d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson RValue EmitCallExpr(const CallExpr *E, 1088d2490a91341b57df7a7e54f8a707e7ecde2eeb4eAnders Carlsson ReturnValueSlot ReturnValue = ReturnValueSlot()); 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1090566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, 1091f0070dbae9535836ad41711081465dec2259786bMike Stump const llvm::Type *Ty); 1092566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, 1093566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson llvm::Value *&This, const llvm::Type *Ty); 1094566abee1e9828a7700b51e4d17ea08234fde3bb4Anders Carlsson 1095b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson RValue EmitCXXMemberCall(const CXXMethodDecl *MD, 1096b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *Callee, 1097a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue, 1098b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson llvm::Value *This, 1099c997d4278d329e18891aac9698fb991b2d4622ebAnders Carlsson llvm::Value *VTT, 1100b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 1101b9de2c55b2a33776e2bee8ee57df7599b374c8a5Anders Carlsson CallExpr::const_arg_iterator ArgEnd); 1102a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, 1103a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 1104a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, 1105a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 11065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 11070f294632f36459174199b77699e339715244b5abAnders Carlsson RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 1108a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson const CXXMethodDecl *MD, 1109a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson ReturnValueSlot ReturnValue); 11101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1111375c31c4673f83f925de221752cf801c2fbbb246Anders Carlsson 11121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RValue EmitBuiltinExpr(const FunctionDecl *FD, 1113ef2abfee3ea16ec74942dc09e9e425f46aeb2582Daniel Dunbar unsigned BuiltinID, const CallExpr *E); 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1115a1736c0c750d4514a5d8fda36670addf1e4de54aAnders Carlsson RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); 111609429b962811f2c0a7a81a1b0a89f96f5878b20cMike Stump 11170dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 11180dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is unhandled by the current target. 1119f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 1120f02e9ddf5efc75917af712b3c7f909581205f0a5Daniel Dunbar 1121564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 1122564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 11230dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1124ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 11257f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 11268fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 11278f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); 11285daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian RValue EmitObjCPropertyGet(const Expr *E); 1129f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S); 113043f447098d5e6162fbfb97ed38365284207a7fbeFariborz Jahanian void EmitObjCPropertySet(const Expr *E, RValue Src); 1131f469557743f77918d2ca8226e2ee2888998ffd4aFariborz Jahanian void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src); 11328fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 11338fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 11344029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in 11354029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6Anders Carlsson /// expression. Will emit a temporary variable if E is not an LValue. 1136a64a869312066ff6119d1d7ae03f88ce499e3f82Anders Carlsson RValue EmitReferenceBindingToExpr(const Expr* E, bool IsInitializer = false); 11373aba09376c5f49c4c8d176109ea4835bc2c528eeAnders Carlsson 1138883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 1139bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 1140883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 1141bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 1142bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 11430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11440dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 11450dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// scalar type, returning the result. 114614c5cbf59cffee52275230922283a247de407712Anders Carlsson llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 11470dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11483707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 11493707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 11503707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 11513707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 11520dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11534f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 11540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// complex type to the specified destination type, where the destination type 11550dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// is an LLVM scalar type. 11564f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 11574f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 11580dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 11590dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1160883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// EmitAggExpr - Emit the computation of the specified expression of 1161883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// aggregate type. The result is computed into DestPtr. Note that if 1162883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// DestPtr is null, the value of the aggregate expression is not needed. 116349d1cd5a09ed3df353371fd7f206674a85e0fb45Mike Stump void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest, 116408c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian bool IgnoreResult = false, bool IsInitializer = false, 116508c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian bool RequiresGCollection = false); 11660dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 116718aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// EmitAggExprToLValue - Emit the computation of the specified expression of 116818aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar /// aggregate type into a temporary LValue. 116918aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar LValue EmitAggExprToLValue(const Expr *E); 117018aba0dd518e486d8b50523e7dafb4b5657135d2Daniel Dunbar 1171082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// EmitGCMemmoveCollectable - Emit special API for structs with object 1172082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian /// pointers. 1173082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, 117408c321380fff07d476a19daab6d29522c046cd49Fariborz Jahanian QualType Ty); 1175082b02e8403d3ee9d2ded969fbe0e5d472f04cd8Fariborz Jahanian 1176b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 117723b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 11787f79f9be5916c51c35da4f126b7c12596a101607Mike Stump ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, 11797f79f9be5916c51c35da4f126b7c12596a101607Mike Stump bool IgnoreImag = false, 11807f79f9be5916c51c35da4f126b7c12596a101607Mike Stump bool IgnoreRealAssign = false, 11817f79f9be5916c51c35da4f126b7c12596a101607Mike Stump bool IgnoreImagAssign = false); 11820dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 118323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 118423b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// of complex type, storing into the specified Value*. 1185190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 1186190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner bool DestIsVolatile); 11877f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar 11887f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar /// StoreComplexToAddr - Store a complex number into the specified address. 11897f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, 11907f8ea5c5b3a6a4332a841eefdd86b0726722ea7bDaniel Dunbar bool DestIsVolatile); 11919b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// LoadComplexFromAddr - Load a complex number from the specified address. 11929b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 11932621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 1194f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global for a 1195f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// static block var decl. 1196761acc19d966a67f2175783d09412d6ac9463400Chris Lattner llvm::GlobalVariable *CreateStaticBlockVarDecl(const VarDecl &D, 1197761acc19d966a67f2175783d09412d6ac9463400Chris Lattner const char *Separator, 1198f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump llvm::GlobalValue::LinkageTypes Linkage); 1199761acc19d966a67f2175783d09412d6ac9463400Chris Lattner 1200761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// AddInitializerToGlobalBlockVarDecl - Add the initializer for 'D' to the 1201761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// global variable that has already been created for it. If the initializer 1202761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// has a different type than GV does, this may free GV and return a different 1203761acc19d966a67f2175783d09412d6ac9463400Chris Lattner /// one. Otherwise it just returns GV. 1204761acc19d966a67f2175783d09412d6ac9463400Chris Lattner llvm::GlobalVariable * 1205761acc19d966a67f2175783d09412d6ac9463400Chris Lattner AddInitializerToGlobalBlockVarDecl(const VarDecl &D, 1206761acc19d966a67f2175783d09412d6ac9463400Chris Lattner llvm::GlobalVariable *GV); 1207761acc19d966a67f2175783d09412d6ac9463400Chris Lattner 12080096acf421c4609ce7f43e8b05f8c5ca866d4611Daniel Dunbar 1209f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ runtime 1210f71d232ce5354bd2f0c94ded30fb936c2a3d968bMike Stump /// initialized static block var decl. 12113b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson void EmitStaticCXXBlockVarDeclInit(const VarDecl &D, 12123b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson llvm::GlobalVariable *GV); 1213e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson 12143b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 12153b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// variable with global storage. 12163b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); 12173b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson 12183b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr 12193b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson /// with the C++ runtime so that its destructor will be called at exit. 122088f4280f6b60edcbdea6a38a3da8b17d66473ad6Fariborz Jahanian void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn, 12213b2e16b3d25f6b311dba2871e2a566c96238c3d2Anders Carlsson llvm::Constant *DeclPtr); 12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// GenerateCXXGlobalInitFunc - Generates code for initializing global 122489ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson /// variables. 122589ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 12266c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman llvm::Constant **Decls, 122789ed31d3f9eeb8ec77c284a5cf404a74bf5e7acfAnders Carlsson unsigned NumDecls); 12281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12296c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D); 12306c6bda3b0b1d8adaac2ba3f4da7056e9f1eef52eEli Friedman 123131ccf377f4a676eb6c205b47eef435de616d5e2dAnders Carlsson void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1233b58d017f2b9eeed33f2ab3ede968b89cf5296bf2Anders Carlsson RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, 12341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::Value *AggLoc = 0, 123514c5cbf59cffee52275230922283a247de407712Anders Carlsson bool IsAggLocVolatile = false, 123614c5cbf59cffee52275230922283a247de407712Anders Carlsson bool IsInitializer = false); 12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1238756b5c4f9d52642d87d1948bee58f97a4f795b24Anders Carlsson void EmitCXXThrowExpr(const CXXThrowExpr *E); 1239c2e84ae9a6d25cea3e583c768e576b4c981ec028Mike Stump 12400ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 12410ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 12420ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 12430dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 12440946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// ContainsLabel - Return true if the statement contains a label in it. If 12450946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// this statement is not executed normally, it not containing a label means 12460946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner /// that we can just remove the code. 12470946ccd1e58c1f1da31ddbca67c5b6301ac8b255Chris Lattner static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 12480dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 12494bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 125031a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// to a constant, or if it does but contains a label, return 0. If it 125131a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// constant folds to 'true' and does not contain a label, return 1, if it 125231a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// constant folds to 'false' and does not contain a label, return -1. 125331a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner int ConstantFoldsToSimpleInteger(const Expr *Cond); 12540dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 125531a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 125631a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// if statement) to the specified blocks. Based on the condition, this might 125731a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattner /// try to simplify the codegen of the conditional based on the branch. 12589bc47e29dce8f095be7a6d07dbb02a5a7a112949Chris Lattner void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 12594bc0455d826e9634b7a68c0d06146edd633c9453Daniel Dunbar llvm::BasicBlock *FalseBlock); 1260be07f60131bc6f8d6696f4644df1ef667a1730d5Mike Stump 126115037caa1542bb810ad54c653aeb80f61df7b00cMike Stump /// getTrapBB - Create a basic block that will call the trap intrinsic. We'll 126215037caa1542bb810ad54c653aeb80f61df7b00cMike Stump /// generate a branch around the created basic block as necessary. 126315037caa1542bb810ad54c653aeb80f61df7b00cMike Stump llvm::BasicBlock* getTrapBB(); 126431a0984b5cb4af99d2407c0f25bf5af68df681c6Chris Lattnerprivate: 12650dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 126629e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar void EmitReturnOfRValue(RValue RV, QualType Ty); 126729e0bccf2bcce22b877f8b2ed173f564c116b97eDaniel Dunbar 12685627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 12695627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 12705627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// 12715627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \param AI - The first function argument of the expansion. 12725627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// \return The argument following the last expanded function 12735627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar /// argument. 12740dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump llvm::Function::arg_iterator 12755627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar ExpandTypeFromArgs(QualType Ty, LValue Dst, 12765627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::Function::arg_iterator AI); 12775627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar 12780dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg 12790dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// Ty, into individual arguments on the provided vector \arg Args. See 12800dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump /// ABIArgInfo::Expand. 12810dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump void ExpandTypeToArgs(QualType Ty, RValue Src, 12825627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar llvm::SmallVector<llvm::Value*, 16> &Args); 1283c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::Value* EmitAsmInput(const AsmStmt &S, 1285b84e8a670ad1d00c0a34295c42ac700cdde04815Daniel Dunbar const TargetInfo::ConstraintInfo &Info, 1286c8c7b187adcd989e01a9fba1ebead6c2abd770c9Anders Carlsson const Expr *InputExpr, std::string &ConstraintStr); 12870dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 1288c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson /// EmitCleanupBlock - emits a single cleanup block. 1289c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson void EmitCleanupBlock(); 1290c71c845fe77ee1f891d60232ec320912d88557eeAnders Carlsson 129187eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// AddBranchFixup - adds a branch instruction to the list of fixups for the 129287eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson /// current cleanup scope. 129387eaf17cc88516277e4389dfa15df93ecfdce559Anders Carlsson void AddBranchFixup(llvm::BranchInst *BI); 12940dd9e88aa972d80025c66fb3d7df0266b44cad1aMike Stump 12950139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson /// EmitCallArg - Emit a single call argument. 12960139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson RValue EmitCallArg(const Expr *E, QualType ArgType); 12971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12980139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson /// EmitCallArgs - Emit call arguments for a function. 12991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// The CallArgTypeInfo parameter is used for iterating over the known 1300af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson /// argument types of the function being called. 1301af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson template<typename T> 1302af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, 13030139bb96494b4c4ba0824617d5d2495dc7e44c76Anders Carlsson CallExpr::const_arg_iterator ArgBeg, 1304af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator ArgEnd) { 1305af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson CallExpr::const_arg_iterator Arg = ArgBeg; 1306af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 1307af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // First, use the argument types that the type info knows about 1308af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson if (CallArgTypeInfo) { 1309af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), 1310af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { 131144b0a3e858af7b19f489619e52cd58970611cd15Eli Friedman assert(Arg != ArgEnd && "Running over edge of argument list!"); 1312af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson QualType ArgType = *I; 1313af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 1314af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getTypePtr() == 13161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getContext().getCanonicalType(Arg->getType()).getTypePtr() && 1317af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "type mismatch in call argument!"); 13181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1320af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson ArgType)); 1321af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 13221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Either we've emitted all the call args, or we have a call to a 1324af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // variadic function. 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && 1326af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson "Extra arguments in non-variadic function!"); 13271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1328af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1330af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson // If we still have any arguments, emit them using the type of the argument. 1331af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson for (; Arg != ArgEnd; ++Arg) { 1332af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson QualType ArgType = Arg->getType(); 1333af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1334af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson ArgType)); 1335af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 1336af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson } 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1339af23f69aa6247e6bd20a66b2e16babb91f192535Anders Carlsson 13405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 13425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1344