Skip to content

Commit 69ee8fb

Browse files
committed
Make branch hint warnings optional, defaulting to off.
Signed-off-by: Chris Dodd <[email protected]>
1 parent 7ea7c37 commit 69ee8fb

10 files changed

+34
-14
lines changed

frontends/common/constantFolding.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ class FilterLikelyAnnot : public Transform {
11221122
prune();
11231123
if (annot->name == IR::Annotation::likelyAnnotation) return nullptr;
11241124
if (annot->name == IR::Annotation::unlikelyAnnotation) {
1125-
warning(ErrorType::WARN_IGNORE, "ignoring %1% on always taken statement", annot);
1125+
// FIXME -- disable this warning due to worries it will trigger too often
1126+
warning(ErrorType::WARN_BRANCH_HINT, "ignoring %1% on always taken statement", annot);
11261127
return nullptr;
11271128
}
11281129
return annot;
@@ -1134,13 +1135,15 @@ const IR::Node *DoConstantFolding::postorder(IR::IfStatement *ifstmt) {
11341135
if (cond->value) {
11351136
if (auto blk = ifstmt->ifFalse ? ifstmt->ifFalse->to<IR::BlockStatement>() : nullptr) {
11361137
if (auto annot = blk->getAnnotation(IR::Annotation::likelyAnnotation))
1137-
warning(ErrorType::WARN_IGNORE, "ignoring %1% on never taken statement", annot);
1138+
warning(ErrorType::WARN_BRANCH_HINT, "ignoring %1% on never taken statement",
1139+
annot);
11381140
}
11391141
return ifstmt->ifTrue->apply(FilterLikelyAnnot());
11401142
} else {
11411143
if (auto blk = ifstmt->ifTrue->to<IR::BlockStatement>()) {
11421144
if (auto annot = blk->getAnnotation(IR::Annotation::likelyAnnotation))
1143-
warning(ErrorType::WARN_IGNORE, "ignoring %1% on never taken statement", annot);
1145+
warning(ErrorType::WARN_BRANCH_HINT, "ignoring %1% on never taken statement",
1146+
annot);
11441147
}
11451148
if (ifstmt->ifFalse == nullptr) {
11461149
return new IR::EmptyStatement(ifstmt->srcInfo);

lib/error_catalog.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818

1919
#include <map>
2020

21+
#include "error_reporter.h"
2122
#include "lib/cstring.h"
2223

2324
namespace P4 {
@@ -71,6 +72,7 @@ const int ErrorType::WARN_ENTRIES_OUT_OF_ORDER = 1022;
7172
const int ErrorType::WARN_MULTI_HDR_EXTRACT = 1023;
7273
const int ErrorType::WARN_EXPRESSION = 1024;
7374
const int ErrorType::WARN_DUPLICATE = 1025;
75+
const int ErrorType::WARN_BRANCH_HINT = 1026;
7476

7577
// ------ Info messages -----------
7678
const int ErrorType::INFO_INFERRED = WARN_MAX + 1;
@@ -124,9 +126,16 @@ std::map<int, cstring> ErrorCatalog::errorCatalog = {
124126
{ErrorType::WARN_MULTI_HDR_EXTRACT, "multi_header_extract"_cs},
125127
{ErrorType::WARN_EXPRESSION, "expr"_cs},
126128
{ErrorType::WARN_DUPLICATE, "duplicate"_cs},
129+
{ErrorType::WARN_BRANCH_HINT, "branch"_cs},
127130

128131
// Info messages
129132
{ErrorType::INFO_INFERRED, "inferred"_cs},
130133
{ErrorType::INFO_PROGRESS, "progress"_cs}};
131134

135+
void ErrorCatalog::initReporter(ErrorReporter &reporter) {
136+
// by default, ignore warnings about branch hints -- user can turn them
137+
// on with --Wwarn=branch
138+
reporter.setDiagnosticAction("branch"_cs, DiagnosticAction::Ignore);
139+
}
140+
132141
} // namespace P4

lib/error_catalog.h

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace P4 {
2828

2929
using MessageType = ErrorMessage::MessageType;
3030

31+
class ErrorReporter;
32+
3133
/// enumerate supported errors
3234
/// It is a class and not an enum class because in C++11 you can't extend an enum class
3335
class ErrorType {
@@ -85,6 +87,7 @@ class ErrorType {
8587
static const int WARN_MULTI_HDR_EXTRACT; // same header may be extracted more than once
8688
static const int WARN_EXPRESSION; // expression related warnings
8789
static const int WARN_DUPLICATE; // duplicate objects
90+
static const int WARN_BRANCH_HINT; // branch frequency/likely hints
8891
// Backends should extend this class with additional warnings in the range 1500-2141.
8992
static const int WARN_MIN_BACKEND = 1500; // first allowed backend warning code
9093
static const int WARN_MAX = 2141; // last allowed warning code
@@ -155,6 +158,8 @@ class ErrorCatalog {
155158
return error;
156159
}
157160

161+
void initReporter(ErrorReporter &reporter);
162+
158163
private:
159164
ErrorCatalog() {}
160165

lib/error_reporter.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class ErrorReporter {
9191
defaultInfoDiagnosticAction(DiagnosticAction::Info),
9292
defaultWarningDiagnosticAction(DiagnosticAction::Warn) {
9393
outputstream = &std::cerr;
94+
ErrorCatalog::getCatalog().initReporter(*this);
9495
}
9596
virtual ~ErrorReporter() = default;
9697

testdata/p4_16_samples/annotation-likely.p4

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <core.p4>
22

3+
@command_line("--Wwarn=branch")
4+
35
struct Headers {
46
bit<8> a;
57
bit<8> b;

testdata/p4_16_samples_outputs/annotation-likely-first.p4

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <core.p4>
22

3-
struct Headers {
3+
@command_line("--Wwarn=branch") struct Headers {
44
bit<8> a;
55
bit<8> b;
66
}

testdata/p4_16_samples_outputs/annotation-likely-frontend.p4

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <core.p4>
22

3-
struct Headers {
3+
@command_line("--Wwarn=branch") struct Headers {
44
bit<8> a;
55
bit<8> b;
66
}

testdata/p4_16_samples_outputs/annotation-likely-midend.p4

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#include <core.p4>
22

3-
struct Headers {
3+
@command_line("--Wwarn=branch") struct Headers {
44
bit<8> a;
55
bit<8> b;
66
}
77

88
control ingress(inout Headers h) {
9-
@hidden action annotationlikely11() {
9+
@hidden action annotationlikely13() {
1010
h.a = 8w0;
1111
h.b = 8w0;
1212
}
13-
@hidden table tbl_annotationlikely11 {
13+
@hidden table tbl_annotationlikely13 {
1414
actions = {
15-
annotationlikely11();
15+
annotationlikely13();
1616
}
17-
const default_action = annotationlikely11();
17+
const default_action = annotationlikely13();
1818
}
1919
apply {
20-
tbl_annotationlikely11.apply();
20+
tbl_annotationlikely13.apply();
2121
}
2222
}
2323

testdata/p4_16_samples_outputs/annotation-likely.p4

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <core.p4>
22

3-
struct Headers {
3+
@command_line("--Wwarn=branch") struct Headers {
44
bit<8> a;
55
bit<8> b;
66
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
annotation-likely.p4(13): [--Wwarn=ignore] warning: ignoring @unlikely on always taken statement
1+
annotation-likely.p4(15): [--Wwarn=branch] warning: ignoring @unlikely on always taken statement
22
if (true) @unlikely {
33
^
4-
annotation-likely.p4(16): [--Wwarn=ignore] warning: ignoring @likely on never taken statement
4+
annotation-likely.p4(18): [--Wwarn=branch] warning: ignoring @likely on never taken statement
55
if (h.a != h.a) @likely {
66
^

0 commit comments

Comments
 (0)