summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-opt-report/OptReport.cpp
diff options
context:
space:
mode:
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-03-19 18:09:51 +0000
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>2019-03-19 18:09:51 +0000
commit9ef60a2539b268f40052f61149aab6c2442732aa (patch)
treed7f7015d028a6118e17cc24b4995a9fd00a251e6 /llvm/tools/llvm-opt-report/OptReport.cpp
parentaea09858142fec87697ca4dd22c51cef410fb97f (diff)
downloadbcm5719-llvm-9ef60a2539b268f40052f61149aab6c2442732aa.tar.gz
bcm5719-llvm-9ef60a2539b268f40052f61149aab6c2442732aa.zip
[Remarks] Add a new Remark / RemarkParser abstraction
This adds a Remark class that allows us to share code when working with remarks. The C API has been updated to reflect this. Instead of the parser generating C structs, it's now using a C++ object that is used through opaque pointers in C. This gives us much more flexibility on what changes we can make to the internal state of the object and interacts much better with scenarios where the library is used through dlopen. * C API updates: * move from C structs to opaque pointers and functions * the remark type is now an enum instead of a string * unit tests updates: * use mostly the C++ API * keep one test for the C API * rename to YAMLRemarksParsingTest * a typo was fixed: AnalysisFPCompute -> AnalysisFPCommute. * a new error message was added: "expected a remark tag." * llvm-opt-report has been updated to use the C++ parser instead of the C API Differential Revision: https://reviews.llvm.org/D59049 llvm-svn: 356491
Diffstat (limited to 'llvm/tools/llvm-opt-report/OptReport.cpp')
-rw-r--r--llvm/tools/llvm-opt-report/OptReport.cpp74
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 43718eaedc0..3ea71fc47ef 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -15,6 +15,7 @@
#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"
@@ -151,40 +152,44 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
return false;
}
- 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);
+ 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;
int VectorizationFactor = 1;
int InterleaveCount = 1;
int UnrollCount = 1;
- 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);
+ 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);
}
- if (Line < 1 || File.empty())
+ const Optional<remarks::RemarkLocation> &Loc = Remark.Loc;
+ if (!Loc)
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.
@@ -194,27 +199,22 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
LLII.Transformed = true;
};
- if (Pass == "inline") {
- auto &LI = LocationInfo[File][Line][Function][Column];
+ if (Remark.PassName == "inline") {
+ auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column];
UpdateLLII(LI.Inlined);
- } else if (Pass == "loop-unroll") {
- auto &LI = LocationInfo[File][Line][Function][Column];
+ } else if (Remark.PassName == "loop-unroll") {
+ auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column];
LI.UnrollCount = UnrollCount;
UpdateLLII(LI.Unrolled);
- } else if (Pass == "loop-vectorize") {
- auto &LI = LocationInfo[File][Line][Function][Column];
+ } else if (Remark.PassName == "loop-vectorize") {
+ auto &LI = LocationInfo[File][Line][Remark.FunctionName][Column];
LI.VectorizationFactor = VectorizationFactor;
LI.InterleaveCount = InterleaveCount;
UpdateLLII(LI.Vectorized);
}
}
- bool HasError = LLVMRemarkParserHasError(Parser);
- if (HasError)
- WithColor::error() << LLVMRemarkParserGetErrorMessage(Parser) << "\n";
-
- LLVMRemarkParserDispose(Parser);
- return !HasError;
+ return true;
}
static bool writeReport(LocationInfoTy &LocationInfo) {
OpenPOWER on IntegriCloud