This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Move class RISCVPassConfig declaration to RISCVTargetMachine.h for downstream. NFC
AbandonedPublic

Authored by Jim on Feb 28 2022, 9:05 PM.

Details

Summary

We have special need to create a new class inherited from RISCVPassConfig
for just overriding some functions in RISCVPassConfig in our downstream.
And return our new customized class instead.

It couldn't achieve this if class RISCVPassConfig declaration is in RISCVTargetMachine.cpp.
So, move it to RISCVTargetMachine.h.

Diff Detail

Event Timeline

Jim created this revision.Feb 28 2022, 9:05 PM
Jim requested review of this revision.Feb 28 2022, 9:05 PM

Can you clarify what *why* this helps downstream?

Jim updated this revision to Diff 411974.Feb 28 2022, 10:08 PM

clang-format

Jim updated this revision to Diff 411976.Feb 28 2022, 10:25 PM

Add commit log

Jim edited the summary of this revision. (Show Details)Feb 28 2022, 10:26 PM
Jim added a comment.Feb 28 2022, 10:31 PM

Can you clarify what *why* this helps downstream?

Add summary.

Isn’t the function that returns the class in this cpp file? Why are you able to change that function in your downstream but can’t add your new class to the cpp in your downstream?

Jim added a comment.Feb 28 2022, 11:21 PM

Isn’t the function that returns the class in this cpp file? Why are you able to change that function in your downstream but can’t add your new class to the cpp in your downstream?

The return function in this cpp is the only place needed to be changed to return new class.
Also add a new #include to include new class header file in this cpp.

In my mind, this two places are hard to conflict with upstream or easily to fix the conflict if upgrade our downstream.

jrtc27 added a comment.Mar 1 2022, 7:38 AM

Inheriting from the pass doesn't make sense, just change the implementations. The TargetPassConfig has access to the TM for a reason. As someone with significant downstream changes I am sympathetic to changing upstream code to be more accommodating, but this change just seems motivated by an arbitrary downstream decision that goes against the intent of LLVM's structure just to avoid the occasional merge conflict (RISCVPassConfig hardly changes much).

jrtc27 added a comment.Mar 1 2022, 7:43 AM

Note that git grep ' : public TargetPassConfig' llvm/lib/Target turns up 21 results, exactly one for each backend, and every single one lives in the backend's TargetMachine.cpp. So moving it to a header, or adding a second one, would go against the convention of every single backend in tree.

Jim added a comment.Mar 1 2022, 5:55 PM

Inheriting from the pass doesn't make sense, just change the implementations. The TargetPassConfig has access to the TM for a reason. As someone with significant downstream changes I am sympathetic to changing upstream code to be more accommodating, but this change just seems motivated by an arbitrary downstream decision that goes against the intent of LLVM's structure just to avoid the occasional merge conflict (RISCVPassConfig hardly changes much).

We create a new class inherited from RISCVPassConfig and make some functions overridden to fit our need. And return our class instead of RISCVPassConfig.
Lot of behaviors between our class and RISCVPassConfig are the same. It doesn't have any change to access TM.
It is not only to avoid the occasional merge conflict. If the class RISCVPassConfig moved to RISCVTargetMachine.h, could let the dowstream reuse RISCVPassConfig in the elegant way (just include header file and inherit it, not touch upstream file much).

Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 5:55 PM
Jim added a comment.Mar 1 2022, 6:03 PM

Note that git grep ' : public TargetPassConfig' llvm/lib/Target turns up 21 results, exactly one for each backend, and every single one lives in the backend's TargetMachine.cpp. So moving it to a header, or adding a second one, would go against the convention of every single backend in tree.

Yes, every backend only have one class inherited from TargetPassConfig. But the downstream class is inherited from RISCVPassConfig. Doesn't have second one public TargetPassConfig.
And I refer from AMDGPU target, it seems AMDGPUPassConfig is declared in AMDGPU/AMDGPUTargetMachine.h not AMDGPU/AMDGPUTargetMachine.cpp.

Creating a new class seems fragile. Does your class call the RISCVPassConfig version of the methods you override? What if your class overrides a method that RISCVPassConfig doesn't override today, but does in the future. Will your class call the newly added override when its done with your override?

Jim added a comment.Mar 1 2022, 6:52 PM

Creating a new class seems fragile. Does your class call the RISCVPassConfig version of the methods you override? What if your class overrides a method that RISCVPassConfig doesn't override today, but does in the future. Will your class call the newly added override when its done with your override?

Our class would call and reuse the RISCVPassConfig version of the methods in most of situations.
If upgrade the base upstream, we have to take care every the newly added override function in the parent class if it is already existed in our class.
If the implementations are the same, remove duplicate one from our class. Or trying to reuse the RISCVPassConfig version depending on the need.

Jim added a comment.Mar 1 2022, 6:59 PM

It not just happen in RISCVPassConfig. If we inherit other class such as RISCVISelDAGToDAG.h and RISCVISelLowering.h, it still need to deal with the newly added override function issue.

jrtc27 added a comment.Mar 1 2022, 7:01 PM

Why do you need to derive from any of them. Just modify them. It's so much more painful to do it the way you're suggesting. I say this as a downstream that makes significant changes to instruction selection and adds totally new ABIs.

Jim abandoned this revision.May 11 2022, 11:57 PM