[clang] [HLSL] Implement Texture2D::mips[][] (PR #186143)
Nathan Gauër via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 25 07:08:16 PDT 2026
================
@@ -609,6 +621,44 @@ BuiltinTypeMethodBuilder::declareLocalVar(LocalVar &Var) {
return *this;
}
+template <typename V, typename S>
+BuiltinTypeMethodBuilder &BuiltinTypeMethodBuilder::concat(V Vec, S Scalar,
+ QualType ResultTy) {
+ ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
+ Expr *VecExpr = convertPlaceholder(Vec);
+ auto *VecTy = VecExpr->getType()->castAs<VectorType>();
+ Expr *ScalarExpr = convertPlaceholder(Scalar);
+
+ // Save the vector to a local variable to avoid evaluating the placeholder
+ // multiple times or sharing the AST node.
+ LocalVar VecVar("vec_tmp", VecTy->desugar());
+ declareLocalVar(VecVar);
+ assign(VecVar, VecExpr);
+
+ QualType EltTy = VecTy->getElementType();
+ unsigned NumElts = VecTy->getNumElements();
+
+ SmallVector<Expr *, 4> Elts;
+ for (unsigned I = 0; I < NumElts; ++I) {
+ Elts.push_back(new (AST) ArraySubscriptExpr(
+ convertPlaceholder(VecVar), DeclBuilder.getConstantIntExpr(I), EltTy,
+ VK_PRValue, OK_Ordinary, SourceLocation()));
+ }
+ Elts.push_back(ScalarExpr);
+
+ auto *InitList =
+ new (AST) InitListExpr(AST, SourceLocation(), Elts, SourceLocation());
+ InitList->setType(ResultTy);
+
+ ExprResult Cast = DeclBuilder.SemaRef.BuildCStyleCastExpr(
----------------
Keenuts wrote:
Should thsi assert ResultTy is a vector type? Or should this even build a vector directly instead of doing a c-style cast?
https://github.com/llvm/llvm-project/pull/186143
More information about the cfe-commits
mailing list