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