Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 2ca5f03

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217949 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c63035a commit 2ca5f03

File tree

2 files changed

+116
-27
lines changed

2 files changed

+116
-27
lines changed

include/llvm/IR/DIBuilder.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,15 @@ namespace llvm {
521521
DITypeRef Ty, bool isLocalToUnit, llvm::Value *Val,
522522
MDNode *Decl = nullptr);
523523

524+
/// createTempStaticVariableFwdDecl - Identical to createStaticVariable
525+
/// except that the resulting DbgNode is temporary and meant to be RAUWed.
526+
DIGlobalVariable
527+
createTempStaticVariableFwdDecl(DIDescriptor Context, StringRef Name,
528+
StringRef LinkageName, DIFile File,
529+
unsigned LineNo, DITypeRef Ty,
530+
bool isLocalToUnit, llvm::Value *Val,
531+
MDNode *Decl = nullptr);
532+
524533

525534
/// createLocalVariable - Create a new descriptor for the specified
526535
/// local variable.
@@ -599,6 +608,21 @@ namespace llvm {
599608
MDNode *TParam = nullptr,
600609
MDNode *Decl = nullptr);
601610

611+
/// createTempFunctionFwdDecl - Identical to createFunction,
612+
/// except that the resulting DbgNode is meant to be RAUWed.
613+
DISubprogram createTempFunctionFwdDecl(DIDescriptor Scope, StringRef Name,
614+
StringRef LinkageName,
615+
DIFile File, unsigned LineNo,
616+
DICompositeType Ty, bool isLocalToUnit,
617+
bool isDefinition,
618+
unsigned ScopeLine,
619+
unsigned Flags = 0,
620+
bool isOptimized = false,
621+
Function *Fn = nullptr,
622+
MDNode *TParam = nullptr,
623+
MDNode *Decl = nullptr);
624+
625+
602626
/// FIXME: this is added for dragonegg. Once we update dragonegg
603627
/// to call resolve function, this will be removed.
604628
DISubprogram createFunction(DIScopeRef Scope, StringRef Name,
@@ -731,7 +755,6 @@ namespace llvm {
731755
Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
732756
DIVariable VarInfo,
733757
Instruction *InsertBefore);
734-
735758
};
736759
} // end namespace llvm
737760

lib/IR/DIBuilder.cpp

Lines changed: 92 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,15 +1012,12 @@ DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
10121012
Val);
10131013
}
10141014

1015-
/// createStaticVariable - Create a new descriptor for the specified static
1016-
/// variable.
1017-
DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
1018-
StringRef Name,
1019-
StringRef LinkageName,
1020-
DIFile F, unsigned LineNumber,
1021-
DITypeRef Ty,
1022-
bool isLocalToUnit,
1023-
Value *Val, MDNode *Decl) {
1015+
static DIGlobalVariable
1016+
createStaticVariableHelper(LLVMContext &VMContext, DIDescriptor Context,
1017+
StringRef Name, StringRef LinkageName, DIFile F,
1018+
unsigned LineNumber, DITypeRef Ty, bool isLocalToUnit,
1019+
Value *Val, MDNode *Decl, bool isDefinition,
1020+
std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
10241021
Value *Elts[] = {
10251022
GetTagConstant(VMContext, dwarf::DW_TAG_variable),
10261023
Constant::getNullValue(Type::getInt32Ty(VMContext)),
@@ -1032,13 +1029,47 @@ DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
10321029
ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
10331030
Ty,
10341031
ConstantInt::get(Type::getInt32Ty(VMContext), isLocalToUnit),
1035-
ConstantInt::get(Type::getInt32Ty(VMContext), 1), /* isDefinition*/
1032+
ConstantInt::get(Type::getInt32Ty(VMContext), isDefinition),
10361033
Val,
10371034
DIDescriptor(Decl)
10381035
};
1039-
MDNode *Node = MDNode::get(VMContext, Elts);
1040-
AllGVs.push_back(Node);
1041-
return DIGlobalVariable(Node);
1036+
1037+
return DIGlobalVariable(CreateFunc(Elts));
1038+
}
1039+
1040+
/// createStaticVariable - Create a new descriptor for the specified
1041+
/// variable.
1042+
DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
1043+
StringRef Name,
1044+
StringRef LinkageName,
1045+
DIFile F, unsigned LineNumber,
1046+
DITypeRef Ty,
1047+
bool isLocalToUnit,
1048+
Value *Val, MDNode *Decl) {
1049+
return createStaticVariableHelper(VMContext, Context, Name, LinkageName, F,
1050+
LineNumber, Ty, isLocalToUnit, Val, Decl, true,
1051+
[&] (ArrayRef<Value *> Elts) -> MDNode * {
1052+
MDNode *Node = MDNode::get(VMContext, Elts);
1053+
AllGVs.push_back(Node);
1054+
return Node;
1055+
});
1056+
}
1057+
1058+
/// createTempStaticVariableFwdDecl - Create a new temporary descriptor for the
1059+
/// specified variable declarartion.
1060+
DIGlobalVariable
1061+
DIBuilder::createTempStaticVariableFwdDecl(DIDescriptor Context,
1062+
StringRef Name,
1063+
StringRef LinkageName,
1064+
DIFile F, unsigned LineNumber,
1065+
DITypeRef Ty,
1066+
bool isLocalToUnit,
1067+
Value *Val, MDNode *Decl) {
1068+
return createStaticVariableHelper(VMContext, Context, Name, LinkageName, F,
1069+
LineNumber, Ty, isLocalToUnit, Val, Decl, false,
1070+
[&] (ArrayRef<Value *> Elts) {
1071+
return MDNode::getTemporary(VMContext, Elts);
1072+
});
10421073
}
10431074

