From f3bb3617506e0e73c94f5928b805922cf021911a Mon Sep 17 00:00:00 2001 From: Gor Nishanov Date: Fri, 5 Aug 2016 16:27:33 +0000 Subject: [PATCH] opt: Adding -O0 to opt tool Summary: Having -O0 in opt allows testing that -O0 optimization pipeline is built correctly. Reviewers: majnemer Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D23208 llvm-svn: 277829 --- llvm/test/Transforms/Coroutines/smoketest.ll | 1 + llvm/tools/opt/opt.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/llvm/test/Transforms/Coroutines/smoketest.ll b/llvm/test/Transforms/Coroutines/smoketest.ll index 2ed7b80..e173564 100644 --- a/llvm/test/Transforms/Coroutines/smoketest.ll +++ b/llvm/test/Transforms/Coroutines/smoketest.ll @@ -1,6 +1,7 @@ ; Test that all coroutine passes run in the correct order at all optimization ; levels and -disable-coroutines removes coroutine passes from the pipeline. ; +; RUN: opt < %s -disable-output -enable-coroutines -debug-pass=Arguments -O0 2>&1 | FileCheck %s ; RUN: opt < %s -disable-output -enable-coroutines -debug-pass=Arguments -O1 2>&1 | FileCheck %s ; RUN: opt < %s -disable-output -enable-coroutines -debug-pass=Arguments -O2 2>&1 | FileCheck %s ; RUN: opt < %s -disable-output -enable-coroutines -debug-pass=Arguments -O3 2>&1 | FileCheck %s diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index ca0f134..66dc563 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -122,6 +122,10 @@ StandardLinkOpts("std-link-opts", cl::desc("Include the standard link time optimizations")); static cl::opt +OptLevelO0("O0", + cl::desc("Optimization level 0. Similar to clang -O0")); + +static cl::opt OptLevelO1("O1", cl::desc("Optimization level 1. Similar to clang -O1")); @@ -515,7 +519,8 @@ int main(int argc, char **argv) { : TargetIRAnalysis())); std::unique_ptr FPasses; - if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { + if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || + OptLevelO3) { FPasses.reset(new legacy::FunctionPassManager(M.get())); FPasses->add(createTargetTransformInfoWrapperPass( TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); @@ -547,6 +552,11 @@ int main(int argc, char **argv) { StandardLinkOpts = false; } + if (OptLevelO0 && OptLevelO0.getPosition() < PassList.getPosition(i)) { + AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); + OptLevelO0 = false; + } + if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); OptLevelO1 = false; @@ -619,6 +629,9 @@ int main(int argc, char **argv) { StandardLinkOpts = false; } + if (OptLevelO0) + AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); + if (OptLevelO1) AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); -- 2.7.4