-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[SandboxIR] Add InsertValueInst #106273
Conversation
✅ 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; |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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++);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 = ""); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
No description provided.