Skip to content

[ORC] Add signext on @sum() arguments in test. #113308

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

Merged
merged 4 commits into from
Nov 5, 2024

Conversation

JonPsson1
Copy link
Contributor

Use static std::strings for the textual representations of @sum(). The usage of static variables is already there, e.g. with TargetTriple, so I have assumed that this is thread-safe.

The TargetTriple is not the full Triple class, but just the string representation. If the complete version of this is needed, the full Triple is needed so that it can be passed to TargetLibraryInfo getExtAttrForI32Param/Return. For now, there is just a string recognition of s390 which does need the extensions. Maybe this is ok for now as this is just a test, after all..?

Fixes: #112503

Copy link

github-actions bot commented Oct 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@JonPsson1
Copy link
Contributor Author

Ping!

Comment on lines 97 to 98
std::string I32RetExt = "";
std::string I32ArgExt = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

These can just be StringRefs.


std::ostringstream OS;
OS << "define " << I32RetExt << " i32 "
<< R"(@sum()" << "i32 " << I32ArgExt << "%x, i32 " << I32ArgExt << "%y)"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think R"(@sum()" could just be "@sum(".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep

Comment on lines 99 to 100
if (StringRef(TargetTriple).starts_with("s390x-ibm-linux"))
I32RetExt = I32ArgExt = "signext ";
Copy link
Contributor

@lhames lhames Oct 28, 2024

Choose a reason for hiding this comment

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

Is there a way that we could move this out into a common header location that could be used elsewhere in LLVM, or at least in the tests?

E.g.

StringRef getExtension(const Triple &TT) {
  switch (TT.getArch()) {
  case Triple::s390x:
    if (TT.getVendor() == Triple::IBM && TT.getOS() == Triple::Linux)
      return "signext ";
    break;
  default:
    break;
  }
  return "";
}

I'm guessing that we'll need this for Kaleidoscope and some other examples and tests too?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just re-read your comment -- I think a common utility like the above could be handy, but doesn't apply in this C API test where we don't have an llvm::Triple available.

@JonPsson1
Copy link
Contributor Author

I think a common utility like the above could be handy, but doesn't apply in this C API test where we don't have an llvm::Triple available.

ok - I reworked the patch a little so that TargetLibraryInfo is queried instead after constructing a Triple based on the string. Also put this into a little struct that might be reused in other places if needed, as you mentioned.

@JonPsson1
Copy link
Contributor Author

ping - is the new version like something you were thinking of?

Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks @JonPsson1!

@JonPsson1 JonPsson1 merged commit 9f73c69 into llvm:main Nov 5, 2024
8 checks passed
@JonPsson1 JonPsson1 deleted the ArgExt_Orc branch November 5, 2024 03:14
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
Make sure the inlined @sum() function has the right extension attributes
on its arguments.

A new struct TargetI32ArgExtensions is added that sets the Ret/Arg extension
strings given a string TargetTriple. This might be used elsewhere as well for
this purpose if needed.

Fixes: llvm#112503
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.

Assertion "Narrow integer argument must have a valid extension type." failed.
2 participants