aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llc/llc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llc/llc.cpp')
-rw-r--r--llvm/tools/llc/llc.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 152f7db..613780e 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -15,6 +15,8 @@
#include "NewPMDriver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/RuntimeLibcallInfo.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
@@ -45,6 +47,7 @@
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/PGOOptions.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
@@ -57,11 +60,13 @@
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/Transforms/Utils/Cloning.h"
+#include <cassert>
#include <memory>
#include <optional>
using namespace llvm;
static codegen::RegisterCodeGenFlags CGF;
+static codegen::RegisterSaveStatsFlag SSF;
// General options for llc. Other pass-specific options are specified
// within the corresponding llc passes, and target-specific options
@@ -281,7 +286,8 @@ static void setPGOOptions(TargetMachine &TM) {
TM.setPGOOption(PGOOpt);
}
-static int compileModule(char **, LLVMContext &);
+static int compileModule(char **argv, LLVMContext &Context,
+ std::string &OutputFilename);
[[noreturn]] static void reportError(Twine Msg, StringRef Filename = "") {
SmallString<256> Prefix;
@@ -301,9 +307,7 @@ static int compileModule(char **, LLVMContext &);
llvm_unreachable("reportError() should not return");
}
-static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
- Triple::OSType OS,
- const char *ProgName) {
+static std::unique_ptr<ToolOutputFile> GetOutputStream(Triple::OSType OS) {
// If we don't yet have an output filename, make one.
if (OutputFilename.empty()) {
if (InputFilename == "-")
@@ -352,11 +356,8 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName,
if (!Binary)
OpenFlags |= sys::fs::OF_TextWithCRLF;
auto FDOut = std::make_unique<ToolOutputFile>(OutputFilename, EC, OpenFlags);
- if (EC) {
+ if (EC)
reportError(EC.message());
- return nullptr;
- }
-
return FDOut;
}
@@ -437,18 +438,22 @@ int main(int argc, char **argv) {
reportError(std::move(E), RemarksFilename);
LLVMRemarkFileHandle RemarksFile = std::move(*RemarksFileOrErr);
+ codegen::MaybeEnableStatistics();
+ std::string OutputFilename;
+
if (InputLanguage != "" && InputLanguage != "ir" && InputLanguage != "mir")
reportError("input language must be '', 'IR' or 'MIR'");
// Compile the module TimeCompilations times to give better compile time
// metrics.
for (unsigned I = TimeCompilations; I; --I)
- if (int RetVal = compileModule(argv, Context))
+ if (int RetVal = compileModule(argv, Context, OutputFilename))
return RetVal;
if (RemarksFile)
RemarksFile->keep();
- return 0;
+
+ return codegen::MaybeSaveStatistics(OutputFilename, "llc");
}
static bool addPass(PassManagerBase &PM, const char *argv0, StringRef PassName,
@@ -480,7 +485,8 @@ static bool addPass(PassManagerBase &PM, const char *argv0, StringRef PassName,
return false;
}
-static int compileModule(char **argv, LLVMContext &Context) {
+static int compileModule(char **argv, LLVMContext &Context,
+ std::string &OutputFilename) {
// Load the module to be compiled...
SMDiagnostic Err;
std::unique_ptr<Module> M;
@@ -541,6 +547,12 @@ static int compileModule(char **argv, LLVMContext &Context) {
InputFilename);
}
+ if (TheTriple.isX86() &&
+ codegen::getFuseFPOps() != FPOpFusion::FPOpFusionMode::Standard)
+ WithColor::warning(errs(), argv[0])
+ << "X86 backend ignores --fp-contract setting; use IR fast-math "
+ "flags instead.";
+
Options.BinutilsVersion =
TargetMachine::parseBinutilsVersion(BinutilsVersion);
Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
@@ -656,14 +668,16 @@ static int compileModule(char **argv, LLVMContext &Context) {
Target->Options.FloatABIType = codegen::getFloatABIForCalls();
// Figure out where we are going to send the output.
- std::unique_ptr<ToolOutputFile> Out =
- GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
+ std::unique_ptr<ToolOutputFile> Out = GetOutputStream(TheTriple.getOS());
if (!Out)
return 1;
// Ensure the filename is passed down to CodeViewDebug.
Target->Options.ObjectFilenameForDebug = Out->outputFilename();
+ // Return a copy of the output filename via the output param
+ OutputFilename = Out->outputFilename();
+
// Tell target that this tool is not necessarily used with argument ABI
// compliance (i.e. narrow integer argument extensions).
Target->Options.VerifyArgABICompliance = 0;
@@ -678,7 +692,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
}
// Add an appropriate TargetLibraryInfo pass for the module's triple.
- TargetLibraryInfoImpl TLII(M->getTargetTriple());
+ TargetLibraryInfoImpl TLII(M->getTargetTriple(), Target->Options.VecLib);
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
@@ -714,6 +728,10 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Build up all of the passes that we want to do to the module.
legacy::PassManager PM;
PM.add(new TargetLibraryInfoWrapperPass(TLII));
+ PM.add(new RuntimeLibraryInfoWrapper(
+ M->getTargetTriple(), Target->Options.ExceptionModel,
+ Target->Options.FloatABIType, Target->Options.EABIVersion,
+ Options.MCOptions.ABIName, Target->Options.VecLib));
{
raw_pwrite_stream *OS = &Out->os();