[clang] [Clang][Interp] Implement constexpr vector unary operators +, -, ~, ! (PR #105996)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 26 00:11:47 PDT 2024
================
@@ -5312,6 +5314,149 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
return true;
}
+template <class Emitter>
+bool Compiler<Emitter>::VisitVectorUnaryOp(const UnaryOperator *E) {
+ const Expr *SubExpr = E->getSubExpr();
+ assert(SubExpr->getType()->isVectorType());
+
+ if (DiscardResult)
+ return this->discard(SubExpr);
+
+ std::optional<PrimType> ResT = classify(E);
+ auto prepareResult = [=]() -> bool {
+ if (!ResT && !Initializing) {
+ std::optional<unsigned> LocalIndex = allocateLocal(SubExpr);
+ if (!LocalIndex)
+ return false;
+ return this->emitGetPtrLocal(*LocalIndex, E);
+ }
+
+ return true;
+ };
+
+ // The offset of the temporary, if we created one.
+ unsigned SubExprOffset = ~0u;
+ auto createTemp = [=, &SubExprOffset]() -> bool {
+ SubExprOffset = this->allocateLocalPrimitive(SubExpr, PT_Ptr, true, false);
+ if (!this->visit(SubExpr))
+ return false;
+ return this->emitSetLocal(PT_Ptr, SubExprOffset, E);
+ };
+
+ const auto *VecT = SubExpr->getType()->getAs<VectorType>();
----------------
tbaederr wrote:
The convention is that things ending in `T` are `PrimType`s. Call this `VT` or `VecTy`.
https://github.com/llvm/llvm-project/pull/105996
More information about the cfe-commits
mailing list