[llvm] [LLVM-Tablegen] Pretty Printing Arguments in LLVM Intrinsics (PR #162629)
Dharuni R Acharya via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 00:08:50 PST 2025
================
@@ -4581,12 +4582,38 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Out << ' ';
writeOperand(Operand, false);
Out << '(';
+ bool HasPrettyPrintedArgs =
+ isa<IntrinsicInst>(CI) &&
+ Intrinsic::hasPrettyPrintedArgs(CI->getIntrinsicID());
+
ListSeparator LS;
- for (unsigned op = 0, Eop = CI->arg_size(); op < Eop; ++op) {
- Out << LS;
- writeParamOperand(CI->getArgOperand(op), PAL.getParamAttrs(op));
- }
+ if (HasPrettyPrintedArgs) {
+ Function *CalledFunc = CI->getCalledFunction();
+ auto PrintArgComment = [&](unsigned ArgNo) {
+ const Constant *ConstArg = dyn_cast<Constant>(CI->getArgOperand(ArgNo));
+ if (!ConstArg)
+ return;
+ std::string ArgComment;
+ raw_string_ostream ArgCommentStream(ArgComment);
+ Intrinsic::ID IID = CalledFunc->getIntrinsicID();
+ Intrinsic::printImmArg(IID, ArgNo, ArgCommentStream, ConstArg);
+ if (ArgComment.empty())
+ return;
+ Out << "/* " << ArgComment << " */ ";
+ };
+ for (unsigned ArgNo = 0, NumArgs = CI->arg_size(); ArgNo < NumArgs;
+ ++ArgNo) {
+ Out << LS;
+ PrintArgComment(ArgNo);
+ writeParamOperand(CI->getArgOperand(ArgNo), PAL.getParamAttrs(ArgNo));
+ }
+ } else {
+ for (unsigned op = 0, Eop = CI->arg_size(); op < Eop; ++op) {
----------------
DharuniRAcharya wrote:
Sure, updated in the latest revision!
https://github.com/llvm/llvm-project/pull/162629
More information about the llvm-commits
mailing list