10441075
/// createVariable - Create a new descriptor for the specified variable.
@@ -1139,14 +1170,13 @@ DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
11391170
Flags, isOptimized, Fn, TParams, Decl);
11401171
}
11411172

1142-
/// createFunction - Create a new descriptor for the specified function.
1143-
DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1144-
StringRef LinkageName, DIFile File,
1145-
unsigned LineNo, DICompositeType Ty,
1146-
bool isLocalToUnit, bool isDefinition,
1147-
unsigned ScopeLine, unsigned Flags,
1148-
bool isOptimized, Function *Fn,
1149-
MDNode *TParams, MDNode *Decl) {
1173+
static DISubprogram
1174+
createFunctionHelper(LLVMContext &VMContext, DIDescriptor Context, StringRef Name,
1175+
StringRef LinkageName, DIFile File, unsigned LineNo,
1176+
DICompositeType Ty, bool isLocalToUnit, bool isDefinition,
1177+
unsigned ScopeLine, unsigned Flags, bool isOptimized,
1178+
Function *Fn, MDNode *TParams, MDNode *Decl,
1179+
std::function<MDNode *(ArrayRef<Value *>)> CreateFunc) {
11501180
assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
11511181
"function types should be subroutines");
11521182
Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) };
@@ -1172,17 +1202,53 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
11721202
MDNode::getTemporary(VMContext, TElts),
11731203
ConstantInt::get(Type::getInt32Ty(VMContext), ScopeLine)
11741204
};
1175-
MDNode *Node = MDNode::get(VMContext, Elts);
11761205

1177-
// Create a named metadata so that we do not lose this mdnode.
1178-
if (isDefinition)
1179-
AllSubprograms.push_back(Node);
1180-
DISubprogram S(Node);
1206+
DISubprogram S(CreateFunc(Elts));
11811207
assert(S.isSubprogram() &&
11821208
"createFunction should return a valid DISubprogram");
11831209
return S;
11841210
}
11851211

1212+
1213+
/// createFunction - Create a new descriptor for the specified function.
1214+
DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1215+
StringRef LinkageName, DIFile File,
1216+
unsigned LineNo, DICompositeType Ty,
1217+
bool isLocalToUnit, bool isDefinition,
1218+
unsigned ScopeLine, unsigned Flags,
1219+
bool isOptimized, Function *Fn,
1220+
MDNode *TParams, MDNode *Decl) {
1221+
return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1222+
LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1223+
Flags, isOptimized, Fn, TParams, Decl,
1224+
[&] (ArrayRef<Value *> Elts) -> MDNode *{
1225+
MDNode *Node = MDNode::get(VMContext, Elts);
1226+
// Create a named metadata so that we
1227+
// do not lose this mdnode.
1228+
if (isDefinition)
1229+
AllSubprograms.push_back(Node);
1230+
return Node;
1231+
});
1232+
}
1233+
1234+
/// createTempFunctionFwdDecl - Create a new temporary descriptor for
1235+
/// the specified function declaration.
1236+
DISubprogram
1237+
DIBuilder::createTempFunctionFwdDecl(DIDescriptor Context, StringRef Name,
1238+
StringRef LinkageName, DIFile File,
1239+
unsigned LineNo, DICompositeType Ty,
1240+
bool isLocalToUnit, bool isDefinition,
1241+
unsigned ScopeLine, unsigned Flags,
1242+
bool isOptimized, Function *Fn,
1243+
MDNode *TParams, MDNode *Decl) {
1244+
return createFunctionHelper(VMContext, Context, Name, LinkageName, File,
1245+
LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
1246+
Flags, isOptimized, Fn, TParams, Decl,
1247+
[&] (ArrayRef<Value *> Elts) {
1248+
return MDNode::getTemporary(VMContext, Elts);
1249+
});
1250+
}
1251+
11861252
/// createMethod - Create a new descriptor for the specified C++ method.
11871253
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
11881254
StringRef LinkageName, DIFile F,

0 commit comments

Comments
 (0)