8000 Switch compilation from C++17 to C++20. by fruffy · Pull Request #4347 · p4lang/p4c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Switch compilation from C++17 to C++20. #4347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ common --enable_workspace
# Enable once #5066 is resolved.
common --noenable_bzlmod

# Use C++17.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
# Use C++20.
build --cxxopt=-std=c++20
build --host_cxxopt=-std=c++20

# Force the use of Clang for all builds.
build --action_env=CC=clang
Expand Down
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ IncludeBlocks: Regroup
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Right
Standard: c++17
Standard: c++20
IncludeCategories:
# Matches common headers first and sorts them before project includes
- Regex: '^<.+/.*\.h>'
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ endif()

project (P4C)

# set (CMAKE_CXX_EXTENSIONS OFF) # prefer using -std=c++17 rather than -std=gnu++17
set (CMAKE_CXX_STANDARD 17)
# set (CMAKE_CXX_EXTENSIONS OFF) # prefer using -std=c++20 rather than -std=gnu++20
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
Expand Down
8000
7 changes: 1 addition & 6 deletions backends/tofino/bf-asm/asm-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ inline bool operator==(int a, const struct value_t &b) { return b.type == tINT &

inline const char *value_desc(const value_t &v) { return value_desc(&v); }

template <class A, class B>
inline bool operator!=(A a, B b) {
return !(a == b);
}

inline value_t &VECTOR(value_t)::operator[](int i) const {
assert(i >= 0 && i < size);
return data[i];
Expand Down Expand Up @@ -410,7 +405,7 @@ class MapIterChecked {
iter(MapIterChecked *s, pair_t *p_) : self(s), p(p_) { check(); }
pair_t &operator*() const { return *p; }
pair_t *operator->() const { return p; }
bool operator==(iter &a) const { return p == a.p; }
bool operator==(const iter &a) const { return p == a.p; }
iter &operator++() {
p++;
check();
Expand Down
5 changes: 3 additions & 2 deletions backends/tofino/bf-asm/atcam_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ void AlgTcamMatchTable::write_regs_vt(REGS &regs) {
}
}

std::unique_ptr<json::vector> AlgTcamMatchTable::gen_memory_resource_allocation_tbl_cfg() const {
std::unique_ptr<json::vector> AlgTcamMatchTable::gen_memory_resource_allocation_tbl_cfg_no_input()
const {
if (col_priority_way.size() == 0)
error(lineno, "No column priority determined for table %s", name());
unsigned fmt_width = format ? (format->size + 127) / 128 : 0;
Expand Down Expand Up @@ -427,7 +428,7 @@ void AlgTcamMatchTable::gen_unit_cfg(json::vector &units, int size) const {
// Assuming atcam next hit table cannot be multiple tables
stage_tbl["default_next_table"] =
!hit_next.empty() ? hit_next[0].next_table_id() : Target::END_OF_PIPE();
stage_tbl["memory_resource_allocation"] = gen_memory_resource_allocation_tbl_cfg();
stage_tbl["memory_resource_allocation"] = gen_memory_resource_allocation_tbl_cfg_no_input();
// Hash functions not necessary currently for ATCAM matches, as the result comes from
// the partition_field_name
stage_tbl["hash_functions"] = json::vector();
Expand Down
6 changes: 3 additions & 3 deletions backends/tofino/bf-asm/deparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
unsigned Deparser::unique_field_list_handle;
Deparser Deparser::singleton_object;

Deparser::Deparser() : Section("deparser") {}
Deparser::~Deparser() {}

struct Deparser::FDEntry {
struct Base {
virtual ~Base() {}
Expand Down Expand Up @@ -202,6 +199,9 @@ struct Deparser::FDEntry {
void check(bitvec &phv_use) { what->check(phv_use); }
};

Deparser::Deparser() : Section("deparser") {}
Deparser::~Deparser() = default;

struct Deparser::Intrinsic::Type {
target_t target;
gress_t gress;
Expand Down
3 changes: 2 additions & 1 deletion backends/tofino/bf-asm/exact_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ void ExactMatchTable::gen_tbl_cfg(json::vector &out) const {
unsigned ram_depth = way.rams.at(0).isLamb() ? LAMB_DEPTH : SRAM_DEPTH;
way_tbl["size"] = way.rams.size() / fmt_width * format->groups() * ram_depth;
add_pack_format(way_tbl, format.get(), false);
way_tbl["memory_resource_allocation"] = gen_memory_resource_allocation_tbl_cfg(way);
way_tbl["memory_resource_allocation"] =
gen_memory_resource_allocation_tbl_cfg_with_way(way);
way_stage_tables.push_back(std::move(way_tbl));
}
}
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-asm/gtest/gtestasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GTestOptions : public Util::Options {
},
"[Compiler debugging] Adjust logging level per file (see below)");
}
std::vector<const char *> *process(int argc, char *const argv[]) {
std::vector<const char *> *process(int argc, char *const argv[]) override {
auto remainingOptions = Util::Options::process(argc, argv);
return remainingOptions;
}
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-asm/input_xbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class InputXbar {
: outer(o), outer_end(oend), inner_valid(false) {
mk_inner_valid();
}
bool operator==(const all_iter &a) {
bool operator==(const all_iter &a) const {
if (outer != a.outer) return false;
if (inner_valid != a.inner_valid) return false;
return inner_valid ? inner == a.inner : true;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-asm/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class vector : public obj, public vector_base {
}
};

typedef ordered_map<obj *, std::unique_ptr<obj>, obj::ptrless> map_base;
using map_base = ordered_map<obj *, std::unique_ptr<obj>, obj::ptrless>;
class map : public obj, public map_base {
public:
map() {}
Expand Down
8 changes: 2 additions & 6 deletions backends/tofino/bf-asm/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
#ifndef BACKENDS_TOFINO_BF_ASM_MISC_H_
#define BACKENDS_TOFINO_BF_ASM_MISC_H_

#include <iomanip>
#include <limits>
#include <memory>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>

#include <boost/numeric/conversion/converter.hpp>

#include "asm-types.h"
#include "backends/tofino/bf-asm/json.h"

Expand Down Expand Up @@ -152,8 +148,8 @@ bool check_range_strict(value_t value, IntType lo, IntType hi) {

/* -- Handle different ranges (signed, unsigned, different size) of the value_t::i
* and IntType. */
typedef boost::numeric::converter<IntType, decltype(value_t::i)> Converter;
if (Converter::out_of_range(value.i)) {

if (!std::in_range<IntType>(value.i)) {
format_error_message(value, lo, hi);
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion backends/tofino/bf-asm/proxy_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ void ProxyHashMatchTable::gen_tbl_cfg(json::vector &out) const {
BUG_CHECK(fmt_width, "width of format is 0");
way_tbl["size"] = way.rams.size() / fmt_width * format->groups() * 1024;
add_pack_format(way_tbl, format.get(), false);
way_tbl["memory_resource_allocation"] = gen_memory_resource_allocation_tbl_cfg(way);
way_tbl["memory_resource_allocation"] =
gen_memory_resource_allocation_tbl_cfg_with_way(way);
way_stage_tables.push_back(std::move(way_tbl));
}
}
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-asm/sram_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool SRamMatchTable::verify_match_key() {
return error_count == 0;
}

std::unique_ptr<json::map> SRamMatchTable::gen_memory_resource_allocation_tbl_cfg(
std::unique_ptr<json::map> SRamMatchTable::gen_memory_resource_allocation_tbl_cfg_with_way(
const Way &way) const {
json::map mra;
unsigned vpn_ctr = 0;
Expand Down
5 changes: 3 additions & 2 deletions backends/tofino/bf-asm/tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "action_bus.h"
#include "backends/tofino/bf-asm/config.h"
#include "backends/tofino/bf-asm/json.h"
#include "backends/tofino/bf-asm/stage.h"
#include "input_xbar.h"
#include "instruction.h"
Expand Down Expand Up @@ -2304,7 +2305,7 @@ void Table::Actions::Action::check_and_add_resource(json::vector &resources,
// present in the resource array
bool found = false;
for (auto &r : resources) {
if (resource == r->to<json::map>()) {
if (resource == r->to<json::obj>()) {
found = true;
break;
}
Expand Down Expand Up @@ -2556,7 +2557,7 @@ void Table::Actions::add_action_format(const Table *table, json::map &tbl) const
json::string name = a.first;
int lo = remove_name_tail_range(name);
json::string immed_name = a.second.name;
if (immed_name != "immediate") continue; // output only immediate fields
if (immed_name != json::string("immediate")) continue; // output only immediate fields
if (!(act.has_param(name) || a.second.is_constant))
continue; // and fields that are parameters or constants
json::map action_format_per_action_imm_field;
Expand Down
12 changes: 6 additions & 6 deletions backends/tofino/bf-asm/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ class Table {
operator bool() const { return all && all->count(name) > 0; }
operator Table *() const { return ::get(all, name); }
Table *operator->() const { return ::get(all, name); }
bool set() const { return lineno >= 0; }
bool operator==(const Table *t) const { return name == t->name_; }
bool operator==(const char *t) const { return name == t; }
bool operator==(const std::string &t) const { return name == t; }
[[nodiscard]] bool set() const { return lineno >= 0; }
bool operator==(const Table &t) const { return name == t.name_; }
bool operator!=(const Table &t) const { return name != t.name_; }
bool operator==(const Ref &a) const { return name == a.name; }
bool operator!=(const Ref &a) const { return name != a.name; }
bool operator<(const Ref &a) const { return name < a.name; }
bool check() const {
if (set() && !*this) error(lineno, "No table named %s", name.c_str());
Expand Down Expand Up @@ -1320,7 +1320,7 @@ DECLARE_ABSTRACT_TABLE_TYPE(SRamMatchTable, MatchTable, // exact, atcam,
void add_field_to_pack_format(json::vector &field_list, unsigned basebit, std::string name,
const Table::Format::Field &field,
const Table::Actions::Action *act) const override;
std::unique_ptr<json::map> gen_memory_resource_allocation_tbl_cfg(const Way &) const;
std::unique_ptr<json::map> gen_memory_resource_allocation_tbl_cfg_with_way(const Way &) const;
Actions *get_actions() const override {
return actions ? actions.get() : (action ? action->actions.get() : nullptr);
}
Expand Down Expand Up @@ -1412,7 +1412,7 @@ DECLARE_TABLE_TYPE(
void verify_format(Target::Tofino) override;
void verify_entry_priority(); void setup_column_priority(); void find_tcam_match();
void gen_unit_cfg(json::vector &units, int size) const;
std::unique_ptr<json::vector> gen_memory_resource_allocation_tbl_cfg() const;
std::unique_ptr<json::vector> gen_memory_resource_allocation_tbl_cfg_no_input() const;
void setup_nibble_mask(Table::Format::Field *match, int group,
std::map<int, match_element> &elems, bitvec &mask);
std::string get_match_mode(const Phv::Ref &pref, int offset) const override;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/common/extract_maupipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SetupActionProperties : public MauModifier {
if (!path) BUG("Default action path %s cannot be found", default_action);
auto actName = refMap->getDeclaration(path->path, true)->externalName();

if (actName == act->name) {
if (act->name == actName) {
is_the_default_action = true;
if (has_constant_default_action) {
can_be_default_action = true; // this is the constant default action
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/mau/asm_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ void MauAsmOutput::emit_static_entries(std::ostream &, indent_t indent, const IR
auto method = method_call->method->to<IR::PathExpression>();
auto path = method->path;
for (auto action : Values(tbl->actions)) {
if (action->name.name == path->name) {
if (path->name == action->name.name) {
context_json_entries << indent << "action_handle: 0x" << hex(action->handle)
<< std::endl;
break;
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/mau/gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const IR::Expression *CanonGatewayExpr::postorder(IR::Operation::Relation *e) {
Pattern::Match<IR::Expression> e1, e2;
Pattern::Match<IR::Constant> k1, k2;
int width = safe_width_bits(e->left->type);
if (((e1 & k1) == k2).match(e) || ((e1 & k1) != k2).match(e)) {
if ((k2 == (e1 & k1)).match(e) || (k2 != (e1 & k1)).match(e)) {
BUG_CHECK(!e1->is<IR::Constant>(), "constant folding failed");
// always true or always false
if ((abs(k1->value) & abs(k2->value)) != abs(k2->value)) {
Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/mau/instruction_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ const IR::Node *RemoveUnnecessaryActionArgSlice::preorder(IR::Slice *sl) {
// Simplify "actionArg != 0 ? f0 : f1" to "actionArg ? f0 : f1"
const IR::Node *SimplifyConditionalActionArg::postorder(IR::Mux *mux) {
Pattern::Match<IR::MAU::ActionArg> aa;
if ((0 != aa).match(mux->e0)) mux->e0 = aa;
if ((aa != 0).match(mux->e0)) mux->e0 = aa;
return mux;
}

Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/mau/stateful_alu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ bool CreateSaluInstruction::preorder(const IR::Operation::Relation *rel, cstring
if (etype == IF) {
Pattern::Match<IR::Expression> e1, e2;
Pattern::Match<IR::Constant> k;
if (Device::statefulAluSpec().CmpMask && ((e1 & k) == e2).match(rel) && !k->fitsUint() &&
if (Device::statefulAluSpec().CmpMask && (e2 == (e1 & k)).match(rel) && !k->fitsUint() &&
!k->fitsInt()) {
// FIXME -- wide "neq" can be done with tmatch too?
opcode = "tmatch"_cs;
Expand Down
6 changes: 3 additions & 3 deletions backends/tofino/bf-p4c/midend/check_unsupported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ void CheckUnsupported::postorder(const IR::P4Table *const table_ptr) {
size_t total_TCAM_key_bits = 0u;

for (const auto *const key_element_ptr : key_ptr->keyElements) {
if ("lpm" == key_element_ptr->matchType->path->name) {
if (key_element_ptr->matchType->path->name == "lpm") {
++lpm_key_count;
}
if ("range" == key_element_ptr->matchType->path->name) {
if (key_element_ptr->matchType->path->name == "range") {
++range_key_count;
}
if ("ternary" == key_element_ptr->matchType->path->name) {
if (key_element_ptr->matchType->path->name == "ternary") {
++ternary_key_count;
const size_t size = table_ptr->getSizeProperty()->asUint64(),
this_TCAM_key_bits =
Expand Down
4 changes: 2 additions & 2 deletions backends/tofino/bf-p4c/parde/extract_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct GetHeaderStackIndex : public Inspector {
BUG_CHECK(hdr, "%1%: not a header reference in extract", statement);

if (!hdr->is<IR::HeaderStackItemRef>()) {
if (header == hdr->to<IR::ConcreteHeaderRef>()->ref->name) {
if (hdr->to<IR::ConcreteHeaderRef>()->ref->name == header) {
rv = 0;
}
}
Expand Down Expand Up @@ -553,7 +553,7 @@ const IR::BFN::Parser *GetBackendParser::createBackendParser() {
while (bitr != binfo->end()) {
auto b = *bitr;
auto bparser = b.first->to<IR::P4Parser>();
if (bparser && (bparser->name.originalName == parser->name) &&
if (bparser && (parser->name.name == bparser->name.originalName) &&
(b.second.gress == parser->thread)) {
if (!b.second.parser_instance_name.isNullOrEmpty())
multiParserName = b.second.parser_instance_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,15 @@ bool HoistCommonMatchOperations::can_hoist(const IR::BFN::LoweredParserMatch *a,

auto extactors_required = extractors_used(a);
auto b_extractors = extractors_used(b);
extactors_required = std::accumulate(b_extractors.begin(), b_extractors.end(),
extactors_required, [](auto &map, const auto &pair) {
map[pair.first] += pair.second;
return map;
});
// then default-constructs value (0 for uint), then += works.
extactors_required =
std::accumulate(b_extractors.begin(), b_extractors.end(), std::move(extactors_required),
[](std::map<unsigned int, unsigned int> current_map,
const std::pair<const unsigned int, unsigned int> &pair) {
current_map[pair.first] += pair.second;
return current_map;
});

for (const auto &[size, max] : Device::pardeSpec().extractorSpec())
if (extactors_required[size] > max) return false;

Expand Down
2 changes: 1 addition & 1 deletion backends/tofino/bf-p4c/phv/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Allocation {
ConditionalConstraintData()
: bitPosition(-1), rotationAllowed(false), container(std::nullopt) {}

bool operator==(ConditionalConstraintData &other) const {
bool operator==(const ConditionalConstraintData &other) const {
return bitPosition == other.bitPosition && rotationAllowed == other.rotationAllowed &&
container == other.container;
}
Expand Down
3 changes: 0 additions & 3 deletions backends/tofino/bf-p4c/phv/v2/utils_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ class ScoreContext {
/// search time related parameters.
const SearchConfig *search_config_i = new SearchConfig();

/// tracer will try to log steps of every allocation.
std::ostream *tracer = nullptr;

private:
static constexpr const char *tab_table[] = {
"", " ", " ", " ", " ", " ", " ", " ", " ",
Expand Down
6 changes: 3 additions & 3 deletions bazel/example/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ common --enable_workspace
# Enable once #5066 is resolved.
common --noenable_bzlmod

# Use C++17.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
# Use C++20.
build --cxxopt=-std=c++20
build --host_cxxopt=-std=c++20

# Force the use of Clang for all builds.
build --action_env=CC=clang
Expand Down
2 changes: 1 addition & 1 deletion docs/C++.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C++ (following the C++ 11 standard) is the implementation language for
C++ (following the C++ 20 standard) is the implementation language for
the compiler. This file contains notes on how we use C++ and conventions
we use for things that C++ does not handle well.

Expand Down
16 changes: 16 additions & 0 deletions ir/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ class Pattern {
Pattern operator||(const Pattern &r) const {
return Pattern(new Binary<IR::LOr>(pattern, r.pattern));
}
/// We use these templates to deal with amgigous overloads introduced by C++20.
/// https://en.cppreference.com/w/cpp/language/default_comparisons
// TODO: Ideally, we would fix these ambiguous overloads by making the Pattern class explicit in
// its initialization but that is a breaking change.
template <class T>
Pattern operator==(Match<T> &m) const {
return *this == Pattern(m);
}
template <class T>
Pattern operator!=(Match<T> &m) const {
return *this != Pattern(m);
}
template <class T>
Pattern operator==(const Match<T> &m) const {
return *this == Pattern(m);
}

bool match(const IR::Node *n) { return pattern->match(n); }
};
Expand Down
Loading
0