diff options
author | Timm Baeder <tbaeder@redhat.com> | 2024-09-13 11:32:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 11:32:12 +0200 |
commit | fbf0a8015389bccab80bba00be49955079913152 (patch) | |
tree | 23c172418b41f3903d13cc97e7f43763acdd4cb4 /clang/lib | |
parent | e054712a85f924e0afe7f180fd960be7a8214d64 (diff) | |
download | llvm-fbf0a8015389bccab80bba00be49955079913152.zip llvm-fbf0a8015389bccab80bba00be49955079913152.tar.gz llvm-fbf0a8015389bccab80bba00be49955079913152.tar.bz2 |
[clang][bytecode] Implement HLSLVectorTruncation casts (#108499)
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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<Emitter>::VisitCastExpr(const CastExpr *CE) { return true; } + case CK_HLSLVectorTruncation: { + assert(SubExpr->getType()->isVectorType()); + if (std::optional<PrimType> 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<VectorType>()->getNumElements(); + assert(SubExpr->getType()->getAs<VectorType>()->getNumElements() > ToSize); + if (!this->visit(SubExpr)) + return false; + return this->emitCopyArray(classifyVectorElementType(CE->getType()), 0, 0, + ToSize, CE); + }; + case CK_ToVoid: return discard(SubExpr); |