Index: include/llvm/IR/DIBuilder.h =================================================================== --- include/llvm/IR/DIBuilder.h +++ include/llvm/IR/DIBuilder.h @@ -521,6 +521,15 @@ DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val, MDNode *Decl = nullptr); + /// createTempStaticVariableFwdDecl - Identical to createStaticVariable + /// except that the resulting DbgNode is temporary and meant to be RAUWed. + DIGlobalVariable + createTempStaticVariableFwdDecl(DIDescriptor Context, StringRef Name, + StringRef LinkageName, DIFile File, + unsigned LineNo, DITypeRef Ty, + bool isLocalToUnit, llvm::Value *Val, + MDNode *Decl = nullptr); + /// createLocalVariable - Create a new descriptor for the specified /// local variable. @@ -599,6 +608,21 @@ MDNode *TParam = nullptr, MDNode *Decl = nullptr); + /// createTempFunctionFwdDecl - Identical to createFunction, + /// except that the resulting DbgNode is meant to be RAUWed. + DISubprogram createTempFunctionFwdDecl(DIDescriptor Scope, StringRef Name, + StringRef LinkageName, + DIFile File, unsigned LineNo, + DICompositeType Ty, bool isLocalToUnit, + bool isDefinition, + unsigned ScopeLine, + unsigned Flags = 0, + bool isOptimized = false, + Function *Fn = nullptr, + MDNode *TParam = nullptr, + MDNode *Decl = nullptr); + + /// FIXME: this is added for dragonegg. Once we update dragonegg /// to call resolve function, this will be removed. DISubprogram createFunction(DIScopeRef Scope, StringRef Name, @@ -732,6 +756,30 @@ DIVariable VarInfo, Instruction *InsertBefore); + private: + /// createFunctionHelper - Helper for createFunction and + /// createTempFunctionFwdDecl. + DISubprogram createFunctionHelper(DIDescriptor Scope, StringRef Name, + StringRef LinkageName, + DIFile File, unsigned LineNo, + DICompositeType Ty, bool isLocalToUnit, + bool isDefinition, + unsigned ScopeLine, + unsigned Flags, + bool isOptimized, + Function *Fn, + MDNode *TParam, + MDNode *Decl, + bool Temporary); + + /// createStaticVariableHelper - Helper for createStaticVariable + /// and createTempStaticVariableFwdDecl. + DIGlobalVariable + createStaticVariableHelper(DIDescriptor Context, StringRef Name, + StringRef LinkageName, DIFile File, unsigned LineNo, + DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val, + MDNode *Decl, bool Temporary); + }; } // end namespace llvm Index: lib/IR/DIBuilder.cpp =================================================================== --- lib/IR/DIBuilder.cpp +++ lib/IR/DIBuilder.cpp @@ -1013,7 +1013,7 @@ Val); } -/// createStaticVariable - Create a new descriptor for the specified static +/// createStaticVariable - Create a new descriptor for the specified /// variable. DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, StringRef Name, @@ -1022,6 +1022,32 @@ DITypeRef Ty, bool isLocalToUnit, Value *Val, MDNode *Decl) { + return createStaticVariableHelper(Context, Name, LinkageName, F, LineNumber, + Ty, isLocalToUnit, Val, Decl, false); +} + +/// createTempStaticVariableFwdDecl - Create a new temporary descriptor for the +/// specified variable declarartion. +DIGlobalVariable +DIBuilder::createTempStaticVariableFwdDecl(DIDescriptor Context, + StringRef Name, + StringRef LinkageName, + DIFile F, unsigned LineNumber, + DITypeRef Ty, + bool isLocalToUnit, + Value *Val, MDNode *Decl) { + return createStaticVariableHelper(Context, Name, LinkageName, F, LineNumber, + Ty, isLocalToUnit, Val, Decl, true); +} + +DIGlobalVariable DIBuilder::createStaticVariableHelper(DIDescriptor Context, + StringRef Name, + StringRef LinkageName, + DIFile F, unsigned LineNumber, + DITypeRef Ty, + bool isLocalToUnit, + Value *Val, MDNode *Decl, + bool Temporary) { Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_variable), Constant::getNullValue(Type::getInt32Ty(VMContext)), @@ -1037,8 +1063,16 @@ Val, DIDescriptor(Decl) }; - MDNode *Node = MDNode::get(VMContext, Elts); - AllGVs.push_back(Node); + MDNode *Node; + + if (Temporary) + Node = MDNode::getTemporary(VMContext, Elts); + else { + Node = MDNode::get(VMContext, Elts); + // Do not put temporary nodes in the GV list. We'll add the + // necessary ones at the finalize step. + AllGVs.push_back(Node); + } return DIGlobalVariable(Node); } @@ -1148,6 +1182,34 @@ unsigned ScopeLine, unsigned Flags, bool isOptimized, Function *Fn, MDNode *TParams, MDNode *Decl) { + return createFunctionHelper(Context, Name, LinkageName, File, LineNo, Ty, + isLocalToUnit, isDefinition, ScopeLine, Flags, + isOptimized, Fn, TParams, Decl, false); +} + +/// createTempFunctionFwdDecl - Create a new temporary descriptor for +/// the specified function declaration. +DISubprogram +DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name, + StringRef LinkageName, DIFile File, + unsigned LineNo, DICompositeType Ty, + bool isLocalToUnit, bool isDefinition, + unsigned ScopeLine, unsigned Flags, + bool isOptimized, Function *Fn, + MDNode *TParams, MDNode *Decl) { + return createFunctionHelper(Context, Name, LinkageName, File, LineNo, Ty, + isLocalToUnit, isDefinition, ScopeLine, Flags, + isOptimized, Fn, TParams, Decl, true); +} + +DISubprogram DIBuilder::createFunctionHelper(DIDescriptor Context, StringRef Name, + StringRef LinkageName, DIFile File, + unsigned LineNo, DICompositeType Ty, + bool isLocalToUnit, bool isDefinition, + unsigned ScopeLine, unsigned Flags, + bool isOptimized, Function *Fn, + MDNode *TParams, MDNode *Decl, + bool Temporary) { assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && "function types should be subroutines"); Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; @@ -1173,11 +1235,16 @@ MDNode::getTemporary(VMContext, TElts), ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine) }; - MDNode *Node = MDNode::get(VMContext, Elts); - - // Create a named metadata so that we do not lose this mdnode. - if (isDefinition) - AllSubprograms.push_back(Node); + MDNode *Node; + + if (Temporary) + Node = MDNode::getTemporary(VMContext, Elts); + else { + Node = MDNode::get(VMContext, Elts); + // Create a named metadata so that we do not lose this mdnode. + if (isDefinition) + AllSubprograms.push_back(Node); + } DISubprogram S(Node); assert(S.isSubprogram() && "createFunction should return a valid DISubprogram");