This patch contains only the FE changes previously found in https://reviews.llvm.org/D76130.
Currently all PPC32-bit targets take the PPC32SVRABI path, this patch branches within that path to consume the va_list emitted for AIX and emit the correct VAArg.
Details
- Reviewers
jasonliu sfertile cebowleratibm Xiangling_L
Diff Detail
Event Timeline
clang/test/CodeGen/aix-vararg.c | ||
---|---|---|
10 | As part of a "va_..." family, do we also want to test va_copy? |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4175 | Does this wording of the comment work? | |
4232 | Thanks, I've found it hard to shake the habits my Grade 8 typing teacher taught me. | |
clang/test/CodeGen/aix-vararg.c | ||
4 | I'm worried about legal/copyright issues with using contents from AIX system headers to LLVM testcases. But I can do that for sure once I understand what I am allowed to do. | |
10 | Good suggestion, added. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4175 | Missed updating the class name. Suggested: PPC32_SVR4_ABIInfo --> PowerPC32ABIInfo. |
Renamed PPC32_SVR4ABIInfo class to PPC32ABIInfo.
Fixed test case to use builtins.
Changed comment.
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4204 | So for AIX we are taking PowerPC32ABIInfo right now. And we know EmitVAArg of this target does the right thing on AIX after the change. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4204 | Looking at the values in initDwarfEHRegSizeTable it has the right sizes for all the registers. Even though the OS is different the underlying hardware is the same. I'm not sure it's something that makes sense to support for AIX though, in which case I think its valid to return true to indicate its not supported. getParamTypeAlignment is used only in the context of the alignment for vaarg, we should make sure its correct for AIX since supporting vaarg is the scope of this patch. | |
4231 | Make sure to address the formatting here. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4204 | In that case, is it better if we have lit test to actually exercise the path in getParamTypeAlignment to show that we actually confirmed the behavior is correct for AIX? And if it is some path we do not care for now(ComplexType? VectorType?), then we would want TODOs on them to show we need further investigation later. |
Created PPCAIX32TargetCodeGenInfo class so that initDwarfEHRegSizeTable now returns true on AIX and added a test.
Fixed formatting.
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4204 |
The AIX stdarg headers show that alignment for the va_list is dependent on mode, so 4 on 32 and 8 on 64-bit. getParamAlignment looks like it aligns 4 for non-complex non-struct args.
We already took this path before this patch and I'm correcting some of the behaviour so it's correct for varargs on AIX. I think that we will need to address this depending on when/if we add an AIXABIInfo class. I added a TODO on line 4247 for just that so I think that implies we will investigate everything required for the correct implementation of the whatever remains after the vaarg handling. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
9925 | I don't think CodeGenOpts.FloatABI == "hard" is what we want though. Currently it means if CodeGenOpts.FloatABI is really "hard", then it will pass in true for SoftFloatABI to indicate we are soft float ABI. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
9925 | You're right. I wanted to keep the symmetry but that's not the correct thing to do. |
clang/test/CodeGen/aix-vararg.c | ||
---|---|---|
16 | #0, #1[the last three lines] are redundant, could you clean them up? |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4203 | I have a question here. AIX32 falls into PPC32 target, so why we don't inherit from PPC32TargetCodeGenInfo instead? | |
4208 | Is getDwarfEHStackPointer necessary to be correct for vararg of AIX to work[I guess possibly not]? If not, should it fall into Dwarf related patch rather than in this one? BTW, if your PPCAIX32TargetCodeGenInfo inherits from PPC32TargetCodeGenInfo instead as I mentioned above, then it would be naturally correct. | |
4432 | As simple as this function is, does it make sense to move the body of return true into the class definition? |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4203 | Do we need a separate AIX specific class? We are implementing 2 functions, 1 of which is the same implementation as its PPC32TargetCodeGenInfo counterpart. If we have access to the triple, we can return true when the OS is AIX in PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable. With the implementations being nearly identical (and after enabling DwarfEHRegSizeTable they will be identical) I think we are better to not add a new class if we can avoid it. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4203 | Not adding a new class makes sense to me if we are sure that DwarfEHRegSizeTable will be identical/viable for AIX. |
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4203 | I had an offline conversation with @sfertile, verified that the existing initDwarfEHRegSizeTable() function can work for AIX with minor changes. At first, I thought it may be useuful to create a stub class for for AIX at least. But I was able to access the AIX triple info through getABIInfo() and we can keep the one PPC32 class and diverge for AIX within the function when required. | |
4208 | It's not related to vaarg but the implementation is pretty simple so we might as well do it since we are here. I also added a testcase with this enabled. |
Rebased on https://reviews.llvm.org/D73290 and this patch now depends on it.
Removed PPCAIX32TargetCodegenClass from previous diff.
Corrected behaviour PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable() for 32BIT AIX, and added the expected output to the test case which has also been renamed to reflect that.
A couple minor comments, but patch is almost ready otherwise.
clang/lib/CodeGen/TargetInfo.cpp | ||
---|---|---|
4227–4228 | Pedantic nit: Can we emit a fatal error if -msvr4-struct-return is specified on AIX. Then we can add a lit test which checks for the error, which will change once we verify the options behavior on AIX and enable it. Note: FWIW both Zarko and I have verified the option is accepted and work as expected by passing in r3/r4, I'm just not sure if any padding is handled the same way on AIX as described below. | |
4420 | Minor nit: Can we restructure like this: // 109: vrsave // 110: vscr AssignToArrayRange(Builder, Address, Four8, 109, 110); // AIX does not have SPE registers so we don't set 111 - 113. if (getABIInfo().getTarget().getTriple().isOSAIX()) return false; // 111: spe_acc // 112: spefscr // 113: sfp AssignToArrayRange(Builder, Address, Four8, 111, 113); return false; | |
clang/test/CodeGen/ppc64-aix32-dwarf.c | ||
1 ↗ | (On Diff #256351) | Minor nit: How about naming the test file ppc-dwarf.c |
Addressed comments
-added error for -msvr4-struct-return on AIX and modified appropriate test case
-changed code structure as per comment
-renamed test file
clang/test/CodeGen/ppc32-struct-return.c | ||
---|---|---|
53 ↗ | (On Diff #256398) | If certain front end option is not supported on certain target, I think it makes more sense to have a standard diagnostic in the driver component, instead of "crash" in the backend. |
clang/test/CodeGen/ppc32-struct-return.c | ||
---|---|---|
53 ↗ | (On Diff #256398) | Its not that we don't intend to support the option on AIX, but that support for the option takes further verification on AIX. Since there is a difference how AIX justifies subregister sized values in its argument passing, we can't just assume that this option will pack the return values the same way on AIX and Linux. The focus of this patch was originally to enable and verify the proper IR generation of va-arg/va-lis/va-start, however the scope of the patch has kept growing. If there are codegen differences in packing the return register with the svr4-return option enabled it will grow this patch once again. The fatal error lets us limit the scope of this patch, while not silently emiting bad codegen if there is a difference in how gcc initializes the return registers. If during verification we decide we don't want to support the option on AIX, then adopting a standard diagnostic in the driver component becomes the appropriate behavior. |
clang/test/CodeGen/ppc32-struct-return.c | ||
---|---|---|
53 ↗ | (On Diff #256398) | It wasn't clear for me from the code that this is not a permanent thing. In that case, does it make sense to leave a TODO here and say we need to re-evaluate this in the future to decide if we want to support it or not on AIX? |
clang/test/CodeGen/ppc32-struct-return.c | ||
---|---|---|
53 ↗ | (On Diff #256398) | Just to avoid ambiguity, I meant I'm not sure if we really need this *option* on AIX. |
clang/test/CodeGen/ppc32-struct-return.c | ||
---|---|---|
53 ↗ | (On Diff #256398) |
@sfertile basically articulated my reasoning quite well here. I just want to add, if verified to work on AIX, then we can simply remove the error in that one place and have the option working. GCC on AIX has those options and they work in the same way as described in https://reviews.llvm.org/D73290. I think implementing a compatible GCC option in a fairly straightforward way doesn't hurt us. I agree with your point made earlier, I will add a TODO to make it clearer that we need to completely verify the behaviour. |
Added a TODO to remove the error for msvr4-struct-return on AIX when we verify it works as expected.
Rebased patch to include latest changes in trunk. Removed that it depended on https://reviews.llvm.org/D73290 in the summary, as that patch has been landed.
Minor nit: target --> targets.