From 0c1381d79567f58655561bd39f5efb1d468c930a Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Thu, 15 Oct 2020 16:45:50 +0100 Subject: [PATCH] [llc] Use -filetype=null to disable MIR printing If you use -stop-after or similar options, llc will normally print MIR. This patch checks for -filetype=null as a special case to disable MIR printing. As the comment says, "The Null output is intended for use for performance analysis ...", and I found this useful for timing a subset of the passes that llc runs without the significant overhead of printing MIR just to send it to /dev/null. Differential Revision: https://reviews.llvm.org/D89476 --- llvm/lib/CodeGen/LLVMTargetMachine.cpp | 13 ++++++++----- llvm/test/tools/llc/filetype-null-stop-after.ll | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 llvm/test/tools/llc/filetype-null-stop-after.ll diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp index e94b7ed4de03..6f3deff8cb3b 100644 --- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -196,11 +196,14 @@ bool LLVMTargetMachine::addPassesToEmitFile( if (!PassConfig) return true; - if (!TargetPassConfig::willCompleteCodeGenPipeline()) - PM.add(createPrintMIRPass(Out)); - else if (addAsmPrinter(PM, Out, DwoOut, FileType, - MMIWP->getMMI().getContext())) - return true; + if (TargetPassConfig::willCompleteCodeGenPipeline()) { + if (addAsmPrinter(PM, Out, DwoOut, FileType, MMIWP->getMMI().getContext())) + return true; + } else { + // MIR printing is redundant with -filetype=null. + if (FileType != CGFT_Null) + PM.add(createPrintMIRPass(Out)); + } PM.add(createFreeMachineFunctionPass()); return false; diff --git a/llvm/test/tools/llc/filetype-null-stop-after.ll b/llvm/test/tools/llc/filetype-null-stop-after.ll new file mode 100644 index 000000000000..5be63a55b648 --- /dev/null +++ b/llvm/test/tools/llc/filetype-null-stop-after.ll @@ -0,0 +1,3 @@ +; -stop-after would normally dump MIR, but with -filetype=null as well check +; there's no output at all. +; RUN: llc -filetype=null -stop-after=finalize-isel -o - %s | count 0