Skip to content

SSA CFG: introduce projections for functions with multiple return values#16668

Merged
clonker merged 4 commits intodevelopfrom
ssa-cfg-extracts
May 4, 2026
Merged

SSA CFG: introduce projections for functions with multiple return values#16668
clonker merged 4 commits intodevelopfrom
ssa-cfg-extracts

Conversation

@clonker
Copy link
Copy Markdown
Member

@clonker clonker commented May 4, 2026

  • removes ValueId = (InstId, outputPos) in favor of plain InstIds
  • multi-return-valued function calls (with >= 2 output values) now have
    • one Inst for the operation itself
    • as many projection Insts as they have outputs
  • single-output ops keep their InstId as value handle

@clonker clonker requested a review from blishko May 4, 2026 09:53
Comment thread libyul/backends/evm/ssa/SSACFG.h Outdated
@clonker clonker force-pushed the ssa-cfg-extracts branch from 81826d1 to 6ec8136 Compare May 4, 2026 09:55
@argotorg argotorg deleted a comment from github-actions Bot May 4, 2026
@clonker clonker force-pushed the ssa-cfg-extracts branch from 6ec8136 to 923cd35 Compare May 4, 2026 09:56
@clonker clonker marked this pull request as ready for review May 4, 2026 09:58
@clonker clonker force-pushed the ssa-cfg-extracts branch from 923cd35 to 07053f4 Compare May 4, 2026 11:06
Copy link
Copy Markdown
Contributor

@blishko blishko 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!

I have a few small comments.

yulAssert(projectionInst.inputs.size() == 1);
InstId const producer = projectionInst.inputs.front();
yulAssert(_id.value > producer.value);
std::size_t const offset = static_cast<std::size_t>(_id.value) - static_cast<std::size_t>(producer.value) - 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this assuming that the projections have ids immediately following the id of the function call instruction?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah exactly. I have elevated that to be an invariant of the SSA CFG. It's not like we can swap around projections and/or only extract a couple things anyways due to the stack nature of things. See here:

InstId makeCallWithProjections(
BlockId const _block,
Call _payload,
std::vector<InstId> _inputs,
InstructionStore::NumReturnsSizeType const _numReturns,
langutil::DebugData::ConstPtr _debugData = {}
)
{
InstId const producer = makeCall(_block, std::move(_payload), std::move(_inputs), _debugData);
if (_numReturns >= 2)
for (InstructionStore::NumReturnsSizeType i = 0; i < _numReturns; ++i)
makeProjection(_block, producer, _debugData);
return producer;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hopefully. I guess it would be good to check this invariant somewhere.
We should eventually have something like a pass to check that the IR is well-formed, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah we should

Comment thread libyul/backends/evm/ssa/SSACFGBuilder.h
Comment thread libyul/backends/evm/ssa/StackLayoutGenerator.cpp Outdated
Comment thread test/libyul/ssa/StackLayoutGeneratorTest.cpp Outdated
@clonker clonker force-pushed the ssa-cfg-extracts branch from 07053f4 to d25627f Compare May 4, 2026 12:07
blishko
blishko previously approved these changes May 4, 2026
Copy link
Copy Markdown
Contributor

@blishko blishko left a comment

Choose a reason for hiding this comment

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

LGTM!

I would like to have one more helper :)

Comment thread libyul/backends/evm/ssa/CodeTransform.cpp Outdated
blishko
blishko previously approved these changes May 4, 2026
Copy link
Copy Markdown
Contributor

@blishko blishko left a comment

Choose a reason for hiding this comment

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

Space missing? :)

Comment thread libyul/backends/evm/ssa/StackLayoutGenerator.cpp Outdated
Copy link
Copy Markdown
Contributor

@blishko blishko left a comment

Choose a reason for hiding this comment

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

Approved!

@clonker clonker merged commit 9cdc2bc into develop May 4, 2026
81 of 82 checks passed
@clonker clonker deleted the ssa-cfg-extracts branch May 4, 2026 14:07
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.

2 participants