-
Notifications
You must be signed in to change notification settings - Fork 82
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
[CIR][CIRGen] Support OpenCL Vector Types #613
base: main
Are you sure you want to change the base?
Conversation
clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Outdated
@@ -646,9 +646,69 @@ RValue CIRGenFunction::buildLoadOfLValue(LValue LV, SourceLocation Loc) { | |||
|
|||
if (LV.isSimple()) | |||
return RValue::get(buildLoadOfScalar(LV, Loc)); | |||
|
|||
if (LV.isVectorElt()) { |
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.
Seems like this is content from the other patch? If there are dependencies between the PRs, it might be better not to put them up for review just yet, otherwise I have to go to the same thing twice and mentally account for it :)
7fb1234
to
ded43cc
Compare
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.
Way to go on the skeleton work and thanks for fixing the testcase, more comments inline.
llvm_unreachable("NYI"); | ||
} | ||
|
||
int64_t CIRGenFunction::getAccessedFieldNo(unsigned int idx, | ||
const mlir::Attribute elts) { |
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.
Given the uses I've seen elsewhere, elts
param could just be a ArrayAttr
assert(elts.isa<mlir::ArrayAttr>()); | ||
|
||
auto elt = elts.cast<mlir::ArrayAttr>()[idx]; | ||
assert(elt.isa<mlir::IntegerAttr>()); |
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.
If you are doing a isa
followed by cast
, better just do dyn_cast
and assert if it's null.
// HLSL allows treating scalars as one-element vectors. Converting the scalar | ||
// IR value to a vector here allows the rest of codegen to behave as normal. | ||
if (getLangOpts().HLSL && !Vec.getType().isa<mlir::cir::VectorType>()) { | ||
auto DstTy = |
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.
Paths that are not tested should be llvm_unreachable("NYI");
. Unless you are adding HLSL tests, please remove the code within this if statement in favor of llvm_unreachable("NYI");
. Please do that for all other places where you didn't add tests to cover those paths.
// a single element. Just codegen as an extractelement. | ||
const auto *ExprVT = LV.getType()->getAs<clang::VectorType>(); | ||
if (!ExprVT) { | ||
int64_t InIdx = getAccessedFieldNo(0, Elts); |
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.
Is this path tested?
@@ -674,6 +727,84 @@ RValue CIRGenFunction::buildLoadOfBitfieldLValue(LValue LV, | |||
return RValue::get(field); | |||
} | |||
|
|||
void CIRGenFunction::buildStoreThroughExtVectorComponentLValue(RValue Src, | |||
LValue Dst) { | |||
mlir::Location loc = Dst.getExtVectorPointer().getLoc(); |
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.
Same for this function, please make sure you add testcases or llvm_unreachable("NYI");
for paths that are not tested.
LValue | ||
CIRGenFunction::buildExtVectorElementExpr(const ExtVectorElementExpr *E) { | ||
// Emit the base vector as an l-value. | ||
LValue Base; |
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.
Same for this function, please make sure you add testcases or llvm_unreachable("NYI");
for paths that are not tested.
// If it is a pointer to a vector, emit the address and form an lvalue with | ||
// it. | ||
LValueBaseInfo BaseInfo; | ||
// TODO(cir): Support TBAA |
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.
Please also add assert(!UnimplementedFeature::tbaa());
// OpenCL: If the condition is a vector, we can treat this condition like | ||
// the select function. | ||
if ((CGF.getLangOpts().OpenCL && condExpr->getType()->isVectorType()) || | ||
condExpr->getType()->isExtVectorType()) { |
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.
Why are you removing this check? I don't think you have testcases to back this up and doing this will probably lead to some mis-compilation that is going hard to track later. There's specific handling that needs to be done for VisitAbstractConditionalOperator
in face of these conditions.
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.
vector_ternary_lowering
is on this path. This was mentioned in the PR description (I'll update it to a brief version though):
A special method is used for the original CodeGen for ternary operator of OpenCL vectors. I don't know why. Since we already have high-level cir.vec.ternary, I skipped this part. And the lowering still works well. Maybe it's about the SPIR-V target.
Probably I'll also comment the corresponding part in the PR review ahead of time : )
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.
Since we already have high-level cir.vec.ternary, I skipped this part
Unfortunately that's not a good rationale and not how we usually go about these things in CIR - if this leads to a miscompile, it's going to be really hard to pinpoint the issue, and might take a lot of investigation time. If something was implemented that is shortcuting here, it should also be fixed to maintain the skeleton the much pristine as possible. It's possible you might find out that you need to do another PR to fix that problem before you can land this one.
Alternatively, if you are deleting this code so one of your testcases may pass, you can then choose to not add that testcase and address the whole issue together in another PR.
assert(isExtVectorElt()); | ||
return V; | ||
} | ||
mlir::Attribute getExtVectorElts() const { |
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.
From overall usage in this PR, looks like this could return an ArrayAttr
instead.
Fix #532 .
Support CIRGen of
ExtVectorElementExpr
that includes swizzlev.xyx
and subscriptionv.s0
.