Skip to content

Commit 2e69a99

Browse files
committed
C-API approach #1 - return a union
1 parent 44008e2 commit 2e69a99

File tree

4 files changed

+75
-70
lines changed

4 files changed

+75
-70
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,10 @@ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
12571257
* \param DebugLoc Debug info location.
12581258
* \param Instr Instruction acting as a location for the new intrinsic.
12591259
*/
1260-
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
1261-
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1262-
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
1260+
LLVMDbgInstRef
1261+
LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
1262+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1263+
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
12631264

12641265
/**
12651266
* Insert a new llvm.dbg.declare intrinsic call at the end of the given basic
@@ -1272,7 +1273,7 @@ LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
12721273
* \param DebugLoc Debug info location.
12731274
* \param Block Basic block acting as a location for the new intrinsic.
12741275
*/
1275-
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
1276+
LLVMDbgInstRef LLVMDIBuilderInsertDeclareAtEnd(
12761277
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
12771278
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
12781279

@@ -1285,12 +1286,10 @@ LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
12851286
* \param DebugLoc Debug info location.
12861287
* \param Instr Instruction acting as a location for the new intrinsic.
12871288
*/
1288-
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
1289-
LLVMValueRef Val,
1290-
LLVMMetadataRef VarInfo,
1291-
LLVMMetadataRef Expr,
1292-
LLVMMetadataRef DebugLoc,
1293-
LLVMValueRef Instr);
1289+
LLVMDbgInstRef
1290+
LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val,
1291+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1292+
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
12941293

12951294
/**
12961295
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
@@ -1303,12 +1302,9 @@ LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
13031302
* \param DebugLoc Debug info location.
13041303
* \param Block Basic block acting as a location for the new intrinsic.
13051304
*/
1306-
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
1307-
LLVMValueRef Val,
1308-
LLVMMetadataRef VarInfo,
1309-
LLVMMetadataRef Expr,
1310-
LLVMMetadataRef DebugLoc,
1311-
LLVMBasicBlockRef Block);
1305+
LLVMDbgInstRef LLVMDIBuilderInsertDbgValueAtEnd(
1306+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1307+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
13121308

13131309
/**
13141310
* Create a new descriptor for a local auto variable.

llvm/include/llvm-c/Types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ typedef struct LLVMOpaqueBinary *LLVMBinaryRef;
173173
* @}
174174
*/
175175

176+
typedef struct LLVMOpaqueDbgRecord *LLVMDbgRecord;
177+
typedef struct {
178+
union {
179+
LLVMValueRef Instr;
180+
LLVMDbgRecord Record;
181+
} Ptr;
182+
int IsInstr;
183+
} LLVMDbgInstRef;
184+
176185
LLVM_C_EXTERN_C_END
177186

178187
#endif

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ namespace llvm {
4242

4343
using DbgInstPtr = PointerUnion<Instruction *, DbgRecord *>;
4444

45+
/* Specialized opaque type conversions.
46+
*/
47+
inline DbgInstPtr unwrapDbgUnion(LLVMDbgInstRef Ref) {
48+
DbgInstPtr Unwrapped;
49+
if (Ref.IsInstr)
50+
Unwrapped = unwrap<Instruction>(Ref.Ptr.Instr);
51+
else
52+
Unwrapped = reinterpret_cast<DbgRecord *>(Ref.Ptr.Record);
53+
return Unwrapped;
54+
}
55+
inline LLVMDbgInstRef wrapDbgUnion(DbgInstPtr Ref) {
56+
LLVMDbgInstRef Wrapped;
57+
if (isa<Instruction *>(Ref)) {
58+
Wrapped.Ptr.Instr =
59+
wrap(reinterpret_cast<Value *>(Ref.get<Instruction *>()));
60+
Wrapped.IsInstr = true;
61+
} else {
62+
Wrapped.Ptr.Record =
63+
reinterpret_cast<LLVMDbgRecord>(Ref.get<DbgRecord *>());
64+
Wrapped.IsInstr = false;
65+
}
66+
return Wrapped;
67+
}
68+
4569
class DIBuilder {
4670
Module &M;
4771
LLVMContext &VMContext;

llvm/lib/IR/DebugInfo.cpp

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

1662-
LLVMValueRef
1662+
LLVMDbgInstRef
16631663
LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
16641664
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
16651665
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-
*/
1674-
}
1675-
1676-
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
1677-
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
1678-
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-
*/
1666+
return wrapDbgUnion(unwrap(Builder)->insertDeclare(
1667+
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1668+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
1669+
unwrap<Instruction>(Instr)));
1670+
}
1671+
1672+
LLVMDbgInstRef
1673+
LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
1674+
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
1675+
LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
1676+
return wrapDbgUnion(unwrap(Builder)->insertDeclare(
1677+
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1678+
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL), unwrap(Block)));
1679+
}
1680+
1681+
LLVMDbgInstRef LLVMDIBuilderInsertDbgValueBefore(
1682+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1683+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) {
1684+
return wrapDbgUnion(unwrap(Builder)->insertDbgValueIntrinsic(
1685+
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1686+
unwrap<DILocation>(DebugLoc), unwrap<Instruction>(Instr)));
1687+
}
1688+
1689+
LLVMDbgInstRef LLVMDIBuilderInsertDbgValueAtEnd(
1690+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1691+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
1692+
return wrapDbgUnion(unwrap(Builder)->insertDbgValueIntrinsic(
1693+
unwrap(Val), unwrap<DILocalVariable>(VarInfo), unwrap<DIExpression>(Expr),
1694+
unwrap<DILocation>(DebugLoc), unwrap(Block)));
17191695
}
17201696

17211697
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(

0 commit comments

Comments
 (0)