diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/docs/CommandGuide/llc.rst | 6 | ||||
| -rw-r--r-- | llvm/docs/ReleaseNotes.md | 1 | ||||
| -rw-r--r-- | llvm/include/llvm/CodeGen/TargetInstrInfo.h | 3 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/MachineSink.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/ObjectYAML/ELFYAML.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/VPlan.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/tools/llc/save-stats.ll | 15 | ||||
| -rw-r--r-- | llvm/tools/llc/llc.cpp | 74 | ||||
| -rw-r--r-- | llvm/unittests/BinaryFormat/MsgPackWriterTest.cpp | 4 | ||||
| -rw-r--r-- | llvm/utils/gn/secondary/llvm/test/BUILD.gn | 7 | ||||
| -rw-r--r-- | llvm/utils/gn/secondary/llvm/tools/llvm-cas/BUILD.gn | 16 |
15 files changed, 125 insertions, 18 deletions
diff --git a/llvm/docs/CommandGuide/llc.rst b/llvm/docs/CommandGuide/llc.rst index cc670f6..ffcccfb 100644 --- a/llvm/docs/CommandGuide/llc.rst +++ b/llvm/docs/CommandGuide/llc.rst @@ -129,6 +129,12 @@ End-user Options Print statistics recorded by code-generation passes. +.. option:: --save-stats, --save-stats=cwd, --save-stats=obj + + Save LLVM statistics to a file in the current directory + (:option:`--save-stats`/"--save-stats=cwd") or the directory + of the output file ("--save-stats=obj") in JSON format. + .. option:: --time-passes Record the amount of time needed for each pass and print a report to standard diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md index 23bba99..fd78c97 100644 --- a/llvm/docs/ReleaseNotes.md +++ b/llvm/docs/ReleaseNotes.md @@ -182,6 +182,7 @@ Changes to the LLVM tools * `llvm-readelf` now dumps all hex format values in lower-case mode. * Some code paths for supporting Python 2.7 in `llvm-lit` have been removed. * Support for `%T` in lit has been removed. +* Add `--save-stats` option to `llc` to save LLVM statistics to a file. Compatible with the Clang option. * `llvm-config` gained a new flag `--quote-paths` which quotes and escapes paths emitted on stdout, to account for spaces or other special characters in path. diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h index 2dcedfb..7010cff 100644 --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -436,7 +436,10 @@ public: /// MachineSink determines on its own whether the instruction is safe to sink; /// this gives the target a hook to override the default behavior with regards /// to which instructions should be sunk. + /// + /// shouldPostRASink() is used by PostRAMachineSink. virtual bool shouldSink(const MachineInstr &MI) const { return true; } + virtual bool shouldPostRASink(const MachineInstr &MI) const { return true; } /// Return false if the instruction should not be hoisted by MachineLICM. /// diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index cdcb29d9..94ed82e 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -2287,6 +2287,10 @@ bool PostRAMachineSinkingImpl::tryToSinkCopy(MachineBasicBlock &CurBB, continue; } + // Don't postRASink instructions that the target prefers not to sink. + if (!TII->shouldPostRASink(MI)) + continue; + if (MI.isDebugOrPseudoInstr()) continue; diff --git a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp index fe881a1..af24540 100644 --- a/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/Orc/TargetProcess/SimpleExecutorMemoryManager.cpp @@ -36,8 +36,6 @@ Expected<ExecutorAddr> SimpleExecutorMemoryManager::reserve(uint64_t Size) { Expected<ExecutorAddr> SimpleExecutorMemoryManager::initialize(tpctypes::FinalizeRequest &FR) { - std::vector<shared::WrapperFunctionCall> DeallocationActions; - if (FR.Segments.empty()) { if (FR.Actions.empty()) return make_error<StringError>("Finalization request is empty", diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 29f2916..d07c37e 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -670,7 +670,7 @@ void ScalarBitSetTraits<ELFYAML::ELF_EF>::bitset(IO &IO, for (unsigned K = ELF::EF_AMDGPU_GENERIC_VERSION_MIN; K <= ELF::EF_AMDGPU_GENERIC_VERSION_MAX; ++K) { std::string Key = "EF_AMDGPU_GENERIC_VERSION_V" + std::to_string(K); - IO.maskedBitSetCase(Value, Key.c_str(), + IO.maskedBitSetCase(Value, Key, K << ELF::EF_AMDGPU_GENERIC_VERSION_OFFSET, ELF::EF_AMDGPU_GENERIC_VERSION); } diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp index a3deb36..3e44e47 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -5421,8 +5421,6 @@ combineUnpackingMovIntoLoad(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { if (!NVPTX::isPackedVectorTy(ElementVT) || ElementVT == MVT::v4i8) return SDValue(); - SmallVector<SDNode *> DeadCopyToRegs; - // Check whether all outputs are either used by an extractelt or are // glue/chain nodes if (!all_of(N->uses(), [&](SDUse &U) { diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 9070d25..1730ec0 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -303,8 +303,6 @@ PreservedAnalyses LoopIdiomRecognizePass::run(Loop &L, LoopAnalysisManager &AM, // but ORE cannot be preserved (see comment before the pass definition). OptimizationRemarkEmitter ORE(L.getHeader()->getParent()); - std::optional<PolynomialInfo> HR; - LoopIdiomRecognize LIR(&AR.AA, &AR.DT, &AR.LI, &AR.SE, &AR.TLI, &AR.TTI, AR.MSSA, DL, ORE); if (!LIR.runOnLoop(&L)) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c27d1ac..ffba0bd 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -21222,7 +21222,6 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP, } ScheduledBundlesList.pop_back(); SmallVector<ScheduleData *> ControlDependentMembers; - SmallPtrSet<Instruction *, 4> Visited; for (Value *V : VL) { if (S.isNonSchedulable(V)) continue; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index dd26a05..5e4303a 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -52,10 +52,6 @@ using namespace llvm; using namespace llvm::VPlanPatternMatch; -namespace llvm { -extern cl::opt<bool> EnableVPlanNativePath; -} - /// @{ /// Metadata attribute names const char LLVMLoopVectorizeFollowupAll[] = "llvm.loop.vectorize.followup_all"; diff --git a/llvm/test/tools/llc/save-stats.ll b/llvm/test/tools/llc/save-stats.ll new file mode 100644 index 0000000..94b17e5 --- /dev/null +++ b/llvm/test/tools/llc/save-stats.ll @@ -0,0 +1,15 @@ +; REQUIRES: asserts + +; RUN: llc -mtriple=arm64-apple-macosx --save-stats=obj -o %t.s %s && cat %t.stats | FileCheck %s +; RUN: llc -mtriple=arm64-apple-macosx --save-stats=cwd -o %t.s %s && cat %{t:stem}.tmp.stats | FileCheck %s +; RUN: llc -mtriple=arm64-apple-macosx --save-stats -o %t.s %s && cat %{t:stem}.tmp.stats | FileCheck %s +; RUN: not llc -mtriple=arm64-apple-macosx --save-stats=invalid -o %t.s %s 2>&1 | FileCheck %s --check-prefix=INVALID_ARG + +; CHECK: { +; CHECK: "asm-printer.EmittedInsts": +; CHECK: } + +; INVALID_ARG: {{.*}}llc{{.*}}: for the --save-stats option: Cannot find option named 'invalid'! +define i32 @func() { + ret i32 0 +} diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 152f7db..dc2f878 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -15,6 +15,7 @@ #include "NewPMDriver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/Statistic.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/CodeGen/CommandFlags.h" #include "llvm/CodeGen/LinkAllAsmWriterComponents.h" @@ -45,6 +46,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,6 +59,7 @@ #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; @@ -208,6 +211,20 @@ static cl::opt<std::string> RemarksFormat( cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml")); +enum SaveStatsMode { None, Cwd, Obj }; + +static cl::opt<SaveStatsMode> SaveStats( + "save-stats", + cl::desc("Save LLVM statistics to a file in the current directory" + "(`-save-stats`/`-save-stats=cwd`) or the directory of the output" + "file (`-save-stats=obj`). (default: cwd)"), + cl::values(clEnumValN(SaveStatsMode::Cwd, "cwd", + "Save to the current working directory"), + clEnumValN(SaveStatsMode::Cwd, "", ""), + clEnumValN(SaveStatsMode::Obj, "obj", + "Save to the output file directory")), + cl::init(SaveStatsMode::None), cl::ValueOptional); + static cl::opt<bool> EnableNewPassManager( "enable-new-pm", cl::desc("Enable the new pass manager"), cl::init(false)); @@ -281,7 +298,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; @@ -360,6 +378,45 @@ static std::unique_ptr<ToolOutputFile> GetOutputStream(const char *TargetName, return FDOut; } +static int MaybeEnableStats() { + if (SaveStats == SaveStatsMode::None) + return 0; + + llvm::EnableStatistics(false); + return 0; +} + +static int MaybeSaveStats(std::string &&OutputFilename) { + if (SaveStats == SaveStatsMode::None) + return 0; + + SmallString<128> StatsFilename; + if (SaveStats == SaveStatsMode::Obj) { + StatsFilename = OutputFilename; + llvm::sys::path::remove_filename(StatsFilename); + } else { + assert(SaveStats == SaveStatsMode::Cwd && + "Should have been a valid --save-stats value"); + } + + auto BaseName = llvm::sys::path::filename(OutputFilename); + llvm::sys::path::append(StatsFilename, BaseName); + llvm::sys::path::replace_extension(StatsFilename, "stats"); + + auto FileFlags = llvm::sys::fs::OF_TextWithCRLF; + std::error_code EC; + auto StatsOS = + std::make_unique<llvm::raw_fd_ostream>(StatsFilename, EC, FileFlags); + if (EC) { + WithColor::error(errs(), "llc") + << "Unable to open statistics file: " << EC.message() << "\n"; + return 1; + } + + llvm::PrintStatisticsJSON(*StatsOS); + return 0; +} + // main - Entry point for the llc compiler. // int main(int argc, char **argv) { @@ -437,18 +494,23 @@ int main(int argc, char **argv) { reportError(std::move(E), RemarksFilename); LLVMRemarkFileHandle RemarksFile = std::move(*RemarksFileOrErr); + if (int RetVal = MaybeEnableStats()) + return RetVal; + 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 MaybeSaveStats(std::move(OutputFilename)); } static bool addPass(PassManagerBase &PM, const char *argv0, StringRef PassName, @@ -480,7 +542,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; @@ -664,6 +727,9 @@ static int compileModule(char **argv, LLVMContext &Context) { // 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; diff --git a/llvm/unittests/BinaryFormat/MsgPackWriterTest.cpp b/llvm/unittests/BinaryFormat/MsgPackWriterTest.cpp index 3a5ba9a..dd8826c 100644 --- a/llvm/unittests/BinaryFormat/MsgPackWriterTest.cpp +++ b/llvm/unittests/BinaryFormat/MsgPackWriterTest.cpp @@ -40,7 +40,7 @@ TEST_F(MsgPackWriter, TestWriteFixPositiveInt) { MPWriter.write(u); std::string Output = OStream.str(); EXPECT_EQ(Output.size(), 1u); - EXPECT_EQ(Output.data()[0], static_cast<uint8_t>(u)); + EXPECT_EQ(Output[0], static_cast<uint8_t>(u)); } } @@ -128,7 +128,7 @@ TEST_F(MsgPackWriter, TestWriteFixNegativeInt) { MPWriter.write(i); std::string Output = OStream.str(); EXPECT_EQ(Output.size(), 1u); - EXPECT_EQ(static_cast<int8_t>(Output.data()[0]), static_cast<int8_t>(i)); + EXPECT_EQ(static_cast<int8_t>(Output[0]), static_cast<int8_t>(i)); } } diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn index b297dbd..1c91cb8 100644 --- a/llvm/utils/gn/secondary/llvm/test/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -195,6 +195,12 @@ write_lit_config("lit_site_cfg") { extra_values += [ "LLVM_ENABLE_LIBXML2=0" ] # Must be 0. } + if (llvm_enable_ondisk_cas) { + extra_values += [ "LLVM_ENABLE_ONDISK_CAS=1" ] + } else { + extra_values += [ "LLVM_ENABLE_ONDISK_CAS=0" ] # Must be 0. + } + if (llvm_enable_expensive_checks) { extra_values += [ "LLVM_ENABLE_EXPENSIVE_CHECKS=1" ] } else { @@ -265,6 +271,7 @@ group("test") { "//llvm/tools/llvm-as", "//llvm/tools/llvm-bcanalyzer", "//llvm/tools/llvm-c-test", + "//llvm/tools/llvm-cas", "//llvm/tools/llvm-cat", "//llvm/tools/llvm-cfi-verify", "//llvm/tools/llvm-cgdata", diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-cas/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-cas/BUILD.gn new file mode 100644 index 0000000..d4cd26a --- /dev/null +++ b/llvm/utils/gn/secondary/llvm/tools/llvm-cas/BUILD.gn @@ -0,0 +1,16 @@ +import("//llvm/utils/TableGen/tablegen.gni") + +tablegen("Options") { + visibility = [ ":llvm-cas" ] + args = [ "-gen-opt-parser-defs" ] +} + +executable("llvm-cas") { + deps = [ + ":Options", + "//llvm/lib/CAS", + "//llvm/lib/Option", + "//llvm/lib/Support", + ] + sources = [ "llvm-cas.cpp" ] +} |
