Skip to content

Commit 63511e0

Browse files
committed
other C-API tactic: use 2 function falvours
1 parent 8b03c20 commit 63511e0

File tree

7 files changed

+220
-78
lines changed

7 files changed

+220
-78
lines changed

llvm/include/llvm-c/Core.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,14 @@ LLVMModuleRef LLVMCloneModule(LLVMModuleRef M);
744744
*/
745745
void LLVMDisposeModule(LLVMModuleRef M);
746746

747+
/**
748+
* Returns true if the module is in the new debug info mode which uses
749+
* non-instruction debug records instead of debug intrinsics for variable
750+
* location tracking.
751+
* See See https://llvm.org/docs/RemoveDIsDebugInfo.html.
752+
*/
753+
LLVMBool LLVMIsNewDbgInfoFormat(LLVMModuleRef M);
754+
747755
/**
748756
* Obtain the identifier of a module.
749757
*

llvm/include/llvm-c/DebugInfo.h

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,10 @@ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
12491249
LLVMMetadataRef Decl, uint32_t AlignInBits);
12501250

12511251
/**
1252+
* Soon to be deprecated.
1253+
* Only use in "old debug mode" (LLVMIsNewDbgFormat() is false).
1254+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1255+
*
12521256
* Insert a new llvm.dbg.declare intrinsic call before the given instruction.
12531257
* \param Builder The DIBuilder.
12541258
* \param Storage The storage of the variable to declare.
@@ -1257,11 +1261,31 @@ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
12571261
* \param DebugLoc Debug info location.
12581262
* \param Instr Instruction acting as a location for the new intrinsic.
12591263
*/
1260-
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
1261-
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1262-
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
1264+
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicBefore(
1265+
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1266+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
1267+
/**
1268+
* Only use in "new debug mode" (LLVMIsNewDbgFormat() is true).
1269+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1270+
*
1271+
* Insert a Declare DbgRecord before the given instruction.
1272+
* \param Builder The DIBuilder.
1273+
* \param Storage The storage of the variable to declare.
1274+
* \param VarInfo The variable's debug info descriptor.
1275+
* \param Expr A complex location expression for the variable.
1276+
* \param DebugLoc Debug info location.
1277+
* \param Instr Instruction acting as a location for the new record.
1278+
*/
1279+
LLVMDbgRecordRef
1280+
LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
1281+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1282+
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
12631283

12641284
/**
1285+
* Soon to be deprecated.
1286+
* Only use in "old debug mode" (LLVMIsNewDbgFormat() is false).
1287+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1288+
*
12651289
* Insert a new llvm.dbg.declare intrinsic call at the end of the given basic
12661290
* block. If the basic block has a terminator instruction, the intrinsic is
12671291
* inserted before that terminator instruction.
@@ -1272,11 +1296,32 @@ LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
12721296
* \param DebugLoc Debug info location.
12731297
* \param Block Basic block acting as a location for the new intrinsic.
12741298
*/
1275-
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
1299+
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicAtEnd(
1300+
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1301+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
1302+
/**
1303+
* Only use in "new debug mode" (LLVMIsNewDbgFormat() is true).
1304+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1305+
*
1306+
* Insert a Declare DbgRecord at the end of the given basic block. If the basic
1307+
* block has a terminator instruction, the record is inserted before that
1308+
* terminator instruction.
1309+
* \param Builder The DIBuilder.
1310+
* \param Storage The storage of the variable to declare.
1311+
* \param VarInfo The variable's debug info descriptor.
1312+
* \param Expr A complex location expression for the variable.
1313+
* \param DebugLoc Debug info location.
1314+
* \param Block Basic block acting as a location for the new record.
1315+
*/
1316+
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareAtEnd(
12761317
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
12771318
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
12781319

12791320
/**
1321+
* Soon to be deprecated.
1322+
* Only use in "old debug mode" (Module::IsNewDbgInfoFormat is false).
1323+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1324+
*
12801325
* Insert a new llvm.dbg.value intrinsic call before the given instruction.
12811326
* \param Builder The DIBuilder.
12821327
* \param Val The value of the variable.
@@ -1285,14 +1330,31 @@ LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
12851330
* \param DebugLoc Debug info location.
12861331
* \param Instr Instruction acting as a location for the new intrinsic.
12871332
*/
1288-
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
1289-
LLVMValueRef Val,
1290-
LLVMMetadataRef VarInfo,
1291-
LLVMMetadataRef Expr,
1292-
LLVMMetadataRef DebugLoc,
1293-
LLVMValueRef Instr);
1333+
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicBefore(
1334+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1335+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
1336+
/**
1337+
* Only use in "new debug mode" (Module::IsNewDbgInfoFormat is true).
1338+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1339+
*
1340+
* Insert a new llvm.dbg.value intrinsic call before the given instruction.
1341+
* \param Builder The DIBuilder.
1342+
* \param Val The value of the variable.
1343+
* \param VarInfo The variable's debug info descriptor.
1344+
* \param Expr A complex location expression for the variable.
1345+
* \param DebugLoc Debug info location.
1346+
* \param Instr Instruction acting as a location for the new intrinsic.
1347+
*/
1348+
LLVMDbgRecordRef
1349+
LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val,
1350+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1351+
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
12941352

12951353
/**
1354+
* Soon to be deprecated.
1355+
* Only use in "old debug mode" (Module::IsNewDbgInfoFormat is false).
1356+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1357+
*
12961358
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
12971359
* block. If the basic block has a terminator instruction, the intrinsic is
12981360
* inserted before that terminator instruction.
@@ -1303,12 +1365,26 @@ LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
13031365
* \param DebugLoc Debug info location.
13041366
* \param Block Basic block acting as a location for the new intrinsic.
13051367
*/
1306-
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
1307-
LLVMValueRef Val,
1308-
LLVMMetadataRef VarInfo,
1309-
LLVMMetadataRef Expr,
1310-
LLVMMetadataRef DebugLoc,
1311-
LLVMBasicBlockRef Block);
1368+
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicAtEnd(
1369+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1370+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
1371+
/**
1372+
* Only use in "new debug mode" (Module::IsNewDbgInfoFormat is true).
1373+
* See https://llvm.org/docs/RemoveDIsDebugInfo.html
1374+
*
1375+
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
1376+
* block. If the basic block has a terminator instruction, the intrinsic is
1377+
* inserted before that terminator instruction.
1378+
* \param Builder The DIBuilder.
1379+
* \param Val The value of the variable.
1380+
* \param VarInfo The variable's debug info descriptor.
1381+
* \param Expr A complex location expression for the variable.
1382+
* \param DebugLoc Debug info location.
1383+
* \param Block Basic block acting as a location for the new intrinsic.
1384+
*/
1385+
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueAtEnd(
1386+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1387+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
13121388

13131389
/**
13141390
* Create a new descriptor for a local auto variable.

llvm/include/llvm-c/Types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ typedef struct LLVMOpaqueJITEventListener *LLVMJITEventListenerRef;
169169
*/
170170
typedef struct LLVMOpaqueBinary *LLVMBinaryRef;
171171

172+
/**
173+
* @see llvm::DbgRecord
174+
*/
175+
typedef struct LLVMOpaqueDbgRecord *LLVMDbgRecordRef;
176+
172177
/**
173178
* @}
174179
*/

llvm/include/llvm/IR/DebugProgramInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,8 @@ getDbgValueRange(DPMarker *DbgMarker) {
643643
return DbgMarker->getDbgValueRange();
644644
}
645645

646+
DEFINE_ISA_CONVERSION_FUNCTIONS(DbgRecord, LLVMDbgRecordRef);
647+
646648
} // namespace llvm
647649

648650
#endif // LLVM_IR_DEBUGPROGRAMINSTRUCTION_H

llvm/lib/IR/Core.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ void LLVMAddModuleFlag(LLVMModuleRef M, LLVMModuleFlagBehavior Behavior,
404404
{Key, KeyLen}, unwrap(Val));
405405
}
406406

407+
LLVMBool LLVMIsNewDbgInfoFormat(LLVMModuleRef M) {
408+
return unwrap(M)->IsNewDbgInfoFormat;
409+
}
410+
407411
/*--.. Printing modules ....................................................--*/
408412

409413
void LLVMDumpModule(LLVMModuleRef M) {

llvm/lib/IR/DebugInfo.cpp

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,63 +1659,90 @@ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
16591659
unwrapDI<MDNode>(Decl), nullptr, AlignInBits));
16601660
}
16611661

