[clang] [llvm] [NVPTX] Fix v2i8 call lowering, use generic ld/st nodes for call params (PR #146930)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 16:50:15 PDT 2025
================
@@ -1487,14 +1380,39 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
// After all vararg is processed, 'VAOffset' holds the size of the
// vararg byte array.
- SDValue VADeclareParam; // vararg byte array
+ SDValue VADeclareParam = SDValue(); // vararg byte array
const unsigned FirstVAArg = CLI.NumFixedArgs; // position of first variadic
unsigned VAOffset = 0; // current offset in the param array
const unsigned UniqueCallSite = GlobalUniqueCallSite++;
- SDValue TempChain = Chain;
- Chain = DAG.getCALLSEQ_START(Chain, UniqueCallSite, 0, dl);
- SDValue InGlue = Chain.getValue(1);
+ const SDValue CallChain = CLI.Chain;
+ const SDValue StartChain =
+ DAG.getCALLSEQ_START(CallChain, UniqueCallSite, 0, dl);
+ SDValue DeclareGlue = StartChain.getValue(1);
+
+ SmallVector<SDValue, 16> CallPrereqs{StartChain};
+
+ const auto DeclareScalarParam = [&](SDValue Symbol, unsigned Size) {
+ // PTX ABI requires integral types to be at least 32 bits in size. FP16 is
+ // loaded/stored using i16, so it's handled here as well.
+ const unsigned SizeBits = promoteScalarArgumentSize(Size * 8);
+ SDValue Declare =
+ DAG.getNode(NVPTXISD::DeclareScalarParam, dl, {MVT::Other, MVT::Glue},
+ {StartChain, Symbol, GetI32(SizeBits), DeclareGlue});
+ CallPrereqs.push_back(Declare);
----------------
AlexMaclean wrote:
I think in this case it is appropriate to update state within this lambda. CallPrereqs is a big list of everything that needs to happen before we make the call. We always want to add all the param declarations to this list, so we'd need to pass the same thing in every single place these functions are called, or update immediately after in every location. Since the state is just a list (which we won't remove items from or even use within the lambda) of all these params I think this is the best approach and not too confusing in this case.
https://github.com/llvm/llvm-project/pull/146930
More information about the llvm-commits
mailing list