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
[flang][driver] Add support for -emit-obj in the frontend driver #1152
[flang][driver] Add support for -emit-obj in the frontend driver #1152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that everything builds and passes tests. There are a few files (noted) that need to have clang-format run on them.
I'm not that familiar with the code so I'm not approving, but I didn't see anything wrong other than the clang-format problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. Couple of small comments/questions.
The title mentions emit-obj
but I see lots of emit-llvm
so I'm a bit confused.
@clementval, thanks for taking a look!
|
Ok fine. That's right github does not have a depends on feature. |
Hi, I have just rebased fir-dev on LLVM 85bf221 from last week. You can update the PR as follow (assuming your branch is called my-branch):
Sorry for the inconvenience, I could not wait for every PR to get in and solve all new conflicts on my side, the rebase |
Rebased on top of the rebased |
This patch implements the `EmitObjAction` frontend action. The `CodeGenAction` is extended to contain an instance of `llvm::LLVMCtx` and `llvm::Module`. These variables are unlikely to be needed in other, non-code-gen actions (or in `CompilerInstance` or `CompilerInvocation`), so these should be the right location. Also, a member method for generating LLVM IR is added (see `GenerateLLVMIR`). The target triple is hard-coded as `native`, i.e. no cross-compilation is supported at this stage. `tripleName` in FirContext.cpp is updated from `fir.triple` to `llvm.target_triple`. The former was effectively ignored. The latter is used when lowering from the LLVM dialect in MLIR to LLVM IR (i.e. it's embedded in the generated LLVM IR module). The driver can then re-use that when configuring the backend. With this change, the LLVM IR files generated by e.g. `tco` will from now on contain the correct target triple. The code-gen.f90 test is replaced with code-gen-x86.f90 and code-gen-aarch64.f90. As these tests are arch specific (they check the generated assembly), support for `!REQUIRES: <arch>-registered-target` was added in LIT. The current approach is a bit fragile and will cause problems if multiple targets are available (e.g. X86 and AArch64). That's because `!REQUIRES: X86-registered-target` will be satisfied even on AArch64 targets if the X86 backend is enabled (through e.g. `LLVM_ENABLE_TARGETS`). However, the test could fail as currently `flang-new -fc1 -emit-obj` always generates code for the host architecture. This can be fixed by adding support for `-target`.
Rebased |
| Rebased on top of the rebased fir-dev. Thanks, tested OK. |
Builds on top of #1113