-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Upstream insert op for VectorType #139146
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
AmrDeveloper
merged 3 commits into
llvm:main
from
AmrDeveloper:cir_upstream_vector_insert
May 12, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,17 @@ Address CIRGenFunction::emitPointerWithAlignment(const Expr *expr, | |
void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst, | ||
bool isInit) { | ||
if (!dst.isSimple()) { | ||
if (dst.isVectorElt()) { | ||
// Read/modify/write the vector, inserting the new element | ||
const mlir::Location loc = dst.getVectorPointer().getLoc(); | ||
const mlir::Value vector = | ||
builder.createLoad(loc, dst.getVectorAddress().getPointer()); | ||
const mlir::Value newVector = builder.create<cir::VecInsertOp>( | ||
loc, vector, src.getScalarVal(), dst.getVectorIdx()); | ||
builder.createStore(loc, newVector, dst.getVectorAddress().getPointer()); | ||
return; | ||
} | ||
|
||
cgm.errorNYI(dst.getPointer().getLoc(), | ||
"emitStoreThroughLValue: non-simple lvalue"); | ||
return; | ||
|
@@ -418,6 +429,13 @@ RValue CIRGenFunction::emitLoadOfLValue(LValue lv, SourceLocation loc) { | |
if (lv.isSimple()) | ||
return RValue::get(emitLoadOfScalar(lv, loc)); | ||
|
||
if (lv.isVectorElt()) { | ||
const mlir::Value load = | ||
builder.createLoad(getLoc(loc), lv.getVectorAddress().getPointer()); | ||
return RValue::get(builder.create<cir::VecExtractOp>(getLoc(loc), load, | ||
lv.getVectorIdx())); | ||
} | ||
|
||
cgm.errorNYI(loc, "emitLoadOfLValue"); | ||
return RValue::get(nullptr); | ||
} | ||
|
@@ -638,12 +656,6 @@ static Address emitArraySubscriptPtr(CIRGenFunction &cgf, | |
|
||
LValue | ||
CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) { | ||
if (e->getBase()->getType()->isVectorType() && | ||
!isa<ExtVectorElementExpr>(e->getBase())) { | ||
cgm.errorNYI(e->getSourceRange(), "emitArraySubscriptExpr: VectorType"); | ||
return LValue::makeAddr(Address::invalid(), e->getType(), LValueBaseInfo()); | ||
} | ||
|
||
if (isa<ExtVectorElementExpr>(e->getBase())) { | ||
cgm.errorNYI(e->getSourceRange(), | ||
"emitArraySubscriptExpr: ExtVectorElementExpr"); | ||
|
@@ -666,18 +678,28 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) { | |
assert((e->getIdx() == e->getLHS() || e->getIdx() == e->getRHS()) && | ||
"index was neither LHS nor RHS"); | ||
|
||
auto emitIdxAfterBase = [&]() -> mlir::Value { | ||
auto emitIdxAfterBase = [&](bool promote) -> mlir::Value { | ||
const mlir::Value idx = emitScalarExpr(e->getIdx()); | ||
|
||
// Extend or truncate the index type to 32 or 64-bits. | ||
auto ptrTy = mlir::dyn_cast<cir::PointerType>(idx.getType()); | ||
if (ptrTy && mlir::isa<cir::IntType>(ptrTy.getPointee())) | ||
if (promote && ptrTy && ptrTy.isPtrTo<cir::IntType>()) | ||
cgm.errorNYI(e->getSourceRange(), | ||
"emitArraySubscriptExpr: index type cast"); | ||
return idx; | ||
}; | ||
|
||
const mlir::Value idx = emitIdxAfterBase(); | ||
// If the base is a vector type, then we are forming a vector element | ||
// with this subscript. | ||
if (e->getBase()->getType()->isVectorType() && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You dropped a comment from the incubator here. Can you bring it in? |
||
!isa<ExtVectorElementExpr>(e->getBase())) { | ||
const mlir::Value idx = emitIdxAfterBase(/*promote=*/false); | ||
const LValue lhs = emitLValue(e->getBase()); | ||
return LValue::makeVectorElt(lhs.getAddress(), idx, e->getBase()->getType(), | ||
lhs.getBaseInfo()); | ||
} | ||
|
||
const mlir::Value idx = emitIdxAfterBase(/*promote=*/true); | ||
if (const Expr *array = getSimpleArrayDecayOperand(e->getBase())) { | ||
LValue arrayLV; | ||
if (const auto *ase = dyn_cast<ArraySubscriptExpr>(array)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AnyType
seems wrong here, in the absence of a verifier. The value has to match the element type of the vector, right? I'm not sure if there's a way to declare that here that will enforce it. If not, we should have a verifier.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.
This is enforced through
TypesMatchWith<"argument type matches vector element type", "vec", "value", "cast<VectorType>($_self).getElementType()">
trait. So no need for verifier.