@@ -1047,13 +1047,36 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
10471047 LinkedInstr->getMetadata (LLVMContext::MD_DIAssignID));
10481048 assert (Link && " Linked instruction must have DIAssign metadata attached" );
10491049
1050- DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign (
1051- Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1052- // Insert after LinkedInstr.
1053- BasicBlock::iterator NextIt = std::next (LinkedInstr->getIterator ());
1054- NextIt.setHeadBit (true );
1055- insertDbgVariableRecord (DVR, NextIt);
1056- return DVR;
1050+ if (M.IsNewDbgInfoFormat ) {
1051+ DbgVariableRecord *DVR = DbgVariableRecord::createDVRAssign (
1052+ Val, SrcVar, ValExpr, Link, Addr, AddrExpr, DL);
1053+ // Insert after LinkedInstr.
1054+ BasicBlock::iterator NextIt = std::next (LinkedInstr->getIterator ());
1055+ NextIt.setHeadBit (true );
1056+ insertDbgVariableRecord (DVR, NextIt);
1057+ return DVR;
1058+ }
1059+
1060+ LLVMContext &Ctx = LinkedInstr->getContext ();
1061+ Module *M = LinkedInstr->getModule ();
1062+ if (!AssignFn)
1063+ AssignFn = Intrinsic::getOrInsertDeclaration (M, Intrinsic::dbg_assign);
1064+
1065+ std::array<Value *, 6 > Args = {
1066+ MetadataAsValue::get (Ctx, ValueAsMetadata::get (Val)),
1067+ MetadataAsValue::get (Ctx, SrcVar),
1068+ MetadataAsValue::get (Ctx, ValExpr),
1069+ MetadataAsValue::get (Ctx, Link),
1070+ MetadataAsValue::get (Ctx, ValueAsMetadata::get (Addr)),
1071+ MetadataAsValue::get (Ctx, AddrExpr),
1072+ };
1073+
1074+ IRBuilder<> B (Ctx);
1075+ B.SetCurrentDebugLocation (DL);
1076+
1077+ auto *DVI = cast<DbgAssignIntrinsic>(B.CreateCall (AssignFn, Args));
1078+ DVI->insertAfter (LinkedInstr->getIterator ());
1079+ return DVI;
10571080}
10581081
10591082// / Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
@@ -1078,10 +1101,18 @@ DbgInstPtr DIBuilder::insertDbgValueIntrinsic(llvm::Value *Val,
10781101 DIExpression *Expr,
10791102 const DILocation *DL,
10801103 InsertPosition InsertPt) {
1081- DbgVariableRecord *DVR =
1082- DbgVariableRecord::createDbgVariableRecord (Val, VarInfo, Expr, DL);
1083- insertDbgVariableRecord (DVR, InsertPt);
1084- return DVR;
1104+ if (M.IsNewDbgInfoFormat ) {
1105+ DbgVariableRecord *DVR =
1106+ DbgVariableRecord::createDbgVariableRecord (Val, VarInfo, Expr, DL);
1107+ insertDbgVariableRecord (DVR, InsertPt);
1108+ return DVR;
1109+ }
1110+
1111+ if (!ValueFn)
1112+ ValueFn = Intrinsic::getOrInsertDeclaration (&M, Intrinsic::dbg_value);
1113+ auto *DVI = insertDbgIntrinsic (ValueFn, Val, VarInfo, Expr, DL, InsertPt);
1114+ cast<CallInst>(DVI)->setTailCall ();
1115+ return DVI;
10851116}
10861117
10871118DbgInstPtr DIBuilder::insertDeclare (Value *Storage, DILocalVariable *VarInfo,
@@ -1093,10 +1124,25 @@ DbgInstPtr DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
10931124 VarInfo->getScope ()->getSubprogram () &&
10941125 " Expected matching subprograms" );
10951126
1096- DbgVariableRecord *DVR =
1097- DbgVariableRecord::createDVRDeclare (Storage, VarInfo, Expr, DL);
1098- insertDbgVariableRecord (DVR, InsertPt);
1099- return DVR;
1127+ if (M.IsNewDbgInfoFormat ) {
1128+ DbgVariableRecord *DVR =
1129+ DbgVariableRecord::createDVRDeclare (Storage, VarInfo, Expr, DL);
1130+ insertDbgVariableRecord (DVR, InsertPt);
1131+ return DVR;
1132+ }
1133+
1134+ if (!DeclareFn)
1135+ DeclareFn = getDeclareIntrin (M);
1136+
1137+ trackIfUnresolved (VarInfo);
1138+ trackIfUnresolved (Expr);
1139+ Value *Args[] = {getDbgIntrinsicValueImpl (VMContext, Storage),
1140+ MetadataAsValue::get (VMContext, VarInfo),
1141+ MetadataAsValue::get (VMContext, Expr)};
1142+
1143+ IRBuilder<> B (DL->getContext ());
1144+ initIRBuilder (B, DL, InsertPt);
1145+ return B.CreateCall (DeclareFn, Args);
11001146}
11011147
11021148void DIBuilder::insertDbgVariableRecord (DbgVariableRecord *DVR,
@@ -1145,12 +1191,23 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
11451191 " Expected matching subprograms" );
11461192
11471193 trackIfUnresolved (LabelInfo);
1148- DbgLabelRecord *DLR = new DbgLabelRecord (LabelInfo, DL);
1149- if (InsertPt.isValid ()) {
1150- auto *BB = InsertPt.getBasicBlock ();
1151- BB->insertDbgRecordBefore (DLR, InsertPt);
1194+ if (M.IsNewDbgInfoFormat ) {
1195+ DbgLabelRecord *DLR = new DbgLabelRecord (LabelInfo, DL);
1196+ if (InsertPt.isValid ()) {
1197+ auto *BB = InsertPt.getBasicBlock ();
1198+ BB->insertDbgRecordBefore (DLR, InsertPt);
1199+ }
1200+ return DLR;
11521201 }
1153- return DLR;
1202+
1203+ if (!LabelFn)
1204+ LabelFn = Intrinsic::getOrInsertDeclaration (&M, Intrinsic::dbg_label);
1205+
1206+ Value *Args[] = {MetadataAsValue::get (VMContext, LabelInfo)};
1207+
1208+ IRBuilder<> B (DL->getContext ());
1209+ initIRBuilder (B, DL, InsertPt);
1210+ return B.CreateCall (LabelFn, Args);
11541211}
11551212
11561213void DIBuilder::replaceVTableHolder (DICompositeType *&T, DIType *VTableHolder) {
0 commit comments