Skip to content
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

[BOLT] Modify MCPlus annotation internals. NFCI. #70412

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

maksfb
Copy link
Contributor

@maksfb maksfb commented Oct 27, 2023

When annotating MCInst instructions, attach extra annotation operands directly to the annotated instruction, instead of attaching them to an instruction pointed to by a special kInst operand.

With this change, it's no longer necessary to allocate MCInst and most of the first-class annotations come with free memory as currently MCInst is declared with:

SmallVector<MCOperand, 10> Operands;

i.e. more operands than are normally being used.

We still create a kInst operand with a nullptr instruction value to designate the beginning of annotation operands. However, this special operand might not be needed if we can rely on MCInstrDesc::NumOperands.

When annotating MCInst instructions, attach extra annotation operands
directly to the annotated instruction, instead of attaching them to an
instruction pointed to by a special kInst operand.

With this change, it's no longer necessary to allocate MCInst and most
of the first-class annotations come with free memory as currently MCInst
is declared with:

  SmallVector<MCOperand, 10> Operands;

i.e. more operands than are normally being used.

We still create a kInst operand with a nullptr instruction value to
designate the beginning of annotation operands. However, this special
operand might not be needed if we can rely on MCInstrDesc::NumOperands.
@yota9
Copy link
Member

yota9 commented Oct 27, 2023

Nice @maksfb Thank you! It shall speed up golang processing time significantly (probably lowering memory consumption too), shall try it when we would have a free time :)

Copy link
Contributor

@mtvec mtvec left a comment

Choose a reason for hiding this comment

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

LGTM in general, just two remarks:

  • There is some duplication of logic between getNumPrimeOperands and getAnnotationInstOp (searching for kInst). Maybe one could be written in function of the other?
  • Since we don't need any MCPlusBuilder state anymore for annotations, should we move all the annotation-related functions to MCPlus? Not saying that should happen in this PR (the diff is probably fairly large) but it seems to be the more logical place for this functionality.

@maksfb maksfb added the BOLT label Oct 30, 2023
@mtvec
Copy link
Contributor

mtvec commented Nov 2, 2023

One more remark: I think MCPlusBuilder::setLabel should also be made const here.

@maksfb
Copy link
Contributor Author

maksfb commented Nov 6, 2023

LGTM in general, just two remarks:

  • There is some duplication of logic between getNumPrimeOperands and getAnnotationInstOp (searching for kInst). Maybe one could be written in function of the other?

getNumPrimeOperands() is a bit more optimized. It can return before finding the kInst.

  • Since we don't need any MCPlusBuilder state anymore for annotations, should we move all the annotation-related functions to MCPlus? Not saying that should happen in this PR (the diff is probably fairly large) but it seems to be the more logical place for this functionality.

We still use AnnotationAllocators for non-trivial annotations though.

@maksfb
Copy link
Contributor Author

maksfb commented Nov 6, 2023

One more remark: I think MCPlusBuilder::setLabel should also be made const here.

Thanks. I'll add const it in #70147.

@maksfb maksfb merged commit 74e0a26 into llvm:main Nov 6, 2023
4 checks passed
@maksfb maksfb deleted the gh-annotations branch November 6, 2023 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants