-
Notifications
You must be signed in to change notification settings - Fork 180
[CIR][WIP] Add ABI lowering pass #1471
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
base: main
Are you sure you want to change the base?
Conversation
|
The direct motivation for this new pass is the proper CallConvLowering of the cir.func @test(%arg0: !cir.method) {
// ...
}Following the current lowering approach, which keeps define dso_local @test({ i64, i64 } %0) {
; ...
}But we actually expect the following LLVM IR (note the differences on the function signatures): define dso_local @test(i64 %0, i64 %1) {
; ...
}To achieve this, I have 3 choices:
At the beginning I thought option 1 would be the easiest way. But as I dig through the rabbit hole I found some tricky stuff behind the scene. The problem comes from the CodeGen of function prologue and epilogue. In the prologue, each argument is assigned a stack slot and stored there. For an argument of type The problem of option 3 is that the LoweringPrepare pass is not a conversion pass, which could be really tricky if you want to do type conversion stuff in it. In my case I have to convert every appearances of Anyway, this PR is still very incomplete and under construction, I'd like to hear some early comments about this from the community. |
d2c4ab8 to
8f89224
Compare
352959f to
fc67ccf
Compare
|
Sorry for the delay here, I finally got the bandwidth to update this PR. The primary goal of this PR is to introduce the cir-abi-lowering pass which performs ABI lowering work for globals and inside each function. The cir-abi-lowering pass converts ABI dependent types to more "fundamental" CIR types, and replaces operations that act on these ABI dependent types with more "fundamental" CIR operations. The idea of cir-abi-lowering is to avoid mixing such ABI lowering logic in LLVM lowering code, which could be confusing and make the code more complex. With the introduction of cir-abi-lowering, we got the following benefits:
|
bcardosolopes
left a comment
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 like the direction overall, thanks for working on this. I feel it's a bit confusing to have both cir-abi-lowering and cir-call-conv-lowering being distinct passes. Can we merge cir-call-conv-lowering into the former while keeping a switch to enable/disable the call conv lowering part (should be default to off for now)? It's fine if you do that in a follow up PR, but I'd like to have a plan before we land this.
That makes sense to me, and I'll do that in a follow-up PR. Actually in short term I also plan to migrate part of LoweringPrepare as well, as some ABI lowering code is put there for now (e.g. the handling of |
…ity and maintainability (llvm#1525) As noted in [this comment](llvm#1442 (comment)), the nested if-arms in `GlobalOpLowering` are somewhat confusing and error-prone. This PR simplifies the logic into more straightforward components. Since LLVM's GlobalOp accepts two types of initializers (either an initializer value or an initializer region), we've extracted the decision logic into a separate function called `lowerInitializer`. This function takes two inout arguments: `mlir::Attribute &init` (for the attribute value) and `bool useInitializerRegion` (as the decision indicator). All code paths then converge at a common epilogue that handles the operation rewriting. The previous implementation for lowering `DataMemberAttr` initializers relied on recursion between MLIR rewrite calls, which made the control flow somewhat opaque. The new version makes this explicit by using a clear self-recursive pattern within `lowerInitializer`.
Fix llvm#1371. Not sure about whether we could remove `convertTypeForMem` completely. Let's fix the doc first.
This change moves all declarations of emit* functions in CIRGenFunction.h into a common location and sorts them alphabetically. The goal of this change is to make it easier to keep upstream and incubator code in a consistent location, making functions easier to find for upstreaming and minimizing conflicts in the incubator when rebasing. I did most of this sort manually, and I've probably been inconsistent in how I treat sorting of uppercase versus lowercase. I made no attempt to provide a rule for ordering different declarations of functions with the same name. We can improve on that over time if anyone feels the need. I tried very hard not to drop comments (one of the reasons I had to do this manually), but I may have lost a few. This change loses the grouping of some declarations that were co-located by common purpose, but most of the declarations lacked a coherent ordering, so I think this is a step forward overall.
This is a rebased version of the inactive PR llvm#1380. --------- Co-authored-by: koparasy <parasyris1@llnl.gov>
Adds implementation for ATanOp's lowering ThroughMLIR.
Lower `vabds_f32` and `vabdd_f64`
Adds implementation for ACosOp's lowering ThroughMLIR.
Lower vmaxv_s32
Adds implementation for ASinOp's lowering ThroughMLIR.
Lower vmaxv_u32
Lower vmaxvq_f64
Lower vmaxnmvq f32 and f64
In the review for upstreaming unary operation support (llvm/llvm-project#131369), it was suggested that the VisitPlus and VisitMinus functions should be combined. This is a backport of that refactoring.
This also removes some unused `#include`s. I choose to allow lowering to LLVM dialect when we're lowering CIR to MLIR core dialects, because some operations don't have their counterparts in these dialects (for example, `UnreachableOp -> llvm.unreachable` and `LLVMIntrinsicCallOp -> cir.llvm.intr.xxx`). I don't think we can delay them to the MLIR->LLVM pass as it seems we assume all CIR operations have been lowered after CIR->MLIR conversion. Co-authored-by: Yue Huang <yh548@cam.ac.uk>
Special handling for array of unions was forcing all non-union C arrays to be emitted as CIR arrays, which differs from OG CodeGen, where array may be emitted as LLVM struct. Closes llvm#1315
We were missing argument handling for `-fclangir-idiom-recognizer` on its own, and were not propagating `-fclangir-lib-opt` for the clang toolchain.
Failure: ``` calling convention does not permit calls call spir_kernel void @bar(ptr addrspace(1) %10) fatal error: error in backend: Lowering from LLVMIR dialect to llvm IR failed! ```
This makes it on par with OG but does not add anything just yet (same NYI asserts should fail).
This will enable handling for records (coming next)
This includes member data attribute in to enable and existing test. LLVM lowering is follow up work. Fixes XFAIL in ../clang/test/CIR/CodeGen/nonzeroinit-struct.cpp
This PR is inspired by the discussion in llvm#1745 (comment). When changing the type of ```mlir IndexAttr:$index, I64Attr:$index ``` in `GetMemberOp`, the `getIndex` method becomes auto-generated. This allows us to remove the custom builder previously defined for this operation.
Backport AbstractConditionalOperator for ComplexType from the upstream Fix: llvm#1788
Previously, when an array of destructible object went out of scope, the object destructors were called in the same order that they were constructed. This is incorrect. The objects should be destructed in reverse order. This change fixes that. This fixes llvm#1759
Backport LValueBitcast support for ComplexType from the upstream
This patch adds a new pass cir-abi-lowering to the CIR dialect. This pass runs before the CallConvLowering pass, and it expands all ABI-dependent types and operations inside a function to their ABI-independent equivalences according to the ABI specification. This patch also moves the lowering code of the following types and operations from the LLVM lowering conversion to the new pass: - The pointer-to-data-member type `cir.data_member`; - The pointer-to-member-function type `cir.method`; - All operations working on operands of the above types.
fc67ccf to
57f037d
Compare
|
Rebased. |
8acaf96 to
58135ea
Compare
This PR attempts to add a new pass
cir-abi-loweringto the CIR dialect. This pass runs before the CallConvLowering pass, and it expands all ABI-dependent types and operations inside a function to their ABI-independent equivalences according to the ABI specification.The patch also moves the lowering code of the following types and operations from the LLVM lowering conversion to the new pass:
cir.data_member;cir.method;