Index: clang/include/clang/Basic/CodeGenOptions.h =================================================================== --- clang/include/clang/Basic/CodeGenOptions.h +++ clang/include/clang/Basic/CodeGenOptions.h @@ -235,7 +235,7 @@ /// The name of the file to which the backend should save YAML optimization /// records. - std::string OptRecordFile; + std::string RecordFile; /// Regular expression to select optimizations for which we should enable /// optimization remarks. Transformation passes whose name matches this Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -1255,7 +1255,7 @@ Conf.UseNewPM = CGOpts.ExperimentalNewPassManager; Conf.DebugPassManager = CGOpts.DebugPassManager; Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness; - Conf.RemarksFilename = CGOpts.OptRecordFile; + Conf.RemarksFilename = CGOpts.RecordFile; Conf.DwoPath = CGOpts.SplitDwarfFile; switch (Action) { case Backend_EmitNothing: Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -57,11 +57,11 @@ return (CodeGenOpts.OptimizationRemarkAnalysisPattern && CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName)); } - bool isMissedOptRemarkEnabled(StringRef PassName) const override { + bool isMissedRemarkEnabled(StringRef PassName) const override { return (CodeGenOpts.OptimizationRemarkMissedPattern && CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName)); } - bool isPassedOptRemarkEnabled(StringRef PassName) const override { + bool isPassedRemarkEnabled(StringRef PassName) const override { return (CodeGenOpts.OptimizationRemarkPattern && CodeGenOpts.OptimizationRemarkPattern->match(PassName)); } @@ -265,19 +265,19 @@ Ctx.setDiagnosticsHotnessThreshold( CodeGenOpts.DiagnosticsHotnessThreshold); - std::unique_ptr OptRecordFile; - if (!CodeGenOpts.OptRecordFile.empty()) { + std::unique_ptr RecordFile; + if (!CodeGenOpts.RecordFile.empty()) { std::error_code EC; - OptRecordFile = llvm::make_unique( - CodeGenOpts.OptRecordFile, EC, sys::fs::F_None); + RecordFile = llvm::make_unique( + CodeGenOpts.RecordFile, EC, sys::fs::F_None); if (EC) { Diags.Report(diag::err_cannot_open_file) << - CodeGenOpts.OptRecordFile << EC.message(); + CodeGenOpts.RecordFile << EC.message(); return; } Ctx.setDiagnosticsOutputFile( - llvm::make_unique(OptRecordFile->os())); + llvm::make_unique(RecordFile->os())); if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone) Ctx.setDiagnosticsHotnessRequested(true); @@ -297,8 +297,8 @@ Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler)); - if (OptRecordFile) - OptRecordFile->keep(); + if (RecordFile) + RecordFile->keep(); } void HandleTagDeclDefinition(TagDecl *D) override { Index: clang/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -459,7 +459,7 @@ AddLinkArgs(C, Args, CmdArgs, Inputs); // For LTO, pass the name of the optimization record file and other - // opt-remarks flags. + // remarks flags. if (Args.hasFlag(options::OPT_fsave_optimization_record, options::OPT_fno_save_optimization_record, false)) { CmdArgs.push_back("-mllvm"); Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1210,8 +1210,8 @@ Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option); bool NeedLocTracking = false; - Opts.OptRecordFile = Args.getLastArgValue(OPT_opt_record_file); - if (!Opts.OptRecordFile.empty()) + Opts.RecordFile = Args.getLastArgValue(OPT_opt_record_file); + if (!Opts.RecordFile.empty()) NeedLocTracking = true; if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) { Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -644,7 +644,7 @@ set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name}) else() if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR - ${name} STREQUAL "OptRemarks" OR + ${name} STREQUAL "Remarks" OR (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM")) set(install_dir lib${LLVM_LIBDIR_SUFFIX}) if(ARG_MODULE OR ARG_SHARED OR BUILD_SHARED_LIBS) Index: llvm/include/llvm-c/Remarks.h =================================================================== --- llvm/include/llvm-c/Remarks.h +++ llvm/include/llvm-c/Remarks.h @@ -1,4 +1,4 @@ -/*===-- llvm-c/OptRemarks.h - OptRemarks Public C Interface -------*- C -*-===*\ +/*===-- llvm-c/Remarks.h - Remarks Public C Interface -------------*- C -*-===*\ |* *| |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| |* Exceptions. *| @@ -7,13 +7,13 @@ |* *| |*===----------------------------------------------------------------------===*| |* *| -|* This header provides a public interface to an opt-remark library. *| +|* This header provides a public interface to a remark diagnostics library. *| |* LLVM provides an implementation of this interface. *| |* *| \*===----------------------------------------------------------------------===*/ -#ifndef LLVM_C_OPT_REMARKS_H -#define LLVM_C_OPT_REMARKS_H +#ifndef LLVM_C_REMARKS_H +#define LLVM_C_REMARKS_H #include "llvm-c/Core.h" #include "llvm-c/Types.h" @@ -25,81 +25,81 @@ #endif /* !defined(__cplusplus) */ /** - * @defgroup LLVMCOPTREMARKS OptRemarks + * @defgroup LLVMCREMARKS Remarks * @ingroup LLVMC * * @{ */ -#define OPT_REMARKS_API_VERSION 0 +#define REMARKS_API_VERSION 0 /** * String containing a buffer and a length. The buffer is not guaranteed to be * zero-terminated. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ typedef struct { const char *Str; uint32_t Len; -} LLVMOptRemarkStringRef; +} LLVMRemarkStringRef; /** * DebugLoc containing File, Line and Column. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ typedef struct { // File: - LLVMOptRemarkStringRef SourceFile; + LLVMRemarkStringRef SourceFile; // Line: uint32_t SourceLineNumber; // Column: uint32_t SourceColumnNumber; -} LLVMOptRemarkDebugLoc; +} LLVMRemarkDebugLoc; /** * Element of the "Args" list. The key might give more information about what * are the semantics of the value, e.g. "Callee" will tell you that the value * is a symbol that names a function. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ typedef struct { // e.g. "Callee" - LLVMOptRemarkStringRef Key; + LLVMRemarkStringRef Key; // e.g. "malloc" - LLVMOptRemarkStringRef Value; + LLVMRemarkStringRef Value; // "DebugLoc": Optional - LLVMOptRemarkDebugLoc DebugLoc; -} LLVMOptRemarkArg; + LLVMRemarkDebugLoc DebugLoc; +} LLVMRemarkArg; /** * One remark entry. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ typedef struct { // e.g. !Missed, !Passed - LLVMOptRemarkStringRef RemarkType; + LLVMRemarkStringRef RemarkType; // "Pass": Required - LLVMOptRemarkStringRef PassName; + LLVMRemarkStringRef PassName; // "Name": Required - LLVMOptRemarkStringRef RemarkName; + LLVMRemarkStringRef RemarkName; // "Function": Required - LLVMOptRemarkStringRef FunctionName; + LLVMRemarkStringRef FunctionName; // "DebugLoc": Optional - LLVMOptRemarkDebugLoc DebugLoc; + LLVMRemarkDebugLoc DebugLoc; // "Hotness": Optional uint32_t Hotness; // "Args": Optional. It is an array of `num_args` elements. uint32_t NumArgs; - LLVMOptRemarkArg *Args; -} LLVMOptRemarkEntry; + LLVMRemarkArg *Args; +} LLVMRemarkEntry; -typedef struct LLVMOptRemarkOpaqueParser *LLVMOptRemarkParserRef; +typedef struct LLVMRemarkOpaqueParser *LLVMRemarkParserRef; /** * Creates a remark parser that can be used to read and parse the buffer located @@ -107,27 +107,27 @@ * * \p Buf cannot be NULL. * - * This function should be paired with LLVMOptRemarkParserDispose() to avoid + * This function should be paired with LLVMRemarkParserDispose() to avoid * leaking resources. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern LLVMOptRemarkParserRef LLVMOptRemarkParserCreate(const void *Buf, - uint64_t Size); +extern LLVMRemarkParserRef LLVMRemarkParserCreate(const void *Buf, + uint64_t Size); /** * Returns the next remark in the file. * * The value pointed to by the return value is invalidated by the next call to - * LLVMOptRemarkParserGetNext(). + * LLVMRemarkParserGetNext(). * * If the parser reaches the end of the buffer, the return value will be NULL. * * In the case of an error, the return value will be NULL, and: * - * 1) LLVMOptRemarkParserHasError() will return `1`. + * 1) LLVMRemarkParserHasError() will return `1`. * - * 2) LLVMOptRemarkParserGetErrorMessage() will return a descriptive error + * 2) LLVMRemarkParserGetErrorMessage() will return a descriptive error * message. * * An error may occur if: @@ -144,26 +144,25 @@ * Here is a quick example of the usage: * * ``` - * LLVMOptRemarkParserRef Parser = LLVMOptRemarkParserCreate(Buf, Size); - * LLVMOptRemarkEntry *Remark = NULL; - * while ((Remark == LLVMOptRemarkParserGetNext(Parser))) { + * LLVMRemarkParserRef Parser = LLVMRemarkParserCreate(Buf, Size); + * LLVMRemarkEntry *Remark = NULL; + * while ((Remark == LLVMRemarkParserGetNext(Parser))) { * // use Remark - * } - * bool HasError = LLVMOptRemarkParserHasError(Parser); - * LLVMOptRemarkParserDispose(Parser); + * } + * bool HasError = LLVMRemarkParserHasError(Parser); + * LLVMRemarkParserDispose(Parser); * ``` * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern LLVMOptRemarkEntry * -LLVMOptRemarkParserGetNext(LLVMOptRemarkParserRef Parser); +extern LLVMRemarkEntry *LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser); /** * Returns `1` if the parser encountered an error while parsing the buffer. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern LLVMBool LLVMOptRemarkParserHasError(LLVMOptRemarkParserRef Parser); +extern LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser); /** * Returns a null-terminated string containing an error message. @@ -171,34 +170,33 @@ * In case of no error, the result is `NULL`. * * The memory of the string is bound to the lifetime of \p Parser. If - * LLVMOptRemarkParserDispose() is called, the memory of the string will be + * LLVMRemarkParserDispose() is called, the memory of the string will be * released. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern const char * -LLVMOptRemarkParserGetErrorMessage(LLVMOptRemarkParserRef Parser); +extern const char *LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser); /** * Releases all the resources used by \p Parser. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern void LLVMOptRemarkParserDispose(LLVMOptRemarkParserRef Parser); +extern void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser); /** - * Returns the version of the opt-remarks dylib. + * Returns the version of the remarks dylib. * - * \since OPT_REMARKS_API_VERSION=0 + * \since REMARKS_API_VERSION=0 */ -extern uint32_t LLVMOptRemarkVersion(void); +extern uint32_t LLVMRemarkVersion(void); /** - * @} // endgoup LLVMCOPTREMARKS + * @} // endgoup LLVMCREMARKS */ #ifdef __cplusplus } #endif /* !defined(__cplusplus) */ -#endif /* LLVM_C_OPT_REMARKS_H */ +#endif /* LLVM_C_REMARKS_H */ Index: llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h =================================================================== --- llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h +++ llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h @@ -74,7 +74,7 @@ bool isEnabled() const override { const Function &Fn = getFunction(); LLVMContext &Ctx = Fn.getContext(); - return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName()); + return Ctx.getDiagHandlerPtr()->isPassedRemarkEnabled(getPassName()); } }; @@ -100,7 +100,7 @@ bool isEnabled() const override { const Function &Fn = getFunction(); LLVMContext &Ctx = Fn.getContext(); - return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName()); + return Ctx.getDiagHandlerPtr()->isMissedRemarkEnabled(getPassName()); } }; Index: llvm/include/llvm/IR/DiagnosticHandler.h =================================================================== --- llvm/include/llvm/IR/DiagnosticHandler.h +++ llvm/include/llvm/IR/DiagnosticHandler.h @@ -51,18 +51,18 @@ /// to provide different implementation. virtual bool isAnalysisRemarkEnabled(StringRef PassName) const; - /// Return true if missed optimization remarks are enabled, override + /// Return true if missed remark diagnostics are enabled, override /// to provide different implementation. - virtual bool isMissedOptRemarkEnabled(StringRef PassName) const; + virtual bool isMissedRemarkEnabled(StringRef PassName) const; - /// Return true if passed optimization remarks are enabled, override + /// Return true if passed remark diagnostics are enabled, override /// to provide different implementation. - virtual bool isPassedOptRemarkEnabled(StringRef PassName) const; + virtual bool isPassedRemarkEnabled(StringRef PassName) const; /// Return true if any type of remarks are enabled for this pass. bool isAnyRemarkEnabled(StringRef PassName) const { - return (isMissedOptRemarkEnabled(PassName) || - isPassedOptRemarkEnabled(PassName) || + return (isMissedRemarkEnabled(PassName) || + isPassedRemarkEnabled(PassName) || isAnalysisRemarkEnabled(PassName)); } Index: llvm/lib/CMakeLists.txt =================================================================== --- llvm/lib/CMakeLists.txt +++ llvm/lib/CMakeLists.txt @@ -16,7 +16,7 @@ add_subdirectory(Object) add_subdirectory(ObjectYAML) add_subdirectory(Option) -add_subdirectory(OptRemarks) +add_subdirectory(Remarks) add_subdirectory(DebugInfo) add_subdirectory(ExecutionEngine) add_subdirectory(Target) Index: llvm/lib/IR/DiagnosticHandler.cpp =================================================================== --- llvm/lib/IR/DiagnosticHandler.cpp +++ llvm/lib/IR/DiagnosticHandler.cpp @@ -75,11 +75,11 @@ return (PassRemarksAnalysisOptLoc.Pattern && PassRemarksAnalysisOptLoc.Pattern->match(PassName)); } -bool DiagnosticHandler::isMissedOptRemarkEnabled(StringRef PassName) const { +bool DiagnosticHandler::isMissedRemarkEnabled(StringRef PassName) const { return (PassRemarksMissedOptLoc.Pattern && PassRemarksMissedOptLoc.Pattern->match(PassName)); } -bool DiagnosticHandler::isPassedOptRemarkEnabled(StringRef PassName) const { +bool DiagnosticHandler::isPassedRemarkEnabled(StringRef PassName) const { return (PassRemarksPassedOptLoc.Pattern && PassRemarksPassedOptLoc.Pattern->match(PassName)); } Index: llvm/lib/IR/DiagnosticInfo.cpp =================================================================== --- llvm/lib/IR/DiagnosticInfo.cpp +++ llvm/lib/IR/DiagnosticInfo.cpp @@ -260,7 +260,7 @@ bool OptimizationRemark::isEnabled() const { const Function &Fn = getFunction(); LLVMContext &Ctx = Fn.getContext(); - return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName()); + return Ctx.getDiagHandlerPtr()->isPassedRemarkEnabled(getPassName()); } OptimizationRemarkMissed::OptimizationRemarkMissed( @@ -281,7 +281,7 @@ bool OptimizationRemarkMissed::isEnabled() const { const Function &Fn = getFunction(); LLVMContext &Ctx = Fn.getContext(); - return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName()); + return Ctx.getDiagHandlerPtr()->isMissedRemarkEnabled(getPassName()); } OptimizationRemarkAnalysis::OptimizationRemarkAnalysis( Index: llvm/lib/LLVMBuild.txt =================================================================== --- llvm/lib/LLVMBuild.txt +++ llvm/lib/LLVMBuild.txt @@ -35,7 +35,7 @@ BinaryFormat ObjectYAML Option - OptRemarks + Remarks Passes ProfileData Support Index: llvm/lib/OptRemarks/CMakeLists.txt =================================================================== --- llvm/lib/OptRemarks/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_llvm_library(LLVMOptRemarks - OptRemarksParser.cpp -) Index: llvm/lib/Remarks/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/lib/Remarks/CMakeLists.txt @@ -0,0 +1,3 @@ +add_llvm_library(LLVMRemarks + RemarkParser.cpp +) Index: llvm/lib/Remarks/LLVMBuild.txt =================================================================== --- llvm/lib/Remarks/LLVMBuild.txt +++ llvm/lib/Remarks/LLVMBuild.txt @@ -1,4 +1,4 @@ -;===- ./lib/OptRemarks/LLVMBuild.txt ---------------------------*- Conf -*--===; +;===- ./lib/Remarks/LLVMBuild.txt ------------------------------*- Conf -*--===; ; ; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ; See https://llvm.org/LICENSE.txt for license information. @@ -16,6 +16,6 @@ [component_0] type = Library -name = OptRemarks +name = Remarks parent = Libraries required_libraries = Support Index: llvm/lib/Remarks/RemarkParser.cpp =================================================================== --- llvm/lib/Remarks/RemarkParser.cpp +++ llvm/lib/Remarks/RemarkParser.cpp @@ -1,4 +1,4 @@ -//===- OptRemarksParser.cpp -----------------------------------------------===// +//===- RemarkParser.cpp --------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// // // This file provides utility methods used by clients that want to use the -// parser for optimization remarks in LLVM. +// parser for remark diagnostics in LLVM. // //===----------------------------------------------------------------------===// -#include "llvm-c/OptRemarks.h" +#include "llvm-c/Remarks.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLTraits.h" @@ -31,14 +31,14 @@ /// Iterator in the YAML stream. yaml::document_iterator DI; /// The parsed remark (if any). - Optional LastRemark; + Optional LastRemark; /// Temporary parsing buffer for the arguments. - SmallVector TmpArgs; + SmallVector TmpArgs; /// The state used by the parser to parse a remark entry. Invalidated with /// every call to `parseYAMLElement`. struct ParseState { /// Temporary parsing buffer for the arguments. - SmallVectorImpl *Args; + SmallVectorImpl *Args; StringRef Type; StringRef Pass; StringRef Name; @@ -49,7 +49,7 @@ Optional Column; Optional Hotness; - ParseState(SmallVectorImpl &Args) : Args(&Args) {} + ParseState(SmallVectorImpl &Args) : Args(&Args) {} /// Use Args only as a **temporary** buffer. ~ParseState() { Args->clear(); } }; @@ -80,7 +80,7 @@ Error parseDebugLoc(Optional &File, Optional &Line, Optional &Column, yaml::KeyValueNode &Node); /// Parse an argument. - Error parseArg(SmallVectorImpl &TmpArgs, yaml::Node &Node); + Error parseArg(SmallVectorImpl &TmpArgs, yaml::Node &Node); /// Handle a diagnostic from the YAML stream. Records the error in the /// RemarkParser class. @@ -114,7 +114,7 @@ char ParseError::ID = 0; -static LLVMOptRemarkStringRef toOptRemarkStr(StringRef Str) { +static LLVMRemarkStringRef toRemarkStr(StringRef Str) { return {Str.data(), static_cast(Str.size())}; } @@ -190,7 +190,7 @@ return Error::success(); } -Error RemarkParser::parseArg(SmallVectorImpl &Args, +Error RemarkParser::parseArg(SmallVectorImpl &Args, yaml::Node &Node) { auto *ArgMap = dyn_cast(&Node); if (!ArgMap) @@ -237,10 +237,10 @@ if (ValueStr.empty()) return make_error("argument value is missing.", *ArgMap); - Args.push_back(LLVMOptRemarkArg{ - toOptRemarkStr(KeyStr), toOptRemarkStr(ValueStr), - LLVMOptRemarkDebugLoc{toOptRemarkStr(File.getValueOr(StringRef())), - Line.getValueOr(0), Column.getValueOr(0)}}); + Args.push_back(LLVMRemarkArg{ + toRemarkStr(KeyStr), toRemarkStr(ValueStr), + LLVMRemarkDebugLoc{toRemarkStr(File.getValueOr(StringRef())), + Line.getValueOr(0), Column.getValueOr(0)}}); return Error::success(); } @@ -302,14 +302,13 @@ return make_error("Type, Pass, Name or Function missing.", *Remark.getRoot()); - LastRemark = LLVMOptRemarkEntry{ - toOptRemarkStr(State.Type), - toOptRemarkStr(State.Pass), - toOptRemarkStr(State.Name), - toOptRemarkStr(State.Function), - LLVMOptRemarkDebugLoc{toOptRemarkStr(State.File.getValueOr(StringRef())), - State.Line.getValueOr(0), - State.Column.getValueOr(0)}, + LastRemark = LLVMRemarkEntry{ + toRemarkStr(State.Type), + toRemarkStr(State.Pass), + toRemarkStr(State.Name), + toRemarkStr(State.Function), + LLVMRemarkDebugLoc{toRemarkStr(State.File.getValueOr(StringRef())), + State.Line.getValueOr(0), State.Column.getValueOr(0)}, State.Hotness.getValueOr(0), static_cast(State.Args->size()), State.Args->data()}; @@ -319,16 +318,16 @@ } // namespace // Create wrappers for C Binding types (see CBindingWrapping.h). -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkParser, LLVMOptRemarkParserRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(RemarkParser, LLVMRemarkParserRef) -extern "C" LLVMOptRemarkParserRef LLVMOptRemarkParserCreate(const void *Buf, - uint64_t Size) { +extern "C" LLVMRemarkParserRef LLVMRemarkParserCreate(const void *Buf, + uint64_t Size) { return wrap( new RemarkParser(StringRef(static_cast(Buf), Size))); } -extern "C" LLVMOptRemarkEntry * -LLVMOptRemarkParserGetNext(LLVMOptRemarkParserRef Parser) { +extern "C" LLVMRemarkEntry * +LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser) { RemarkParser &TheParser = *unwrap(Parser); // Check for EOF. if (TheParser.HadAnyErrors || TheParser.DI == TheParser.Stream.end()) @@ -348,20 +347,20 @@ ++TheParser.DI; // Return the just-parsed remark. - if (Optional &Entry = TheParser.LastRemark) + if (Optional &Entry = TheParser.LastRemark) return &*Entry; return nullptr; } -extern "C" LLVMBool LLVMOptRemarkParserHasError(LLVMOptRemarkParserRef Parser) { +extern "C" LLVMBool LLVMRemarkParserHasError(LLVMRemarkParserRef Parser) { return unwrap(Parser)->HadAnyErrors; } extern "C" const char * -LLVMOptRemarkParserGetErrorMessage(LLVMOptRemarkParserRef Parser) { +LLVMRemarkParserGetErrorMessage(LLVMRemarkParserRef Parser) { return unwrap(Parser)->ErrorStream.str().c_str(); } -extern "C" void LLVMOptRemarkParserDispose(LLVMOptRemarkParserRef Parser) { +extern "C" void LLVMRemarkParserDispose(LLVMRemarkParserRef Parser) { delete unwrap(Parser); } Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp =================================================================== --- llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp +++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp @@ -555,7 +555,7 @@ // Other CFA registers than FP are not supported by compact unwind. // Fallback on DWARF. - // FIXME: When opt-remarks are supported in MC, add a remark to notify + // FIXME: When remarks are supported in MC, add a remark to notify // the user. if (XReg != AArch64::FP) return CU::UNWIND_ARM64_MODE_DWARF; Index: llvm/test/tools/gold/X86/opt-remarks.ll =================================================================== --- llvm/test/tools/gold/X86/opt-remarks.ll +++ llvm/test/tools/gold/X86/opt-remarks.ll @@ -1,12 +1,12 @@ -; Test plugin options for opt-remarks. +; Test plugin options for remarks. ; RUN: llvm-as %s -o %t.o ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \ ; RUN: -plugin-opt=save-temps \ -; RUN: -plugin-opt=opt-remarks-filename=%t.yaml %t.o -o %t2.o 2>&1 +; RUN: -plugin-opt=remarks-filename=%t.yaml %t.o -o %t2.o 2>&1 ; RUN: llvm-dis %t2.o.0.4.opt.bc -o - | FileCheck %s ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \ -; RUN: -plugin-opt=opt-remarks-with-hotness \ -; RUN: -plugin-opt=opt-remarks-filename=%t.hot.yaml %t.o -o %t2.o 2>&1 +; RUN: -plugin-opt=remarks-with-hotness \ +; RUN: -plugin-opt=remarks-filename=%t.hot.yaml %t.o -o %t2.o 2>&1 ; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML ; RUN: cat %t.hot.yaml | FileCheck %s -check-prefix=YAML-HOT Index: llvm/tools/gold/gold-plugin.cpp =================================================================== --- llvm/tools/gold/gold-plugin.cpp +++ llvm/tools/gold/gold-plugin.cpp @@ -206,8 +206,8 @@ static std::string stats_file; // Optimization remarks filename and hotness options - static std::string OptRemarksFilename; - static bool OptRemarksWithHotness = false; + static std::string RemarksFilename; + static bool RemarksWithHotness = false; static void process_plugin_option(const char *opt_) { @@ -275,10 +275,10 @@ debug_pass_manager = true; } else if (opt.startswith("dwo_dir=")) { dwo_dir = opt.substr(strlen("dwo_dir=")); - } else if (opt.startswith("opt-remarks-filename=")) { - OptRemarksFilename = opt.substr(strlen("opt-remarks-filename=")); - } else if (opt == "opt-remarks-with-hotness") { - OptRemarksWithHotness = true; + } else if (opt.startswith("remarks-filename=")) { + RemarksFilename = opt.substr(strlen("remarks-filename=")); + } else if (opt == "remarks-with-hotness") { + RemarksWithHotness = true; } else if (opt.startswith("stats-file=")) { stats_file = opt.substr(strlen("stats-file=")); } else { @@ -895,8 +895,8 @@ Conf.DwoDir = options::dwo_dir; // Set up optimization remarks handling. - Conf.RemarksFilename = options::OptRemarksFilename; - Conf.RemarksWithHotness = options::OptRemarksWithHotness; + Conf.RemarksFilename = options::RemarksFilename; + Conf.RemarksWithHotness = options::RemarksWithHotness; // Use new pass manager if set in driver Conf.UseNewPM = options::new_pass_manager; Index: llvm/tools/llvm-lto2/llvm-lto2.cpp =================================================================== --- llvm/tools/llvm-lto2/llvm-lto2.cpp +++ llvm/tools/llvm-lto2/llvm-lto2.cpp @@ -92,10 +92,10 @@ "Replace unspecified target triples in input files with this triple")); static cl::opt - OptRemarksOutput("pass-remarks-output", - cl::desc("YAML output file for optimization remarks")); + RemarksOutput("pass-remarks-output", + cl::desc("YAML output file for optimization remarks")); -static cl::opt OptRemarksWithHotness( +static cl::opt RemarksWithHotness( "pass-remarks-with-hotness", cl::desc("Whether to include hotness informations in the remarks.\n" "Has effect only if -pass-remarks-output is specified.")); @@ -210,8 +210,8 @@ "Config::addSaveTemps failed"); // Optimization remarks. - Conf.RemarksFilename = OptRemarksOutput; - Conf.RemarksWithHotness = OptRemarksWithHotness; + Conf.RemarksFilename = RemarksOutput; + Conf.RemarksWithHotness = RemarksWithHotness; Conf.SampleProfile = SamplePGOFile; Index: llvm/tools/llvm-opt-report/CMakeLists.txt =================================================================== --- llvm/tools/llvm-opt-report/CMakeLists.txt +++ llvm/tools/llvm-opt-report/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LLVM_LINK_COMPONENTS Core Demangle Object OptRemarks Support) +set(LLVM_LINK_COMPONENTS Core Demangle Object Remarks Support) add_llvm_tool(llvm-opt-report OptReport.cpp Index: llvm/tools/llvm-opt-report/OptReport.cpp =================================================================== --- llvm/tools/llvm-opt-report/OptReport.cpp +++ llvm/tools/llvm-opt-report/OptReport.cpp @@ -13,6 +13,7 @@ /// //===----------------------------------------------------------------------===// +#include "llvm-c/Remarks.h" #include "llvm/Demangle/Demangle.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" @@ -27,7 +28,6 @@ #include "llvm/Support/WithColor.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" -#include "llvm-c/OptRemarks.h" #include #include #include @@ -152,11 +152,11 @@ } StringRef Buffer = (*Buf)->getBuffer(); - LLVMOptRemarkParserRef Parser = - LLVMOptRemarkParserCreate(Buffer.data(), Buffer.size()); + LLVMRemarkParserRef Parser = + LLVMRemarkParserCreate(Buffer.data(), Buffer.size()); - LLVMOptRemarkEntry *Remark = nullptr; - while ((Remark = LLVMOptRemarkParserGetNext(Parser))) { + LLVMRemarkEntry *Remark = nullptr; + while ((Remark = LLVMRemarkParserGetNext(Parser))) { bool Transformed = StringRef(Remark->RemarkType.Str, Remark->RemarkType.Len) == "!Passed"; StringRef Pass(Remark->PassName.Str, Remark->PassName.Len); @@ -165,13 +165,13 @@ StringRef Function(Remark->FunctionName.Str, Remark->FunctionName.Len); uint32_t Line = Remark->DebugLoc.SourceLineNumber; uint32_t Column = Remark->DebugLoc.SourceColumnNumber; - ArrayRef Args(Remark->Args, Remark->NumArgs); + ArrayRef Args(Remark->Args, Remark->NumArgs); int VectorizationFactor = 1; int InterleaveCount = 1; int UnrollCount = 1; - for (const LLVMOptRemarkArg &Arg : Args) { + for (const LLVMRemarkArg &Arg : Args) { StringRef ArgKeyName(Arg.Key.Str, Arg.Key.Len); StringRef ArgValue(Arg.Value.Str, Arg.Value.Len); if (ArgKeyName == "VectorizationFactor") @@ -209,11 +209,11 @@ } } - bool HasError = LLVMOptRemarkParserHasError(Parser); + bool HasError = LLVMRemarkParserHasError(Parser); if (HasError) - WithColor::error() << LLVMOptRemarkParserGetErrorMessage(Parser) << "\n"; + WithColor::error() << LLVMRemarkParserGetErrorMessage(Parser) << "\n"; - LLVMOptRemarkParserDispose(Parser); + LLVMRemarkParserDispose(Parser); return !HasError; } Index: llvm/tools/opt-remarks/CMakeLists.txt =================================================================== --- llvm/tools/opt-remarks/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -set(LLVM_LINK_COMPONENTS - OptRemarks - ) - -set(SOURCES - liboptremarks.cpp - ) - -set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/OptRemarks.exports) - -add_llvm_library(OptRemarks SHARED ${SOURCES}) - -install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/OptRemarks.h - DESTINATION include/llvm-c - COMPONENT OptRemarks) - -if (APPLE) - set(OPTREMARKS_VERSION ${LLVM_VERSION_MAJOR}) - set_property(TARGET OptRemarks APPEND_STRING PROPERTY - LINK_FLAGS - " -compatibility_version 1 -current_version ${OPTREMARKS_VERSION}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") -endif() Index: llvm/tools/opt-remarks/OptRemarks.exports =================================================================== --- llvm/tools/opt-remarks/OptRemarks.exports +++ /dev/null @@ -1,6 +0,0 @@ -LLVMOptRemarkParserCreate -LLVMOptRemarkParserGetNext -LLVMOptRemarkParserHasError -LLVMOptRemarkParserGetErrorMessage -LLVMOptRemarkParserDispose -LLVMOptRemarkVersion Index: llvm/tools/opt/NewPMDriver.h =================================================================== --- llvm/tools/opt/NewPMDriver.h +++ llvm/tools/opt/NewPMDriver.h @@ -58,7 +58,7 @@ /// nullptr. bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, ToolOutputFile *Out, ToolOutputFile *ThinLinkOut, - ToolOutputFile *OptRemarkFile, StringRef PassPipeline, + ToolOutputFile *RemarkFile, StringRef PassPipeline, opt_tool::OutputKind OK, opt_tool::VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, Index: llvm/tools/opt/NewPMDriver.cpp =================================================================== --- llvm/tools/opt/NewPMDriver.cpp +++ llvm/tools/opt/NewPMDriver.cpp @@ -207,7 +207,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, - ToolOutputFile *OptRemarkFile, + ToolOutputFile *RemarkFile, StringRef PassPipeline, OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, @@ -341,8 +341,8 @@ ThinLTOLinkOut->keep(); } - if (OptRemarkFile) - OptRemarkFile->keep(); + if (RemarkFile) + RemarkFile->keep(); return true; } Index: llvm/tools/opt/opt.cpp =================================================================== --- llvm/tools/opt/opt.cpp +++ llvm/tools/opt/opt.cpp @@ -527,17 +527,17 @@ if (PassRemarksHotnessThreshold) Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold); - std::unique_ptr OptRemarkFile; + std::unique_ptr RemarkFile; if (RemarksFilename != "") { std::error_code EC; - OptRemarkFile = + RemarkFile = llvm::make_unique(RemarksFilename, EC, sys::fs::F_None); if (EC) { errs() << EC.message() << '\n'; return 1; } Context.setDiagnosticsOutputFile( - llvm::make_unique(OptRemarkFile->os())); + llvm::make_unique(RemarkFile->os())); } // Load the input module... @@ -647,7 +647,7 @@ // string. Hand off the rest of the functionality to the new code for that // layer. return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(), - OptRemarkFile.get(), PassPipeline, OK, VK, + RemarkFile.get(), PassPipeline, OK, VK, PreserveAssemblyUseListOrder, PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash, EnableDebugify) @@ -883,8 +883,8 @@ "the compile-twice option\n"; Out->os() << BOS->str(); Out->keep(); - if (OptRemarkFile) - OptRemarkFile->keep(); + if (RemarkFile) + RemarkFile->keep(); return 1; } Out->os() << BOS->str(); @@ -897,8 +897,8 @@ if (!NoOutput || PrintBreakpoints) Out->keep(); - if (OptRemarkFile) - OptRemarkFile->keep(); + if (RemarkFile) + RemarkFile->keep(); if (ThinLinkOut) ThinLinkOut->keep(); Index: llvm/tools/remarks-shlib/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/tools/remarks-shlib/CMakeLists.txt @@ -0,0 +1,22 @@ +set(LLVM_LINK_COMPONENTS + Remarks + ) + +set(SOURCES + libremarks.cpp + ) + +set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports) + +add_llvm_library(Remarks SHARED ${SOURCES}) + +install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h + DESTINATION include/llvm-c + COMPONENT Remarks) + +if (APPLE) + set(REMARKS_VERSION ${LLVM_VERSION_MAJOR}) + set_property(TARGET Remarks APPEND_STRING PROPERTY + LINK_FLAGS + " -compatibility_version 1 -current_version ${REMARKS_VERSION}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}") +endif() Index: llvm/tools/remarks-shlib/Remarks.exports =================================================================== --- /dev/null +++ llvm/tools/remarks-shlib/Remarks.exports @@ -0,0 +1,6 @@ +LLVMRemarkParserCreate +LLVMRemarkParserGetNext +LLVMRemarkParserHasError +LLVMRemarkParserGetErrorMessage +LLVMRemarkParserDispose +LLVMRemarkVersion Index: llvm/tools/remarks-shlib/libremarks.cpp =================================================================== --- llvm/tools/remarks-shlib/libremarks.cpp +++ llvm/tools/remarks-shlib/libremarks.cpp @@ -1,4 +1,4 @@ -//===-liboptremarks.cpp - LLVM Opt-Remarks Shared Library -----------------===// +//===-libremarks.cpp - LLVM Remarks Shared Library ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,12 +6,12 @@ // //===----------------------------------------------------------------------===// // -// Provide a library to work with optimization remarks. +// Provide a library to work with remark diagnostics. // //===----------------------------------------------------------------------===// -#include "llvm-c/OptRemarks.h" +#include "llvm-c/Remarks.h" -extern uint32_t LLVMOptRemarkVersion(void) { - return OPT_REMARKS_API_VERSION; +extern uint32_t LLVMRemarkVersion(void) { + return REMARKS_API_VERSION; } Index: llvm/unittests/CMakeLists.txt =================================================================== --- llvm/unittests/CMakeLists.txt +++ llvm/unittests/CMakeLists.txt @@ -26,7 +26,7 @@ add_subdirectory(Object) add_subdirectory(ObjectYAML) add_subdirectory(Option) -add_subdirectory(OptRemarks) +add_subdirectory(Remarks) add_subdirectory(Passes) add_subdirectory(ProfileData) add_subdirectory(Support) Index: llvm/unittests/OptRemarks/CMakeLists.txt =================================================================== --- llvm/unittests/OptRemarks/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -set(LLVM_LINK_COMPONENTS - OptRemarks - Support - ) - -add_llvm_unittest(OptRemarksTests - OptRemarksParsingTest.cpp - ) Index: llvm/unittests/Remarks/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/unittests/Remarks/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_LINK_COMPONENTS + Remarks + Support + ) + +add_llvm_unittest(RemarksTests + RemarksParsingTest.cpp + ) Index: llvm/unittests/Remarks/RemarksParsingTest.cpp =================================================================== --- /dev/null +++ llvm/unittests/Remarks/RemarksParsingTest.cpp @@ -0,0 +1,436 @@ +//===- unittest/Support/RemarksParsingTest.cpp - OptTable tests --------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "llvm-c/Remarks.h" +#include "gtest/gtest.h" + +using namespace llvm; + +template bool tryParse(const char (&Buf)[N]) { + LLVMRemarkParserRef Parser = LLVMRemarkParserCreate(Buf, N - 1); + LLVMRemarkEntry *Remark = nullptr; + while (LLVMRemarkEntry *NewRemark = LLVMRemarkParserGetNext(Parser)) { + EXPECT_TRUE(Remark == nullptr); // Only one remark per test. + Remark = NewRemark; + } + EXPECT_TRUE(Remark != nullptr); // We need *exactly* one remark per test. + bool HasError = LLVMRemarkParserHasError(Parser); + LLVMRemarkParserDispose(Parser); + return !HasError; +} + +template +bool parseExpectError(const char (&Buf)[N], const char *Error) { + LLVMRemarkParserRef Parser = LLVMRemarkParserCreate(Buf, N - 1); + LLVMRemarkEntry *Remark = nullptr; + while (LLVMRemarkEntry *NewRemark = LLVMRemarkParserGetNext(Parser)) { + EXPECT_FALSE(NewRemark); + } + EXPECT_TRUE(Remark == nullptr); // We are parsing only one malformed remark. + EXPECT_TRUE(LLVMRemarkParserHasError(Parser)); + bool MatchesError = + StringRef(LLVMRemarkParserGetErrorMessage(Parser)).contains(Error); + LLVMRemarkParserDispose(Parser); + + return MatchesError; +} + +TEST(Remarks, RemarksParsingEmpty) { + StringRef Buf = "\n" + "\n"; + LLVMRemarkParserRef Parser = LLVMRemarkParserCreate(Buf.data(), Buf.size()); + LLVMRemarkEntry *NewRemark = LLVMRemarkParserGetNext(Parser); + EXPECT_TRUE(NewRemark == nullptr); // No remark expected. + EXPECT_TRUE(LLVMRemarkParserHasError(Parser)); + EXPECT_TRUE(StringRef(LLVMRemarkParserGetErrorMessage(Parser)) + .contains("document root is not of mapping type.")); + LLVMRemarkParserDispose(Parser); +} + +TEST(Remarks, RemarksParsingGood) { + EXPECT_TRUE(tryParse("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "DebugLoc: { File: file.c, Line: 3, Column: 12 }\n" + "Function: foo\n" + "Args:\n" + " - Callee: bar\n" + " - String: ' will not be inlined into '\n" + " - Caller: foo\n" + " DebugLoc: { File: file.c, Line: 2, Column: 0 }\n" + " - String: ' because its definition is unavailable'\n" + "")); + + // No debug loc should also pass. + EXPECT_TRUE(tryParse("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args:\n" + " - Callee: bar\n" + " - String: ' will not be inlined into '\n" + " - Caller: foo\n" + " DebugLoc: { File: file.c, Line: 2, Column: 0 }\n" + " - String: ' because its definition is unavailable'\n" + "")); + + // No args is also ok. + EXPECT_TRUE(tryParse("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "DebugLoc: { File: file.c, Line: 3, Column: 12 }\n" + "Function: foo\n" + "")); + + // Different order. + EXPECT_TRUE(tryParse("\n" + "--- !Missed\n" + "DebugLoc: { Line: 3, Column: 12, File: file.c }\n" + "Function: foo\n" + "Name: NoDefinition\n" + "Args:\n" + " - Callee: bar\n" + " - String: ' will not be inlined into '\n" + " - Caller: foo\n" + " DebugLoc: { File: file.c, Line: 2, Column: 0 }\n" + " - String: ' because its definition is unavailable'\n" + "Pass: inline\n" + "")); +} + +// Mandatory common part of a remark. +#define COMMON_REMARK "\nPass: inline\nName: NoDefinition\nFunction: foo\n\n" +// Test all the types. +TEST(Remarks, RemarksParsingTypes) { + // Type: Passed + EXPECT_TRUE(tryParse("--- !Passed" COMMON_REMARK)); + // Type: Missed + EXPECT_TRUE(tryParse("--- !Missed" COMMON_REMARK)); + // Type: Analysis + EXPECT_TRUE(tryParse("--- !Analysis" COMMON_REMARK)); + // Type: AnalysisFPCompute + EXPECT_TRUE(tryParse("--- !AnalysisFPCompute" COMMON_REMARK)); + // Type: AnalysisAliasing + EXPECT_TRUE(tryParse("--- !AnalysisAliasing" COMMON_REMARK)); + // Type: Failure + EXPECT_TRUE(tryParse("--- !Failure" COMMON_REMARK)); +} +#undef COMMON_REMARK + +TEST(Remarks, RemarksParsingMissingFields) { + // No type. + EXPECT_TRUE(parseExpectError("\n" + "---\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "", + "error: Type, Pass, Name or Function missing.")); + // No pass. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Name: NoDefinition\n" + "Function: foo\n" + "", + "error: Type, Pass, Name or Function missing.")); + // No name. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Function: foo\n" + "", + "error: Type, Pass, Name or Function missing.")); + // No function. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "", + "error: Type, Pass, Name or Function missing.")); + // Debug loc but no file. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { Line: 3, Column: 12 }\n" + "", + "DebugLoc node incomplete.")); + // Debug loc but no line. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Column: 12 }\n" + "", + "DebugLoc node incomplete.")); + // Debug loc but no column. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Line: 3 }\n" + "", + "DebugLoc node incomplete.")); +} + +TEST(Remarks, RemarksParsingWrongTypes) { + // Wrong debug loc type. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: foo\n" + "", + "expected a value of mapping type.")); + // Wrong line type. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Line: b, Column: 12 }\n" + "", + "expected a value of integer type.")); + // Wrong column type. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Line: 3, Column: c }\n" + "", + "expected a value of integer type.")); + // Wrong args type. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args: foo\n" + "", + "wrong value type for key.")); + // Wrong key type. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "{ A: a }: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "", + "key is not a string.")); + // Debug loc with unknown entry. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Column: 12, Unknown: 12 }\n" + "", + "unknown entry in DebugLoc map.")); + // Unknown entry. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Unknown: inline\n" + "", + "unknown key.")); + // Not a scalar. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: { File: a, Line: 1, Column: 2 }\n" + "Name: NoDefinition\n" + "Function: foo\n" + "", + "expected a value of scalar type.")); + // Not a string file in debug loc. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: { a: b }, Column: 12, Line: 12 }\n" + "", + "expected a value of scalar type.")); + // Not a integer column in debug loc. + EXPECT_TRUE(parseExpectError( + "\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Column: { a: b }, Line: 12 }\n" + "", + "expected a value of scalar type.")); + // Not a integer line in debug loc. + EXPECT_TRUE(parseExpectError( + "\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Column: 12, Line: { a: b } }\n" + "", + "expected a value of scalar type.")); + // Not a mapping type value for args. + EXPECT_TRUE(parseExpectError( + "\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "DebugLoc: { File: file.c, Column: 12, Line: { a: b } }\n" + "", + "expected a value of scalar type.")); +} + +TEST(Remarks, RemarksParsingWrongArgs) { + // Multiple debug locs per arg. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args:\n" + " - Str: string\n" + " DebugLoc: { File: a, Line: 1, Column: 2 }\n" + " DebugLoc: { File: a, Line: 1, Column: 2 }\n" + "", + "only one DebugLoc entry is allowed per argument.")); + // Multiple strings per arg. + EXPECT_TRUE( + parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args:\n" + " - Str: string\n" + " Str2: string\n" + " DebugLoc: { File: a, Line: 1, Column: 2 }\n" + "", + "only one string entry is allowed per argument.")); + // No arg value. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args:\n" + " - Callee: ''\n" + " - DebugLoc: { File: a, Line: 1, Column: 2 }\n" + "", + "argument value is missing.")); + // No arg value. + EXPECT_TRUE(parseExpectError("\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "Function: foo\n" + "Args:\n" + " - DebugLoc: { File: a, Line: 1, Column: 2 }\n" + "", + "argument key is missing.")); +} + +TEST(Remarks, RemarksGoodStruct) { + StringRef Buf = "\n" + "--- !Missed\n" + "Pass: inline\n" + "Name: NoDefinition\n" + "DebugLoc: { File: file.c, Line: 3, Column: 12 }\n" + "Function: foo\n" + "Args:\n" + " - Callee: bar\n" + " - String: ' will not be inlined into '\n" + " - Caller: foo\n" + " DebugLoc: { File: file.c, Line: 2, Column: 0 }\n" + " - String: ' because its definition is unavailable'\n" + "\n"; + + LLVMRemarkParserRef Parser = LLVMRemarkParserCreate(Buf.data(), Buf.size()); + LLVMRemarkEntry *Remark = LLVMRemarkParserGetNext(Parser); + EXPECT_FALSE(Remark == nullptr); + EXPECT_EQ(StringRef(Remark->RemarkType.Str, 7), "!Missed"); + EXPECT_EQ(Remark->RemarkType.Len, 7U); + EXPECT_EQ(StringRef(Remark->PassName.Str, 6), "inline"); + EXPECT_EQ(Remark->PassName.Len, 6U); + EXPECT_EQ(StringRef(Remark->RemarkName.Str, 12), "NoDefinition"); + EXPECT_EQ(Remark->RemarkName.Len, 12U); + EXPECT_EQ(StringRef(Remark->FunctionName.Str, 3), "foo"); + EXPECT_EQ(Remark->FunctionName.Len, 3U); + EXPECT_EQ(StringRef(Remark->DebugLoc.SourceFile.Str, 6), "file.c"); + EXPECT_EQ(Remark->DebugLoc.SourceFile.Len, 6U); + EXPECT_EQ(Remark->DebugLoc.SourceLineNumber, 3U); + EXPECT_EQ(Remark->DebugLoc.SourceColumnNumber, 12U); + EXPECT_EQ(Remark->Hotness, 0U); + EXPECT_EQ(Remark->NumArgs, 4U); + // Arg 0 + { + LLVMRemarkArg &Arg = Remark->Args[0]; + EXPECT_EQ(StringRef(Arg.Key.Str, 6), "Callee"); + EXPECT_EQ(Arg.Key.Len, 6U); + EXPECT_EQ(StringRef(Arg.Value.Str, 3), "bar"); + EXPECT_EQ(Arg.Value.Len, 3U); + EXPECT_EQ(StringRef(Arg.DebugLoc.SourceFile.Str, 0), ""); + EXPECT_EQ(Arg.DebugLoc.SourceFile.Len, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceLineNumber, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceColumnNumber, 0U); + } + // Arg 1 + { + LLVMRemarkArg &Arg = Remark->Args[1]; + EXPECT_EQ(StringRef(Arg.Key.Str, 6), "String"); + EXPECT_EQ(Arg.Key.Len, 6U); + EXPECT_EQ(StringRef(Arg.Value.Str, 26), " will not be inlined into "); + EXPECT_EQ(Arg.Value.Len, 26U); + EXPECT_EQ(StringRef(Arg.DebugLoc.SourceFile.Str, 0), ""); + EXPECT_EQ(Arg.DebugLoc.SourceFile.Len, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceLineNumber, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceColumnNumber, 0U); + } + // Arg 2 + { + LLVMRemarkArg &Arg = Remark->Args[2]; + EXPECT_EQ(StringRef(Arg.Key.Str, 6), "Caller"); + EXPECT_EQ(Arg.Key.Len, 6U); + EXPECT_EQ(StringRef(Arg.Value.Str, 3), "foo"); + EXPECT_EQ(Arg.Value.Len, 3U); + EXPECT_EQ(StringRef(Arg.DebugLoc.SourceFile.Str, 6), "file.c"); + EXPECT_EQ(Arg.DebugLoc.SourceFile.Len, 6U); + EXPECT_EQ(Arg.DebugLoc.SourceLineNumber, 2U); + EXPECT_EQ(Arg.DebugLoc.SourceColumnNumber, 0U); + } + // Arg 3 + { + LLVMRemarkArg &Arg = Remark->Args[3]; + EXPECT_EQ(StringRef(Arg.Key.Str, 6), "String"); + EXPECT_EQ(Arg.Key.Len, 6U); + EXPECT_EQ(StringRef(Arg.Value.Str, 38), + " because its definition is unavailable"); + EXPECT_EQ(Arg.Value.Len, 38U); + EXPECT_EQ(StringRef(Arg.DebugLoc.SourceFile.Str, 0), ""); + EXPECT_EQ(Arg.DebugLoc.SourceFile.Len, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceLineNumber, 0U); + EXPECT_EQ(Arg.DebugLoc.SourceColumnNumber, 0U); + } + + EXPECT_EQ(LLVMRemarkParserGetNext(Parser), nullptr); + + EXPECT_FALSE(LLVMRemarkParserHasError(Parser)); + LLVMRemarkParserDispose(Parser); +}