1662-
LLVMValueRef
1662+
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicBefore(
1663+
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1664+
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) {
1665+
return wrap(
1666+
unwrap(Builder)
1667+
->insertDeclare(unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1668+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1669+
unwrap<Instruction>(Instr))
1670+
.get<Instruction *>());
1671+
}
1672+
LLVMDbgRecordRef
16631673
LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
16641674
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
16651675
LLVMMetadataRef DL, LLVMValueRef Instr) {
1666-
return LLVMValueRef();
1667-
// FIXME: What to do here?
1668-
/*
1669-
return wrap(unwrap(Builder)->insertDeclare(
1670-
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1671-
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1672-
unwrap<Instruction>(Instr)));
1673-
*/
1676+
return wrap(
1677+
unwrap(Builder)
1678+
->insertDeclare(unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1679+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1680+
unwrap<Instruction>(Instr))
1681+
.get<DbgRecord *>());
16741682
}
16751683

1676-
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
1684+
LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicAtEnd(
16771685
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
16781686
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
1679-
return LLVMValueRef();
1680-
// FIXME: What to do here?
1681-
/*
1682-
return wrap(unwrap(Builder)->insertDeclare(
1683-
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1684-
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1685-
unwrap(Block)));
1686-
*/
1687-
}
1688-
1689-
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
1690-
LLVMValueRef Val,
1691-
LLVMMetadataRef VarInfo,
1692-
LLVMMetadataRef Expr,
1693-
LLVMMetadataRef DebugLoc,
1694-
LLVMValueRef Instr) {
1695-
return LLVMValueRef();
1696-
// FIXME: What to do here?
1697-
/*
1698-
return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1699-
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1700-
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1701-
unwrap<Instruction>(Instr)));
1702-
*/
1703-
}
1704-
1705-
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
1706-
LLVMValueRef Val,
1707-
LLVMMetadataRef VarInfo,
1708-
LLVMMetadataRef Expr,
1709-
LLVMMetadataRef DebugLoc,
1710-
LLVMBasicBlockRef Block) {
1711-
return LLVMValueRef();
1712-
// FIXME: What to do here?
1713-
/*
1714-
return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
1715-
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1716-
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1717-
unwrap(Block)));
1718-
*/
1687+
return wrap(unwrap(Builder)
1688+
->insertDeclare(unwrap(Storage),
1689+
unwrap<DILocalVariable>(VarInfo),
1690+
unwrap<DIExpression>(Expr),
1691+
unwrap<DILocation>(DL), unwrap(Block))
1692+
.get<Instruction *>());
1693+
}
1694+
LLVMDbgRecordRef
1695+
LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
1696+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1697+
LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
1698+
return wrap(unwrap(Builder)
1699+
->insertDeclare(unwrap(Storage),
1700+
unwrap<DILocalVariable>(VarInfo),
1701+
unwrap<DIExpression>(Expr),
1702+
unwrap<DILocation>(DL), unwrap(Block))
1703+
.get<DbgRecord *>());
1704+
}
1705+
1706+
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicBefore(
1707+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1708+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) {
1709+
return wrap(unwrap(Builder)
1710+
->insertDbgValueIntrinsic(
1711+
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1712+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1713+
unwrap<Instruction>(Instr))
1714+
.get<Instruction *>());
1715+
}
1716+
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueBefore(
1717+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1718+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) {
1719+
return wrap(unwrap(Builder)
1720+
->insertDbgValueIntrinsic(
1721+
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1722+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1723+
unwrap<Instruction>(Instr))
1724+
.get<DbgRecord *>());
1725+
}
1726+
1727+
LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicAtEnd(
1728+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1729+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
1730+
return wrap(unwrap(Builder)
1731+
->insertDbgValueIntrinsic(
1732+
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1733+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1734+
unwrap(Block))
1735+
.get<Instruction *>());
1736+
}
1737+
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueAtEnd(
1738+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1739+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
1740+
return wrap(unwrap(Builder)
1741+
->insertDbgValueIntrinsic(
1742+
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1743+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
1744+
unwrap(Block))
1745+
.get<DbgRecord *>());
17191746
}
17201747

17211748
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(

0 commit comments

Comments
 (0)