This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Support reserving arbitrary general purpose registers
ClosedPublic

Authored by phosek on Jan 3 2019, 8:22 PM.

Details

Summary

This is a follow up to D48580 and D48581 which allows reserving
arbitrary general purpose registers with the exception of registers
with special purpose (X8, X16-X18, X29, X30) and registers used by LLVM
(X0, X19). This change also generalizes some of the existing logic to
rely entirely on values generated from tablegen.

Diff Detail

Repository
rC Clang

Event Timeline

phosek created this revision.Jan 3 2019, 8:22 PM
phosek updated this revision to Diff 180251.Jan 4 2019, 8:58 AM
trong added inline comments.Jan 4 2019, 2:49 PM
clang/include/clang/Driver/Options.td
2121 ↗(On Diff #180251)

With this patch x9-15 can be specified as both reserved and callee-saved. Could you extend test/CodeGen/AArch64/arm64-reserve-call-saved-reg.ll as well?

clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

What happens (should happen) if we reserve x0 and compile a function with a return value?

carwil added a subscriber: carwil.Jan 18 2019, 10:03 AM

Hi, we're currently working on similar functionality for the ARM backend, so I got pointed to take a look at this patch.
Looks good to me, I quite like the tablegen improvements, but agree with trong's comments.

I assume you've omitted X19, as LLVM uses it as the base pointer?

phosek updated this revision to Diff 185667.Feb 6 2019, 4:17 PM
phosek marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 6 2019, 4:17 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
phosek added a comment.Feb 6 2019, 4:17 PM

Hi, we're currently working on similar functionality for the ARM backend, so I got pointed to take a look at this patch.
Looks good to me, I quite like the tablegen improvements, but agree with trong's comments.

Done.

I assume you've omitted X19, as LLVM uses it as the base pointer?

Yes.

clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

Clang throws error: AArch64 doesn't support function calls if any of the argument registers is reserved. as for any other argument register.

trong added inline comments.Feb 12 2019, 9:59 AM
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

Yes, if x0 is reserved, it can't be used to pass arguments. But what happens if x0 is used to return a value? For example:

int foo() {
    return 1;
}

It would be helpful if compiling foo() with x0 reserved threw an error.

Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 9:59 AM
trong accepted this revision.Feb 12 2019, 10:13 AM
trong added inline comments.
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

OTOH, gcc doesn't complain, so maybe we're OK here.

This revision is now accepted and ready to land.Feb 12 2019, 10:13 AM
efriedma added inline comments.Feb 12 2019, 2:34 PM
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

IIRC gcc never reports any errors for its version of these flags; that doesn't mean we should accept constructs which don't have defined behavior. I'd prefer to print an error in any situation where we would implicitly use a reserved register.

phosek updated this revision to Diff 186583.Feb 12 2019, 8:14 PM
phosek marked 5 inline comments as done.
phosek edited the summary of this revision. (Show Details)
phosek added inline comments.Feb 12 2019, 10:00 PM
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
318 ↗(On Diff #180251)

I've looked into it, but there are several places where LLVM assumes and uses x0, so I think it's safer for now to disallow reserving x0 just like we do with x19.

This revision was automatically updated to reflect the committed changes.