@@ -960,20 +960,15 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
960
960
File, Line, Col);
961
961
}
962
962
963
- DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
964
- DIExpression *Expr, const DILocation *DL,
965
- Instruction *InsertBefore) {
966
- return insertDeclare (Storage, VarInfo, Expr, DL, InsertBefore->getParent (),
967
- InsertBefore);
968
- }
969
-
970
963
DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
971
964
DIExpression *Expr, const DILocation *DL,
972
965
BasicBlock *InsertAtEnd) {
973
966
// If this block already has a terminator then insert this intrinsic before
974
967
// the terminator. Otherwise, put it at the end of the block.
975
968
Instruction *InsertBefore = InsertAtEnd->getTerminator ();
976
- return insertDeclare (Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
969
+ return insertDeclare (Storage, VarInfo, Expr, DL,
970
+ InsertBefore ? InsertBefore->getIterator ()
971
+ : InsertAtEnd->end ());
977
972
}
978
973
979
974
DbgInstPtr DIBuilder::insertDbgAssign (Instruction *LinkedInstr, Value *Val,
@@ -988,11 +983,10 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
988
983
if (M.IsNewDbgInfoFormat ) {
989
984
DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign (
990
985
Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
991
- BasicBlock *InsertBB = LinkedInstr->getParent ();
992
986
// Insert after LinkedInstr.
993
987
BasicBlock::iterator NextIt = std::next (LinkedInstr->getIterator ());
994
- Instruction *InsertBefore = NextIt == InsertBB-> end () ? nullptr : &*NextIt ;
995
- insertDbgVariableRecord (DVR, InsertBB, InsertBefore, true );
988
+ NextIt. setHeadBit ( true ) ;
989
+ insertDbgVariableRecord (DVR, NextIt );
996
990
return DVR;
997
991
}
998
992
@@ -1018,47 +1012,11 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
1018
1012
return DVI;
1019
1013
}
1020
1014
1021
- DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
1022
- Instruction *InsertBefore) {
1023
- return insertLabel (LabelInfo, DL,
1024
- InsertBefore ? InsertBefore->getParent () : nullptr ,
1025
- InsertBefore);
1026
- }
1027
-
1028
- DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
1029
- BasicBlock *InsertAtEnd) {
1030
- return insertLabel (LabelInfo, DL, InsertAtEnd, nullptr );
1031
- }
1032
-
1033
- DbgInstPtr DIBuilder::insertDbgValueIntrinsic (Value *V,
1034
- DILocalVariable *VarInfo,
1035
- DIExpression *Expr,
1036
- const DILocation *DL,
1037
- Instruction *InsertBefore) {
1038
- DbgInstPtr DVI = insertDbgValueIntrinsic (
1039
- V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent () : nullptr ,
1040
- InsertBefore);
1041
- if (auto *Inst = dyn_cast<Instruction *>(DVI))
1042
- cast<CallInst>(Inst)->setTailCall ();
1043
- return DVI;
1044
- }
1045
-
1046
- DbgInstPtr DIBuilder::insertDbgValueIntrinsic (Value *V,
1047
- DILocalVariable *VarInfo,
1048
- DIExpression *Expr,
1049
- const DILocation *DL,
1050
- BasicBlock *InsertAtEnd) {
1051
- return insertDbgValueIntrinsic (V, VarInfo, Expr, DL, InsertAtEnd, nullptr );
1052
- }
1053
-
1054
1015
// / Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
1055
1016
// / This abstracts over the various ways to specify an insert position.
1056
1017
static void initIRBuilder (IRBuilder<> &Builder, const DILocation *DL,
1057
- BasicBlock *InsertBB, Instruction *InsertBefore) {
1058
- if (InsertBefore)
1059
- Builder.SetInsertPoint (InsertBefore);
1060
- else if (InsertBB)
1061
- Builder.SetInsertPoint (InsertBB);
1018
+ InsertPosition InsertPt) {
1019
+ Builder.SetInsertPoint (InsertPt.getBasicBlock (), InsertPt);
1062
1020
Builder.SetCurrentDebugLocation (DL);
1063
1021
}
1064
1022
@@ -1071,26 +1029,28 @@ static Function *getDeclareIntrin(Module &M) {
1071
1029
return Intrinsic::getOrInsertDeclaration (&M, Intrinsic::dbg_declare);
1072
1030
}
1073
1031
1074
- DbgInstPtr DIBuilder::insertDbgValueIntrinsic (
1075
- llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
1076
- const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
1032
+ DbgInstPtr DIBuilder::insertDbgValueIntrinsic (llvm::Value *Val,
1033
+ DILocalVariable *VarInfo,
1034
+ DIExpression *Expr,
1035
+ const DILocation *DL,
1036
+ InsertPosition InsertPt) {
1077
1037
if (M.IsNewDbgInfoFormat ) {
1078
1038
DbgVariableRecord *DVR =
1079
1039
DbgVariableRecord::createDbgVariableRecord (Val, VarInfo, Expr, DL);
1080
- insertDbgVariableRecord (DVR, InsertBB, InsertBefore );
1040
+ insertDbgVariableRecord (DVR, InsertPt );
1081
1041
return DVR;
1082
1042
}
1083
1043
1084
1044
if (!ValueFn)
1085
1045
ValueFn = Intrinsic::getOrInsertDeclaration (&M, Intrinsic::dbg_value);
1086
- return insertDbgIntrinsic (ValueFn, Val, VarInfo, Expr, DL, InsertBB,
1087
- InsertBefore);
1046
+ auto *DVI = insertDbgIntrinsic (ValueFn, Val, VarInfo, Expr, DL, InsertPt);
1047
+ cast<CallInst>(DVI)->setTailCall ();
1048
+ return DVI;
1088
1049
}
1089
1050
1090
1051
DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
1091
1052
DIExpression *Expr, const DILocation *DL,
1092
- BasicBlock *InsertBB,
1093
- Instruction *InsertBefore) {
1053
+ InsertPosition InsertPt) {
1094
1054
assert (VarInfo && " empty or invalid DILocalVariable* passed to dbg.declare" );
1095
1055
assert (DL && " Expected debug loc" );
1096
1056
assert (DL->getScope ()->getSubprogram () ==
@@ -1100,7 +1060,7 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
1100
1060
if (M.IsNewDbgInfoFormat ) {
1101
1061
DbgVariableRecord *DVR =
1102
1062
DbgVariableRecord::createDVRDeclare (Storage, VarInfo, Expr, DL);
1103
- insertDbgVariableRecord (DVR, InsertBB, InsertBefore );
1063
+ insertDbgVariableRecord (DVR, InsertPt );
1104
1064
return DVR;
1105
1065
}
1106
1066
@@ -1114,35 +1074,27 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
1114
1074
MetadataAsValue::get (VMContext, Expr)};
1115
1075
1116
1076
IRBuilder<> B (DL->getContext ());
1117
- initIRBuilder (B, DL, InsertBB, InsertBefore );
1077
+ initIRBuilder (B, DL, InsertPt );
1118
1078
return B.CreateCall (DeclareFn, Args);
1119
1079
}
1120
1080
1121
1081
void DIBuilder::insertDbgVariableRecord (DbgVariableRecord *DVR,
1122
- BasicBlock *InsertBB,
1123
- Instruction *InsertBefore,
1124
- bool InsertAtHead) {
1125
- assert (InsertBefore || InsertBB);
1082
+ InsertPosition InsertPt) {
1083
+ assert (InsertPt.isValid ());
1126
1084
trackIfUnresolved (DVR->getVariable ());
1127
1085
trackIfUnresolved (DVR->getExpression ());
1128
1086
if (DVR->isDbgAssign ())
1129
1087
trackIfUnresolved (DVR->getAddressExpression ());
1130
1088
1131
- BasicBlock::iterator InsertPt;
1132
- if (InsertBB && InsertBefore)
1133
- InsertPt = InsertBefore->getIterator ();
1134
- else if (InsertBB)
1135
- InsertPt = InsertBB->end ();
1136
- InsertPt.setHeadBit (InsertAtHead);
1137
- InsertBB->insertDbgRecordBefore (DVR, InsertPt);
1089
+ auto *BB = InsertPt.getBasicBlock ();
1090
+ BB->insertDbgRecordBefore (DVR, InsertPt);
1138
1091
}
1139
1092
1140
1093
Instruction *DIBuilder::insertDbgIntrinsic (llvm::Function *IntrinsicFn,
1141
1094
Value *V, DILocalVariable *VarInfo,
1142
1095
DIExpression *Expr,
1143
1096
const DILocation *DL,
1144
- BasicBlock *InsertBB,
1145
- Instruction *InsertBefore) {
1097
+ InsertPosition InsertPt) {
1146
1098
assert (IntrinsicFn && " must pass a non-null intrinsic function" );
1147
1099
assert (V && " must pass a value to a dbg intrinsic" );
1148
1100
assert (VarInfo &&
@@ -1159,13 +1111,12 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
1159
1111
MetadataAsValue::get (VMContext, Expr)};
1160
1112
1161
1113
IRBuilder<> B (DL->getContext ());
1162
- initIRBuilder (B, DL, InsertBB, InsertBefore );
1114
+ initIRBuilder (B, DL, InsertPt );
1163
1115
return B.CreateCall (IntrinsicFn, Args);
1164
1116
}
1165
1117
1166
1118
DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
1167
- BasicBlock *InsertBB,
1168
- Instruction *InsertBefore) {
1119
+ InsertPosition InsertPt) {
1169
1120
assert (LabelInfo && " empty or invalid DILabel* passed to dbg.label" );
1170
1121
assert (DL && " Expected debug loc" );
1171
1122
assert (DL->getScope ()->getSubprogram () ==
@@ -1175,10 +1126,10 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
1175
1126
trackIfUnresolved (LabelInfo);
1176
1127
if (M.IsNewDbgInfoFormat ) {
1177
1128
DbgLabelRecord *DLR = new DbgLabelRecord (LabelInfo, DL);
1178
- if (InsertBB && InsertBefore)
1179
- InsertBB-> insertDbgRecordBefore (DLR, InsertBefore-> getIterator () );
1180
- else if (InsertBB)
1181
- InsertBB-> insertDbgRecordBefore (DLR, InsertBB-> end ());
1129
+ if (InsertPt. isValid ()) {
1130
+ auto *BB = InsertPt. getBasicBlock ( );
1131
+ BB-> insertDbgRecordBefore (DLR, InsertPt);
1132
+ }
1182
1133
return DLR;
1183
1134
}
1184
1135
@@ -1188,7 +1139,7 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
1188
1139
Value *Args[] = {MetadataAsValue::get (VMContext, LabelInfo)};
1189
1140
1190
1141
IRBuilder<> B (DL->getContext ());
1191
- initIRBuilder (B, DL, InsertBB, InsertBefore );
1142
+ initIRBuilder (B, DL, InsertPt );
1192
1143
return B.CreateCall (LabelFn, Args);
1193
1144
}
1194
1145
0 commit comments