[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 02:25:06 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);
----------------
DharuniRAcharya wrote:

Yes, you're right. When an intrinsic with pretty-printed arguments has a non-immediate argument as a constant value, `Intrinsic::printImmArg` gets called. However, for arguments without pretty-printing configured, it returns early, leaving `ArgComment` empty. I've added a test case to cover this edge case in the latest revision. 

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


More information about the llvm-commits mailing list