Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jaynus
Copy link

@jaynus jaynus commented Oct 2, 2025

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_operand family of functions (including get_operands) to return a new OperandValue. They currently had Either<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 to LLVMIsNewDbgInfoFormat
    Module::set_new_debug_format - this corresponds to LLVMSetIsNewDbgInfoFormat
  • Added as_metadata_value to the suite of DI* types, as all these types are metadata values that can be fetched via instruction operands (old) or DbgRecord (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_operand call.

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 be into_basic_value() or try_into() or into()
  • All right() calls must now be into_basic_block() or try_into() or into()

Checklist

…truction operand handling to support debug metadata, with some fixes to error messaging around value types too.
@TheDan64 TheDan64 self-requested a review October 7, 2025 22:10
@TheDan64 TheDan64 added this to the 0.7.0 milestone Oct 7, 2025
/// An operand within a given instruction can be a value, basic block, or metadata.
/// This is a wrapper type to handle those variations returned by `InstructionValue::get_operand` family.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub enum OperandValue<'ctx> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea making a new enum rather than using Either. I think we should swap out usages of Either elsewhere in the codebase as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheDan64 0.7.0 milestone, maybe?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably 0.8.0, trying to get 0.7.0 soon since it's been requested a number of times

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, darn, I was hoping to finish the Orc Engine before the 0.7.0 release.

Copy link
Owner

@TheDan64 TheDan64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@TheDan64
Copy link
Owner

There are some tests that are failing and need to be fixed

@TheDan64
Copy link
Owner

@jaynus are you able to fix the tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants