Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions llvm/tools/opt/NewPMDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,30 @@
using namespace llvm;
using namespace opt_tool;

namespace llvm {
cl::opt<bool> DebugifyEach(
cl::opt<bool> llvm::DebugifyEach(
"debugify-each",
cl::desc("Start each pass with debugify and end it with check-debugify"));

cl::opt<std::string>
DebugifyExport("debugify-export",
cl::desc("Export per-pass debugify statistics to this file"),
cl::value_desc("filename"));
cl::opt<std::string> llvm::DebugifyExport(
"debugify-export",
cl::desc("Export per-pass debugify statistics to this file"),
cl::value_desc("filename"));

cl::opt<bool> VerifyEachDebugInfoPreserve(
cl::opt<bool> llvm::VerifyEachDebugInfoPreserve(
"verify-each-debuginfo-preserve",
cl::desc("Start each pass with collecting and end it with checking of "
"debug info preservation."));

cl::opt<std::string> llvm::VerifyDIPreserveExport(
"verify-di-preserve-export",
cl::desc("Export debug info preservation failures into "
"specified (JSON) file (should be abs path as we use"
" append mode to insert new JSON objects)"),
cl::value_desc("filename"), cl::init(""));

static cl::opt<bool> EnableLoopFusion("enable-loopfusion", cl::init(false),
cl::Hidden,
cl::desc("Enable the LoopFuse Pass"));
cl::opt<std::string>
VerifyDIPreserveExport("verify-di-preserve-export",
cl::desc("Export debug info preservation failures into "
"specified (JSON) file (should be abs path as we use"
" append mode to insert new JSON objects)"),
cl::value_desc("filename"), cl::init(""));

} // namespace llvm

enum class DebugLogging { None, Normal, Verbose, Quiet };

Expand Down Expand Up @@ -356,7 +354,7 @@ bool llvm::runPassPipeline(
ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
ArrayRef<PassPlugin> PassPlugins,
ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks,
ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks,
OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve,
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/opt/NewPMDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum PGOKind {
SampleUse
};
enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
}
} // namespace opt_tool

void printPasses(raw_ostream &OS);

Expand All @@ -70,7 +70,7 @@ bool runPassPipeline(
ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
ArrayRef<PassPlugin> PassPlugins,
ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks,
ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks,
opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex,
Expand Down
8 changes: 5 additions & 3 deletions llvm/tools/opt/opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include "llvm/ADT/ArrayRef.h"
#include <functional>

using namespace llvm;

namespace llvm {
class PassBuilder;
}

extern "C" int optMain(int argc, char **argv,
llvm::ArrayRef<std::function<void(llvm::PassBuilder &)>>
PassBuilderCallbacks);
extern "C" int
optMain(int argc, char **argv,
ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks);

int main(int argc, char **argv) { return optMain(argc, argv, {}); }
42 changes: 22 additions & 20 deletions llvm/tools/opt/optdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,25 @@ static CodeGenOptLevel GetCodeGenOptLevel() {
return static_cast<CodeGenOptLevel>(unsigned(CodeGenOptLevelCL));
}

namespace {
struct TimeTracerRAII {
TimeTracerRAII(StringRef ProgramName) {
if (TimeTrace)
timeTraceProfilerInitialize(TimeTraceGranularity, ProgramName);
}
~TimeTracerRAII() {
if (TimeTrace) {
if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) {
handleAllErrors(std::move(E), [&](const StringError &SE) {
errs() << SE.getMessage() << "\n";
});
return;
}
timeTraceProfilerCleanup();
if (!TimeTrace)
return;
if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) {
handleAllErrors(std::move(E), [&](const StringError &SE) {
errs() << SE.getMessage() << "\n";
});
return;
}
timeTraceProfilerCleanup();
}
};
} // namespace

// For use in NPM transition. Currently this contains most codegen-specific
// passes. Remove passes from here when porting to the NPM.
Expand Down Expand Up @@ -377,18 +379,18 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
"callbrprepare",
"scalarizer",
};
for (const auto &P : PassNamePrefix)
for (StringLiteral P : PassNamePrefix)
if (Pass.starts_with(P))
return true;
for (const auto &P : PassNameContain)
for (StringLiteral P : PassNameContain)
if (Pass.contains(P))
return true;
return llvm::is_contained(PassNameExact, Pass);
}

// For use in NPM transition.
static bool shouldForceLegacyPM() {
for (const auto &P : PassList) {
for (const PassInfo *P : PassList) {
StringRef Arg = P->getPassArgument();
if (shouldPinPassToLegacyPM(Arg))
return true;
Expand All @@ -399,9 +401,9 @@ static bool shouldForceLegacyPM() {
//===----------------------------------------------------------------------===//
// main for opt
//
extern "C" int optMain(
int argc, char **argv,
ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks) {
extern "C" int
optMain(int argc, char **argv,
ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks) {
InitLLVM X(argc, argv);

// Enable debug stream buffering.
Expand Down Expand Up @@ -673,7 +675,7 @@ extern "C" int optMain(
else {
// Disable individual builtin functions in TargetLibraryInfo.
LibFunc F;
for (auto &FuncName : DisableBuiltins) {
for (const std::string &FuncName : DisableBuiltins) {
if (TLII.getLibFunc(FuncName, F))
TLII.setUnavailable(F);
else {
Expand All @@ -683,7 +685,7 @@ extern "C" int optMain(
}
}

for (auto &FuncName : EnableBuiltins) {
for (const std::string &FuncName : EnableBuiltins) {
if (TLII.getLibFunc(FuncName, F))
TLII.setAvailable(F);
else {
Expand Down Expand Up @@ -814,9 +816,8 @@ extern "C" int optMain(
Passes.add(TPC);
}

// Create a new optimization pass for each one specified on the command line
for (unsigned i = 0; i < PassList.size(); ++i) {
const PassInfo *PassInf = PassList[i];
// Create a new optimization pass for each one specified on the command line.
for (const PassInfo *PassInf : PassList) {
if (PassInf->getNormalCtor()) {
Pass *P = PassInf->getNormalCtor()();
if (P) {
Expand All @@ -826,9 +827,10 @@ extern "C" int optMain(
if (VerifyEach)
Passes.add(createVerifierPass());
}
} else
} else {
errs() << argv[0] << ": cannot create pass: " << PassInf->getPassName()
<< "\n";
}
}

// Check that the module is well formed on completion of optimization
Expand Down