Skip to content

[SandboxIR] Add InsertValueInst #106273

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 3 commits into from
Aug 28, 2024
Merged

Conversation

slackito
Copy link
Collaborator

No description provided.

Copy link

github-actions bot commented Aug 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
const Twine &Name = "");

using idx_iterator = llvm::InsertValueInst::idx_iterator;

Choose a reason for hiding this comment

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

No

static bool classof(const Value *From) {
    return From->getSubclassID() == ClassID::InsertValueInst;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm @slackito does the test pass without the classof? Shouldn't it crash here?

  auto *Ins0 = cast<sandboxir::InsertValueInst>(&*It++);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tschuett good catch, thanks!

@vporpo It does pass, and I just double-checked I'm running them with asserts enabled (debug build).

I think it's falling back to Instruction::classof and accidentally passing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there is a good way to check that classof has been implemented. Perhaps a test that uses the .def file and does something with <subclass>::classof() so that we get a compile-time error if we forget to implement it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wrote a small test that checks EXPECT_NE(&<subclass>::classof, &Instruction::classof); and one of the insturctions is missing a classof!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! Can you commit that test (and the missing classof) separately from this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I will upload a PR in a few minutes.

static Value *create(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
const Twine &Name = "");

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing getInedexedType(). If it is missing for a reason then we should add a TODO comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are you sure? I only see getIndexedType methods in GetElementPtrInst and ExtractValueInst, not in InsertValueInst.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops I was looking at the ExtractValueInst :)

BBIterator WhereIt, BasicBlock *WhereBB, Context &Ctx,
const Twine &Name = "");

using idx_iterator = llvm::InsertValueInst::idx_iterator;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm @slackito does the test pass without the classof? Shouldn't it crash here?

  auto *Ins0 = cast<sandboxir::InsertValueInst>(&*It++);

auto *Zero = sandboxir::ConstantInt::get(Type::getInt32Ty(C), 0, Ctx);
auto *ShouldBeConstant = sandboxir::InsertValueInst::create(
Ins1->getOperand(0), Zero, ArrayRef<unsigned>({0}), BB->end(), BB, Ctx);
EXPECT_TRUE(isa<sandboxir::Constant>(ShouldBeConstant));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Constants are unique, so we could also do something EXPECT_EQ(ShouldBeConstant, ExpectedConstant)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

EXPECT_TRUE(isa<sandboxir::Constant>(ShouldBeConstant));

// idx_begin / idx_end
auto IdxIt = Ins0->idx_begin();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could you check the indices with an InsertValueInst with at least 2 indices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

- Added `classof` static method.
- Added test case for `insertvalue` with more than one index.
- Check constant equality in the "folded constant" case
Copy link
Contributor

@vporpo vporpo 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, thanks!

@slackito slackito merged commit b40677c into llvm:main Aug 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants