llvm.org GIT mirror llvm / aa50fa7
DI: Rewrite the DIBuilder local variable API Replace the general `createLocalVariable()` with two more specific functions: `createParameterVariable()` and `createAutoVariable()`, and rewrite the documentation. Besides cleaning up the API, this avoids exposing the fake DWARF tags `DW_TAG_arg_variable` and `DW_TAG_auto_variable` to frontends, and is preparation for removing them completely. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243764 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
6 changed file(s) with 67 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
8383 }
8484
8585 LLVMMetadataRef LLVMDIBuilderCreateLocalVariable(
86 LLVMDIBuilderRef Dref, unsigned Tag, LLVMMetadataRef Scope,
86 LLVMDIBuilderRef Dref, unsigned, LLVMMetadataRef Scope,
8787 const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty,
8888 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
8989 DIBuilder *D = unwrap(Dref);
90 return wrap(D->createLocalVariable(
91 Tag, unwrap(Scope), Name, unwrap(File), Line,
92 unwrap(Ty), AlwaysPreserve, Flags, ArgNo));
90 // FIXME: Update the Go bindings to match the DIBuilder API.
91 if (ArgNo)
92 return wrap(D->createParameterVariable(
93 unwrap(Scope), Name, ArgNo, unwrap(File), Line,
94 unwrap(Ty), AlwaysPreserve, Flags));
95 return wrap(D->createAutoVariable(unwrap(Scope), Name,
96 unwrap(File), Line,
97 unwrap(Ty), AlwaysPreserve, Flags));
9398 }
9499
95100 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
394394 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
395395 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
396396 KSDbgInfo.TheCU.getDirectory());
397 DILocalVariable D = DBuilder->createLocalVariable(
398 dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
399 KSDbgInfo.getDoubleTy(), true, 0, Idx + 1);
397 DILocalVariable D = DBuilder->createParameterVariable(
398 Scope, Args[Idx], Idx + 1, Unit, Line, KSDbgInfo.getDoubleTy(), true);
400399
401400 Instruction *Call = DBuilder->insertDeclare(
402401 Alloca, D, DBuilder->createExpression(), Builder.GetInsertBlock());
12521252 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
12531253 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
12541254 KSDbgInfo.TheCU->getDirectory());
1255 DILocalVariable *D = DBuilder->createLocalVariable(
1256 dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
1257 KSDbgInfo.getDoubleTy(), true, 0, Idx + 1);
1255 DILocalVariable *D = DBuilder->createParameterVariable(
1256 Scope, Args[Idx], Idx + 1, Unit, Line, KSDbgInfo.getDoubleTy(), true);
12581257
12591258 DBuilder->insertDeclare(Alloca, D, DBuilder->createExpression(),
12601259 DebugLoc::get(Line, 0, Scope),
456456 unsigned LineNo, DIType *Ty, bool isLocalToUnit, llvm::Constant *Val,
457457 MDNode *Decl = nullptr);
458458
459 /// Create a new descriptor for the specified
460 /// local variable.
461 /// \param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
462 /// DW_TAG_arg_variable.
463 /// \param Scope Variable scope.
464 /// \param Name Variable name.
465 /// \param File File where this variable is defined.
466 /// \param LineNo Line number.
467 /// \param Ty Variable Type
468 /// \param AlwaysPreserve Boolean. Set to true if debug info for this
469 /// variable should be preserved in optimized build.
470 /// \param Flags Flags, e.g. artificial variable.
471 /// \param ArgNo If this variable is an argument then this argument's
472 /// number. 1 indicates 1st argument.
473 DILocalVariable *createLocalVariable(unsigned Tag, DIScope *Scope,
474 StringRef Name, DIFile *File,
475 unsigned LineNo, DIType *Ty,
459 /// Create a new descriptor for an auto variable. This is a local variable
460 /// that is not a subprogram parameter.
461 ///
462 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
463 /// leads to a \a DISubprogram.
464 ///
465 /// If \c AlwaysPreserve, this variable will be referenced from its
466 /// containing subprogram, and will survive some optimizations.
467 DILocalVariable *createAutoVariable(DIScope *Scope, StringRef Name,
468 DIFile *File, unsigned LineNo,
469 DIType *Ty,
476470 bool AlwaysPreserve = false,
477 unsigned Flags = 0,
478 unsigned ArgNo = 0);
471 unsigned Flags = 0);
472
473 /// Create a new descriptor for a parameter variable.
474 ///
475 /// \c Scope must be a \a DILocalScope, and thus its scope chain eventually
476 /// leads to a \a DISubprogram.
477 ///
478 /// \c ArgNo is the index (starting from \c 1) of this variable in the
479 /// subprogram parameters. \c ArgNo should not conflict with other
480 /// parameters of the same subprogram.
481 ///
482 /// If \c AlwaysPreserve, this variable will be referenced from its
483 /// containing subprogram, and will survive some optimizations.
484 DILocalVariable *createParameterVariable(DIScope *Scope, StringRef Name,
485 unsigned ArgNo, DIFile *File,
486 unsigned LineNo, DIType *Ty,
487 bool AlwaysPreserve = false,
488 unsigned Flags = 0);
479489
480490 /// Create a new descriptor for the specified
481491 /// variable which has a complex address expression for its address.
601601 .release();
602602 }
603603
604 DILocalVariable *DIBuilder::createLocalVariable(
605 unsigned Tag, DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
606 DIType *Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
604 static DILocalVariable *createLocalVariable(
605 LLVMContext &VMContext,
606 DenseMap> &PreservedVariables,
607 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
608 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) {
607609 // FIXME: Why getNonCompileUnitScope()?
608610 // FIXME: Why is "!Context" okay here?
609611 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
610612 // the only valid scopes)?
611613 DIScope *Context = getNonCompileUnitScope(Scope);
612614
615 dwarf::Tag Tag = ArgNo ? dwarf::DW_TAG_arg_variable : dwarf::DW_TAG_auto_variable;
613616 auto *Node = DILocalVariable::get(
614617 VMContext, Tag, cast_or_null(Context), Name, File, LineNo,
615618 DITypeRef::get(Ty), ArgNo, Flags);
622625 PreservedVariables[Fn].emplace_back(Node);
623626 }
624627 return Node;
628 }
629
630 DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
631 DIFile *File, unsigned LineNo,
632 DIType *Ty, bool AlwaysPreserve,
633 unsigned Flags) {
634 return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
635 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
636 Flags);
637 }
638
639 DILocalVariable *DIBuilder::createParameterVariable(
640 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
641 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, unsigned Flags) {
642 assert(ArgNo && "Expected non-zero argument number for parameter");
643 return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
644 File, LineNo, Ty, AlwaysPreserve, Flags);
625645 }
626646
627647 DIExpression *DIBuilder::createExpression(ArrayRef Addr) {
254254 auto *IntType =
255255 DBuilder.createBasicType("int", 32, 0, dwarf::DW_ATE_signed);
256256 auto *E = DBuilder.createExpression();
257 auto *Variable = DBuilder.createLocalVariable(
258 dwarf::DW_TAG_auto_variable, Subprogram, "x", File, 5, IntType, true);
257 auto *Variable =
258 DBuilder.createAutoVariable(Subprogram, "x", File, 5, IntType, true);
259259 auto *DL = DILocation::get(Subprogram->getContext(), 5, 0, Subprogram);
260260 DBuilder.insertDeclare(Alloca, Variable, E, DL, Store);
261261 DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, DL,