llvm.org GIT mirror llvm / 5e06bb8
Let front-end tie subprogram declaration with subprogram definition directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130028 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 9 years ago
5 changed file(s) with 68 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
432432 i32, ;; Line number where defined
433433 metadata, ;; Reference to type descriptor
434434 i1, ;; True if the global is local to compile unit (static)
435 i1 ;; True if the global is defined in the compile unit (not extern)
436 i32 ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
437 i32 ;; Index into a virtual function
435 i1, ;; True if the global is defined in the compile unit (not extern)
436 i32, ;; Virtuality, e.g. dwarf::DW_VIRTUALITY__virtual
437 i32, ;; Index into a virtual function
438438 metadata, ;; indicates which base type contains the vtable pointer for the
439439 ;; derived class
440 i1 ;; isArtificial
441 i1 ;; isOptimized
442 Function *;; Pointer to LLVM function
443 metadata ;; Lists function template parameters
440 i1, ;; isArtificial
441 i1, ;; isOptimized
442 Function *,;; Pointer to LLVM function
443 metadata, ;; Lists function template parameters
444 metadata ;; Function declaration descriptor
444445 }
445446
446447
400400 unsigned Flags = 0,
401401 bool isOptimized = false,
402402 Function *Fn = 0,
403 MDNode *TParam = 0);
403 MDNode *TParam = 0,
404 MDNode *Decl = 0);
404405
405406 /// createMethod - Create a new descriptor for the specified C++ method.
406407 /// See comments in DISubprogram for descriptions of these fields.
537537
538538 Function *getFunction() const { return getFunctionField(16); }
539539 DIArray getTemplateParams() const { return getFieldAs(17); }
540 DISubprogram getFunctionDeclaration() const {
541 return getFieldAs(18);
542 }
540543 };
541544
542545 /// DIGlobalVariable - This is a wrapper for a global variable.
671671 bool isLocalToUnit, bool isDefinition,
672672 unsigned Flags, bool isOptimized,
673673 Function *Fn,
674 MDNode *TParams) {
674 MDNode *TParams,
675 MDNode *Decl) {
675676 Value *Elts[] = {
676677 GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
677678 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
690691 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
691692 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
692693 Fn,
693 TParams
694 TParams,
695 Decl
694696 };
695697 MDNode *Node = MDNode::get(VMContext, Elts);
696698
321321 return SPDie;
322322
323323 SPDie = new DIE(dwarf::DW_TAG_subprogram);
324
325 // DW_TAG_inlined_subroutine may refer to this DIE.
326 SPCU->insertDIE(SP, SPDie);
327
328 // Add to context owner.
329 SPCU->addToContextOwner(SPDie, SP.getContext());
330
331 // Add function template parameters.
332 SPCU->addTemplateParams(*SPDie, SP.getTemplateParams());
333
334 // If this DIE is going to refer declaration info using AT_specification
335 // then there is no need to add other attributes.
336 if (SP.getFunctionDeclaration().isSubprogram())
337 return SPDie;
338
324339 // Constructors and operators for anonymous aggregates do not have names.
325340 if (!SP.getName().empty())
326341 SPCU->addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string,
335350
336351 if (SP.isPrototyped())
337352 SPCU->addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
338
353
339354 // Add Return Type.
340355 DICompositeType SPTy = SP.getType();
341356 DIArray Args = SPTy.getTypeArray();
389404 if (unsigned isa = Asm->getISAEncoding()) {
390405 SPCU->addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
391406 }
392
393 // Add function template parameters.
394 SPCU->addTemplateParams(*SPDie, SP.getTemplateParams());
395
396 // DW_TAG_inlined_subroutine may refer to this DIE.
397 SPCU->insertDIE(SP, SPDie);
398
399 // Add to context owner.
400 SPCU->addToContextOwner(SPDie, SP.getContext());
401407
402408 return SPDie;
403409 }
453459 assert(SPDie && "Unable to find subprogram DIE!");
454460 DISubprogram SP(SPNode);
455461
456 // There is not any need to generate specification DIE for a function
457 // defined at compile unit level. If a function is defined inside another
458 // function then gdb prefers the definition at top level and but does not
459 // expect specification DIE in parent function. So avoid creating
460 // specification DIE for a function defined inside a function.
461 if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
462 !SP.getContext().isFile() &&
463 !isSubprogramContext(SP.getContext())) {
464 SPCU-> addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
465
466 // Add arguments.
467 DICompositeType SPTy = SP.getType();
468 DIArray Args = SPTy.getTypeArray();
469 unsigned SPTag = SPTy.getTag();
470 if (SPTag == dwarf::DW_TAG_subroutine_type)
471 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
472 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
473 DIType ATy = DIType(DIType(Args.getElement(i)));
474 SPCU->addType(Arg, ATy);
475 if (ATy.isArtificial())
476 SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
477 SPDie->addChild(Arg);
478 }
479 DIE *SPDeclDie = SPDie;
480 SPDie = new DIE(dwarf::DW_TAG_subprogram);
462 DISubprogram SPDecl = SP.getFunctionDeclaration();
463 if (SPDecl.isSubprogram())
464 // Refer function declaration directly.
481465 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
482 SPDeclDie);
483 SPCU->addDie(SPDie);
484 }
485
466 createSubprogramDIE(SPDecl));
467 else {
468 // There is not any need to generate specification DIE for a function
469 // defined at compile unit level. If a function is defined inside another
470 // function then gdb prefers the definition at top level and but does not
471 // expect specification DIE in parent function. So avoid creating
472 // specification DIE for a function defined inside a function.
473 if (SP.isDefinition() && !SP.getContext().isCompileUnit() &&
474 !SP.getContext().isFile() &&
475 !isSubprogramContext(SP.getContext())) {
476 SPCU-> addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
477
478 // Add arguments.
479 DICompositeType SPTy = SP.getType();
480 DIArray Args = SPTy.getTypeArray();
481 unsigned SPTag = SPTy.getTag();
482 if (SPTag == dwarf::DW_TAG_subroutine_type)
483 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
484 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
485 DIType ATy = DIType(DIType(Args.getElement(i)));
486 SPCU->addType(Arg, ATy);
487 if (ATy.isArtificial())
488 SPCU->addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1);
489 SPDie->addChild(Arg);
490 }
491 DIE *SPDeclDie = SPDie;
492 SPDie = new DIE(dwarf::DW_TAG_subprogram);
493 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_specification, dwarf::DW_FORM_ref4,
494 SPDeclDie);
495 SPCU->addDie(SPDie);
496 }
497 }
486498 // Pick up abstract subprogram DIE.
487499 if (DIE *AbsSPDIE = AbstractSPDies.lookup(SPNode)) {
488500 SPDie = new DIE(dwarf::DW_TAG_subprogram);