This is an archive of the discontinued LLVM Phabricator instance.

[MachineOutliner] Add IsOutlined to MachineFunction
ClosedPublic

Authored by pcwang-thead on Mar 15 2023, 9:04 PM.

Details

Summary

We add a field IsOutlined to indicate whether a MachineFunction
is outlined and set it true for outlined functions in MachineOutliner.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 9:04 PM
pcwang-thead requested review of this revision.Mar 15 2023, 9:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 9:04 PM
craig.topper added inline comments.
llvm/include/llvm/CodeGen/MachineFunction.h
377

If we add this property, it needs to be connected to MIR parsing and printing.

Is there a reason we can't instead add the right live-outs?

Is there a reason we can't instead add the right live-outs?

I tried, but it seems to be hard.
We call these outlined functions as function, but they are just shared code fragments with only one basic block. There are some differences between normal functions and outlined functions:

  1. For outlined functions, they end with a JALR instruction (in which isReturn is false); while for normal functions, they end with a PseudoRET (in which isReturn is true). So the only basic block in outlined function is not ReturnBlock(See MachineBasicBlock::isReturnBlock()).
  2. For normal functions, the live-outs of ReturnBlock are callee-saved registers and return value(s)? (IIUC, correct me if I am wrong). But all defs in outlined functions should be live.

I digged into LivePhysRegs.cpp and I could't find a way to add live-outs manually.

Add MIR parsing and printing.

pcwang-thead marked an inline comment as done.Mar 22 2023, 12:30 AM

Do the T-Head specific pseudos being expanded need to expanded as late as the other pseudos? Could you have an earlier expansion pass? I was already nervous about the short forward branch instructions being affected before. I know we determined those cases were ok.

Do the T-Head specific pseudos being expanded need to expanded as late as the other pseudos? Could you have an earlier expansion pass? I was already nervous about the short forward branch instructions being affected before. I know we determined those cases were ok.

Yes and thanks, I just tried. They can be placed in addPreEmitPass() just like MCP.
Apart from this, do you think it's still worthy marking outlined functions?

asb added a comment.Mar 28 2023, 5:40 AM

Do the T-Head specific pseudos being expanded need to expanded as late as the other pseudos? Could you have an earlier expansion pass? I was already nervous about the short forward branch instructions being affected before. I know we determined those cases were ok.

Yes and thanks, I just tried. They can be placed in addPreEmitPass() just like MCP.
Apart from this, do you think it's still worthy marking outlined functions?

For my part, I'd be really interested in @paquette's thoughts on this.

Do the T-Head specific pseudos being expanded need to expanded as late as the other pseudos? Could you have an earlier expansion pass? I was already nervous about the short forward branch instructions being affected before. I know we determined those cases were ok.

Yes and thanks, I just tried. They can be placed in addPreEmitPass() just like MCP.
Apart from this, do you think it's still worthy marking outlined functions?

For my part, I'd be really interested in @paquette's thoughts on this.

If you mean adding the IsOutlined field, I think that it's a good idea. Currently the only way to recognize if a function is outlined is to look at its name, which isn't great. The field is an improvement.

I think it needs a small MIR testcase though. :)

asb added a comment.Mar 29 2023, 7:56 AM

Thanks Jessica - in that case, LGTM once it has the MIR test case Jessica requested.

Thanks Jessica - in that case, LGTM once it has the MIR test case Jessica requested.

I thought the earlier conclusion was that the RISC-V part wasn’t needed if T-Head moves their pseudo expansion in their downstream.

asb added a comment.Mar 29 2023, 8:45 AM

Thanks Jessica - in that case, LGTM once it has the MIR test case Jessica requested.

I thought the earlier conclusion was that the RISC-V part wasn’t needed if T-Head moves their pseudo expansion in their downstream.

Yes, let's drop the RISC-V part of this if there's not a good motivation for running MCP so late.

Remove MCP parts and add MIR test.

I didn't find a target-independent way to test this, so I add some CHECKs to existed RISCV test.

pcwang-thead retitled this revision from [MachineOutliner][MCP][RISCV] Don't run MCP on outlined functions to [MachineOutliner] Add IsOutlined to MachineFunction.Mar 30 2023, 5:12 AM
pcwang-thead edited the summary of this revision. (Show Details)
paquette accepted this revision.Apr 6 2023, 8:29 PM

LGTM!

This revision is now accepted and ready to land.Apr 6 2023, 8:29 PM