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