aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/bugpoint/OptimizerDriver.cpp11
-rw-r--r--llvm/tools/llc/llc.cpp40
-rw-r--r--llvm/tools/llvm-as/llvm-as.cpp7
-rw-r--r--llvm/tools/llvm-dis/llvm-dis.cpp8
-rw-r--r--llvm/tools/llvm-extract/llvm-extract.cpp16
-rw-r--r--llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp16
-rw-r--r--llvm/tools/llvm-link/llvm-link.cpp15
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkFilter.cpp8
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp14
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h9
-rw-r--r--llvm/tools/opt/optdriver.cpp22
11 files changed, 88 insertions, 78 deletions
diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp
index 56a0fa4..3daacfd 100644
--- a/llvm/tools/bugpoint/OptimizerDriver.cpp
+++ b/llvm/tools/bugpoint/OptimizerDriver.cpp
@@ -38,11 +38,6 @@ namespace llvm {
extern cl::opt<std::string> OutputPrefix;
}
-static cl::opt<bool> PreserveBitcodeUseListOrder(
- "preserve-bc-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM bitcode."),
- cl::init(true), cl::Hidden);
-
static cl::opt<std::string>
OptCmd("opt-command", cl::init(""),
cl::desc("Path to opt. (default: search path "
@@ -51,7 +46,7 @@ static cl::opt<std::string>
/// This writes the current "Program" to the named bitcode file. If an error
/// occurs, true is returned.
static bool writeProgramToFileAux(ToolOutputFile &Out, const Module &M) {
- WriteBitcodeToFile(M, Out.os(), PreserveBitcodeUseListOrder);
+ WriteBitcodeToFile(M, Out.os(), /* ShouldPreserveUseListOrder */ true);
Out.os().close();
if (!Out.os().has_error()) {
Out.keep();
@@ -68,7 +63,7 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
bool BugDriver::writeProgramToFile(int FD, const Module &M) const {
raw_fd_ostream OS(FD, /*shouldClose*/ false);
- WriteBitcodeToFile(M, OS, PreserveBitcodeUseListOrder);
+ WriteBitcodeToFile(M, OS, /* ShouldPreserveUseListOrder */ true);
OS.flush();
if (!OS.has_error())
return false;
@@ -155,7 +150,7 @@ bool BugDriver::runPasses(Module &Program,
DiscardTemp Discard{*Temp};
raw_fd_ostream OS(Temp->FD, /*shouldClose*/ false);
- WriteBitcodeToFile(Program, OS, PreserveBitcodeUseListOrder);
+ WriteBitcodeToFile(Program, OS, /* ShouldPreserveUseListOrder */ true);
OS.flush();
if (OS.has_error()) {
errs() << "Error writing bitcode file: " << Temp->TmpName << "\n";
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 7551a80..f04b256 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -44,6 +44,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
@@ -243,6 +244,39 @@ static cl::opt<RunPassOption, true, cl::parser<std::string>> RunPass(
cl::desc("Run compiler only for specified passes (comma separated list)"),
cl::value_desc("pass-name"), cl::location(RunPassOpt));
+// PGO command line options
+enum PGOKind {
+ NoPGO,
+ SampleUse,
+};
+
+static cl::opt<PGOKind>
+ PGOKindFlag("pgo-kind", cl::init(NoPGO), cl::Hidden,
+ cl::desc("The kind of profile guided optimization"),
+ cl::values(clEnumValN(NoPGO, "nopgo", "Do not use PGO."),
+ clEnumValN(SampleUse, "pgo-sample-use-pipeline",
+ "Use sampled profile to guide PGO.")));
+
+// Function to set PGO options on TargetMachine based on command line flags.
+static void setPGOOptions(TargetMachine &TM) {
+ std::optional<PGOOptions> PGOOpt;
+
+ switch (PGOKindFlag) {
+ case SampleUse:
+ // Use default values for other PGOOptions parameters. This parameter
+ // is used to test that PGO data is preserved at -O0.
+ PGOOpt = PGOOptions("", "", "", "", PGOOptions::SampleUse,
+ PGOOptions::NoCSAction);
+ break;
+ case NoPGO:
+ PGOOpt = std::nullopt;
+ break;
+ }
+
+ if (PGOOpt)
+ TM.setPGOOption(PGOOpt);
+}
+
static int compileModule(char **, LLVMContext &);
[[noreturn]] static void reportError(Twine Msg, StringRef Filename = "") {
@@ -558,6 +592,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
TheTriple, CPUStr, FeaturesStr, Options, RM, CM, OLvl));
assert(Target && "Could not allocate target machine!");
+ // Set PGO options based on command line flags
+ setPGOOptions(*Target);
+
return Target->createDataLayout().getStringRepresentation();
};
if (InputLanguage == "mir" ||
@@ -601,6 +638,9 @@ static int compileModule(char **argv, LLVMContext &Context) {
TheTriple, CPUStr, FeaturesStr, Options, RM, CM, OLvl));
assert(Target && "Could not allocate target machine!");
+ // Set PGO options based on command line flags
+ setPGOOptions(*Target);
+
// If we don't have a module then just exit now. We do this down
// here since the CPU/Feature help is underneath the target machine
// creation.
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
index 2164867..200e6a5 100644
--- a/llvm/tools/llvm-as/llvm-as.cpp
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -57,11 +57,6 @@ static cl::opt<bool>
cl::desc("Do not run verifier on input LLVM (dangerous!)"),
cl::cat(AsCat));
-static cl::opt<bool> PreserveBitcodeUseListOrder(
- "preserve-bc-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM bitcode."),
- cl::init(true), cl::Hidden, cl::cat(AsCat));
-
static cl::opt<std::string> ClDataLayout("data-layout",
cl::desc("data layout string to use"),
cl::value_desc("layout-string"),
@@ -100,7 +95,7 @@ static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) {
// any non-null Index along with it as a per-module Index.
// If both are empty, this will give an empty module block, which is
// the expected behavior.
- WriteBitcodeToFile(*M, Out->os(), PreserveBitcodeUseListOrder,
+ WriteBitcodeToFile(*M, Out->os(), /* ShouldPreserveUseListOrder */ true,
IndexToWrite, EmitModuleHash);
else
// Otherwise, with an empty Module but non-empty Index, we write a
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 2b43d27..35c5409 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -80,11 +80,6 @@ static cl::opt<bool>
cl::desc("Add informational comments to the .ll file"),
cl::cat(DisCategory));
-static cl::opt<bool> PreserveAssemblyUseListOrder(
- "preserve-ll-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM assembly."),
- cl::init(false), cl::Hidden, cl::cat(DisCategory));
-
static cl::opt<bool>
MaterializeMetadata("materialize-metadata",
cl::desc("Load module without materializing metadata, "
@@ -255,7 +250,8 @@ int main(int argc, char **argv) {
if (!DontPrint) {
if (M) {
M->removeDebugIntrinsicDeclarations();
- M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);
+ M->print(Out->os(), Annotator.get(),
+ /* ShouldPreserveUseListOrder */ false);
}
if (Index)
Index->print(Out->os());
diff --git a/llvm/tools/llvm-extract/llvm-extract.cpp b/llvm/tools/llvm-extract/llvm-extract.cpp
index 69636ca..439a4a4 100644
--- a/llvm/tools/llvm-extract/llvm-extract.cpp
+++ b/llvm/tools/llvm-extract/llvm-extract.cpp
@@ -129,16 +129,6 @@ static cl::opt<bool> OutputAssembly("S",
cl::desc("Write output as LLVM assembly"),
cl::Hidden, cl::cat(ExtractCat));
-static cl::opt<bool> PreserveBitcodeUseListOrder(
- "preserve-bc-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM bitcode."),
- cl::init(true), cl::Hidden, cl::cat(ExtractCat));
-
-static cl::opt<bool> PreserveAssemblyUseListOrder(
- "preserve-ll-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM assembly."),
- cl::init(false), cl::Hidden, cl::cat(ExtractCat));
-
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
@@ -421,9 +411,11 @@ int main(int argc, char **argv) {
}
if (OutputAssembly)
- PM.addPass(PrintModulePass(Out.os(), "", PreserveAssemblyUseListOrder));
+ PM.addPass(
+ PrintModulePass(Out.os(), "", /* ShouldPreserveUseListOrder */ false));
else if (Force || !CheckBitcodeOutputToConsole(Out.os()))
- PM.addPass(BitcodeWriterPass(Out.os(), PreserveBitcodeUseListOrder));
+ PM.addPass(
+ BitcodeWriterPass(Out.os(), /* ShouldPreserveUseListOrder */ true));
PM.run(*M, MAM);
diff --git a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
index 434449c..1031932 100644
--- a/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
+++ b/llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
@@ -253,25 +253,17 @@ public:
break;
}
case BasicBlockLevel: {
- const auto &BBVecMap = Emb->getBBVecMap();
for (const BasicBlock &BB : F) {
- auto It = BBVecMap.find(&BB);
- if (It != BBVecMap.end()) {
- OS << BB.getName() << ":";
- It->second.print(OS);
- }
+ OS << BB.getName() << ":";
+ Emb->getBBVector(BB).print(OS);
}
break;
}
case InstructionLevel: {
- const auto &InstMap = Emb->getInstVecMap();
for (const BasicBlock &BB : F) {
for (const Instruction &I : BB) {
- auto It = InstMap.find(&I);
- if (It != InstMap.end()) {
- I.print(OS);
- It->second.print(OS);
- }
+ I.print(OS);
+ Emb->getInstVector(I).print(OS);
}
}
break;
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 22ea54e..93b1fb6 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -110,16 +110,6 @@ static cl::opt<bool> SuppressWarnings("suppress-warnings",
cl::desc("Suppress all linking warnings"),
cl::init(false), cl::cat(LinkCategory));
-static cl::opt<bool> PreserveBitcodeUseListOrder(
- "preserve-bc-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM bitcode."),
- cl::init(true), cl::Hidden, cl::cat(LinkCategory));
-
-static cl::opt<bool> PreserveAssemblyUseListOrder(
- "preserve-ll-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM assembly."),
- cl::init(false), cl::Hidden, cl::cat(LinkCategory));
-
static cl::opt<bool> NoVerify("disable-verify",
cl::desc("Do not run the verifier"), cl::Hidden,
cl::cat(LinkCategory));
@@ -525,9 +515,10 @@ int main(int argc, char **argv) {
errs() << "Writing bitcode...\n";
Composite->removeDebugIntrinsicDeclarations();
if (OutputAssembly) {
- Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
+ Composite->print(Out.os(), nullptr, /* ShouldPreserveUseListOrder */ false);
} else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
- WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
+ WriteBitcodeToFile(*Composite, Out.os(),
+ /* ShouldPreserveUseListOrder */ true);
}
// Declare success.
diff --git a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
index 507ae36..9b521b4 100644
--- a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
@@ -48,12 +48,8 @@ static Error tryFilter() {
return MaybeParser.takeError();
auto &Parser = **MaybeParser;
- Format SerializerFormat = OutputFormat;
- if (SerializerFormat == Format::Auto) {
- SerializerFormat = Parser.ParserFormat;
- if (OutputFileName.empty() || OutputFileName == "-")
- SerializerFormat = Format::YAML;
- }
+ Format SerializerFormat =
+ getSerializerFormat(OutputFileName, OutputFormat, Parser.ParserFormat);
auto MaybeOF = getOutputFileForRemarks(OutputFileName, SerializerFormat);
if (!MaybeOF)
diff --git a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
index be52948..b6204d0 100644
--- a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
@@ -54,6 +54,20 @@ getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat) {
: sys::fs::OF_None);
}
+Format getSerializerFormat(StringRef OutputFileName, Format SelectedFormat,
+ Format DefaultFormat) {
+ if (SelectedFormat != Format::Auto)
+ return SelectedFormat;
+ SelectedFormat = DefaultFormat;
+ if (OutputFileName.empty() || OutputFileName == "-" ||
+ OutputFileName.ends_with_insensitive(".yaml") ||
+ OutputFileName.ends_with_insensitive(".yml"))
+ SelectedFormat = Format::YAML;
+ if (OutputFileName.ends_with_insensitive(".bitstream"))
+ SelectedFormat = Format::Bitstream;
+ return SelectedFormat;
+}
+
Expected<FilterMatcher>
FilterMatcher::createRE(const llvm::cl::opt<std::string> &Arg) {
return createRE(Arg.ArgStr, Arg);
diff --git a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
index 0dd550765..73867fe 100644
--- a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
+++ b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
@@ -47,7 +47,8 @@
"serializer", cl::init(Format::Auto), \
cl::desc("Output remark format to serialize"), \
cl::values(clEnumValN(Format::Auto, "auto", \
- "Follow the parser format (default)"), \
+ "Automatic detection based on output file " \
+ "extension or parser format (default)"), \
clEnumValN(Format::YAML, "yaml", "YAML"), \
clEnumValN(Format::Bitstream, "bitstream", "Bitstream")), \
cl::sub(SUBOPT));
@@ -151,6 +152,12 @@ getOutputFileWithFlags(StringRef OutputFileName, sys::fs::OpenFlags Flags);
Expected<std::unique_ptr<ToolOutputFile>>
getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat);
+/// Choose the serializer format. If \p SelectedFormat is Format::Auto, try to
+/// detect the format based on the extension of \p OutputFileName or fall back
+/// to \p DefaultFormat.
+Format getSerializerFormat(StringRef OutputFileName, Format SelectedFormat,
+ Format DefaultFormat);
+
/// Filter object which can be either a string or a regex to match with the
/// remark properties.
class FilterMatcher {
diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp
index d4fa6eb..2ac8de7 100644
--- a/llvm/tools/opt/optdriver.cpp
+++ b/llvm/tools/opt/optdriver.cpp
@@ -232,16 +232,6 @@ static cl::opt<std::string> ClDataLayout("data-layout",
cl::value_desc("layout-string"),
cl::init(""));
-static cl::opt<bool> PreserveBitcodeUseListOrder(
- "preserve-bc-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM bitcode."),
- cl::init(true), cl::Hidden);
-
-static cl::opt<bool> PreserveAssemblyUseListOrder(
- "preserve-ll-uselistorder",
- cl::desc("Preserve use-list order when writing LLVM assembly."),
- cl::init(false), cl::Hidden);
-
static cl::opt<bool> RunTwice("run-twice",
cl::desc("Run all passes twice, re-using the "
"same pass manager (legacy PM only)."),
@@ -753,9 +743,9 @@ extern "C" int optMain(
return runPassPipeline(
argv[0], *M, TM.get(), &TLII, Out.get(), ThinLinkOut.get(),
RemarksFile.get(), Pipeline, PluginList, PassBuilderCallbacks,
- OK, VK, PreserveAssemblyUseListOrder,
- PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash,
- EnableDebugify, VerifyDebugInfoPreserve,
+ OK, VK, /* ShouldPreserveAssemblyUseListOrder */ false,
+ /* ShouldPreserveBitcodeUseListOrder */ true, EmitSummaryIndex,
+ EmitModuleHash, EnableDebugify, VerifyDebugInfoPreserve,
EnableProfileVerification, UnifiedLTO)
? 0
: 1;
@@ -877,9 +867,11 @@ extern "C" int optMain(
OS = BOS.get();
}
if (OutputAssembly)
- Passes.add(createPrintModulePass(*OS, "", PreserveAssemblyUseListOrder));
+ Passes.add(createPrintModulePass(
+ *OS, "", /* ShouldPreserveAssemblyUseListOrder */ false));
else
- Passes.add(createBitcodeWriterPass(*OS, PreserveBitcodeUseListOrder));
+ Passes.add(createBitcodeWriterPass(
+ *OS, /* ShouldPreserveBitcodeUseListOrder */ true));
}
// Before executing passes, print the final values of the LLVM options.