Skip to content
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

Refactoring & cleanup of linkage properties #5836

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

janvrany
Copy link
Contributor

@janvrany janvrany commented Mar 1, 2021

The aim of this draft is to serve as a starting point for upcoming OMR arch meeting #5816.

The code does the refactoring for RISC-V backend and for POWER backend (unfinished as of now, I intend push some more work), the rest is kept as it is for now.

FYI @fjeremic , @aviansie-ben (as I'm hacking POWER backend too)

Comment on lines +171 to +174
FOR_EACH_RESERVED_REGISTER(machine, _properties,
reg->setState(TR::RealRegister::Locked);
reg->setAssignedRegister(reg);
);
Copy link
Contributor

@fjeremic fjeremic Mar 1, 2021

Choose a reason for hiding this comment

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

Personally I don't find this macro useful. Similarly for other similar macros introduced here. To me it adds an extra layer of abstraction/complexity when it is merely just a for loop. I recall when I first started with the codebase and didn't have a proper editor with symbols setup and I saw the:

https://github.com/eclipse/omr/blob/eb4f5a875f3b30b1dd3512f77b3c7a1293a78724/compiler/env/OMRCPU.cpp#L150-L160

OMRPORT_ACCESS_FROM_OMRPORT and similar macros. I could never find what that was doing or where this magical privatePortLibrary local variable was coming from. It turns out all that macro does is declare a local variable:

https://github.com/eclipse/omr/blob/eb4f5a875f3b30b1dd3512f77b3c7a1293a78724/include_core/omrport.h#L70

And then omrsysinfo_* macros consume that local variable silently:

https://github.com/eclipse/omr/blob/eb4f5a875f3b30b1dd3512f77b3c7a1293a78724/include_core/omrport.h#L2688

This is super unintuitive to me as a new contributor to the codebase. To me simply declaring the local variable and using the API by passing all arguments is much more clear. No need to peel layers of complexity to understand what is happening, i.e. "in the FOR_EACH_RESERVED_REGISTER which argument needs a comma, and which argument needs a semicolon?".

I'd say a similar principle applies here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally I don't find this macro useful.

I must say I find it useful in a sense it makes it much shorter so the body is not "burried" in copy-pasted boilerplate code (*) - it is used on several places in linkage code.

(*) like geting a TR::RealRegister* for given TR::RealRegister::RegNum while filtering by register flags.

I do share your dislike for macros (and #define of constants) and I'd like to replace this macro with range-based for-loop so one can do something like

for (auto reg : this->getReservedRegisters()) { ... }

but as of now, coding standards forbid range-based for-loops (but they're out of date, AFAIK, see #5592). Also for time reasons, I left this exercise for a future.

@janvrany janvrany force-pushed the pr/riscv-refactor-linkage-properties branch from 0c6abc7 to 6b2143f Compare March 3, 2021 15:39
janvrany added 19 commits March 3, 2021 15:42
…RESERVED_REGISTER()` macro

Signed-off-by: Jan Vrany <[email protected]>
This makes them available for use in other linkages too.

Signed-off-by: Jan Vrany <[email protected]>
This allows one using for-loop over registers without having to cast
to int and back.

Signed-off-by: Jan Vrany <[email protected]>
…ived members

Linkage properties have a number of members whose values can be derived from register flags.
This commit introduces a new method initialize() that computes these values based on
_registerFlags.

Linkages are expected to fill in register flags and then call initialize() to finish properties
initialization.

Signed-off-by: Jan Vrany <[email protected]>
… class

This commit introduces a new class, RVSystemLinkageProperties and moves all
necessary initialization to its ctor (from RVSystemLinkage ctor).

This is a preparation to make linkage properties static.

Signed-off-by: Jan Vrany <[email protected]>
This is a preparation to common some parts of linkage properties.

Signed-off-by: Jan Vrany <[email protected]>
This is a preparation for commoning.

Signed-off-by: Jan Vrany <[email protected]>
This is a preparation to common some parts of linkage properties.

Signed-off-by: Jan Vrany <[email protected]>
This commit hoists ++ operators for RegNum type from RISC-V to common code.
This requires all platforms to define FirstRealRegister and LastRealRegister
enum values (in RealRegisterEnum.hpp) - this commit does so only for RISC-V and
POWER!

Signed-off-by: Jan Vrany <[email protected]>
…erties

Alternate stack pointer register is not used in OMR nor in OpenJ9 and this can
be removed.

Signed-off-by: Jan Vrany <[email protected]>
This is a preparation for commoning large chunk or linkage properties.

Signed-off-by: Jan Vrany <[email protected]>
This commit reorders and regroups some POWER-specific linkage
members to improve readability. Also changes type of members
holding registers from uint8_t to TR::RealRegister::RegNum - this
makes it more obvious when debugging (GDB prints the symbolic name
rather than numerical value)

Signed-off-by: Jan Vrany <[email protected]>
It's meaning is not documented and bit unclear, the aim of this commit
is to make a note an revisit later.

Signed-off-by: Jan Vrany <[email protected]>
…ived members

This commit follows similar commit in RISC-V.

However, the resulting linkage properties differ in few ways:

 * gr11 is no longer among _argumentRegisters[] array. This seems to
   be some POWER hack, see @ymanton's explanation [1].
 * the value of _firstAllocatableIntegerRegisters (and ..Float... and ...Vector...)
   is different - it is now the first argument register as per ABI.
   Why it was different is unclear.

[1]: https://eclipse-omr.slack.com/archives/CBSE78L4U/p1614372165001600

Signed-off-by: Jan Vrany <[email protected]>
@janvrany janvrany force-pushed the pr/riscv-refactor-linkage-properties branch from 6b2143f to 08534c2 Compare March 3, 2021 15:49
@janvrany
Copy link
Contributor Author

janvrany commented Mar 3, 2021

omr-genie build aix, plinux, riscv

@janvrany
Copy link
Contributor Author

janvrany commented Mar 3, 2021

genie-omr build aix, plinux, riscv

Individual backends can extend this class to add their own members and/or tweak values.
This commit does this only for RISC-V and POWER as POC.

Signed-off-by: Jan Vrany <[email protected]>
@janvrany janvrany force-pushed the pr/riscv-refactor-linkage-properties branch from 47636d3 to 3376c96 Compare March 4, 2021 16:52
@janvrany
Copy link
Contributor Author

janvrany commented Mar 4, 2021

genie-omr build aix, plinux

@gita-omr
Copy link
Contributor

gita-omr commented Mar 4, 2021

@zl-wang fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants