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

Allow extensions to GlobalRegisterAllocator #6577

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

kevindean12
Copy link
Contributor

Splits TR_RegisterCandidate, TR_RegisterCandidates, and GlobalSet into OMR and TR namespaces to allow downstream projects to provide derived classes that extend their functionality. Makes TR_GlobalRegister a proper extensible class, which is necessary because the way that TR_GlobalRegister is used requires that it does not have any virtual functions (instances are initialized inside of a TR_Array and memset to 0, which would interfere with the vtable if the class used dynamic polymorphism). Finally, makes some members of GlobalRegisterAllocator virtual and moves some members' access in GlobalRegisterAllocator from private to protected to allow downstream projects to create derived class extensions of GlobalRegisterAllocator.

@kevindean12 kevindean12 changed the title Allow extensions to GlobalRegisterAllocator WIP Allow extensions to GlobalRegisterAllocator Jun 20, 2022
@kevindean12 kevindean12 force-pushed the extend-regcan branch 3 times, most recently from 7d17d38 to 31f5471 Compare June 21, 2022 20:20
@kevindean12 kevindean12 changed the title WIP Allow extensions to GlobalRegisterAllocator Allow extensions to GlobalRegisterAllocator Jun 30, 2022
@kevindean12
Copy link
Contributor Author

Jenkins build all

@kevindean12
Copy link
Contributor Author

Jenkins build all

@0xdaryl
Copy link
Contributor

0xdaryl commented Feb 7, 2023

@hzongaro : please review

Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

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

I think the changes look good overall. One question I had was whether you considered moving GlobalRegisterAllocator itself to the TR and OMR namespaces as well, and if not, why not?

As I don't have a lot of experience with the tradeoffs involved, I'm just wondering whether doing that now would cause problems for the kind of extension to GlobalRegisterAllocator that you're working on, or if some other downstream project required it in the future, what kind of difficulty it might cause for your project at that point.


#include "optimizer/OMRGlobalRegister_inlines.hpp"

#endif
Copy link
Member

Choose a reason for hiding this comment

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

There's a newline missing at the end of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I didn't strongly consider moving all of TR_GlobalRegisterAllocator to OMR/TR namespace, but that was basically only because it wasn't strictly needed to allow the extension points I was trying to enable here. That being said, I'm not opposed to it, and I don't think that if other projects wanted it structured that way it would cause any problems in downstream projects that I'm aware of.

My understanding (for what it's worth; others with more experience with the OMR code than I may have additional thoughts) is that the tradeoff there is largely a matter of whether making a change to the structure of the class in that way may inadvertently lead to new bugs/disruptions to existing projects, against the consistency it would afford, both to OMR itself in having a consistent style and to downstream projects in having a more consistent set of extension points for the various optimization classes, to have all of the optimizations structured in a similar way (which at the moment actually isn't consistent across the various optimizations - some are TR_, others are in the OMR/TR namespace, others are fully extensible classes - but probably it would be nice if it were consistently one or another of those options).

Copy link
Member

Choose a reason for hiding this comment

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

OK, that sounds reasonable. Once you have a chance to add the missing newline, I'll mark my review as approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a newline to the end of the file.

int32_t numberOfRegistersLiveOnEntry(TR_Array<TR::GlobalRegister> &, bool);
TR_PairedSymbols *findOrCreatePairedSymbols(TR::SymbolReference *symRef1, TR::SymbolReference *symRef2);
bool isDependentStore(TR::Node *, const TR_UseDefInfo::BitVector &, TR::SymbolReference *, bool *);
TR::TreeTop * findPrevTreeTop(TR::TreeTop * &, TR::Node * &, TR::Block *, TR::Block *);
Copy link
Member

Choose a reason for hiding this comment

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

Did you really intend to make _visitCount and all the other fields that follow protected rather than leaving them private? I'm guessing "yes", but it's hard to know what might need to be accessed in downstream implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did intend to make those protected, yes.

@kevindean12 kevindean12 force-pushed the extend-regcan branch 2 times, most recently from caffe97 to 492fd8a Compare March 3, 2023 16:04
Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

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

Looks good to me

@hzongaro
Copy link
Member

hzongaro commented Mar 6, 2023

Jenkins build all

@0xdaryl 0xdaryl self-assigned this Mar 6, 2023
@hzongaro
Copy link
Member

hzongaro commented Mar 6, 2023

I just came across issue #3519, which describes the on-going goal of moving compiler APIs to the TR namespace. Just mentioning it as @0xdaryl requested in that issue.

@hzongaro
Copy link
Member

