Skip to content

Commit d59d357

Browse files
committed
SIL: add -Xllvm -sil-print-no-uses to not print use-list comments in textual SIL
1 parent 7cceaff commit d59d357

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ llvm::cl::opt<bool>
8181
SILPrintTypes("sil-print-types", llvm::cl::init(false),
8282
llvm::cl::desc("always print type annotations for instruction operands in SIL output"));
8383

84+
llvm::cl::opt<bool>
85+
SILPrintNoUses("sil-print-no-uses", llvm::cl::init(false),
86+
llvm::cl::desc("omit use comments in SIL output"));
87+
8488
llvm::cl::opt<bool> SILPrintGenericSpecializationInfo(
8589
"sil-print-generic-specialization-info", llvm::cl::init(false),
8690
llvm::cl::desc("Include generic specialization"
@@ -828,6 +832,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
828832
}
829833

830834
void printBlockArgumentUses(const SILBasicBlock *BB) {
835+
if (SILPrintNoUses)
836+
return;
837+
831838
if (BB->args_empty())
832839
return;
833840

@@ -942,7 +949,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
942949
printBlockArguments(BB);
943950
*this << ":";
944951

945-
if (!BB->pred_empty()) {
952+
if (!BB->pred_empty() && !SILPrintNoUses) {
946953
PrintState.OS.PadToColumn(50);
947954

948955
*this << "// Preds:";
@@ -1032,6 +1039,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
10321039
}
10331040

10341041
void printUserList(ArrayRef<SILValue> values, SILNodePointer node) {
1042+
if (SILPrintNoUses)
1043+
return;
1044+
10351045
// If the set of values is empty, we need to print the ID of
10361046
// the instruction. Otherwise, if none of the values has a use,
10371047
// we don't need to do anything.

test/SIL/Parser/pure_mode.sil

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-sil-opt %s | %target-sil-opt -sil-print-no-uses | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
import SwiftShims
8+
9+
sil_global hidden @$s3nix2ggSSvp : $String
10+
11+
sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
12+
[%1: noescape **]
13+
[global: read,write,copy,deinit_barrier]
14+
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
15+
alloc_global @$s3nix2ggSSvp
16+
%3 = global_addr @$s3nix2ggSSvp : $*String
17+
%4 = integer_literal $Builtin.Int64, 0
18+
br bb1
19+
20+
bb2:
21+
// CHECK: struct $String (%{{[0-9]+}} : $_StringGuts)
22+
%10 = struct $String (%9 : $_StringGuts)
23+
// CHECK: store %{{[0-9]+}} to %{{[0-9]+$}}
24+
store %10 to %3 : $*String
25+
%12 = integer_literal $Builtin.Int32, 0
26+
%13 = struct $Int32 (%12 : $Builtin.Int32)
27+
return %13 : $Int32
28+
29+
bb1:
30+
%5 = integer_literal $Builtin.Int64, -2305843009213693952
31+
// CHECK: struct $UInt64 (%{{[0-9]+}})
32+
// CHECK-NOT: user:
33+
%6 = struct $UInt64 (%4 : $Builtin.Int64)
34+
%7 = value_to_bridge_object %5 : $Builtin.Int64
35+
%8 = struct $_StringObject (%6 : $UInt64, %7 : $Builtin.BridgeObject)
36+
%9 = struct $_StringGuts (%8 : $_StringObject)
37+
br bb2
38+
}

0 commit comments

Comments
 (0)