From fbf0a8015389bccab80bba00be49955079913152 Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Fri, 13 Sep 2024 11:32:12 +0200 Subject: [clang][bytecode] Implement HLSLVectorTruncation casts (#108499) --- clang/lib/AST/ByteCode/Compiler.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 265350e..5247b8c 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -644,6 +644,31 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { return true; } + case CK_HLSLVectorTruncation: { + assert(SubExpr->getType()->isVectorType()); + if (std::optional 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 from one vector type to another. + assert(CE->getType()->isVectorType()); + + if (!Initializing) { + unsigned LocalIndex = allocateTemporary(CE); + if (!this->emitGetPtrLocal(LocalIndex, CE)) + return false; + } + unsigned ToSize = CE->getType()->getAs()->getNumElements(); + assert(SubExpr->getType()->getAs()->getNumElements() > ToSize); + if (!this->visit(SubExpr)) + return false; + return this->emitCopyArray(classifyVectorElementType(CE->getType()), 0, 0, + ToSize, CE); + }; + case CK_ToVoid: return discard(SubExpr); -- cgit v1.1