[llvm] r371134 - [Remarks] Add comparison operators to the Remark object
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 15:35:37 PDT 2019
Author: thegameg
Date: Thu Sep 5 15:35:37 2019
New Revision: 371134
URL: http://llvm.org/viewvc/llvm-project?rev=371134&view=rev
Log:
[Remarks] Add comparison operators to the Remark object
and related structs.
This also adds tests for the remarks::Remark object in general.
Added:
llvm/trunk/unittests/Remarks/RemarksAPITest.cpp
Modified:
llvm/trunk/include/llvm/Remarks/Remark.h
llvm/trunk/unittests/Remarks/CMakeLists.txt
Modified: llvm/trunk/include/llvm/Remarks/Remark.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Remarks/Remark.h?rev=371134&r1=371133&r2=371134&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Remarks/Remark.h (original)
+++ llvm/trunk/include/llvm/Remarks/Remark.h Thu Sep 5 15:35:37 2019
@@ -109,6 +109,36 @@ private:
// Create wrappers for C Binding types (see CBindingWrapping.h).
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Remark, LLVMRemarkEntryRef)
+/// Comparison operators for Remark objects and dependent objects.
+inline bool operator==(const RemarkLocation &LHS, const RemarkLocation &RHS) {
+ return LHS.SourceFilePath == RHS.SourceFilePath &&
+ LHS.SourceLine == RHS.SourceLine &&
+ LHS.SourceColumn == RHS.SourceColumn;
+}
+
+inline bool operator!=(const RemarkLocation &LHS, const RemarkLocation &RHS) {
+ return !(LHS == RHS);
+}
+
+inline bool operator==(const Argument &LHS, const Argument &RHS) {
+ return LHS.Key == RHS.Key && LHS.Val == RHS.Val && LHS.Loc == RHS.Loc;
+}
+
+inline bool operator!=(const Argument &LHS, const Argument &RHS) {
+ return !(LHS == RHS);
+}
+
+inline bool operator==(const Remark &LHS, const Remark &RHS) {
+ return LHS.RemarkType == RHS.RemarkType && LHS.PassName == RHS.PassName &&
+ LHS.RemarkName == RHS.RemarkName &&
+ LHS.FunctionName == RHS.FunctionName && LHS.Loc == RHS.Loc &&
+ LHS.Hotness == RHS.Hotness && LHS.Args == RHS.Args;
+}
+
+inline bool operator!=(const Remark &LHS, const Remark &RHS) {
+ return !(LHS == RHS);
+}
+
} // end namespace remarks
} // end namespace llvm
Modified: llvm/trunk/unittests/Remarks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Remarks/CMakeLists.txt?rev=371134&r1=371133&r2=371134&view=diff
==============================================================================
--- llvm/trunk/unittests/Remarks/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Remarks/CMakeLists.txt Thu Sep 5 15:35:37 2019
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_unittest(RemarksTests
BitstreamRemarksFormatTest.cpp
BitstreamRemarksSerializerTest.cpp
+ RemarksAPITest.cpp
RemarksStrTabParsingTest.cpp
YAMLRemarksParsingTest.cpp
YAMLRemarksSerializerTest.cpp
Added: llvm/trunk/unittests/Remarks/RemarksAPITest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Remarks/RemarksAPITest.cpp?rev=371134&view=auto
==============================================================================
--- llvm/trunk/unittests/Remarks/RemarksAPITest.cpp (added)
+++ llvm/trunk/unittests/Remarks/RemarksAPITest.cpp Thu Sep 5 15:35:37 2019
@@ -0,0 +1,77 @@
+//===- unittest/Support/RemarksAPITest.cpp - C++ API 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/Remarks/Remark.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+TEST(RemarksAPI, Comparison) {
+ remarks::Remark R;
+ R.RemarkType = remarks::Type::Missed;
+ R.PassName = "pass";
+ R.RemarkName = "name";
+ R.FunctionName = "func";
+ R.Loc = remarks::RemarkLocation{"path", 3, 4};
+ R.Hotness = 5;
+ R.Args.emplace_back();
+ R.Args.back().Key = "key";
+ R.Args.back().Val = "value";
+ R.Args.emplace_back();
+ R.Args.back().Key = "keydebug";
+ R.Args.back().Val = "valuedebug";
+ R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
+
+ // Check that == works.
+ EXPECT_EQ(R, R);
+
+ // Check that != works.
+ remarks::Remark R2 = R.clone();
+ R2.FunctionName = "func0";
+ EXPECT_NE(R, R2);
+
+ // Check that we iterate through all the arguments.
+ remarks::Remark R3 = R.clone();
+ R3.Args.back().Val = "not";
+ EXPECT_NE(R, R3);
+}
+
+TEST(RemarksAPI, Clone) {
+ remarks::Remark R;
+ R.RemarkType = remarks::Type::Missed;
+ R.PassName = "pass";
+ R.RemarkName = "name";
+ R.FunctionName = "func";
+ R.Loc = remarks::RemarkLocation{"path", 3, 4};
+ R.Hotness = 5;
+ R.Args.emplace_back();
+ R.Args.back().Key = "key";
+ R.Args.back().Val = "value";
+ R.Args.emplace_back();
+ R.Args.back().Key = "keydebug";
+ R.Args.back().Val = "valuedebug";
+ R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
+
+ // Check that clone works.
+ remarks::Remark R2 = R.clone();
+ EXPECT_EQ(R, R2);
+}
+
+TEST(RemarksAPI, ArgsAsMsg) {
+ remarks::Remark R;
+ R.RemarkType = remarks::Type::Missed;
+ R.Args.emplace_back();
+ R.Args.back().Key = "key";
+ R.Args.back().Val = "can not do this ";
+ R.Args.emplace_back();
+ R.Args.back().Key = "keydebug";
+ R.Args.back().Val = "because of that.";
+ R.Args.back().Loc = remarks::RemarkLocation{"argpath", 6, 7};
+
+ EXPECT_EQ(R.getArgsAsMsg(), "can not do this because of that.");
+}
More information about the llvm-commits
mailing list