@@ -925,35 +925,47 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
925
925
File, Line, Col);
926
926
}
927
927
928
- Instruction * DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
929
- DIExpression *Expr, const DILocation *DL,
930
- Instruction *InsertBefore) {
928
+ DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
929
+ DIExpression *Expr, const DILocation *DL,
930
+ Instruction *InsertBefore) {
931
931
return insertDeclare (Storage, VarInfo, Expr, DL, InsertBefore->getParent (),
932
932
InsertBefore);
933
933
}
934
934
935
- Instruction * DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
936
- DIExpression *Expr, const DILocation *DL,
937
- BasicBlock *InsertAtEnd) {
935
+ DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
936
+ DIExpression *Expr, const DILocation *DL,
937
+ BasicBlock *InsertAtEnd) {
938
938
// If this block already has a terminator then insert this intrinsic before
939
939
// the terminator. Otherwise, put it at the end of the block.
940
940
Instruction *InsertBefore = InsertAtEnd->getTerminator ();
941
941
return insertDeclare (Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
942
942
}
943
943
944
- DbgAssignIntrinsic *
945
- DIBuilder::insertDbgAssign (Instruction *LinkedInstr, Value *Val,
946
- DILocalVariable *SrcVar, DIExpression *ValExpr,
947
- Value *Addr, DIExpression *AddrExpr,
948
- const DILocation *DL) {
944
+ DbgInstPtr DIBuilder::insertDbgAssign (Instruction *LinkedInstr, Value *Val,
945
+ DILocalVariable *SrcVar,
946
+ DIExpression *ValExpr, Value *Addr,
947
+ DIExpression *AddrExpr,
948
+ const DILocation *DL) {
949
+ auto *Link = cast_or_null<DIAssignID>(
950
+ LinkedInstr->getMetadata (LLVMContext::MD_DIAssignID));
951
+ assert (Link && " Linked instruction must have DIAssign metadata attached" );
952
+
953
+ if (M.IsNewDbgInfoFormat ) {
954
+ DPValue *DPV = DPValue::createDPVAssign (Val, SrcVar, ValExpr, Link, Addr,
955
+ AddrExpr, DL);
956
+ BasicBlock *InsertBB = LinkedInstr->getParent ();
957
+ // Insert after LinkedInstr.
958
+ BasicBlock::iterator NextIt = std::next (LinkedInstr->getIterator ());
959
+ Instruction *InsertBefore = NextIt == InsertBB->end () ? nullptr : &*NextIt;
960
+ insertDPValue (DPV, InsertBB, InsertBefore, true );
961
+ return DPV;
962
+ }
963
+
949
964
LLVMContext &Ctx = LinkedInstr->getContext ();
950
965
Module *M = LinkedInstr->getModule ();
951
966
if (!AssignFn)
952
967
AssignFn = Intrinsic::getDeclaration (M, Intrinsic::dbg_assign);
953
968
954
- auto *Link = LinkedInstr->getMetadata (LLVMContext::MD_DIAssignID);
955
- assert (Link && " Linked instruction must have DIAssign metadata attached" );
956
-
957
969
std::array<Value *, 6 > Args = {
958
970
MetadataAsValue::get (Ctx, ValueAsMetadata::get (Val)),
959
971
MetadataAsValue::get (Ctx, SrcVar),
@@ -971,35 +983,36 @@ DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
971
983
return DVI;
972
984
}
973
985
974
- Instruction * DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
975
- Instruction *InsertBefore) {
986
+ DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
987
+ Instruction *InsertBefore) {
976
988
return insertLabel (LabelInfo, DL,
977
989
InsertBefore ? InsertBefore->getParent () : nullptr ,
978
990
InsertBefore);
979
991
}
980
992
981
- Instruction * DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
982
- BasicBlock *InsertAtEnd) {
993
+ DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
994
+ BasicBlock *InsertAtEnd) {
983
995
return insertLabel (LabelInfo, DL, InsertAtEnd, nullptr );
984
996
}
985
997
986
- Instruction * DIBuilder::insertDbgValueIntrinsic (Value *V,
987
- DILocalVariable *VarInfo,
988
- DIExpression *Expr,
989
- const DILocation *DL,
990
- Instruction *InsertBefore) {
991
- Instruction * DVI = insertDbgValueIntrinsic (
998
+ DbgInstPtr DIBuilder::insertDbgValueIntrinsic (Value *V,
999
+ DILocalVariable *VarInfo,
1000
+ DIExpression *Expr,
1001
+ const DILocation *DL,
1002
+ Instruction *InsertBefore) {
1003
+ DbgInstPtr DVI = insertDbgValueIntrinsic (
992
1004
V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent () : nullptr ,
993
1005
InsertBefore);
994
- cast<CallInst>(DVI)->setTailCall ();
1006
+ if (DVI.is <Instruction *>())
1007
+ cast<CallInst>(DVI.get <Instruction *>())->setTailCall ();
995
1008
return DVI;
996
1009
}
997
1010
998
- Instruction * DIBuilder::insertDbgValueIntrinsic (Value *V,
999
- DILocalVariable *VarInfo,
1000
- DIExpression *Expr,
1001
- const DILocation *DL,
1002
- BasicBlock *InsertAtEnd) {
1011
+ DbgInstPtr DIBuilder::insertDbgValueIntrinsic (Value *V,
1012
+ DILocalVariable *VarInfo,
1013
+ DIExpression *Expr,
1014
+ const DILocation *DL,
1015
+ BasicBlock *InsertAtEnd) {
1003
1016
return insertDbgValueIntrinsic (V, VarInfo, Expr, DL, InsertAtEnd, nullptr );
1004
1017
}
1005
1018
@@ -1023,24 +1036,37 @@ static Function *getDeclareIntrin(Module &M) {
1023
1036
return Intrinsic::getDeclaration (&M, Intrinsic::dbg_declare);
1024
1037
}
1025
1038
1026
- Instruction * DIBuilder::insertDbgValueIntrinsic (
1039
+ DbgInstPtr DIBuilder::insertDbgValueIntrinsic (
1027
1040
llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
1028
1041
const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
1042
+ if (M.IsNewDbgInfoFormat ) {
1043
+ DPValue *DPV = DPValue::createDPValue (Val, VarInfo, Expr, DL);
1044
+ insertDPValue (DPV, InsertBB, InsertBefore);
1045
+ return DPV;
1046
+ }
1047
+
1029
1048
if (!ValueFn)
1030
1049
ValueFn = Intrinsic::getDeclaration (&M, Intrinsic::dbg_value);
1031
1050
return insertDbgIntrinsic (ValueFn, Val, VarInfo, Expr, DL, InsertBB,
1032
1051
InsertBefore);
1033
1052
}
1034
1053
1035
- Instruction * DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
1036
- DIExpression *Expr, const DILocation *DL,
1037
- BasicBlock *InsertBB,
1038
- Instruction *InsertBefore) {
1054
+ DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
1055
+ DIExpression *Expr, const DILocation *DL,
1056
+ BasicBlock *InsertBB,
1057
+ Instruction *InsertBefore) {
1039
1058
assert (VarInfo && " empty or invalid DILocalVariable* passed to dbg.declare" );
1040
1059
assert (DL && " Expected debug loc" );
1041
1060
assert (DL->getScope ()->getSubprogram () ==
1042
1061
VarInfo->getScope ()->getSubprogram () &&
1043
1062
" Expected matching subprograms" );
1063
+
1064
+ if (M.IsNewDbgInfoFormat ) {
1065
+ DPValue *DPV = DPValue::createDPVDeclare (Storage, VarInfo, Expr, DL);
1066
+ insertDPValue (DPV, InsertBB, InsertBefore);
1067
+ return DPV;
1068
+ }
1069
+
1044
1070
if (!DeclareFn)
1045
1071
DeclareFn = getDeclareIntrin (M);
1046
1072
@@ -1055,6 +1081,23 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
1055
1081
return B.CreateCall (DeclareFn, Args);
1056
1082
}
1057
1083
1084
+ void DIBuilder::insertDPValue (DPValue *DPV, BasicBlock *InsertBB,
1085
+ Instruction *InsertBefore, bool InsertAtHead) {
1086
+ assert (InsertBefore || InsertBB);
1087
+ trackIfUnresolved (DPV->getVariable ());
1088
+ trackIfUnresolved (DPV->getExpression ());
1089
+ if (DPV->isDbgAssign ())
1090
+ trackIfUnresolved (DPV->getAddressExpression ());
1091
+
1092
+ BasicBlock::iterator InsertPt;
1093
+ if (InsertBB && InsertBefore)
1094
+ InsertPt = InsertBefore->getIterator ();
1095
+ else if (InsertBB)
1096
+ InsertPt = InsertBB->end ();
1097
+ InsertPt.setHeadBit (InsertAtHead);
1098
+ InsertBB->insertDPValueBefore (DPV, InsertPt);
1099
+ }
1100
+
1058
1101
Instruction *DIBuilder::insertDbgIntrinsic (llvm::Function *IntrinsicFn,
1059
1102
Value *V, DILocalVariable *VarInfo,
1060
1103
DIExpression *Expr,
@@ -1081,18 +1124,28 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
1081
1124
return B.CreateCall (IntrinsicFn, Args);
1082
1125
}
1083
1126
1084
- Instruction * DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
1085
- BasicBlock *InsertBB,
1086
- Instruction *InsertBefore) {
1127
+ DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
1128
+ BasicBlock *InsertBB,
1129
+ Instruction *InsertBefore) {
1087
1130
assert (LabelInfo && " empty or invalid DILabel* passed to dbg.label" );
1088
1131
assert (DL && " Expected debug loc" );
1089
1132
assert (DL->getScope ()->getSubprogram () ==
1090
1133
LabelInfo->getScope ()->getSubprogram () &&
1091
1134
" Expected matching subprograms" );
1135
+
1136
+ trackIfUnresolved (LabelInfo);
1137
+ if (M.IsNewDbgInfoFormat ) {
1138
+ DPLabel *DPL = new DPLabel (LabelInfo, DL);
1139
+ if (InsertBB && InsertBefore)
1140
+ InsertBB->insertDPValueBefore (DPL, InsertBefore->getIterator ());
1141
+ else if (InsertBB)
1142
+ InsertBB->insertDPValueBefore (DPL, InsertBB->end ());
1143
+ return DPL;
1144
+ }
1145
+
1092
1146
if (!LabelFn)
1093
1147
LabelFn = Intrinsic::getDeclaration (&M, Intrinsic::dbg_label);
1094
1148
1095
- trackIfUnresolved (LabelInfo);
1096
1149
Value *Args[] = {MetadataAsValue::get (VMContext, LabelInfo)};
1097
1150
1098
1151
IRBuilder<> B (DL->getContext ());
0 commit comments