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