diff options
| author | Frederic Riss <friss@apple.com> | 2014-09-17 09:28:34 +0000 |
|---|---|---|
| committer | Frederic Riss <friss@apple.com> | 2014-09-17 09:28:34 +0000 |
| commit | 5e6bc9e162f650d8d95282fab102995e8b289dcd (patch) | |
| tree | 4a725c6f51d6a801644323cb4eec4c14cce10ecd /llvm/lib/IR/DIBuilder.cpp | |
| parent | 559b47d0516d769e3f20acf58163f6dc4df99c75 (diff) | |
| download | bcm5719-llvm-5e6bc9e162f650d8d95282fab102995e8b289dcd.tar.gz bcm5719-llvm-5e6bc9e162f650d8d95282fab102995e8b289dcd.zip | |
Add DIBuilder functions to build RAUWable DIVariables and DIFunctions.
Summary: These will be used to implement support for useful forward declarartions.
Reviewers: echristo, dblaikie, aprantl
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D5328
llvm-svn: 217949
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
| -rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 118 |
1 files changed, 92 insertions, 26 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 181c60f17ca..f1ee51af0ad 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -1012,15 +1012,12 @@ DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F, Val); } -/// createStaticVariable - Create a new descriptor for the specified static -/// variable. -DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, - StringRef Name, - StringRef LinkageName, - DIFile F, unsigned LineNumber, - DITypeRef Ty, - bool isLocalToUnit, - Value *Val, MDNode *Decl) { +static DIGlobalVariable +createStaticVariableHelper(LLVMContext &VMContext, DIDescriptor Context, + StringRef Name, StringRef LinkageName, DIFile F, + unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit, + Value *Val, MDNode *Decl, bool isDefinition, + std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) { Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_variable), Constant::getNullValue(Type::getInt32Ty(VMContext)), @@ -1032,13 +1029,47 @@ DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), Ty, ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit), - ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/ + ConstantInt::get(Type::getInt32Ty(VMContext), isDefinition), Val, DIDescriptor(Decl) }; - MDNode *Node = MDNode::get(VMContext, Elts); - AllGVs.push_back(Node); - return DIGlobalVariable(Node); + + return DIGlobalVariable(CreateFunc(Elts)); +} + +/// createStaticVariable - Create a new descriptor for the specified +/// variable. +DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context, + StringRef Name, + StringRef LinkageName, + DIFile F, unsigned LineNumber, + DITypeRef Ty, + bool isLocalToUnit, + Value *Val, MDNode *Decl) { + return createStaticVariableHelper(VMContext, Context, Name, LinkageName, F, + LineNumber, Ty, isLocalToUnit, Val, Decl, true, + [&] (ArrayRef<Value *> Elts) -> MDNode * { + MDNode *Node = MDNode::get(VMContext, Elts); + AllGVs.push_back(Node); + return Node; + }); +} + +/// 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(VMContext, Context, Name, LinkageName, F, + LineNumber, Ty, isLocalToUnit, Val, Decl, false, + [&] (ArrayRef<Value *> Elts) { + return MDNode::getTemporary(VMContext, Elts); + }); } /// createVariable - Create a new descriptor for the specified variable. @@ -1139,14 +1170,13 @@ DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name, Flags, isOptimized, Fn, TParams, Decl); } -/// createFunction - Create a new descriptor for the specified function. -DISubprogram DIBuilder::createFunction(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) { +static DISubprogram +createFunctionHelper(LLVMContext &VMContext, 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, + std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) { assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type && "function types should be subroutines"); Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; @@ -1172,17 +1202,53 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name, 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); - DISubprogram S(Node); + DISubprogram S(CreateFunc(Elts)); assert(S.isSubprogram() && "createFunction should return a valid DISubprogram"); return S; } + +/// createFunction - Create a new descriptor for the specified function. +DISubprogram DIBuilder::createFunction(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(VMContext, Context, Name, LinkageName, File, + LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, + Flags, isOptimized, Fn, TParams, Decl, + [&] (ArrayRef<Value *> Elts) -> MDNode *{ + MDNode *Node = MDNode::get(VMContext, Elts); + // Create a named metadata so that we + // do not lose this mdnode. + if (isDefinition) + AllSubprograms.push_back(Node); + return Node; + }); +} + +/// 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(VMContext, Context, Name, LinkageName, File, + LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, + Flags, isOptimized, Fn, TParams, Decl, + [&] (ArrayRef<Value *> Elts) { + return MDNode::getTemporary(VMContext, Elts); + }); +} + /// createMethod - Create a new descriptor for the specified C++ method. DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, StringRef LinkageName, DIFile F, |

