From 0b57cec536236d46e3dba9bd041533462f33dbb7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 20 Dec 2019 19:53:05 +0000 Subject: Move all sources from the llvm project into contrib/llvm-project. This uses the new layout of the upstream repository, which was recently migrated to GitHub, and converted into a "monorepo". That is, most of the earlier separate sub-projects with their own branches and tags were consolidated into one top-level directory, and are now branched and tagged together. Updating the vendor area to match this layout is next. --- contrib/llvm-project/llvm/lib/IR/OptBisect.cpp | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 contrib/llvm-project/llvm/lib/IR/OptBisect.cpp (limited to 'contrib/llvm-project/llvm/lib/IR/OptBisect.cpp') diff --git a/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp b/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp new file mode 100644 index 000000000000..3104b90f3070 --- /dev/null +++ b/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp @@ -0,0 +1,56 @@ +//===- llvm/IR/OptBisect/Bisect.cpp - LLVM Bisect support -----------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file +/// This file implements support for a bisecting optimizations based on a +/// command line option. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/OptBisect.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Pass.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include + +using namespace llvm; + +static cl::opt OptBisectLimit("opt-bisect-limit", cl::Hidden, + cl::init(std::numeric_limits::max()), + cl::Optional, + cl::desc("Maximum optimization to perform")); + +OptBisect::OptBisect() : OptPassGate() { + BisectEnabled = OptBisectLimit != std::numeric_limits::max(); +} + +static void printPassMessage(const StringRef &Name, int PassNum, + StringRef TargetDesc, bool Running) { + StringRef Status = Running ? "" : "NOT "; + errs() << "BISECT: " << Status << "running pass " + << "(" << PassNum << ") " << Name << " on " << TargetDesc << "\n"; +} + +bool OptBisect::shouldRunPass(const Pass *P, StringRef IRDescription) { + assert(BisectEnabled); + + return checkPass(P->getPassName(), IRDescription); +} + +bool OptBisect::checkPass(const StringRef PassName, + const StringRef TargetDesc) { + assert(BisectEnabled); + + int CurBisectNum = ++LastBisectNum; + bool ShouldRun = (OptBisectLimit == -1 || CurBisectNum <= OptBisectLimit); + printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun); + return ShouldRun; +} -- cgit v1.2.3