diff options
Diffstat (limited to 'llvm/tools/llvm-opt-report/OptReport.cpp')
-rw-r--r-- | llvm/tools/llvm-opt-report/OptReport.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp index 3ea71fc47ef..43718eaedc0 100644 --- a/llvm/tools/llvm-opt-report/OptReport.cpp +++ b/llvm/tools/llvm-opt-report/OptReport.cpp @@ -15,7 +15,6 @@ #include "llvm-c/Remarks.h" #include "llvm/Demangle/Demangle.h" -#include "llvm/Remarks/RemarkParser.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" @@ -152,44 +151,40 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) { return false; } - remarks::Parser Parser((*Buf)->getBuffer()); - - while (true) { - Expected<const remarks::Remark *> RemarkOrErr = Parser.getNext(); - if (!RemarkOrErr) { - handleAllErrors(RemarkOrErr.takeError(), [&](const ErrorInfoBase &PE) { - PE.log(WithColor::error()); - }); - return false; - } - if (!*RemarkOrErr) // End of file. - break; - - const remarks::Remark &Remark = **RemarkOrErr; - - bool Transformed = Remark.RemarkType == remarks::Type::Passed; + StringRef Buffer = (*Buf)->getBuffer(); + LLVMRemarkParserRef Parser = + LLVMRemarkParserCreate(Buffer.data(), Buffer.size()); + + 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); + StringRef File(Remark->DebugLoc.SourceFile.Str, + Remark->DebugLoc.SourceFile.Len); + StringRef Function(Remark->FunctionName.Str, Remark->FunctionName.Len); + uint32_t Line = Remark->DebugLoc.SourceLineNumber; + uint32_t Column = Remark->DebugLoc.SourceColumnNumber; + ArrayRef<LLVMRemarkArg> Args(Remark->Args, Remark->NumArgs); int VectorizationFactor = 1; int InterleaveCount = 1; int UnrollCount = 1; - for (const remarks::Argument &Arg : Remark.Args) { - if (Arg.Key == "VectorizationFactor") - Arg.Val.getAsInteger(10, VectorizationFactor); - else if (Arg.Key == "InterleaveCount") - Arg.Val.getAsInteger(10, InterleaveCount); - else if (Arg.Key == "UnrollCount") - Arg.Val.getAsInteger(10, UnrollCount); + for (const LLVMRemarkArg &Arg : Args) { + StringRef ArgKeyName(Arg.Key.Str, Arg.Key.Len); + StringRef ArgValue(Arg.Value.Str, Arg.Value.Len); + if (ArgKeyName == "VectorizationFactor") + ArgValue.getAsInteger(10, VectorizationFactor); + else if (ArgKeyName == "InterleaveCount") + ArgValue.getAsInteger(10, InterleaveCount); + else if (ArgKeyName == "UnrollCount") + ArgValue.getAsInteger(10, UnrollCount); } - const Optional<remarks::RemarkLocation> &Loc = Remark.Loc; - if (!Loc) + if (Line < 1 || File.empty()) continue; - StringRef File = Loc->SourceFilePath; - unsigned Line = Loc->SourceLine; - unsigned Column = Loc->SourceColumn; - // We track information on both actual and potential transformations. This // way, if there are multiple possible things on a line that are, or could // have been transformed, we can indicate that explicitly in the output. @@ -199,22 +194,27 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) { LLII.Transformed = true; }; - if (Remark.PassName == "inline") { - auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column]; + if (Pass == "inline") { + auto &LI = LocationInfo[File][Line][Function][Column]; UpdateLLII(LI.Inlined); - } else if (Remark.PassName == "loop-unroll") { - auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column]; + } else if (Pass == "loop-unroll") { + auto &LI = LocationInfo[File][Line][Function][Column]; LI.UnrollCount = UnrollCount; UpdateLLII(LI.Unrolled); - } else if (Remark.PassName == "loop-vectorize") { - auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column]; + } else if (Pass == "loop-vectorize") { + auto &LI = LocationInfo[File][Line][Function][Column]; LI.VectorizationFactor = VectorizationFactor; LI.InterleaveCount = InterleaveCount; UpdateLLII(LI.Vectorized); } } - return true; + bool HasError = LLVMRemarkParserHasError(Parser); + if (HasError) + WithColor::error() << LLVMRemarkParserGetErrorMessage(Parser) << "\n"; + + LLVMRemarkParserDispose(Parser); + return !HasError; } static bool writeReport(LocationInfoTy &LocationInfo) { |