P4C
The P4 Compiler
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
instruction.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_INSTRUCTION_H_
19#define BACKENDS_TOFINO_BF_ASM_INSTRUCTION_H_
20
21#include <functional>
22
23#include "backends/tofino/bf-asm/config.h"
24#include "backends/tofino/bf-asm/tables.h"
25
26struct Instruction : public IHasDbPrint {
27 int lineno;
28 int slot;
29 explicit Instruction(int l) : lineno(l), slot(-1) {}
30 virtual ~Instruction() {}
31 virtual Instruction *pass1(Table *, Table::Actions::Action *) = 0;
32 virtual std::string name() = 0;
33 virtual void pass2(Table *, Table::Actions::Action *) = 0;
34 virtual void dbprint(std::ostream &) const = 0;
35 virtual bool equiv(Instruction *a) = 0;
36 bool equiv(const std::unique_ptr<Instruction> &a) { return equiv(a.get()); }
37 virtual bool salu_output() const { return false; }
38 virtual bool salu_alu() const { return false; }
39 virtual bool phvRead(std::function<void(const Phv::Slice &sl)>) = 0;
40 bool phvRead() {
41 return phvRead([](const Phv::Slice &sl) {});
42 }
43#define VIRTUAL_TARGET_METHODS(TARGET) \
44 virtual void write_regs(Target::TARGET::mau_regs &, Table *, Table::Actions::Action *) = 0;
45 FOR_ALL_REGISTER_SETS(VIRTUAL_TARGET_METHODS)
46#undef VIRTUAL_TARGET_METHODS
47#define DECLARE_FORWARD_VIRTUAL_INSTRUCTION_WRITE_REGS(TARGET) \
48 void write_regs(Target::TARGET::mau_regs &regs, Table *tbl, Table::Actions::Action *act) \
49 override;
50 static Instruction *decode(Table *, const Table::Actions::Action *, const VECTOR(value_t) &);
51
52 enum instruction_set_t { VLIW_ALU = 0, STATEFUL_ALU = 1, NUM_SETS = 2 };
53 struct Decode {
54 static std::multimap<std::string, Decode *> opcode[NUM_SETS];
55 bool type_suffix;
56 unsigned targets;
57 explicit Decode(const char *name, int set = VLIW_ALU, bool ts = false);
58 Decode(const char *name, target_t target, int set = VLIW_ALU, bool ts = false);
59 Decode(const char *name, std::set<target_t> target, int set = VLIW_ALU, bool ts = false);
60 const Decode &alias(const char *name, int set = VLIW_ALU, bool ts = false) {
61 opcode[set].emplace(name, this);
62 return *this;
63 }
64 virtual Instruction *decode(Table *tbl, const Table::Actions::Action *act,
65 const VECTOR(value_t) & op) const = 0;
66 };
67};
68
69namespace VLIW {
70std::unique_ptr<Instruction> genNoopFill(Table *tbl, Table::Actions::Action *act, const char *op,
71 int slot);
72}
73
74#endif /* BACKENDS_TOFINO_BF_ASM_INSTRUCTION_H_ */
Definition stringify.h:33
Definition bf-asm/phv.h:83
Definition tables.h:98
Definition tables.h:538
Definition asm-types.h:114