@@ -1012,15 +1012,12 @@ DIGlobalVariable DIBuilder::createGlobalVariable(StringRef Name, DIFile F,
1012
1012
Val);
1013
1013
}
1014
1014
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) {
1024
1021
Value *Elts[] = {
1025
1022
GetTagConstant (VMContext, dwarf::DW_TAG_variable),
1026
1023
Constant::getNullValue (Type::getInt32Ty (VMContext)),
@@ -1032,13 +1029,47 @@ DIGlobalVariable DIBuilder::createStaticVariable(DIDescriptor Context,
1032
1029
ConstantInt::get (Type::getInt32Ty (VMContext), LineNumber),
1033
1030
Ty,
1034
1031
ConstantInt::get (Type::getInt32Ty (VMContext), isLocalToUnit),
1035
- ConstantInt::get (Type::getInt32Ty (VMContext), 1 ), /* isDefinition */
1032
+ ConstantInt::get (Type::getInt32Ty (VMContext), isDefinition),
1036
1033
Val,
1037
1034
DIDescriptor (Decl)
1038
1035
};
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
+ });
1042
1073
}
1043
1074
1044
1075
// / createVariable - Create a new descriptor for the specified variable.
@@ -1139,14 +1170,13 @@ DISubprogram DIBuilder::createFunction(DIScopeRef Context, StringRef Name,
1139
1170
Flags, isOptimized, Fn, TParams, Decl);
1140
1171
}
1141
1172
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) {
1150
1180
assert (Ty.getTag () == dwarf::DW_TAG_subroutine_type &&
1151
1181
" function types should be subroutines" );
1152
1182
Value *TElts[] = { GetTagConstant (VMContext, DW_TAG_base_type) };
@@ -1172,17 +1202,53 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context, StringRef Name,
1172
1202
MDNode::getTemporary (VMContext, TElts),
1173
1203
ConstantInt::get (Type::getInt32Ty (VMContext), ScopeLine)
1174
1204
};
1175
- MDNode *Node = MDNode::get (VMContext, Elts);
1176
1205
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));
1181
1207
assert (S.isSubprogram () &&
1182
1208
" createFunction should return a valid DISubprogram" );
1183
1209
return S;
1184
1210
}
1185
1211
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
+
1186
1252
// / createMethod - Create a new descriptor for the specified C++ method.
1187
1253
DISubprogram DIBuilder::createMethod (DIDescriptor Context, StringRef Name,
1188
1254
StringRef LinkageName, DIFile F,
0 commit comments