Skip to content

[SandboxIR][Region] Implement an auxiliary vector in Region #126376

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

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

vporpo
Copy link
Contributor

@vporpo vporpo commented Feb 8, 2025

This patch adds additional functionality to the sandboxir Region. The Region is used as a way of passing a set of Instructions across region passes in a way that can be represented in the IR with metadata. This is a design choice that allows us to test region passes in isolation with lit tests.

Up until now the region was only used to tag the instructions generated by the passes. There is a need to represent an ordered set of instructions, which can be used as a way to represent the initial seeds to the first vectorization pass. This patch implements this auxiliary vector that can be used to convey such information.

@vporpo
Copy link
Contributor Author

vporpo commented Feb 10, 2025

Added Region::clearAux().


/// MDNode that we'll use to mark instructions as being part of the region.
MDNode *RegionMDN;
static constexpr const char *MDKind = "sandboxvec";
static constexpr const char *RegionStr = "sandboxregion";
static constexpr const char *AuxMDKind = "sbaux";
Copy link
Collaborator

Choose a reason for hiding this comment

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

the other names use "sandbox" instead of "sb" as a prefix. Should this be "sandboxaux"? Or even "sandboxregionaux"? (I don't know how long these strings usually are)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, yeah we should make this consistent. I will change it to "sandboxaux".

llvm::Constant *IdxC =
dyn_cast<ConstantAsMetadata>(AuxMDN->getOperand(0))->getValue();
auto Idx = cast<llvm::ConstantInt>(IdxC)->getSExtValue();
R->setAux(Idx, &Inst);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we could have a check that we don't have two different values whose metadata claims the same index in the aux vector.

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 added a check in setAux(Idx, I) but this function is only called internally so using the same index shouldn't be possible unless this function is broken.

Copy link
Collaborator

@slackito slackito Feb 13, 2025

Choose a reason for hiding this comment

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

You could have incorrect metadata, right? Something like

define void @foo(i8 %v) {
  %t0 = add i8 %v, 0, !sandboxvec !0, !sandboxaux !1
  %t1 = add i8 %v, 1, !sandboxvec !0, !sandboxaux !1
  ret void
}
!0 = distinct !{!"sandboxregion"}
!1 = !{i32 0}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I think I should be able to add a test for it too.

This patch adds additional functionality to the sandboxir Region.
The Region is used as a way of passing a set of Instructions across region
passes in a way that can be represented in the IR with metadata.
This is a design choice that allows us to test region passes in isolation
with lit tests.

Up until now the region was only used to tag the instructions generated
by the passes. There is a need to represent an ordered set of instructions,
which can be used as a way to represent the initial seeds to the first
vectorization pass. This patch implements this auxiliary vector that
can be used to convey such information.
@vporpo vporpo merged commit c9ba2b0 into llvm:main Feb 13, 2025
5 of 7 checks passed
chapuni added a commit that referenced this pull request Feb 14, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
)

This patch adds additional functionality to the sandboxir Region. The
Region is used as a way of passing a set of Instructions across region
passes in a way that can be represented in the IR with metadata. This is
a design choice that allows us to test region passes in isolation with
lit tests.

Up until now the region was only used to tag the instructions generated
by the passes. There is a need to represent an ordered set of
instructions, which can be used as a way to represent the initial seeds
to the first vectorization pass. This patch implements this auxiliary
vector that can be used to convey such information.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
)

This patch adds additional functionality to the sandboxir Region. The
Region is used as a way of passing a set of Instructions across region
passes in a way that can be represented in the IR with metadata. This is
a design choice that allows us to test region passes in isolation with
lit tests.

Up until now the region was only used to tag the instructions generated
by the passes. There is a need to represent an ordered set of
instructions, which can be used as a way to represent the initial seeds
to the first vectorization pass. This patch implements this auxiliary
vector that can be used to convey such information.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
auto &LLVMCtx = Ctx.LLVMCtx;
for (auto [Idx, I] : enumerate(Aux)) {
llvm::ConstantInt *IdxC =
llvm::ConstantInt::get(LLVMCtx, llvm::APInt(32, Idx, false));
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://discourse.llvm.org/t/second-stage-of-build-on-windows-fails-in-sandboxir/84841
@vporpo - could you replace the APInt with the ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) variant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RKSimon Thanks for letting me know about the issue. I just created a PR with your suggestion: #129082

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.

4 participants