CodeGenFunction.h revision c2e84ae9a6d25cea3e583c768e576b4c981ec028
1//===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This is the internal per-function state used for llvm translation. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef CLANG_CODEGEN_CODEGENFUNCTION_H 15#define CLANG_CODEGEN_CODEGENFUNCTION_H 16 17#include "clang/AST/Type.h" 18#include "clang/AST/ExprCXX.h" 19#include "clang/AST/ExprObjC.h" 20#include "clang/Basic/TargetInfo.h" 21#include "llvm/ADT/DenseMap.h" 22#include "llvm/ADT/SmallVector.h" 23#include "llvm/Support/ValueHandle.h" 24#include <map> 25#include "CodeGenModule.h" 26#include "CGBlocks.h" 27#include "CGBuilder.h" 28#include "CGCall.h" 29#include "CGCXX.h" 30#include "CGValue.h" 31 32namespace llvm { 33 class BasicBlock; 34 class LLVMContext; 35 class Module; 36 class SwitchInst; 37 class Twine; 38 class Value; 39} 40 41namespace clang { 42 class ASTContext; 43 class CXXDestructorDecl; 44 class CXXTryStmt; 45 class Decl; 46 class EnumConstantDecl; 47 class FunctionDecl; 48 class FunctionProtoType; 49 class LabelStmt; 50 class ObjCContainerDecl; 51 class ObjCInterfaceDecl; 52 class ObjCIvarDecl; 53 class ObjCMethodDecl; 54 class ObjCImplementationDecl; 55 class ObjCPropertyImplDecl; 56 class TargetInfo; 57 class VarDecl; 58 class ObjCForCollectionStmt; 59 class ObjCAtTryStmt; 60 class ObjCAtThrowStmt; 61 class ObjCAtSynchronizedStmt; 62 63namespace CodeGen { 64 class CodeGenModule; 65 class CodeGenTypes; 66 class CGDebugInfo; 67 class CGFunctionInfo; 68 class CGRecordLayout; 69 70/// CodeGenFunction - This class organizes the per-function state that is used 71/// while generating LLVM code. 72class CodeGenFunction : public BlockFunction { 73 CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT 74 void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT 75public: 76 CodeGenModule &CGM; // Per-module state. 77 const TargetInfo &Target; 78 79 typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; 80 CGBuilderTy Builder; 81 82 /// CurFuncDecl - Holds the Decl for the current function or ObjC method. 83 /// This excludes BlockDecls. 84 const Decl *CurFuncDecl; 85 /// CurCodeDecl - This is the inner-most code context, which includes blocks. 86 const Decl *CurCodeDecl; 87 const CGFunctionInfo *CurFnInfo; 88 QualType FnRetTy; 89 llvm::Function *CurFn; 90 91 /// ReturnBlock - Unified return block. 92 llvm::BasicBlock *ReturnBlock; 93 /// ReturnValue - The temporary alloca to hold the return value. This is null 94 /// iff the function has no return value. 95 llvm::Instruction *ReturnValue; 96 97 /// AllocaInsertPoint - This is an instruction in the entry block before which 98 /// we prefer to insert allocas. 99 llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; 100 101 const llvm::Type *LLVMIntTy; 102 uint32_t LLVMPointerWidth; 103 104public: 105 /// ObjCEHValueStack - Stack of Objective-C exception values, used for 106 /// rethrows. 107 llvm::SmallVector<llvm::Value*, 8> ObjCEHValueStack; 108 109 /// PushCleanupBlock - Push a new cleanup entry on the stack and set the 110 /// passed in block as the cleanup block. 111 void PushCleanupBlock(llvm::BasicBlock *CleanupEntryBlock, 112 llvm::BasicBlock *CleanupExitBlock = 0); 113 114 /// CleanupBlockInfo - A struct representing a popped cleanup block. 115 struct CleanupBlockInfo { 116 /// CleanupEntryBlock - the cleanup entry block 117 llvm::BasicBlock *CleanupBlock; 118 119 /// SwitchBlock - the block (if any) containing the switch instruction used 120 /// for jumping to the final destination. 121 llvm::BasicBlock *SwitchBlock; 122 123 /// EndBlock - the default destination for the switch instruction. 124 llvm::BasicBlock *EndBlock; 125 126 CleanupBlockInfo(llvm::BasicBlock *cb, llvm::BasicBlock *sb, 127 llvm::BasicBlock *eb) 128 : CleanupBlock(cb), SwitchBlock(sb), EndBlock(eb) {} 129 }; 130 131 /// PopCleanupBlock - Will pop the cleanup entry on the stack, process all 132 /// branch fixups and return a block info struct with the switch block and end 133 /// block. 134 CleanupBlockInfo PopCleanupBlock(); 135 136 /// CleanupScope - RAII object that will create a cleanup block and set the 137 /// insert point to that block. When destructed, it sets the insert point to 138 /// the previous block and pushes a new cleanup entry on the stack. 139 class CleanupScope { 140 CodeGenFunction& CGF; 141 llvm::BasicBlock *CurBB; 142 llvm::BasicBlock *CleanupEntryBB; 143 llvm::BasicBlock *CleanupExitBB; 144 145 public: 146 CleanupScope(CodeGenFunction &cgf) 147 : CGF(cgf), CurBB(CGF.Builder.GetInsertBlock()), 148 CleanupEntryBB(CGF.createBasicBlock("cleanup")), CleanupExitBB(0) { 149 CGF.Builder.SetInsertPoint(CleanupEntryBB); 150 } 151 152 llvm::BasicBlock *getCleanupExitBlock() { 153 if (!CleanupExitBB) 154 CleanupExitBB = CGF.createBasicBlock("cleanup.exit"); 155 return CleanupExitBB; 156 } 157 158 ~CleanupScope() { 159 CGF.PushCleanupBlock(CleanupEntryBB, CleanupExitBB); 160 // FIXME: This is silly, move this into the builder. 161 if (CurBB) 162 CGF.Builder.SetInsertPoint(CurBB); 163 else 164 CGF.Builder.ClearInsertionPoint(); 165 } 166 }; 167 168 /// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup 169 /// blocks that have been added. 170 void EmitCleanupBlocks(size_t OldCleanupStackSize); 171 172 /// EmitBranchThroughCleanup - Emit a branch from the current insert block 173 /// through the cleanup handling code (if any) and then on to \arg Dest. 174 /// 175 /// FIXME: Maybe this should really be in EmitBranch? Don't we always want 176 /// this behavior for branches? 177 void EmitBranchThroughCleanup(llvm::BasicBlock *Dest); 178 179 /// PushConditionalTempDestruction - Should be called before a conditional 180 /// part of an expression is emitted. For example, before the RHS of the 181 /// expression below is emitted: 182 /// 183 /// b && f(T()); 184 /// 185 /// This is used to make sure that any temporaryes created in the conditional 186 /// branch are only destroyed if the branch is taken. 187 void PushConditionalTempDestruction(); 188 189 /// PopConditionalTempDestruction - Should be called after a conditional 190 /// part of an expression has been emitted. 191 void PopConditionalTempDestruction(); 192 193private: 194 CGDebugInfo *DebugInfo; 195 196 /// IndirectBranch - The first time an indirect goto is seen we create a 197 /// block with an indirect branch. Every time we see the address of a label 198 /// taken, we add the label to the indirect goto. Every subsequent indirect 199 /// goto is codegen'd as a jump to the IndirectBranch's basic block. 200 llvm::IndirectBrInst *IndirectBranch; 201 202 /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C 203 /// decls. 204 llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap; 205 206 /// LabelMap - This keeps track of the LLVM basic block for each C label. 207 llvm::DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap; 208 209 // BreakContinueStack - This keeps track of where break and continue 210 // statements should jump to. 211 struct BreakContinue { 212 BreakContinue(llvm::BasicBlock *bb, llvm::BasicBlock *cb) 213 : BreakBlock(bb), ContinueBlock(cb) {} 214 215 llvm::BasicBlock *BreakBlock; 216 llvm::BasicBlock *ContinueBlock; 217 }; 218 llvm::SmallVector<BreakContinue, 8> BreakContinueStack; 219 220 /// SwitchInsn - This is nearest current switch instruction. It is null if if 221 /// current context is not in a switch. 222 llvm::SwitchInst *SwitchInsn; 223 224 /// CaseRangeBlock - This block holds if condition check for last case 225 /// statement range in current switch instruction. 226 llvm::BasicBlock *CaseRangeBlock; 227 228 /// InvokeDest - This is the nearest exception target for calls 229 /// which can unwind, when exceptions are being used. 230 llvm::BasicBlock *InvokeDest; 231 232 // VLASizeMap - This keeps track of the associated size for each VLA type. 233 // We track this by the size expression rather than the type itself because 234 // in certain situations, like a const qualifier applied to an VLA typedef, 235 // multiple VLA types can share the same size expression. 236 // FIXME: Maybe this could be a stack of maps that is pushed/popped as we 237 // enter/leave scopes. 238 llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; 239 240 /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid 241 /// calling llvm.stacksave for multiple VLAs in the same scope. 242 bool DidCallStackSave; 243 244 struct CleanupEntry { 245 /// CleanupEntryBlock - The block of code that does the actual cleanup. 246 llvm::BasicBlock *CleanupEntryBlock; 247 248 /// CleanupExitBlock - The cleanup exit block. 249 llvm::BasicBlock *CleanupExitBlock; 250 251 /// Blocks - Basic blocks that were emitted in the current cleanup scope. 252 std::vector<llvm::BasicBlock *> Blocks; 253 254 /// BranchFixups - Branch instructions to basic blocks that haven't been 255 /// inserted into the current function yet. 256 std::vector<llvm::BranchInst *> BranchFixups; 257 258 explicit CleanupEntry(llvm::BasicBlock *CleanupEntryBlock, 259 llvm::BasicBlock *CleanupExitBlock) 260 : CleanupEntryBlock(CleanupEntryBlock), 261 CleanupExitBlock(CleanupExitBlock) {} 262 }; 263 264 /// CleanupEntries - Stack of cleanup entries. 265 llvm::SmallVector<CleanupEntry, 8> CleanupEntries; 266 267 typedef llvm::DenseMap<llvm::BasicBlock*, size_t> BlockScopeMap; 268 269 /// BlockScopes - Map of which "cleanup scope" scope basic blocks have. 270 BlockScopeMap BlockScopes; 271 272 /// CXXThisDecl - When parsing an C++ function, this will hold the implicit 273 /// 'this' declaration. 274 ImplicitParamDecl *CXXThisDecl; 275 276 /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary. 277 struct CXXLiveTemporaryInfo { 278 /// Temporary - The live temporary. 279 const CXXTemporary *Temporary; 280 281 /// ThisPtr - The pointer to the temporary. 282 llvm::Value *ThisPtr; 283 284 /// DtorBlock - The destructor block. 285 llvm::BasicBlock *DtorBlock; 286 287 /// CondPtr - If this is a conditional temporary, this is the pointer to 288 /// the condition variable that states whether the destructor should be 289 /// called or not. 290 llvm::Value *CondPtr; 291 292 CXXLiveTemporaryInfo(const CXXTemporary *temporary, 293 llvm::Value *thisptr, llvm::BasicBlock *dtorblock, 294 llvm::Value *condptr) 295 : Temporary(temporary), ThisPtr(thisptr), DtorBlock(dtorblock), 296 CondPtr(condptr) { } 297 }; 298 299 llvm::SmallVector<CXXLiveTemporaryInfo, 4> LiveTemporaries; 300 301 /// ConditionalTempDestructionStack - Contains the number of live temporaries 302 /// when PushConditionalTempDestruction was called. This is used so that 303 /// we know how many temporaries were created by a certain expression. 304 llvm::SmallVector<size_t, 4> ConditionalTempDestructionStack; 305 306 307 /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM 308 /// type as well as the field number that contains the actual data. 309 llvm::DenseMap<const ValueDecl *, std::pair<const llvm::Type *, 310 unsigned> > ByRefValueInfo; 311 312 /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field 313 /// number that holds the value. 314 unsigned getByRefValueLLVMField(const ValueDecl *VD) const; 315 316public: 317 CodeGenFunction(CodeGenModule &cgm); 318 319 ASTContext &getContext() const; 320 CGDebugInfo *getDebugInfo() { return DebugInfo; } 321 322 llvm::BasicBlock *getInvokeDest() { return InvokeDest; } 323 void setInvokeDest(llvm::BasicBlock *B) { InvokeDest = B; } 324 325 llvm::LLVMContext &getLLVMContext() { return VMContext; } 326 327 //===--------------------------------------------------------------------===// 328 // Objective-C 329 //===--------------------------------------------------------------------===// 330 331 void GenerateObjCMethod(const ObjCMethodDecl *OMD); 332 333 void StartObjCMethod(const ObjCMethodDecl *MD, 334 const ObjCContainerDecl *CD); 335 336 /// GenerateObjCGetter - Synthesize an Objective-C property getter function. 337 void GenerateObjCGetter(ObjCImplementationDecl *IMP, 338 const ObjCPropertyImplDecl *PID); 339 340 /// GenerateObjCSetter - Synthesize an Objective-C property setter function 341 /// for the given property. 342 void GenerateObjCSetter(ObjCImplementationDecl *IMP, 343 const ObjCPropertyImplDecl *PID); 344 345 //===--------------------------------------------------------------------===// 346 // Block Bits 347 //===--------------------------------------------------------------------===// 348 349 llvm::Value *BuildBlockLiteralTmp(const BlockExpr *); 350 llvm::Constant *BuildDescriptorBlockDecl(bool BlockHasCopyDispose, 351 uint64_t Size, 352 const llvm::StructType *, 353 std::vector<HelperInfo> *); 354 355 llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr, 356 const BlockInfo& Info, 357 const Decl *OuterFuncDecl, 358 llvm::DenseMap<const Decl*, llvm::Value*> ldm, 359 uint64_t &Size, uint64_t &Align, 360 llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls, 361 bool &subBlockHasCopyDispose); 362 363 void BlockForwardSelf(); 364 llvm::Value *LoadBlockStruct(); 365 366 uint64_t AllocateBlockDecl(const BlockDeclRefExpr *E); 367 llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E); 368 const llvm::Type *BuildByRefType(const ValueDecl *D); 369 370 void GenerateCode(GlobalDecl GD, llvm::Function *Fn); 371 void StartFunction(GlobalDecl GD, QualType RetTy, 372 llvm::Function *Fn, 373 const FunctionArgList &Args, 374 SourceLocation StartLoc); 375 376 /// EmitReturnBlock - Emit the unified return block, trying to avoid its 377 /// emission when possible. 378 void EmitReturnBlock(); 379 380 /// FinishFunction - Complete IR generation of the current function. It is 381 /// legal to call this function even if there is no current insertion point. 382 void FinishFunction(SourceLocation EndLoc=SourceLocation()); 383 384 /// DynamicTypeAdjust - Do the non-virtual and virtual adjustments on an 385 /// object pointer to alter the dynamic type of the pointer. Used by 386 /// GenerateCovariantThunk for building thunks. 387 llvm::Value *DynamicTypeAdjust(llvm::Value *V, int64_t nv, int64_t v); 388 389 /// GenerateThunk - Generate a thunk for the given method 390 llvm::Constant *GenerateThunk(llvm::Function *Fn, const CXXMethodDecl *MD, 391 bool Extern, int64_t nv, int64_t v); 392 llvm::Constant *GenerateCovariantThunk(llvm::Function *Fn, 393 const CXXMethodDecl *MD, bool Extern, 394 int64_t nv_t, int64_t v_t, 395 int64_t nv_r, int64_t v_r); 396 397 void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type); 398 399 void SynthesizeCXXCopyConstructor(const CXXConstructorDecl *Ctor, 400 CXXCtorType Type, 401 llvm::Function *Fn, 402 const FunctionArgList &Args); 403 404 void SynthesizeCXXCopyAssignment(const CXXMethodDecl *CD, 405 llvm::Function *Fn, 406 const FunctionArgList &Args); 407 408 void SynthesizeDefaultConstructor(const CXXConstructorDecl *Ctor, 409 CXXCtorType Type, 410 llvm::Function *Fn, 411 const FunctionArgList &Args); 412 413 void SynthesizeDefaultDestructor(const CXXDestructorDecl *Dtor, 414 CXXDtorType Type, 415 llvm::Function *Fn, 416 const FunctionArgList &Args); 417 418 /// EmitDtorEpilogue - Emit all code that comes at the end of class's 419 /// destructor. This is to call destructors on members and base classes 420 /// in reverse order of their construction. 421 void EmitDtorEpilogue(const CXXDestructorDecl *Dtor, 422 CXXDtorType Type); 423 424 /// EmitFunctionProlog - Emit the target specific LLVM code to load the 425 /// arguments for the given function. This is also responsible for naming the 426 /// LLVM function arguments. 427 void EmitFunctionProlog(const CGFunctionInfo &FI, 428 llvm::Function *Fn, 429 const FunctionArgList &Args); 430 431 /// EmitFunctionEpilog - Emit the target specific LLVM code to return the 432 /// given temporary. 433 void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue); 434 435 const llvm::Type *ConvertTypeForMem(QualType T); 436 const llvm::Type *ConvertType(QualType T); 437 438 /// LoadObjCSelf - Load the value of self. This function is only valid while 439 /// generating code for an Objective-C method. 440 llvm::Value *LoadObjCSelf(); 441 442 /// TypeOfSelfObject - Return type of object that this self represents. 443 QualType TypeOfSelfObject(); 444 445 /// hasAggregateLLVMType - Return true if the specified AST type will map into 446 /// an aggregate LLVM type or is void. 447 static bool hasAggregateLLVMType(QualType T); 448 449 /// createBasicBlock - Create an LLVM basic block. 450 llvm::BasicBlock *createBasicBlock(const char *Name="", 451 llvm::Function *Parent=0, 452 llvm::BasicBlock *InsertBefore=0) { 453#ifdef NDEBUG 454 return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore); 455#else 456 return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore); 457#endif 458 } 459 460 /// getBasicBlockForLabel - Return the LLVM basicblock that the specified 461 /// label maps to. 462 llvm::BasicBlock *getBasicBlockForLabel(const LabelStmt *S); 463 464 /// SimplifyForwardingBlocks - If the given basic block is only a 465 /// branch to another basic block, simplify it. This assumes that no 466 /// other code could potentially reference the basic block. 467 void SimplifyForwardingBlocks(llvm::BasicBlock *BB); 468 469 /// EmitBlock - Emit the given block \arg BB and set it as the insert point, 470 /// adding a fall-through branch from the current insert block if 471 /// necessary. It is legal to call this function even if there is no current 472 /// insertion point. 473 /// 474 /// IsFinished - If true, indicates that the caller has finished emitting 475 /// branches to the given block and does not expect to emit code into it. This 476 /// means the block can be ignored if it is unreachable. 477 void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); 478 479 /// EmitBranch - Emit a branch to the specified basic block from the current 480 /// insert block, taking care to avoid creation of branches from dummy 481 /// blocks. It is legal to call this function even if there is no current 482 /// insertion point. 483 /// 484 /// This function clears the current insertion point. The caller should follow 485 /// calls to this function with calls to Emit*Block prior to generation new 486 /// code. 487 void EmitBranch(llvm::BasicBlock *Block); 488 489 /// HaveInsertPoint - True if an insertion point is defined. If not, this 490 /// indicates that the current code being emitted is unreachable. 491 bool HaveInsertPoint() const { 492 return Builder.GetInsertBlock() != 0; 493 } 494 495 /// EnsureInsertPoint - Ensure that an insertion point is defined so that 496 /// emitted IR has a place to go. Note that by definition, if this function 497 /// creates a block then that block is unreachable; callers may do better to 498 /// detect when no insertion point is defined and simply skip IR generation. 499 void EnsureInsertPoint() { 500 if (!HaveInsertPoint()) 501 EmitBlock(createBasicBlock()); 502 } 503 504 /// ErrorUnsupported - Print out an error that codegen doesn't support the 505 /// specified stmt yet. 506 void ErrorUnsupported(const Stmt *S, const char *Type, 507 bool OmitOnError=false); 508 509 //===--------------------------------------------------------------------===// 510 // Helpers 511 //===--------------------------------------------------------------------===// 512 513 Qualifiers MakeQualifiers(QualType T) { 514 Qualifiers Quals = getContext().getCanonicalType(T).getQualifiers(); 515 Quals.setObjCGCAttr(getContext().getObjCGCAttrKind(T)); 516 return Quals; 517 } 518 519 /// CreateTempAlloca - This creates a alloca and inserts it into the entry 520 /// block. 521 llvm::AllocaInst *CreateTempAlloca(const llvm::Type *Ty, 522 const llvm::Twine &Name = "tmp"); 523 524 /// EvaluateExprAsBool - Perform the usual unary conversions on the specified 525 /// expression and compare the result against zero, returning an Int1Ty value. 526 llvm::Value *EvaluateExprAsBool(const Expr *E); 527 528 /// EmitAnyExpr - Emit code to compute the specified expression which can have 529 /// any type. The result is returned as an RValue struct. If this is an 530 /// aggregate expression, the aggloc/agglocvolatile arguments indicate where 531 /// the result should be returned. 532 /// 533 /// \param IgnoreResult - True if the resulting value isn't used. 534 RValue EmitAnyExpr(const Expr *E, llvm::Value *AggLoc = 0, 535 bool IsAggLocVolatile = false, bool IgnoreResult = false, 536 bool IsInitializer = false); 537 538 // EmitVAListRef - Emit a "reference" to a va_list; this is either the address 539 // or the value of the expression, depending on how va_list is defined. 540 llvm::Value *EmitVAListRef(const Expr *E); 541 542 /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will 543 /// always be accessible even if no aggregate location is provided. 544 RValue EmitAnyExprToTemp(const Expr *E, bool IsAggLocVolatile = false, 545 bool IsInitializer = false); 546 547 /// EmitAggregateCopy - Emit an aggrate copy. 548 /// 549 /// \param isVolatile - True iff either the source or the destination is 550 /// volatile. 551 void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, 552 QualType EltTy, bool isVolatile=false); 553 554 void EmitAggregateClear(llvm::Value *DestPtr, QualType Ty); 555 556 /// StartBlock - Start new block named N. If insert block is a dummy block 557 /// then reuse it. 558 void StartBlock(const char *N); 559 560 /// GetAddrOfStaticLocalVar - Return the address of a static local variable. 561 llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD); 562 563 /// GetAddrOfLocalVar - Return the address of a local variable. 564 llvm::Value *GetAddrOfLocalVar(const VarDecl *VD); 565 566 /// getAccessedFieldNo - Given an encoded value and a result number, return 567 /// the input field number being accessed. 568 static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); 569 570 llvm::BlockAddress *GetAddrOfLabel(const LabelStmt *L); 571 llvm::BasicBlock *GetIndirectGotoBlock(); 572 573 /// EmitMemSetToZero - Generate code to memset a value of the given type to 0. 574 void EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty); 575 576 // EmitVAArg - Generate code to get an argument from the passed in pointer 577 // and update it accordingly. The return value is a pointer to the argument. 578 // FIXME: We should be able to get rid of this method and use the va_arg 579 // instruction in LLVM instead once it works well enough. 580 llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); 581 582 // EmitVLASize - Generate code for any VLA size expressions that might occur 583 // in a variably modified type. If Ty is a VLA, will return the value that 584 // corresponds to the size in bytes of the VLA type. Will return 0 otherwise. 585 /// 586 /// This function can be called with a null (unreachable) insert point. 587 llvm::Value *EmitVLASize(QualType Ty); 588 589 // GetVLASize - Returns an LLVM value that corresponds to the size in bytes 590 // of a variable length array type. 591 llvm::Value *GetVLASize(const VariableArrayType *); 592 593 /// LoadCXXThis - Load the value of 'this'. This function is only valid while 594 /// generating code for an C++ member function. 595 llvm::Value *LoadCXXThis(); 596 597 /// GetAddressCXXOfBaseClass - This function will add the necessary delta 598 /// to the load of 'this' and returns address of the base class. 599 // FIXME. This currently only does a derived to non-virtual base conversion. 600 // Other kinds of conversions will come later. 601 llvm::Value *GetAddressCXXOfBaseClass(llvm::Value *BaseValue, 602 const CXXRecordDecl *ClassDecl, 603 const CXXRecordDecl *BaseClassDecl, 604 bool NullCheckValue); 605 606 llvm::Value * 607 GetVirtualCXXBaseClassOffset(llvm::Value *This, 608 const CXXRecordDecl *ClassDecl, 609 const CXXRecordDecl *BaseClassDecl); 610 611 void EmitClassAggrMemberwiseCopy(llvm::Value *DestValue, 612 llvm::Value *SrcValue, 613 const ArrayType *Array, 614 const CXXRecordDecl *BaseClassDecl, 615 QualType Ty); 616 617 void EmitClassAggrCopyAssignment(llvm::Value *DestValue, 618 llvm::Value *SrcValue, 619 const ArrayType *Array, 620 const CXXRecordDecl *BaseClassDecl, 621 QualType Ty); 622 623 void EmitClassMemberwiseCopy(llvm::Value *DestValue, llvm::Value *SrcValue, 624 const CXXRecordDecl *ClassDecl, 625 const CXXRecordDecl *BaseClassDecl, 626 QualType Ty); 627 628 void EmitClassCopyAssignment(llvm::Value *DestValue, llvm::Value *SrcValue, 629 const CXXRecordDecl *ClassDecl, 630 const CXXRecordDecl *BaseClassDecl, 631 QualType Ty); 632 633 void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, 634 llvm::Value *This, 635 CallExpr::const_arg_iterator ArgBeg, 636 CallExpr::const_arg_iterator ArgEnd); 637 638 void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 639 const ConstantArrayType *ArrayTy, 640 llvm::Value *ArrayPtr); 641 void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, 642 llvm::Value *NumElements, 643 llvm::Value *ArrayPtr); 644 645 void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, 646 const ArrayType *Array, 647 llvm::Value *This); 648 649 void EmitCXXAggrDestructorCall(const CXXDestructorDecl *D, 650 llvm::Value *NumElements, 651 llvm::Value *This); 652 653 llvm::Constant * GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D, 654 const ArrayType *Array, 655 llvm::Value *This); 656 657 void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, 658 llvm::Value *This); 659 660 void PushCXXTemporary(const CXXTemporary *Temporary, llvm::Value *Ptr); 661 void PopCXXTemporary(); 662 663 llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); 664 void EmitCXXDeleteExpr(const CXXDeleteExpr *E); 665 666 llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); 667 668 //===--------------------------------------------------------------------===// 669 // Declaration Emission 670 //===--------------------------------------------------------------------===// 671 672 /// EmitDecl - Emit a declaration. 673 /// 674 /// This function can be called with a null (unreachable) insert point. 675 void EmitDecl(const Decl &D); 676 677 /// EmitBlockVarDecl - Emit a block variable declaration. 678 /// 679 /// This function can be called with a null (unreachable) insert point. 680 void EmitBlockVarDecl(const VarDecl &D); 681 682 /// EmitLocalBlockVarDecl - Emit a local block variable declaration. 683 /// 684 /// This function can be called with a null (unreachable) insert point. 685 void EmitLocalBlockVarDecl(const VarDecl &D); 686 687 void EmitStaticBlockVarDecl(const VarDecl &D); 688 689 /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. 690 void EmitParmDecl(const VarDecl &D, llvm::Value *Arg); 691 692 //===--------------------------------------------------------------------===// 693 // Statement Emission 694 //===--------------------------------------------------------------------===// 695 696 /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. 697 void EmitStopPoint(const Stmt *S); 698 699 /// EmitStmt - Emit the code for the statement \arg S. It is legal to call 700 /// this function even if there is no current insertion point. 701 /// 702 /// This function may clear the current insertion point; callers should use 703 /// EnsureInsertPoint if they wish to subsequently generate code without first 704 /// calling EmitBlock, EmitBranch, or EmitStmt. 705 void EmitStmt(const Stmt *S); 706 707 /// EmitSimpleStmt - Try to emit a "simple" statement which does not 708 /// necessarily require an insertion point or debug information; typically 709 /// because the statement amounts to a jump or a container of other 710 /// statements. 711 /// 712 /// \return True if the statement was handled. 713 bool EmitSimpleStmt(const Stmt *S); 714 715 RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, 716 llvm::Value *AggLoc = 0, bool isAggVol = false); 717 718 /// EmitLabel - Emit the block for the given label. It is legal to call this 719 /// function even if there is no current insertion point. 720 void EmitLabel(const LabelStmt &S); // helper for EmitLabelStmt. 721 722 void EmitLabelStmt(const LabelStmt &S); 723 void EmitGotoStmt(const GotoStmt &S); 724 void EmitIndirectGotoStmt(const IndirectGotoStmt &S); 725 void EmitIfStmt(const IfStmt &S); 726 void EmitWhileStmt(const WhileStmt &S); 727 void EmitDoStmt(const DoStmt &S); 728 void EmitForStmt(const ForStmt &S); 729 void EmitReturnStmt(const ReturnStmt &S); 730 void EmitDeclStmt(const DeclStmt &S); 731 void EmitBreakStmt(const BreakStmt &S); 732 void EmitContinueStmt(const ContinueStmt &S); 733 void EmitSwitchStmt(const SwitchStmt &S); 734 void EmitDefaultStmt(const DefaultStmt &S); 735 void EmitCaseStmt(const CaseStmt &S); 736 void EmitCaseStmtRange(const CaseStmt &S); 737 void EmitAsmStmt(const AsmStmt &S); 738 739 void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); 740 void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); 741 void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); 742 void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); 743 744 void EmitCXXTryStmt(const CXXTryStmt &S); 745 746 //===--------------------------------------------------------------------===// 747 // LValue Expression Emission 748 //===--------------------------------------------------------------------===// 749 750 /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. 751 RValue GetUndefRValue(QualType Ty); 752 753 /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E 754 /// and issue an ErrorUnsupported style diagnostic (using the 755 /// provided Name). 756 RValue EmitUnsupportedRValue(const Expr *E, 757 const char *Name); 758 759 /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue 760 /// an ErrorUnsupported style diagnostic (using the provided Name). 761 LValue EmitUnsupportedLValue(const Expr *E, 762 const char *Name); 763 764 /// EmitLValue - Emit code to compute a designator that specifies the location 765 /// of the expression. 766 /// 767 /// This can return one of two things: a simple address or a bitfield 768 /// reference. In either case, the LLVM Value* in the LValue structure is 769 /// guaranteed to be an LLVM pointer type. 770 /// 771 /// If this returns a bitfield reference, nothing about the pointee type of 772 /// the LLVM value is known: For example, it may not be a pointer to an 773 /// integer. 774 /// 775 /// If this returns a normal address, and if the lvalue's C type is fixed 776 /// size, this method guarantees that the returned pointer type will point to 777 /// an LLVM type of the same size of the lvalue's type. If the lvalue has a 778 /// variable length type, this is not possible. 779 /// 780 LValue EmitLValue(const Expr *E); 781 782 /// EmitLoadOfScalar - Load a scalar value from an address, taking 783 /// care to appropriately convert from the memory representation to 784 /// the LLVM value representation. 785 llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, 786 QualType Ty); 787 788 /// EmitStoreOfScalar - Store a scalar value to an address, taking 789 /// care to appropriately convert from the memory representation to 790 /// the LLVM value representation. 791 void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, 792 bool Volatile, QualType Ty); 793 794 /// EmitLoadOfLValue - Given an expression that represents a value lvalue, 795 /// this method emits the address of the lvalue, then loads the result as an 796 /// rvalue, returning the rvalue. 797 RValue EmitLoadOfLValue(LValue V, QualType LVType); 798 RValue EmitLoadOfExtVectorElementLValue(LValue V, QualType LVType); 799 RValue EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType); 800 RValue EmitLoadOfPropertyRefLValue(LValue LV, QualType ExprType); 801 RValue EmitLoadOfKVCRefLValue(LValue LV, QualType ExprType); 802 803 804 /// EmitStoreThroughLValue - Store the specified rvalue into the specified 805 /// lvalue, where both are guaranteed to the have the same type, and that type 806 /// is 'Ty'. 807 void EmitStoreThroughLValue(RValue Src, LValue Dst, QualType Ty); 808 void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst, 809 QualType Ty); 810 void EmitStoreThroughPropertyRefLValue(RValue Src, LValue Dst, QualType Ty); 811 void EmitStoreThroughKVCRefLValue(RValue Src, LValue Dst, QualType Ty); 812 813 /// EmitStoreThroughLValue - Store Src into Dst with same constraints as 814 /// EmitStoreThroughLValue. 815 /// 816 /// \param Result [out] - If non-null, this will be set to a Value* for the 817 /// bit-field contents after the store, appropriate for use as the result of 818 /// an assignment to the bit-field. 819 void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, 820 llvm::Value **Result=0); 821 822 // Note: only availabe for agg return types 823 LValue EmitBinaryOperatorLValue(const BinaryOperator *E); 824 // Note: only available for agg return types 825 LValue EmitCallExprLValue(const CallExpr *E); 826 // Note: only available for agg return types 827 LValue EmitVAArgExprLValue(const VAArgExpr *E); 828 LValue EmitDeclRefLValue(const DeclRefExpr *E); 829 LValue EmitStringLiteralLValue(const StringLiteral *E); 830 LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); 831 LValue EmitPredefinedFunctionName(unsigned Type); 832 LValue EmitPredefinedLValue(const PredefinedExpr *E); 833 LValue EmitUnaryOpLValue(const UnaryOperator *E); 834 LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); 835 LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); 836 LValue EmitMemberExpr(const MemberExpr *E); 837 LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); 838 LValue EmitConditionalOperatorLValue(const ConditionalOperator *E); 839 LValue EmitCastLValue(const CastExpr *E); 840 LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E); 841 842 LValue EmitPointerToDataMemberLValue(const FieldDecl *Field); 843 844 llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, 845 const ObjCIvarDecl *Ivar); 846 LValue EmitLValueForField(llvm::Value* Base, FieldDecl* Field, 847 bool isUnion, unsigned CVRQualifiers); 848 LValue EmitLValueForIvar(QualType ObjectTy, 849 llvm::Value* Base, const ObjCIvarDecl *Ivar, 850 unsigned CVRQualifiers); 851 852 LValue EmitLValueForBitfield(llvm::Value* Base, FieldDecl* Field, 853 unsigned CVRQualifiers); 854 855 LValue EmitBlockDeclRefLValue(const BlockDeclRefExpr *E); 856 857 LValue EmitCXXConditionDeclLValue(const CXXConditionDeclExpr *E); 858 LValue EmitCXXConstructLValue(const CXXConstructExpr *E); 859 LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); 860 LValue EmitCXXExprWithTemporariesLValue(const CXXExprWithTemporaries *E); 861 LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); 862 863 LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); 864 LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); 865 LValue EmitObjCPropertyRefLValue(const ObjCPropertyRefExpr *E); 866 LValue EmitObjCKVCRefLValue(const ObjCImplicitSetterGetterRefExpr *E); 867 LValue EmitObjCSuperExprLValue(const ObjCSuperExpr *E); 868 LValue EmitStmtExprLValue(const StmtExpr *E); 869 LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); 870 871 //===--------------------------------------------------------------------===// 872 // Scalar Expression Emission 873 //===--------------------------------------------------------------------===// 874 875 /// EmitCall - Generate a call of the given function, expecting the given 876 /// result type, and using the given argument list which specifies both the 877 /// LLVM arguments and the types they were derived from. 878 /// 879 /// \param TargetDecl - If given, the decl of the function in a 880 /// direct call; used to set attributes on the call (noreturn, 881 /// etc.). 882 RValue EmitCall(const CGFunctionInfo &FnInfo, 883 llvm::Value *Callee, 884 const CallArgList &Args, 885 const Decl *TargetDecl = 0); 886 887 RValue EmitCall(llvm::Value *Callee, QualType FnType, 888 CallExpr::const_arg_iterator ArgBeg, 889 CallExpr::const_arg_iterator ArgEnd, 890 const Decl *TargetDecl = 0); 891 RValue EmitCallExpr(const CallExpr *E); 892 893 llvm::Value *BuildVirtualCall(const CXXMethodDecl *MD, llvm::Value *This, 894 const llvm::Type *Ty); 895 llvm::Value *BuildVirtualCall(const CXXDestructorDecl *DD, CXXDtorType Type, 896 llvm::Value *&This, const llvm::Type *Ty); 897 898 RValue EmitCXXMemberCall(const CXXMethodDecl *MD, 899 llvm::Value *Callee, 900 llvm::Value *This, 901 CallExpr::const_arg_iterator ArgBeg, 902 CallExpr::const_arg_iterator ArgEnd); 903 RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E); 904 RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E); 905 906 RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, 907 const CXXMethodDecl *MD); 908 909 910 RValue EmitBuiltinExpr(const FunctionDecl *FD, 911 unsigned BuiltinID, const CallExpr *E); 912 913 RValue EmitBlockCallExpr(const CallExpr *E); 914 915 /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call 916 /// is unhandled by the current target. 917 llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 918 919 llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); 920 llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); 921 922 llvm::Value *EmitShuffleVector(llvm::Value* V1, llvm::Value *V2, ...); 923 llvm::Value *EmitVector(llvm::Value * const *Vals, unsigned NumVals, 924 bool isSplat = false); 925 926 llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); 927 llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); 928 llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); 929 RValue EmitObjCMessageExpr(const ObjCMessageExpr *E); 930 RValue EmitObjCPropertyGet(const Expr *E); 931 RValue EmitObjCSuperPropertyGet(const Expr *Exp, const Selector &S); 932 void EmitObjCPropertySet(const Expr *E, RValue Src); 933 void EmitObjCSuperPropertySet(const Expr *E, const Selector &S, RValue Src); 934 935 936 /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in 937 /// expression. Will emit a temporary variable if E is not an LValue. 938 RValue EmitReferenceBindingToExpr(const Expr* E, QualType DestType, 939 bool IsInitializer = false); 940 941 //===--------------------------------------------------------------------===// 942 // Expression Emission 943 //===--------------------------------------------------------------------===// 944 945 // Expressions are broken into three classes: scalar, complex, aggregate. 946 947 /// EmitScalarExpr - Emit the computation of the specified expression of LLVM 948 /// scalar type, returning the result. 949 llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); 950 951 /// EmitScalarConversion - Emit a conversion from the specified type to the 952 /// specified destination type, both of which are LLVM scalar types. 953 llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, 954 QualType DstTy); 955 956 /// EmitComplexToScalarConversion - Emit a conversion from the specified 957 /// complex type to the specified destination type, where the destination type 958 /// is an LLVM scalar type. 959 llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, 960 QualType DstTy); 961 962 963 /// EmitAggExpr - Emit the computation of the specified expression of 964 /// aggregate type. The result is computed into DestPtr. Note that if 965 /// DestPtr is null, the value of the aggregate expression is not needed. 966 void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest, 967 bool IgnoreResult = false, bool IsInitializer = false, 968 bool RequiresGCollection = false); 969 970 /// EmitGCMemmoveCollectable - Emit special API for structs with object 971 /// pointers. 972 void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, 973 QualType Ty); 974 975 /// EmitComplexExpr - Emit the computation of the specified expression of 976 /// complex type, returning the result. 977 ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, 978 bool IgnoreImag = false, 979 bool IgnoreRealAssign = false, 980 bool IgnoreImagAssign = false); 981 982 /// EmitComplexExprIntoAddr - Emit the computation of the specified expression 983 /// of complex type, storing into the specified Value*. 984 void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr, 985 bool DestIsVolatile); 986 987 /// StoreComplexToAddr - Store a complex number into the specified address. 988 void StoreComplexToAddr(ComplexPairTy V, llvm::Value *DestAddr, 989 bool DestIsVolatile); 990 /// LoadComplexFromAddr - Load a complex number from the specified address. 991 ComplexPairTy LoadComplexFromAddr(llvm::Value *SrcAddr, bool SrcIsVolatile); 992 993 /// CreateStaticBlockVarDecl - Create a zero-initialized LLVM global 994 /// for a static block var decl. 995 llvm::GlobalVariable * CreateStaticBlockVarDecl(const VarDecl &D, 996 const char *Separator, 997 llvm::GlobalValue::LinkageTypes 998 Linkage); 999 1000 /// EmitStaticCXXBlockVarDeclInit - Create the initializer for a C++ 1001 /// runtime initialized static block var decl. 1002 void EmitStaticCXXBlockVarDeclInit(const VarDecl &D, 1003 llvm::GlobalVariable *GV); 1004 1005 /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ 1006 /// variable with global storage. 1007 void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr); 1008 1009 /// EmitCXXGlobalDtorRegistration - Emits a call to register the global ptr 1010 /// with the C++ runtime so that its destructor will be called at exit. 1011 void EmitCXXGlobalDtorRegistration(llvm::Constant *DtorFn, 1012 llvm::Constant *DeclPtr); 1013 1014 /// GenerateCXXGlobalInitFunc - Generates code for initializing global 1015 /// variables. 1016 void GenerateCXXGlobalInitFunc(llvm::Function *Fn, 1017 const VarDecl **Decls, 1018 unsigned NumDecls); 1019 1020 void EmitCXXConstructExpr(llvm::Value *Dest, const CXXConstructExpr *E); 1021 1022 RValue EmitCXXExprWithTemporaries(const CXXExprWithTemporaries *E, 1023 llvm::Value *AggLoc = 0, 1024 bool IsAggLocVolatile = false, 1025 bool IsInitializer = false); 1026 1027 void EmitCXXThrowExpr(const CXXThrowExpr *E); 1028 1029 //===--------------------------------------------------------------------===// 1030 // Internal Helpers 1031 //===--------------------------------------------------------------------===// 1032 1033 /// ContainsLabel - Return true if the statement contains a label in it. If 1034 /// this statement is not executed normally, it not containing a label means 1035 /// that we can just remove the code. 1036 static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); 1037 1038 /// ConstantFoldsToSimpleInteger - If the specified expression does not fold 1039 /// to a constant, or if it does but contains a label, return 0. If it 1040 /// constant folds to 'true' and does not contain a label, return 1, if it 1041 /// constant folds to 'false' and does not contain a label, return -1. 1042 int ConstantFoldsToSimpleInteger(const Expr *Cond); 1043 1044 /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an 1045 /// if statement) to the specified blocks. Based on the condition, this might 1046 /// try to simplify the codegen of the conditional based on the branch. 1047 void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, 1048 llvm::BasicBlock *FalseBlock); 1049private: 1050 1051 void EmitReturnOfRValue(RValue RV, QualType Ty); 1052 1053 /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty 1054 /// from function arguments into \arg Dst. See ABIArgInfo::Expand. 1055 /// 1056 /// \param AI - The first function argument of the expansion. 1057 /// \return The argument following the last expanded function 1058 /// argument. 1059 llvm::Function::arg_iterator 1060 ExpandTypeFromArgs(QualType Ty, LValue Dst, 1061 llvm::Function::arg_iterator AI); 1062 1063 /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg 1064 /// Ty, into individual arguments on the provided vector \arg Args. See 1065 /// ABIArgInfo::Expand. 1066 void ExpandTypeToArgs(QualType Ty, RValue Src, 1067 llvm::SmallVector<llvm::Value*, 16> &Args); 1068 1069 llvm::Value* EmitAsmInput(const AsmStmt &S, 1070 const TargetInfo::ConstraintInfo &Info, 1071 const Expr *InputExpr, std::string &ConstraintStr); 1072 1073 /// EmitCleanupBlock - emits a single cleanup block. 1074 void EmitCleanupBlock(); 1075 1076 /// AddBranchFixup - adds a branch instruction to the list of fixups for the 1077 /// current cleanup scope. 1078 void AddBranchFixup(llvm::BranchInst *BI); 1079 1080 /// EmitCallArg - Emit a single call argument. 1081 RValue EmitCallArg(const Expr *E, QualType ArgType); 1082 1083 /// EmitCallArgs - Emit call arguments for a function. 1084 /// The CallArgTypeInfo parameter is used for iterating over the known 1085 /// argument types of the function being called. 1086 template<typename T> 1087 void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, 1088 CallExpr::const_arg_iterator ArgBeg, 1089 CallExpr::const_arg_iterator ArgEnd) { 1090 CallExpr::const_arg_iterator Arg = ArgBeg; 1091 1092 // First, use the argument types that the type info knows about 1093 if (CallArgTypeInfo) { 1094 for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), 1095 E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { 1096 QualType ArgType = *I; 1097 1098 assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). 1099 getTypePtr() == 1100 getContext().getCanonicalType(Arg->getType()).getTypePtr() && 1101 "type mismatch in call argument!"); 1102 1103 Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1104 ArgType)); 1105 } 1106 1107 // Either we've emitted all the call args, or we have a call to a 1108 // variadic function. 1109 assert((Arg == ArgEnd || CallArgTypeInfo->isVariadic()) && 1110 "Extra arguments in non-variadic function!"); 1111 1112 } 1113 1114 // If we still have any arguments, emit them using the type of the argument. 1115 for (; Arg != ArgEnd; ++Arg) { 1116 QualType ArgType = Arg->getType(); 1117 Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 1118 ArgType)); 1119 } 1120 } 1121}; 1122 1123 1124} // end namespace CodeGen 1125} // end namespace clang 1126 1127#endif 1128