19#ifndef BF_P4C_PHV_SOLVER_ACTION_CONSTRAINT_SOLVER_H_
20#define BF_P4C_PHV_SOLVER_ACTION_CONSTRAINT_SOLVER_H_
25#include "backends/tofino/bf-p4c/ir/bitrange.h"
26#include "backends/tofino/bf-p4c/phv/solver/symbolic_bitvec.h"
27#include "lib/bitvec.h"
28#include "lib/cstring.h"
29#include "lib/ordered_map.h"
47 virtual cstring name()
const = 0;
48 virtual cstring to_cstring()
const = 0;
64 : dest(dest), src1(src1), left_rotate(left_rotate), mask(mask), src2(src2) {}
65 cstring name()
const override {
return "deposit-field"_cs; };
66 cstring to_cstring()
const override;
78 : dest(dest), src1(src1), src2(src2), mask(mask) {}
79 cstring name()
const override {
return "bitmasked-set"_cs; };
80 cstring to_cstring()
const override;
95 : dest(dest), src1(src1), shift1(shift1), src2(src2), shift2(shift2), mask(mask) {}
96 cstring name()
const override {
return "byte-rotate-merge"_cs; };
97 cstring to_cstring()
const override;
108 cstring name()
const override {
return "set"_cs; };
109 cstring to_cstring()
const override;
112enum class ErrorCode {
115 too_many_container_sources = 3,
116 too_many_unaligned_sources = 4,
117 invalid_for_deposit_field = 5,
118 smt_sovler_unknown = 6,
119 deposit_src2_must_be_dest = 7,
120 non_rot_aligned_and_non_byte_shiftable = 8,
121 invalid_whole_container_write = 9,
122 dark_container_ad_or_const_source = 10,
141 std::optional<Error> err;
142 std::vector<const Instruction *> instructions;
146 explicit Result(
const std::vector<const Instruction *> &instructions)
147 : instructions(instructions) {}
148 bool ok() {
return !err; }
156 bool operator==(
const Operand &b)
const {
157 return is_ad_or_const == b.is_ad_or_const && container == b.container && range == b.range;
159 bool operator!=(
const Operand &b)
const {
return !(*
this == b); }
161std::ostream &operator<<(std::ostream &s,
const Operand &);
172std::ostream &operator<<(std::ostream &s,
const Assign &);
173std::ostream &operator<<(std::ostream &s,
const std::vector<Assign> &);
186 bool enable_bitmasked_set_i =
true;
236 enable_bitmasked_set_i =
true;
262 std::optional<Error> dest_meet_expectation(
const ContainerID dest,
263 const std::vector<Assign> &src1,
264 const std::vector<Assign> &src2,
272 const std::vector<Assign> &src1,
273 const std::vector<Assign> &src2)
const;
276 Result run_deposit_field_solver(
const ContainerID dest,
const std::vector<Assign> &src1,
277 const std::vector<Assign> &src2)
const;
285 const std::vector<Assign> &src1,
286 const std::vector<Assign> &src2)
const;
290 Result run_byte_rotate_merge_solver(
const ContainerID dest,
const std::vector<Assign> &src1,
291 const std::vector<Assign> &src2)
const;
Definition ordered_map.h:32
Definition action_constraint_solver.h:352
Result solve() override
Definition phv/solver/action_constraint_solver.cpp:736
Definition action_constraint_solver.h:341
Result solve() override
solve checks that either
Definition phv/solver/action_constraint_solver.cpp:715
Definition action_constraint_solver.h:259
Result solve() override
return solve result.
Definition phv/solver/action_constraint_solver.cpp:663
ActionSolverBase contains basic methods and states for all solvers.
Definition action_constraint_solver.h:179
virtual void clear()
clear all states and will reset enable_bitmasked_set to true.
Definition action_constraint_solver.h:232
virtual Result solve()=0
return solve result.
Result try_container_set(const ContainerID dest, const RotateClassifiedAssigns &offset_assigns) const
Definition phv/solver/action_constraint_solver.cpp:186
ordered_map< ContainerID, RotateClassifiedAssigns > dest_assigns_i
destination-clustered assignments.
Definition action_constraint_solver.h:182
void enable_bitmasked_set(bool enable)
set true to enable bitmasked_set set, otherwise disable. default: enable.
Definition action_constraint_solver.h:209
std::optional< Error > check_whole_container_set_with_none_source_allocated() const
Definition phv/solver/action_constraint_solver.cpp:215
std::optional< Error > validate_input() const
Definition phv/solver/action_constraint_solver.cpp:273
ordered_map< ContainerID, bitvec > src_unallocated_bits
bits that will be written in this action but their sources have not been allcoated.
Definition action_constraint_solver.h:185
virtual void add_src_unallocated_assign(const ContainerID &c, const le_bitrange &range)
Definition phv/solver/action_constraint_solver.cpp:251
virtual void add_assign(const Operand &dst, Operand src)
add an assignment from the action.
Definition phv/solver/action_constraint_solver.cpp:235
virtual void set_container_spec(ContainerID id, int size, bitvec live)
set_container_spec will update the container spec.
Definition phv/solver/action_constraint_solver.cpp:263
Definition action_constraint_solver.h:71
Definition action_constraint_solver.h:85
Definition action_constraint_solver.h:103
Definition action_constraint_solver.h:56
Definition action_constraint_solver.h:45
Definition symbolic_bitvec.h:60
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
@ Error
Print a warning and continue compilation.
Definition phv/solver/action_constraint_solver.cpp:33
Operand make_ad_or_const_operand()
Constructor helper functions for operand.
Definition phv/solver/action_constraint_solver.cpp:182
std::map< int, std::vector< Assign > > RotateClassifiedAssigns
right-rotate-offset-indexed assignments.
Definition action_constraint_solver.h:176
bitvec live
bits that will have live fieldslices allocated, after action.
Definition action_constraint_solver.h:136
Assign is a set instruction that move operand src bits to dst.
Definition action_constraint_solver.h:168
ContainerSpec container specification.
Definition action_constraint_solver.h:133
Definition common/field_defuse.cpp:590
Error type for all solver.
Definition action_constraint_solver.h:126
Operand represents either a source or a destination of an instruction.
Definition action_constraint_solver.h:152
Result contains either an error or all instructions for an action.
Definition action_constraint_solver.h:140