Skip to content

[RemoveDIs] Update OCaml API and test #86529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions llvm/bindings/ocaml/debuginfo/debuginfo_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ value llvm_dibuild_create_parameter_variable_bytecode(value *argv, int arg) {
value llvm_dibuild_insert_declare_before_native(value Builder, value Storage,
value VarInfo, value Expr,
value DebugLoc, value Instr) {
LLVMValueRef Value = LLVMDIBuilderInsertDeclareBefore(
LLVMDbgRecordRef Value = LLVMDIBuilderInsertDeclareBefore(
DIBuilder_val(Builder), Value_val(Storage), Metadata_val(VarInfo),
Metadata_val(Expr), Metadata_val(DebugLoc), Value_val(Instr));
return to_val(Value);
Expand All @@ -992,7 +992,7 @@ value llvm_dibuild_insert_declare_before_bytecode(value *argv, int arg) {
value llvm_dibuild_insert_declare_at_end_native(value Builder, value Storage,
value VarInfo, value Expr,
value DebugLoc, value Block) {
LLVMValueRef Value = LLVMDIBuilderInsertDeclareAtEnd(
LLVMDbgRecordRef Value = LLVMDIBuilderInsertDeclareAtEnd(
DIBuilder_val(Builder), Value_val(Storage), Metadata_val(VarInfo),
Metadata_val(Expr), Metadata_val(DebugLoc), BasicBlock_val(Block));
return to_val(Value);
Expand All @@ -1012,3 +1012,14 @@ value llvm_dibuild_expression(value Builder, value Addr) {
return to_val(LLVMDIBuilderCreateExpression(
DIBuilder_val(Builder), (uint64_t *)Op_val(Addr), Wosize_val(Addr)));
}

/* llmodule -> bool */
value llvm_is_new_dbg_info_format(value Module) {
return Val_bool(LLVMIsNewDbgInfoFormat(Module_val(Module)));
}

/* llmodule -> bool -> unit */
value llvm_set_is_new_dbg_info_format(value Module, value UseNewFormat) {
LLVMSetIsNewDbgInfoFormat(Module_val(Module), Bool_val(UseNewFormat));
return Val_unit;
}
10 changes: 8 additions & 2 deletions llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ external dibuild_insert_declare_before :
expr:Llvm.llmetadata ->
location:Llvm.llmetadata ->
instr:Llvm.llvalue ->
Llvm.llvalue
Llvm.lldbgrecord
= "llvm_dibuild_insert_declare_before_bytecode" "llvm_dibuild_insert_declare_before_native"

external dibuild_insert_declare_at_end :
Expand All @@ -609,11 +609,17 @@ external dibuild_insert_declare_at_end :
expr:Llvm.llmetadata ->
location:Llvm.llmetadata ->
block:Llvm.llbasicblock ->
Llvm.llvalue
Llvm.lldbgrecord
= "llvm_dibuild_insert_declare_at_end_bytecode" "llvm_dibuild_insert_declare_at_end_native"

external dibuild_expression :
lldibuilder ->
Int64.t array ->
Llvm.llmetadata
= "llvm_dibuild_expression"

external is_new_dbg_info_format : Llvm.llmodule -> bool
= "llvm_is_new_dbg_info_format"

external set_is_new_dbg_info_format : Llvm.llmodule -> bool -> unit
= "llvm_set_is_new_dbg_info_format"
10 changes: 8 additions & 2 deletions llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ val dibuild_insert_declare_before :
expr:Llvm.llmetadata ->
location:Llvm.llmetadata ->
instr:Llvm.llvalue ->
Llvm.llvalue
Llvm.lldbgrecord
(** [dibuild_insert_declare_before] Insert a new llvm.dbg.declare
intrinsic call before the given instruction [instr]. *)

Expand All @@ -670,7 +670,7 @@ val dibuild_insert_declare_at_end :
expr:Llvm.llmetadata ->
location:Llvm.llmetadata ->
block:Llvm.llbasicblock ->
Llvm.llvalue
Llvm.lldbgrecord
(** [dibuild_insert_declare_at_end] Insert a new llvm.dbg.declare
intrinsic call at the end of basic block [block]. If [block]
has a terminator instruction, the intrinsic is inserted
Expand All @@ -680,3 +680,9 @@ val dibuild_expression : lldibuilder -> Int64.t array -> Llvm.llmetadata
(** [dibuild_expression] Create a new descriptor for the specified variable
which has a complex address expression for its address.
See LLVMDIBuilderCreateExpression. *)

val is_new_dbg_info_format : Llvm.llmodule -> bool
(** [is_new_dbg_info_format] See LLVMIsNewDbgInfoFormat *)

val set_is_new_dbg_info_format : Llvm.llmodule -> bool -> unit
(** [set_is_new_dbg_info_format] See LLVMSetIsNewDbgInfoFormat *)
2 changes: 2 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type llmodule
type llmetadata
type lltype
type llvalue
type lldbgrecord
type lluse
type llbasicblock
type llbuilder
Expand Down Expand Up @@ -528,6 +529,7 @@ external value_name : llvalue -> string = "llvm_value_name"
external set_value_name : string -> llvalue -> unit = "llvm_set_value_name"
external dump_value : llvalue -> unit = "llvm_dump_value"
external string_of_llvalue : llvalue -> string = "llvm_string_of_llvalue"
external string_of_lldbgrecord : lldbgrecord -> string = "llvm_string_of_lldbgrecord"
external replace_all_uses_with : llvalue -> llvalue -> unit
= "llvm_replace_all_uses_with"

Expand Down
6 changes: 6 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ type lltype
This type covers a wide range of subclasses. *)
type llvalue

(** Non-instruction debug info record. See the [llvm::DbgRecord] class.*)
type lldbgrecord

(** Used to store users and usees of values. See the [llvm::Use] class. *)
type lluse

Expand Down Expand Up @@ -793,6 +796,9 @@ val dump_value : llvalue -> unit
(** [string_of_llvalue v] returns a string describing the value [v]. *)
val string_of_llvalue : llvalue -> string

(** [string_of_lldbgrecord r] returns a string describing the DbgRecord [r]. *)
val string_of_lldbgrecord : lldbgrecord -> string

(** [replace_all_uses_with old new] replaces all uses of the value [old]
with the value [new]. See the method [llvm::Value::replaceAllUsesWith]. *)
val replace_all_uses_with : llvalue -> llvalue -> unit
Expand Down
9 changes: 9 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,15 @@ value llvm_string_of_llvalue(value M) {
return ValueStr;
}

/* lldbgrecord -> string */
value llvm_string_of_lldbgrecord(value Record) {
char *ValueCStr = LLVMPrintDbgRecordToString(DbgRecord_val(Record));
value ValueStr = caml_copy_string(ValueCStr);
LLVMDisposeMessage(ValueCStr);

return ValueStr;
}

/* llvalue -> llvalue -> unit */
value llvm_replace_all_uses_with(value OldVal, value NewVal) {
LLVMReplaceAllUsesWith(Value_val(OldVal), Value_val(NewVal));
Expand Down
1 change: 1 addition & 0 deletions llvm/bindings/ocaml/llvm/llvm_ocaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void *from_val_array(value Elements);
#define Metadata_val(v) ((LLVMMetadataRef)from_val(v))
#define Type_val(v) ((LLVMTypeRef)from_val(v))
#define Value_val(v) ((LLVMValueRef)from_val(v))
#define DbgRecord_val(v) ((LLVMDbgRecordRef)from_val(v))
#define Use_val(v) ((LLVMUseRef)from_val(v))
#define BasicBlock_val(v) ((LLVMBasicBlockRef)from_val(v))
#define MemoryBuffer_val(v) ((LLVMMemoryBufferRef)from_val(v))
Expand Down
11 changes: 9 additions & 2 deletions llvm/docs/RemoveDIsDebugInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ New functions (all to be deprecated)
LLVMIsNewDbgInfoFormat # Returns true if the module is in the new non-instruction mode.
LLVMSetIsNewDbgInfoFormat # Convert to the requested debug info format.

LLVMDIBuilderInsertDeclareIntrinsicBefore # Insert a debug intrinsic (old debug info format).
LLVMDIBuilderInsertDeclareIntrinsicBefore # Insert a debug intrinsic (old debug info format).
LLVMDIBuilderInsertDeclareIntrinsicAtEnd # Same as above.
LLVMDIBuilderInsertDbgValueIntrinsicBefore # Same as above.
LLVMDIBuilderInsertDbgValueIntrinsicAtEnd # Same as above.

LLVMDIBuilderInsertDeclareRecordBefore # Insert a debug record (new debug info format).
LLVMDIBuilderInsertDeclareRecordBefore # Insert a debug record (new debug info format).
LLVMDIBuilderInsertDeclareRecordAtEnd # Same as above.
LLVMDIBuilderInsertDbgValueRecordBefore # Same as above.
LLVMDIBuilderInsertDbgValueRecordAtEnd # Same as above.

Existing functions (behaviour change)
-------------------------------------
LLVMDIBuilderInsertDeclareBefore # Insert a debug record (new debug info format) instead of a debug intrinsic (old debug info format).
LLVMDIBuilderInsertDeclareAtEnd # Same as above.
LLVMDIBuilderInsertDbgValueBefore # Same as above.
LLVMDIBuilderInsertDbgValueAtEnd # Same as above.
```

# Anything else?
Expand Down
8 changes: 8 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,14 @@ void LLVMDumpValue(LLVMValueRef Val);
*/
char *LLVMPrintValueToString(LLVMValueRef Val);

/**
* Return a string representation of the DbgRecord. Use
* LLVMDisposeMessage to free the string.
*
* @see llvm::DbgRecord::print()
*/
char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record);

/**
* Replace all uses of a value with another one.
*
Expand Down
60 changes: 40 additions & 20 deletions llvm/include/llvm-c/DebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1249,21 +1249,26 @@ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(
LLVMMetadataRef Decl, uint32_t AlignInBits);

/*
* Insert a new llvm.dbg.declare intrinsic call before the given instruction.
* Insert a new Declare DbgRecord before the given instruction.
*
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* Use LLVMSetIsNewDbgInfoFormat(LLVMBool) to convert between formats.
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* \param Builder The DIBuilder.
* \param Storage The storage of the variable to declare.
* \param VarInfo The variable's debug info descriptor.
* \param Expr A complex location expression for the variable.
* \param DebugLoc Debug info location.
* \param Instr Instruction acting as a location for the new intrinsic.
*/
LLVMValueRef
LLVMDbgRecordRef
LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage,
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
/**
* Soon to be deprecated.
* Only use in "old debug mode" (LLVMIsNewDbgFormat() is false).
* Only use in "old debug mode" (LLVMIsNewDbgInfoFormat() is false).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.declare intrinsic call before the given instruction.
Expand All @@ -1279,7 +1284,7 @@ LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicBefore(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
/**
* Soon to be deprecated.
* Only use in "new debug mode" (LLVMIsNewDbgFormat() is true).
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a Declare DbgRecord before the given instruction.
Expand All @@ -1295,22 +1300,27 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordBefore(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);

/**
* Insert a new llvm.dbg.declare intrinsic call at the end of the given basic
* block. If the basic block has a terminator instruction, the intrinsic is
* inserted before that terminator instruction.
* Insert a new Declare DbgRecord at the end of the given basic block. If the
* basic block has a terminator instruction, the intrinsic is inserted before
* that terminator instruction.
*
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* Use LLVMSetIsNewDbgInfoFormat(LLVMBool) to convert between formats.
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* \param Builder The DIBuilder.
* \param Storage The storage of the variable to declare.
* \param VarInfo The variable's debug info descriptor.
* \param Expr A complex location expression for the variable.
* \param DebugLoc Debug info location.
* \param Block Basic block acting as a location for the new intrinsic.
*/
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
LLVMDbgRecordRef LLVMDIBuilderInsertDeclareAtEnd(
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
/**
* Soon to be deprecated.
* Only use in "old debug mode" (LLVMIsNewDbgFormat() is false).
* Only use in "old debug mode" (LLVMIsNewDbgInfoFormat() is false).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.declare intrinsic call at the end of the given basic
Expand All @@ -1328,7 +1338,7 @@ LLVMValueRef LLVMDIBuilderInsertDeclareIntrinsicAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
/**
* Soon to be deprecated.
* Only use in "new debug mode" (LLVMIsNewDbgFormat() is true).
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a Declare DbgRecord at the end of the given basic block. If the basic
Expand All @@ -1346,21 +1356,26 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDeclareRecordAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);

/**
* Insert a new llvm.dbg.value intrinsic call before the given instruction.
* Insert a new Value DbgRecord before the given instruction.
*
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* Use LLVMSetIsNewDbgInfoFormat(LLVMBool) to convert between formats.
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* \param Builder The DIBuilder.
* \param Val The value of the variable.
* \param VarInfo The variable's debug info descriptor.
* \param Expr A complex location expression for the variable.
* \param DebugLoc Debug info location.
* \param Instr Instruction acting as a location for the new intrinsic.
*/
LLVMValueRef
LLVMDbgRecordRef
LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val,
LLVMMetadataRef VarInfo, LLVMMetadataRef Expr,
LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
/**
* Soon to be deprecated.
* Only use in "old debug mode" (Module::IsNewDbgInfoFormat is false).
* Only use in "old debug mode" (LLVMIsNewDbgInfoFormat() is false).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.value intrinsic call before the given instruction.
Expand All @@ -1376,7 +1391,7 @@ LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicBefore(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);
/**
* Soon to be deprecated.
* Only use in "new debug mode" (Module::IsNewDbgInfoFormat is true).
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.value intrinsic call before the given instruction.
Expand All @@ -1392,22 +1407,27 @@ LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueRecordBefore(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr);

/**
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
* block. If the basic block has a terminator instruction, the intrinsic is
* inserted before that terminator instruction.
* Insert a new Value DbgRecord at the end of the given basic block. If the
* basic block has a terminator instruction, the intrinsic is inserted before
* that terminator instruction.
*
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* Use LLVMSetIsNewDbgInfoFormat(LLVMBool) to convert between formats.
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* \param Builder The DIBuilder.
* \param Val The value of the variable.
* \param VarInfo The variable's debug info descriptor.
* \param Expr A complex location expression for the variable.
* \param DebugLoc Debug info location.
* \param Block Basic block acting as a location for the new intrinsic.
*/
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(
LLVMDbgRecordRef LLVMDIBuilderInsertDbgValueAtEnd(
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
/**
* Soon to be deprecated.
* Only use in "old debug mode" (Module::IsNewDbgInfoFormat is false).
* Only use in "old debug mode" (LLVMIsNewDbgInfoFormat() is false).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
Expand All @@ -1425,7 +1445,7 @@ LLVMValueRef LLVMDIBuilderInsertDbgValueIntrinsicAtEnd(
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
/**
* Soon to be deprecated.
* Only use in "new debug mode" (Module::IsNewDbgInfoFormat is true).
* Only use in "new debug mode" (LLVMIsNewDbgInfoFormat() is true).
* See https://llvm.org/docs/RemoveDIsDebugInfo.html#c-api-changes
*
* Insert a new llvm.dbg.value intrinsic call at the end of the given basic
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,20 @@ char* LLVMPrintValueToString(LLVMValueRef Val) {
return strdup(buf.c_str());
}

char *LLVMPrintDbgRecordToString(LLVMDbgRecordRef Record) {
std::string buf;
raw_string_ostream os(buf);

if (unwrap(Record))
unwrap(Record)->print(os);
else
os << "Printing <null> DbgRecord";

os.flush();

return strdup(buf.c_str());
}

void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
}
Expand Down
Loading