Skip to content

[CodeGen] Enhance inline asm constraint diagnostics #101354

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

e-kud
Copy link
Contributor

@e-kud e-kud commented Jul 31, 2024

No description provided.

@e-kud
Copy link
Contributor Author

e-kud commented Jul 31, 2024

This is a continuation of #96363. Here I want backends to provide additional information why a register can't be allocated.

My points of concerns:

  • I don't like using std::string for error messages.
  • I've tried to return Expected<std::pair<unsigned, const TargetRegisterClass *>> from getRegForInlineAsmConstraint. But this is much more intrusive change than simply adding the reference argument. Because we need to update all return statements in all backends.
  • In case of X86, TargetLowering::getRegForInlineAsmConstraint may override the error message obtained from switches before. But it's not a problem to preserve a message if any, and ignore the one from generic version.

Hi @arsenm @RKSimon @efriedma-quic @phoebewang what do you think? Are there better ways to make backends more friendly in terms of diagnostics.

This is a draft. When or if we agree with the approach, I'll cover all failures from getRegForInlineAsmConstraint for X86. For now I've covered only cases from tests.

@@ -2,7 +2,7 @@
; RUN: not llc -o /dev/null %s 2>&1 | FileCheck %s
target triple = "x86_64-unknown-linux-gnu"

; CHECK: error: couldn't allocate input reg for constraint 'r'
; CHECK: error: couldn't allocate input reg for constraint 'r': couldn't allocate for type v8i16
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can be more specific? Something like "expected an integer, found v8i16"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is hard. To be precise and informative we need to name all the vector combinations that can fit in 128 bits in case of 'x' constraint and even naming is not simple, as we need to understand whether v8f16 is available or not to include it into the message. Or do you mean r constraint in particular?

@@ -5034,7 +5034,8 @@ class TargetLowering : public TargetLoweringBase {
/// returns a register number of 0 and a null register class pointer.
virtual std::pair<unsigned, const TargetRegisterClass *>
getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
StringRef Constraint, MVT VT) const;
StringRef Constraint, MVT VT,
std::string &ErrMsg) const;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe SmallStringImpl&?

I don't really see how you can do much better than that; an error message is, ultimately, just a string, given we don't support translation or anything like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Error or StringError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of SmallString. Error and StringError, they consist of std::string and additionally have a return code that we don't have use of.

Ok, since there aren't strong points for using something like Expected, I'll continue with returning an error message by reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out argument string message is a worse API. I would prefer to use one of the proper return with bundled error message options

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.

3 participants