Add debug information utility functions and support Metadata on Operands
Description
Adds a few utility functions around debug information and changes instruction operand handling to support debug metadata, with some fixes to error messaging around value types too.
Changes
- Changes
InstructionValue::get_operandfamily of functions (includingget_operands) to return a newOperandValue. They currently hadEither<BasicValue, BasicBlock>which is insufficient for operands - they can be metadata values as well. - Added Helper functions for the transitional DbgRecord changes.
Module::is_new_debug_format- this corresponds toLLVMIsNewDbgInfoFormatModule::set_new_debug_format- this corresponds toLLVMSetIsNewDbgInfoFormat - Added
as_metadata_valueto the suite ofDI*types, as all these types are metadata values that can be fetched via instruction operands (old) orDbgRecord(new) - Better output to the panics in the enum variants, so you can see what kind was unimplemente
- Updated tests to all pass for the new
get_operandcall.
How This Has Been Tested
This was tested with llvm 20.1 locally in a personal project. Ex usage such as:
module.set_new_debug_format(false);
module.get_functions().for_each(|function| {
function.get_basic_blocks().iter().for_each(|block| {
block.get_instructions().skip(1).for_each(|instr| {
(0..instr.get_num_operands()).for_each(|i| {
if let Some(OperandValue::BasicMetadataValue(metadata)) =
instr.get_operand(i)
{
... Handle debug metadata operands here....
}
});
});
}
});
});
Breaking Changes
Changes InstructionValue::get_operand and OperandIter to use OperandValue instead of Either<BasicValue, BasicBlock>. This was required because operands on a value instruction can be more than just BasicValue or BasicBlock, they can also be MetadataValue in the case of debug intrinsics.
- All
left()calls must now beinto_basic_value()ortry_into()orinto() - All
right()calls must now beinto_basic_block()ortry_into()orinto()
Checklist
- [x] I have read the Contributing Guide
There are some tests that are failing and need to be fixed
@jaynus are you able to fix the tests?
@jaynus bump, would like to get this into the upcoming release if possible
@jaynus, if you ever get around to finishing this up, I just want to apologize for creating a merge conflict. You see, I thought your idea of using the OperandValue enum was a good idea, and I decided to go ahead and replace all instances of Either with a specialized enum, but I didn't realize that your PR hadn't been merged yet, so unfortunately I wrote code that will conflict with your code, and now my PR has been merged. Sorry for stepping on your toes.