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

HLS: Initial conversion of llvm intrinsics generated by Clang #483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sjalander
Copy link
Collaborator

Currently only llvm.smin.i32 is handled

Currently only llvm.smin.i32 is handled
@sjalander sjalander requested a review from phate May 14, 2024 06:47
Copy link
Owner

@phate phate left a comment

Choose a reason for hiding this comment

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

I stopped reviewing after I saw that this is extremely limited and would only cover cases for the intrinsic being in the lambda subregion (and not even in any gamma/theta node of the lambda).

The absolutely right way to go about this would be to:

  1. Introduce an smin operation similar like we did for the memcpy intrinsic
  2. Detect the smin intrinsic in the frontend when converting LLVM to RVSDG similarly like we do for memcpy.
  3. Add support for converting the smin operation/node back to an LLVM intrinsic in the backend.
  4. Add a pass in the HLS part that checks for the smin/node and converts it to a gamma.

If you want to restrict it to the HLS part of the compiler (and not touch the other parts of the compiler), then you should:

  1. Add an HLS pass that iterates through all the (sub-)regions of an RVSDG/lambda (you only have one lambda I guess). There is no need for a toplogical sorting, so taking the nodes directly should be enough. For every call node that you find, you :
  2. Compute the CallTypeClassifier
  3. If the call type classifier is an external call and the argument is a smin intrisinc, then replace this node with a gamma node.

{
auto arg = root->argument(i);
auto imp = dynamic_cast<const llvm::impport *>(&arg->port());
std::cout << "impport " << imp->name() << ": " << imp->type().debug_string() << "\n";
Copy link
Owner

Choose a reason for hiding this comment

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

I do not think that that it is intended to print stuff here, no?

std::cout << "impport " << imp->name() << ": " << imp->type().debug_string() << "\n";
if (imp->name().rfind("llvm.", 0) == 0)
{
std::cout << "replacing intrinsic " << imp->name() << std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

Same here.

@@ -413,9 +414,81 @@ rvsdg2ref(llvm::RvsdgModule & rhls, std::string path)
dump_ref(rhls, path);
}

void
Copy link
Owner

Choose a reason for hiding this comment

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

static void

}
}

void
Copy link
Owner

Choose a reason for hiding this comment

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

static void

Comment on lines +420 to +425
for (auto user : *out)
{
if (auto ni = dynamic_cast<rvsdg::node_input *>(user))
{
if (dynamic_cast<const llvm::CallOperation *>(&ni->node()->operation()))
{
Copy link
Owner

@phate phate May 14, 2024

Choose a reason for hiding this comment

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

This will fail to detect the smin if the call node is not in the lambda subregion (i.e., in a gamma or theta of any further nested region)

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.

None yet

2 participants