[clang] [HLSL] Implement output parameter (PR #101083)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 27 14:58:17 PDT 2024


================
@@ -5432,6 +5434,57 @@ LValue CodeGenFunction::EmitOpaqueValueLValue(const OpaqueValueExpr *e) {
   return getOrCreateOpaqueLValueMapping(e);
 }
 
+LValue CodeGenFunction::BindHLSLOutArgExpr(const HLSLOutArgExpr *E,
+                                           Address OutTemp) {
+  LValue Result = MakeAddrLValue(OutTemp, E->getType());
+  OpaqueValueMappingData::bind(*this, E->getCastedTemporary(), Result);
+  return Result;
+}
+
+void CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
+                                         CallArgList &Args, QualType Ty) {
+
+  // Emitting the casted temporary through an opaque value.
+  LValue BaseLV = EmitLValue(E->getArgLValue());
+  OpaqueValueMappingData::bind(*this, E->getOpaqueArgLValue(), BaseLV);
+
+  LValue TempLV;
+
+  if (E->isInOut()) {
----------------
rjmccall wrote:

We can simplify this further, I think — let's just make a temporary and then emit the initialization into it.  There's a function in CGExprAgg called `EmitInitializationToLValue` that you can steal for the second half of that; you'll just need to cut the dependency on `Dest.isZeroed()` by passing it in as a flag.

https://github.com/llvm/llvm-project/pull/101083


More information about the cfe-commits mailing list