@@ -925,35 +925,47 @@ DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File,
925925 File, Line, Col);
926926}
927927
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) {
931931 return insertDeclare (Storage, VarInfo, Expr, DL, InsertBefore->getParent (),
932932 InsertBefore);
933933}
934934
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) {
938938 // If this block already has a terminator then insert this intrinsic before
939939 // the terminator. Otherwise, put it at the end of the block.
940940 Instruction *InsertBefore = InsertAtEnd->getTerminator ();
941941 return insertDeclare (Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore);
942942}
943943
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+
949964 LLVMContext &Ctx = LinkedInstr->getContext ();
950965 Module *M = LinkedInstr->getModule ();
951966 if (!AssignFn)
952967 AssignFn = Intrinsic::getDeclaration (M, Intrinsic::dbg_assign);
953968
954- auto *Link = LinkedInstr->getMetadata (LLVMContext::MD_DIAssignID);
955- assert (Link && " Linked instruction must have DIAssign metadata attached" );
956-
957969 std::array<Value *, 6 > Args = {
958970 MetadataAsValue::get (Ctx, ValueAsMetadata::get (Val)),
959971 MetadataAsValue::get (Ctx, SrcVar),
@@ -971,35 +983,36 @@ DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
971983 return DVI;
972984}
973985
974- Instruction * DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
975- Instruction *InsertBefore) {
986+ DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
987+ Instruction *InsertBefore) {
976988 return insertLabel (LabelInfo, DL,
977989 InsertBefore ? InsertBefore->getParent () : nullptr ,
978990 InsertBefore);
979991}
980992
981- Instruction * DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
982- BasicBlock *InsertAtEnd) {
993+ DbgInstPtr DIBuilder::insertLabel (DILabel *LabelInfo, const DILocation *DL,
994+ BasicBlock *InsertAtEnd) {
983995 return insertLabel (LabelInfo, DL, InsertAtEnd, nullptr );
984996}
985997
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 (
9921004 V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent () : nullptr ,
9931005 InsertBefore);
994- cast<CallInst>(DVI)->setTailCall ();
1006+ if (DVI.is <Instruction *>())
1007+ cast<CallInst>(DVI.get <Instruction *>())->setTailCall ();
9951008 return DVI;
9961009}
9971010
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) {
10031016 return insertDbgValueIntrinsic (V, VarInfo, Expr, DL, InsertAtEnd, nullptr );
10041017}
10051018
@@ -1023,24 +1036,37 @@ static Function *getDeclareIntrin(Module &M) {
10231036 return Intrinsic::getDeclaration (&M, Intrinsic::dbg_declare);
10241037}
10251038
1026- Instruction * DIBuilder::insertDbgValueIntrinsic (
1039+ DbgInstPtr DIBuilder::insertDbgValueIntrinsic (
10271040 llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
10281041 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+
10291048 if (!ValueFn)
10301049 ValueFn = Intrinsic::getDeclaration (&M, Intrinsic::dbg_value);
10311050 return insertDbgIntrinsic (ValueFn, Val, VarInfo, Expr, DL, InsertBB,
10321051 InsertBefore);
10331052}
10341053
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) {
10391058 assert (VarInfo && " empty or invalid DILocalVariable* passed to dbg.declare" );
10401059 assert (DL && " Expected debug loc" );
10411060 assert (DL->getScope ()->getSubprogram () ==
10421061 VarInfo->getScope ()->getSubprogram () &&
10431062 " 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+
10441070 if (!DeclareFn)
10451071 DeclareFn = getDeclareIntrin (M);
10461072
@@ -1055,6 +1081,23 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
10551081 return B.CreateCall (DeclareFn, Args);
10561082}
10571083
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+
10581101Instruction *DIBuilder::insertDbgIntrinsic (llvm::Function *IntrinsicFn,
10591102 Value *V, DILocalVariable *VarInfo,
10601103 DIExpression *Expr,
@@ -1081,18 +1124,28 @@ Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn,
10811124 return B.CreateCall (IntrinsicFn, Args);
10821125}
10831126
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) {
10871130 assert (LabelInfo && " empty or invalid DILabel* passed to dbg.label" );
10881131 assert (DL && " Expected debug loc" );
10891132 assert (DL->getScope ()->getSubprogram () ==
10901133 LabelInfo->getScope ()->getSubprogram () &&
10911134 " 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+
10921146 if (!LabelFn)
10931147 LabelFn = Intrinsic::getDeclaration (&M, Intrinsic::dbg_label);
10941148
1095- trackIfUnresolved (LabelInfo);
10961149 Value *Args[] = {MetadataAsValue::get (VMContext, LabelInfo)};
10971150
10981151 IRBuilder<> B (DL->getContext ());
0 commit comments