Skip to content

[LLVM-C] Add LLVMCreateTargetMachineWithABI #68406

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

Conversation

sebastianpoeplau
Copy link
Contributor

The ABI parameter is used by a number of common backends, including ARM, MIPS, PPC, and RISCV. Exposing it via the C API makes it possible for users of those backends to configure the ABI without custom bindings.

@sebastianpoeplau sebastianpoeplau force-pushed the add-llvm-create-target-machine-with-abi branch 2 times, most recently from c898472 to c574067 Compare October 10, 2023 12:56
@artagnon artagnon requested review from MaskRay and aeubanks October 11, 2023 13:38
@aeubanks
Copy link
Contributor

with so many params, I think for future-proofing the API we should go the route of having an Options opaque struct where callers can fill in whatever params they'd like and a create* function that takes the Options. and have the old API forward to the new one. see https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm-c/Transforms/PassBuilder.h for an example

@sebastianpoeplau
Copy link
Contributor Author

I like that 👍 Will work on it.

@sebastianpoeplau sebastianpoeplau force-pushed the add-llvm-create-target-machine-with-abi branch from c574067 to 0ce4173 Compare October 18, 2023 11:12
@sebastianpoeplau
Copy link
Contributor Author

Done, modeled after the pass builder interface: Users create and manipulate an opaque option structure, then pass it to the new function LLVMCreateTargetMachineWithOptions; the implementation of LLVMCreateTargetMachine uses the option structure.

case LLVMCodeGenLevelAggressive:
OL = CodeGenOptLevel::Aggressive;
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't have a default, we should report_fatal_error() if the user passes an invalid value in

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh wow, GitHub says you reviewed my change on Oct 18, but it didn't show me the review until now 😳 Anyway, I copied the default from the previous implementation, but I agree that raising an error makes more sense; will change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The default was actually a way to handle LLVMCodeGenLevelDefault; I've handled that value explicitly and left the switch statement without a default, so that the compiler now warns if the enum is extended. Same for the translation of the LLVMRelocMode.

@sebastianpoeplau sebastianpoeplau force-pushed the add-llvm-create-target-machine-with-abi branch 3 times, most recently from 2e969b2 to 52aacfe Compare October 26, 2023 08:09
@aeubanks
Copy link
Contributor

looks good, but we really should have tests like llvm/unittests/Passes/PassBuilderBindings/PassBuilderBindingsTest.cpp, can you add some? (sorry that they don't already exist)

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

thanks for adding the test! lgtm with one comment

// Get the default target to keep the test as generic as possible. This may
// not be a target for which we can generate code; in that case we give up.

auto *Triple = LLVMGetDefaultTargetTriple();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm seeing checks in the other unittest that checks if this is empty and bails if so, perhaps we also need it here? I think it's possible to not have a default target triple.

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 point, done.

@aeubanks
Copy link
Contributor

oh, also needs release notes in llvm/docs/ReleaseNotes.rst

@@ -0,0 +1,54 @@
#include "llvm-c/Core.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

also needs license

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

LLVMCreateTargetMachine takes a lot of parameters. This commit therefore
introduces a dedicated option structure in the C interface, allowing the
user to configure the various options and providing reasonable defaults.

It also exposes the ABI option, which is used by a number of common
backends, including ARM, MIPS, PPC, and RISCV. Exposing it via the C API
makes it possible for users of those backends to configure the ABI
without custom bindings.
@sebastianpoeplau sebastianpoeplau force-pushed the add-llvm-create-target-machine-with-abi branch from b9ed30e to 98b88de Compare October 30, 2023 12:41
@aeubanks
Copy link
Contributor

lgtm!

@sebastianpoeplau
Copy link
Contributor Author

lgtm!

Thanks! I don't have permission to merge though - would you mind? 😊

@aeubanks aeubanks merged commit 3351097 into llvm:main Oct 31, 2023
@sebastianpoeplau
Copy link
Contributor Author

Interesting, it seems that the changes are squashed and then committed with the PR description as the commit message 🧐 I'll know for next time that I need to keep the title and description up to date...

Also, I've received an email reporting a build failure on NVPTX builders; it seems that the unit test needs to declare additional dependencies at least in that configuration. What's the process to get a fix in? Do I just create a follow-up PR?

dtcxzyw added a commit that referenced this pull request Nov 1, 2023
This patch adds missing dependencies required by the new unittest introduced by #68406.
@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 1, 2023

@sebastianpoeplau I have the same problem with my local build. It should be fixed by dfcb890.

@sebastianpoeplau
Copy link
Contributor Author

@sebastianpoeplau I have the same problem with my local build. It should be fixed by dfcb890.

Great, thanks for the fix @dtcxzyw!

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