hzongaro commented Mar 9, 2023

@kevindean12, the copyright updates that you made now conflict with the changes to the new style of copyright from pull request #6923. It also looks like the CI builds never ran for some reason. Once you've removed your updates to the copyrights, I'll request the CI builds again.

-Put TR_RegisterCandidate, TR_RegisterCandidates, and GlobalSet classes
into the OMR namespace and create derived classes in TR namespace,
allowing downstream projects to add a project-level class to those
hierarchies in order to extend functionality.
-Make members of the above classes protected
-Make the following methods virtual:
  -GlobalSet::collectReferencedAutoSymRefs()
  -RegisterCandidate::symbolIsLive()
  -RegisterCandidate::processLiveOnEntryBlocks()
  -RegisterCandidates::findOrCreate()
  -RegisterCandidates::find(TR::SymbolReference *)
  -RegisterCandidates::assign()
  -RegisterCandidates::computeAvailableRegisters()
@kevindean12
Copy link
Contributor Author

Rebased and resolved the copyrights conflicts.

@kevindean12
Copy link
Contributor Author

Jenkins build all

@hzongaro
Copy link
Member

hzongaro commented Mar 10, 2023

MacOS failure appears to be due to #6516 - or it could be the more recently reported #6924, if that's a distinct problem.

Daryl 0xdaryl, I think this change looks good to merge.

@0xdaryl
Copy link
Contributor

0xdaryl commented Mar 14, 2023

@hzongaro : Henry, this will need a corresponding change to the makefiles in OpenJ9 to handle the rename of "OMRRegisterCandidate.cpp" and the addition of "OMRGlobalRegister.cpp"

These are the "common.mk" files used for the older SDK 8 builds.

If you could create a PR for that then I could do a coordinated merge of the two PRs. Thanks.

@hzongaro
Copy link
Member

this will need a corresponding change to the makefiles in OpenJ9

@0xdaryl, thank you for catching that! I will take care of it.

hzongaro added a commit to hzongaro/openj9 that referenced this pull request Mar 14, 2023
OMR pull request eclipse/omr#6577 renames RegisterCandidate.cpp to
OMRRegisterCandidate.cpp, and adds a new file, OMRGlobalRegister.cpp.
Both of these files are located in omr/compiler/optimizer.  This change
updates the OpenJ9 common.mk file that is used by older versions of the
build infrastructure to compile those files.

Signed-off-by:  Henry Zongaro <[email protected]>
Copy link
Member

@hzongaro hzongaro left a comment

Choose a reason for hiding this comment

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

Kevin @kevindean12, sorry for the late re-review comments!

@@ -155,7 +155,7 @@ JIT_PRODUCT_BACKEND_SOURCES+=\
$(JIT_OMR_DIRTY_DIR)/optimizer/ReachingDefinitions.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/OMRRecognizedCallTransformer.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/RedundantAsyncCheckRemoval.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/RegisterCandidate.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/OMRRegisterCandidate.cpp \
Copy link
Member

Choose a reason for hiding this comment

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

Daryl's comment prompted me to take a look at the changes to these common.mk files again. I believe a new entry will be needed for OMRGlobalRegister.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks for catching it! I'll update these two common.mk files.

@@ -157,7 +157,7 @@ JIT_PRODUCT_BACKEND_SOURCES+=\
$(JIT_OMR_DIRTY_DIR)/optimizer/ReachingDefinitions.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/OMRRecognizedCallTransformer.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/RedundantAsyncCheckRemoval.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/RegisterCandidate.cpp \
$(JIT_OMR_DIRTY_DIR)/optimizer/OMRRegisterCandidate.cpp \
Copy link
Member

Choose a reason for hiding this comment

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

Daryl's comment prompted me to take a look at the changes to these common.mk files again. I believe a new entry will be needed for OMRGlobalRegister.cpp

-replace uses of TR_GlobalRegister with TR::GlobalRegister
-the following GRA methods are made virtual for downstream projects
to be able to extend functionality:
	-markAutosUsedIn()
	-transformNode()
	-prepareForBlockExit()
	-registerIsLiveAcrossEdge()
-make several GRA members protected
-make TR_LiveRangeSplitter members protected

Closes: eclipse#6529
@kevindean12
Copy link
Contributor Author

Jenkins build all

@hzongaro
Copy link
Member

Thanks, Kevin @kevindean12. The one failure with the macOS build again appears to be due to #6924, so I think everything looks good.

Daryl @0xdaryl - FYI

@0xdaryl 0xdaryl merged commit 1a20c5d into eclipse:master Mar 20, 2023
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