CodeGenFunction.h revision 9c3fc703b29a31d40bcf5027dbb4784dd393804e
1bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This is the internal per-function state used for llvm translation. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENFUNCTION_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 17391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner#include "clang/AST/Type.h" 185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "llvm/ADT/DenseMap.h" 19da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner#include "llvm/ADT/SmallVector.h" 2050b36741673258aaebcd3c7fe1260031901cae57Chris Lattner#include "llvm/Support/IRBuilder.h" 215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/Expr.h" 225549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek#include "clang/AST/ExprObjC.h" 235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector> 250ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar#include <map> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 278f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar#include "CGValue.h" 288f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm { 30c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class BasicBlock; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Module; 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class ASTContext; 365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class Decl; 37c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class EnumConstantDecl; 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class FunctionDecl; 39c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class FunctionTypeProto; 40c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class LabelStmt; 41391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner class ObjCMethodDecl; 42af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar class ObjCPropertyImplDecl; 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class TargetInfo; 44c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar class VarDecl; 455549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen { 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer class CodeGenModule; 48b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel class CodeGenTypes; 4988a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel class CGRecordLayout; 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenFunction - This class organizes the per-function state that is used 525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while generating LLVM code. 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenFunction { 54bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattnerpublic: 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenModule &CGM; // Per-module state. 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer TargetInfo &Target; 57bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 5858dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 5985e356825b291f86c6e926638914222b834b71a3Chris Lattner llvm::IRBuilder<> Builder; 605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 61c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner // Holds the Decl for the current function or method 624111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner const Decl *CurFuncDecl; 63391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner QualType FnRetTy; 645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Function *CurFn; 655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// AllocaInsertPoint - This is an instruction in the entry block before which 675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// we prefer to insert allocas. 685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Instruction *AllocaInsertPt; 690ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *LLVMIntTy; 717b66000bdfc2684351fb03208e672f23012ed569Hartmut Kaiser uint32_t LLVMPointerWidth; 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 737f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattnerprivate: 740ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// LabelIDs - Track arbitrary ids assigned to labels for use in 750ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// implementing the GCC address-of-label extension and indirect 760ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// goto. IDs are assigned to labels inside getIDForAddrOfLabel(). 770ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::map<const LabelStmt*, unsigned> LabelIDs; 780ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 790ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// IndirectSwitches - Record the list of switches for indirect 800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// gotos. Emission of the actual switching code needs to be delayed 810ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// until all AddrLabelExprs have been seen. 820ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar std::vector<llvm::SwitchInst*> IndirectSwitches; 830ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// decls. 865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LabelMap - This keeps track of the LLVM basic block for each C label. 895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 90da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 91da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner // BreakContinueStack - This keeps track of where break and continue 92da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner // statements should jump to. 93da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner struct BreakContinue { 94da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) 95da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner : BreakBlock(bb), ContinueBlock(cb) {} 96da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 97da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *BreakBlock; 98da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::BasicBlock *ContinueBlock; 99da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner }; 100da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 101da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner 10280fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// SwitchInsn - This is nearest current switch instruction. It is null if 10380fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// if current context is not in a switch. 10451b09f2c528c8460b5465c676173324e44176d62Devang Patel llvm::SwitchInst *SwitchInsn; 10551b09f2c528c8460b5465c676173324e44176d62Devang Patel 10680fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// CaseRangeBlock - This block holds if condition check for last case 10780fd5f96e6805ac43aab99faabd5b4c8b19551b7Devang Patel /// statement range in current switch instruction. 108c049e4f406a7f7179eba98659044a32508e53289Devang Patel llvm::BasicBlock *CaseRangeBlock; 109c049e4f406a7f7179eba98659044a32508e53289Devang Patel 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CodeGenFunction(CodeGenModule &cgm); 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ASTContext &getContext() const; 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 115391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner void GenerateObjCMethod(const ObjCMethodDecl *OMD); 116af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 117af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void StartObjCMethod(const ObjCMethodDecl *MD); 118af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 119af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// GenerateObjCGetter - Synthesize an Objective-C property getter 120af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// function. 121af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void GenerateObjCGetter(const ObjCPropertyImplDecl *PID); 122af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 123af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// GenerateObjCSetter - Synthesize an Objective-C property setter 124af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar /// function for the given property. 125af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void GenerateObjCSetter(const ObjCPropertyImplDecl *PID); 126af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar 127bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar void GenerateCode(const FunctionDecl *FD, 128bd012ff1fa088181646a784f385b28867372d434Daniel Dunbar llvm::Function *Fn); 129af05bb9073319d8381b71c4325188853fd4b8ed6Daniel Dunbar void FinishFunction(SourceLocation EndLoc=SourceLocation()); 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const llvm::Type *ConvertType(QualType T); 132c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner 133b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// LoadObjCSelf - Load the value of self. This function is only 134b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// valid while generating code for an Objective-C method. 135c8aa5f1f264fb230c38182adab944232bb160c2bChris Lattner llvm::Value *LoadObjCSelf(); 1364111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 1374111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// isObjCPointerType - Return true if the specificed AST type will map onto 1384111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner /// some Objective-C pointer type. 1394111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner static bool isObjCPointerType(QualType T); 1404111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// hasAggregateLLVMType - Return true if the specified AST type will map into 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an aggregate LLVM type or is void. 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static bool hasAggregateLLVMType(QualType T); 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// label maps to. 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitBlock(llvm::BasicBlock *BB); 151dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner 152488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar /// ErrorUnsupported - Print out an error that codegen doesn't support the 153dc5e8268292046114ffe02e48773572a91a310f1Chris Lattner /// specified stmt yet. 154488e993a135ce700b982bf099c3d6b856301d642Daniel Dunbar void ErrorUnsupported(const Stmt *S, const char *Type); 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helpers 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// CreateTempAlloca - This creates a alloca and inserts it into the entry 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// block. 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *Name = "tmp"); 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// expression and compare the result against zero, returning an Int1Ty value. 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::Value *EvaluateExprAsBool(const Expr *E); 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1699b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// EmitAnyExpr - Emit code to compute the specified expression which can have 1709b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// any type. The result is returned as an RValue struct. If this is an 1719b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 1729b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// the result should be returned. 1739b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 1749b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner bool isAggLocVolatile = false); 175d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 176d9363c3a80168283b3da518b4e17f545a6246857Devang Patel /// isDummyBlock - Return true if BB is an empty basic block 177d9363c3a80168283b3da518b4e17f545a6246857Devang Patel /// with no predecessors. 178d9363c3a80168283b3da518b4e17f545a6246857Devang Patel static bool isDummyBlock(const llvm::BasicBlock *BB); 179d9363c3a80168283b3da518b4e17f545a6246857Devang Patel 18051b09f2c528c8460b5465c676173324e44176d62Devang Patel /// StartBlock - Start new block named N. If insert block is a dummy block 18151b09f2c528c8460b5465c676173324e44176d62Devang Patel /// then reuse it. 18251b09f2c528c8460b5465c676173324e44176d62Devang Patel void StartBlock(const char *N); 18351b09f2c528c8460b5465c676173324e44176d62Devang Patel 18488a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel /// getCGRecordLayout - Return record layout info. 18588a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy); 186813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio 187813733577d33ec56479667b49e1bff42dc6bba90Lauro Ramos Venancio /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 188248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 1894f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1904f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// getAccessedFieldNo - Given an encoded value and a result number, return 1914f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman /// the input field number being accessed. 1924f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 1934f8d123e3e2c260de3377208106ddba87cee28b4Dan Gohman 1940ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar unsigned GetIDForAddrOfLabel(const LabelStmt *L); 1950ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Declaration Emission 1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDecl(const Decl &D); 2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitEnumConstantDecl(const EnumConstantDecl &D); 202248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitBlockVarDecl(const VarDecl &D); 203248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitLocalBlockVarDecl(const VarDecl &D); 204248a753f6b670692523c99afaeb8fe98f7ae3ca7Steve Naroff void EmitStaticBlockVarDecl(const VarDecl &D); 205b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar 206b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 207b7ec246872b412f0e7bb9e93eacfd78cfa6adfb3Daniel Dunbar void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Statement Emission 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStmt(const Stmt *S); 2149b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 2159b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner llvm::Value *AggLoc = 0, bool isAggVol = false); 21691d723da7b68be5245c3ac58aa2a36d04658cfb8Chris Lattner void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitLabelStmt(const LabelStmt &S); 2185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitGotoStmt(const GotoStmt &S); 2190ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 2205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitIfStmt(const IfStmt &S); 2215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitWhileStmt(const WhileStmt &S); 2225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDoStmt(const DoStmt &S); 2235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitForStmt(const ForStmt &S); 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitReturnStmt(const ReturnStmt &S); 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitDeclStmt(const DeclStmt &S); 226da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner void EmitBreakStmt(); 227da13870e99fe33934b2122f06528a5063f78ae4cChris Lattner void EmitContinueStmt(); 22851b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitSwitchStmt(const SwitchStmt &S); 22951b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitDefaultStmt(const DefaultStmt &S); 23051b09f2c528c8460b5465c676173324e44176d62Devang Patel void EmitCaseStmt(const CaseStmt &S); 231c049e4f406a7f7179eba98659044a32508e53289Devang Patel void EmitCaseStmtRange(const CaseStmt &S); 232fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson void EmitAsmStmt(const AsmStmt &S); 233fb1aeb804c08d5288a923fb278161783e6abdc66Anders Carlsson 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // LValue Expression Emission 2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2386ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E 2396ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// and issue an ErrorUnsupported style diagnostic (using the 2406ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar /// provided Name). 2416ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar LValue EmitUnsupportedLValue(const Expr *E, 2426ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar const char *Name); 2436ba82a4a4b295e54cf192c3e98b28f39990c6194Daniel Dunbar 2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLValue - Emit code to compute a designator that specifies the location 2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// of the expression. 2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// This can return one of two things: a simple address or a bitfield 2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// reference. In either case, the LLVM Value* in the LValue structure is 2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// guaranteed to be an LLVM pointer type. 2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a bitfield reference, nothing about the pointee type of 2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// the LLVM value is known: For example, it may not be a pointer to an 2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// integer. 2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If this returns a normal address, and if the lvalue's C type is fixed 2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// size, this method guarantees that the returned pointer type will point to 2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// variable length type, this is not possible. 2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitLValue(const Expr *E); 2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// this method emits the address of the lvalue, then loads the result as an 2645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// rvalue, returning the rvalue. 2655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitLoadOfLValue(LValue V, QualType LVType); 266213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 2673b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancio RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 2685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26934cdc86af5b0a54084a512a1b2643365b8f5bdd2Chris Lattner 2705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// EmitStoreThroughLValue - Store the specified rvalue into the specified 2715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// lvalue, where both are guaranteed to the have the same type, and that type 2725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// is 'Ty'. 2735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 274213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 275213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman QualType Ty); 276a0c5d0eacede0f67ce46707263ddf4d8de0df706Lauro Ramos Venancio void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty); 27722c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb 27822c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb // Note: only availabe for agg return types 27922c940ee588a420cd2e6c8f68be2ac3cc80061ffChristopher Lamb LValue EmitCallExprLValue(const CallExpr *E); 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitDeclRefLValue(const DeclRefExpr *E); 2825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitStringLiteralLValue(const StringLiteral *E); 283d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner LValue EmitPredefinedLValue(const PredefinedExpr *E); 2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitUnaryOpLValue(const UnaryOperator *E); 2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 286213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 287b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel LValue EmitMemberExpr(const MemberExpr *E); 28806e863f2902b8ba55b056308875c19f7ba3dab25Eli Friedman LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 289472778eb4fce241721c563280886e98389bc7219Eli Friedman 290472778eb4fce241721c563280886e98389bc7219Eli Friedman LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, 2911e692ace08959399794363e77499b73da5494af9Eli Friedman bool isUnion, unsigned CVRQualifiers); 292391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner 2930a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 294391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 2950a04d77bde7e3a661c2b41b60630d125d09ed6efDaniel Dunbar 2965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 297883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner // Scalar Expression Emission 2985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 2995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RValue EmitCallExpr(const CallExpr *E); 3015549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 3025549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek RValue EmitCallExpr(Expr *FnExpr, CallExpr::const_arg_iterator ArgBeg, 3035549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 3045549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 3055193b8a3e57c4f696161aeddfe8227c294c0a7feEli Friedman RValue EmitCallExpr(llvm::Value *Callee, QualType FnType, 3065549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgBeg, 3075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek CallExpr::const_arg_iterator ArgEnd); 3085549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek 3098f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar RValue EmitCallExprExt(llvm::Value *Callee, 3108f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar QualType ResultType, 3118f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar CallExpr::const_arg_iterator ArgBeg, 3128f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar CallExpr::const_arg_iterator ArgEnd, 3138f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar llvm::Value **ExtraArgs, 3148f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar unsigned NumExtraArgs); 3158f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar 3161e4d21ea5849637c49fd4222b09c4b5dedff7765Chris Lattner RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 3175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 318564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 319564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 320564f1de67d7ba43646b8740db86d6269e3dfbe0bAnders Carlsson 321cc23acae84c6d5c37b4805edbcd95ee5d821c400Anders Carlsson llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); 3224119d1aeca8016654d381ce079864058d1709571Nate Begeman llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, 3234119d1aeca8016654d381ce079864058d1709571Nate Begeman bool isSplat = false); 3246086bbd1799e22e75561c3d31dc9b923f0508fa5Anders Carlsson 325ed7c618f849e2541b1d0288c43154937652c5b15Daniel Dunbar llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 3267f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 3278fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 3288f2926b73ed635afecd020da787af6a837601a2bDaniel Dunbar RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); 3299c3fc703b29a31d40bcf5027dbb4784dd393804eDaniel Dunbar RValue EmitObjCPropertyGet(const ObjCPropertyRefExpr *E); 3308fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 3318fdf32822be2238aa7db62d40e75b168b637ab7dChris Lattner 332883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 333bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expression Emission 334883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner //===--------------------------------------------------------------------===// 335bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner 336bfc0c1ae4b505b52b36f572a9641f99e76879cabChris Lattner // Expressions are broken into three classes: scalar, complex, aggregate. 337883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner 3387f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// EmitScalarExpr - Emit the computation of the specified expression of 3397f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner /// LLVM scalar type, returning the result. 3407f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner llvm::Value *EmitScalarExpr(const Expr *E); 3417f02f721d48772e4eee4fccd8af4f800be1bbc1eChris Lattner 3423707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// EmitScalarConversion - Emit a conversion from the specified type to the 3433707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner /// specified destination type, both of which are LLVM scalar types. 3443707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 3453707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner QualType DstTy); 3463707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 3474f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// EmitComplexToScalarConversion - Emit a conversion from the specified 3484f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// complex type to the specified destination type, where the destination 3494f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner /// type is an LLVM scalar type. 3504f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 3514f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner QualType DstTy); 3524f1a7b380809b4ca19ad2daff61bc11cd1e979d8Chris Lattner 3533707b255f8993fb362904c9cff87b0e9bc6ca317Chris Lattner 354883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// EmitAggExpr - Emit the computation of the specified expression of 355883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// aggregate type. The result is computed into DestPtr. Note that if 356883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner /// DestPtr is null, the value of the aggregate expression is not needed. 357883f6a7cc7dccb1d675e27121a82614d63492a8dChris Lattner void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest); 358b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner 359b6ef18a2b06d6760459e1756a61f79ff496cee19Chris Lattner /// EmitComplexExpr - Emit the computation of the specified expression of 36023b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// complex type, returning the result. 36158dee10ed2eee34035f62d1c2d32b3639e9182f8Chris Lattner ComplexPairTy EmitComplexExpr(const Expr *E); 36223b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner 36323b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 36423b1cdb0b5e089468bb8475b8ec9287af67b4b59Chris Lattner /// of complex type, storing into the specified Value*. 365190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 366190dbe203c2e892ac40f1786035c6c9be3f44a4cChris Lattner bool DestIsVolatile); 3679b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner /// LoadComplexFromAddr - Load a complex number from the specified address. 3689b65551d0b387a7597fb39356a4d8ef10046445eChris Lattner ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 3692621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner 3702621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// GenerateStaticBlockVarDecl - return the the static 3712621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner /// declaration of local variable. 3722621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner llvm::GlobalValue *GenerateStaticBlockVarDecl(const VarDecl &D, 3732621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner bool NoInit, 3742621fd1d6d3c5eadcae246859f62738645df7540Chris Lattner const char *Separator); 3750ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 376e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson // GenerateStaticBlockVarDecl - return the static declaration of 377e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson // a local variable. Performs initialization of the variable if necessary. 378e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson llvm::GlobalValue *GenerateStaticCXXBlockVarDecl(const VarDecl &D); 379e1b29efab32d02e114046d33cca242a88585bf8aAnders Carlsson 3800ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 3810ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar // Internal Helpers 3820ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar //===--------------------------------------------------------------------===// 3830ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar 3840ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbarprivate: 3850ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// EmitIndirectSwitches - Emit code for all of the switch 3860ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar /// instructions in IndirectSwitches. 3870ffb125996336fc7602b162c0a9e392f1a93060fDaniel Dunbar void EmitIndirectSwitches(); 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace CodeGen 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 3915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 393