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