================
@@ -811,6 +811,179 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE)
{
case CK_LValueBitCast:
return this->emitInvalidCast(CastKind::ReinterpretLike, /*Fatal=*/true,
CE);
+ case CK_HLSLArrayRValue: {
+ // Non-decaying array rvalue cast - creates an rvalue copy of an lvalue
+ // array, similar to LValueToRValue for composite types.
+ if (!Initializing) {
+ UnsignedOrNone LocalIndex = allocateLocal(CE);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, CE))
+ return false;
+ }
+ if (!this->visit(SubExpr))
+ return false;
+ return this->emitMemcpy(CE);
+ }
+
+ case CK_HLSLMatrixTruncation: {
+ assert(SubExpr->getType()->isConstantMatrixType());
+ if (OptPrimType ResultT = classify(CE)) {
+ assert(!DiscardResult);
+ // Result must be either a float or integer. Take the first element.
+ if (!this->visit(SubExpr))
+ return false;
+ return this->emitArrayElemPop(*ResultT, 0, CE);
+ }
+ // Otherwise, this truncates to a a constant matrix type.
+ assert(CE->getType()->isConstantMatrixType());
+
+ if (!Initializing) {
+ UnsignedOrNone LocalIndex = allocateTemporary(CE);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, CE))
+ return false;
+ }
+ unsigned ToSize =
+ CE->getType()->getAs<ConstantMatrixType>()->getNumElementsFlattened();
+ if (!this->visit(SubExpr))
+ return false;
+ return this->emitCopyArray(classifyMatrixElementType(SubExpr->getType()),
0,
+ 0, ToSize, CE);
+ }
+
+ case CK_HLSLAggregateSplatCast: {
+ // Aggregate splat cast: convert a scalar value to one of an aggregate
type.
+ // TODO: Aggregate splat to struct and array types
+ assert(canClassify(SubExpr->getType()));
+
+ unsigned NumElts;
+ PrimType DestElemT;
+ QualType DestElemType;
+ if (const auto *VT = CE->getType()->getAs<VectorType>()) {
+ NumElts = VT->getNumElements();
+ DestElemType = VT->getElementType();
+ } else if (const auto *MT = CE->getType()->getAs<ConstantMatrixType>()) {
+ NumElts = MT->getNumElementsFlattened();
+ DestElemType = MT->getElementType();
+ } else {
+ return false;
+ }
+ DestElemT = classifyPrim(DestElemType);
+
+ if (!Initializing) {
+ UnsignedOrNone LocalIndex = allocateLocal(CE);
+ if (!LocalIndex)
+ return false;
+ if (!this->emitGetPtrLocal(*LocalIndex, CE))
+ return false;
+ }
+
+ PrimType SrcElemT = classifyPrim(SubExpr->getType());
+ unsigned SrcOffset =
+ allocateLocalPrimitive(SubExpr, DestElemT, /*IsConst=*/true);
+
+ if (!this->visit(SubExpr))
+ return false;
+ if (classifyPrim(SubExpr) == PT_Ptr && !this->emitLoadPop(SrcElemT, CE))
----------------
tbaederr wrote:
Why is this necessary? Is that not handled by the AST? Can a `nullptr`
initialized a matrix to 0?
https://github.com/llvm/llvm-project/pull/183424
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits