Skip to content

Add support for compilation-hints proposal #2627

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Lukasdoe
Copy link
Contributor

Title says it all, this PR adds support for compilation hints.

…tr_freq` and `metadata.code.call_targets` annotations and sections
Copy link
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

CC @kripken who has worked on this in binaryen. Does this approach look reasonable to you?

name(name),
type(Type::InstructionFrequency) {
new (&hint.instruction_frequency)
InstructionFrequency(instruction_frequency);
Copy link
Member

Choose a reason for hiding this comment

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

Can you just do hint.instruction_frequency = instruction_frequency here instead of the placement new?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since hint.instruction_frequency is not a valid C++ object, we're not allowed to use its assignment copy operator. In practice, using it should work as expected, but it is still undefined behavior nevertheless (afaik). That's why I opted for just writing over it, which should definitely be safe.

InstructionFrequency instruction_frequency{};
std::vector<CallTarget> call_targets;
Hint() {}
~Hint() {}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the explicit ctor and dtor here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! The explicit constructor is not required, but the noop destructor is required, since the default one is automatically deleted. (and we do destruction from outside the union based on the stored type.

Copy link
Contributor Author

@Lukasdoe Lukasdoe Aug 22, 2025

Choose a reason for hiding this comment

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

Nvm, while it works on my machine, the CI compilers complain when I remove the constructor^^

std::vector<CallTarget> call_targets;
Hint() {}
~Hint() {}
} hint;
Copy link
Member

Choose a reason for hiding this comment

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

Can this be an anonymous union?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we need to overwrite the constructor, we need to name the union, afaik. But please correct me if there's a way to define a destructor for an anonymous union in C++.


std::string_view name;
std::vector<uint8_t> data;
Type type;
Copy link
Member

Choose a reason for hiding this comment

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

Does type need to be public here?

InstructionFrequency,
CallTargets
};

explicit CodeMetadataExpr(std::string_view name,
Copy link
Member

Choose a reason for hiding this comment

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

IIUC we don't normally use/need the explicit keyword except for single argument ctors?

@Lukasdoe Lukasdoe marked this pull request as ready for review August 22, 2025 14:09
@Lukasdoe Lukasdoe requested a review from sbc100 August 22, 2025 14:34
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.

2 participants