"fmoe/vscode:/vscode.git/clone" did not exist on "5f8e399905ee536537caa0c4b6874cef78d5641e"
instruction.hpp 2.31 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
#ifndef MIGRAPH_GUARD_MIGRAPHLIB_INSTRUCTION_HPP
#define MIGRAPH_GUARD_MIGRAPHLIB_INSTRUCTION_HPP

#include <migraph/literal.hpp>
#include <migraph/shape.hpp>
#include <migraph/instruction_ref.hpp>
Paul's avatar
Paul committed
7
#include <migraph/operation.hpp>
Paul's avatar
Paul committed
8
#include <string>
Paul's avatar
Paul committed
9
#include <utility>
Paul's avatar
Paul committed
10

Paul's avatar
Paul committed
11
namespace migraph {
Paul's avatar
Paul committed
12

Paul's avatar
Paul committed
13
shape compute_shape(const operation& op, const std::vector<instruction_ref>& args);
Paul's avatar
Paul committed
14

Paul's avatar
Paul committed
15
16
struct instruction
{
Paul's avatar
Paul committed
17
18
    instruction() {}

Paul's avatar
Paul committed
19
    instruction(operation o, shape r, std::vector<instruction_ref> args);
Paul's avatar
Paul committed
20

Paul's avatar
Paul committed
21
    instruction(literal l);
Paul's avatar
Paul committed
22

Paul's avatar
Paul committed
23
    void replace(const shape& r);
Paul's avatar
Paul committed
24

Paul's avatar
Paul committed
25
    void recompute_shape();
Paul's avatar
Paul committed
26

Paul's avatar
Paul committed
27
    void clear_arguments();
Paul's avatar
Paul committed
28

Paul's avatar
Paul committed
29
    friend bool operator==(const instruction& i, instruction_ref ref);
Paul's avatar
Paul committed
30

Paul's avatar
Paul committed
31
    bool valid(instruction_ref start) const;
Paul's avatar
Paul committed
32

Paul's avatar
Paul committed
33
    bool valid() const;
Paul's avatar
Paul committed
34

Paul's avatar
Paul committed
35
36
    shape get_shape() const;
    const literal& get_literal() const;
37

Paul's avatar
Paul committed
38
    const operation& get_operator() const;
Paul's avatar
Paul committed
39

Paul's avatar
Paul committed
40
    std::string name() const;
Paul's avatar
Paul committed
41

Paul's avatar
Paul committed
42
    const std::vector<instruction_ref>& inputs() const;
Paul's avatar
Paul committed
43

Paul's avatar
Paul committed
44
    const std::vector<instruction_ref>& outputs() const;
Paul's avatar
Paul committed
45

Paul's avatar
Paul committed
46
    friend bool operator==(instruction_ref ref, const instruction& i);
Paul's avatar
Paul committed
47

Paul's avatar
Paul committed
48
    friend bool operator!=(const instruction& i, instruction_ref ref);
Paul's avatar
Paul committed
49

Paul's avatar
Paul committed
50
    friend bool operator!=(instruction_ref ref, const instruction& i);
Paul's avatar
Paul committed
51

Paul's avatar
Paul committed
52
    void add_output(instruction_ref ins);
Paul's avatar
Paul committed
53

Paul's avatar
Paul committed
54
    template <class T>
Paul's avatar
Paul committed
55
    void remove_output(const T& ins);
Paul's avatar
Paul committed
56

Paul's avatar
Paul committed
57
    static void backreference(instruction_ref ref);
Paul's avatar
Paul committed
58

Paul's avatar
Paul committed
59
    static void replace_argument(instruction_ref ins, instruction_ref old, instruction_ref new_ins);
Paul's avatar
Paul committed
60

Paul's avatar
Paul committed
61
    static void
Paul's avatar
Paul committed
62
    replace(instruction_ref ins, operation o, const shape& r, std::vector<instruction_ref> args);
Paul's avatar
Paul committed
63
64

    private:
Paul's avatar
Paul committed
65
    // internal
Paul's avatar
Paul committed
66
    void replace(operation o, const shape& r, std::vector<instruction_ref> args);
Paul's avatar
Paul committed
67

Paul's avatar
Paul committed
68
    // internal
Paul's avatar
Paul committed
69
    void replace(std::vector<instruction_ref> args);
Paul's avatar
Paul committed
70

Paul's avatar
Paul committed
71
    // internal
Paul's avatar
Paul committed
72
    void replace_argument(instruction_ref old, instruction_ref new_ins);
Paul's avatar
Paul committed
73

Paul's avatar
Paul committed
74
    operation op;
Paul's avatar
Paul committed
75
    shape result;
Paul's avatar
Paul committed
76
    std::vector<instruction_ref> output;
Paul's avatar
Paul committed
77
    std::vector<instruction_ref> arguments;
Paul's avatar
Paul committed
78
    literal lit;
Paul's avatar
Paul committed
79
80
};

Paul's avatar
Paul committed
81
} // namespace migraph
Paul's avatar
Paul committed
82

Paul's avatar
Paul committed
83
84
85
namespace std {
template <>
struct hash<migraph::instruction_ref>
86
{
Paul's avatar
Paul committed
87
88
89
    using argument_type = migraph::instruction_ref;
    using result_type   = std::size_t;
    result_type operator()(const argument_type& x) const noexcept
90
    {
Paul's avatar
Paul committed
91
92
93
        return std::hash<migraph::instruction*>{}(&*x);
    }
};
94
95
} // namespace std

Paul's avatar
Paul committed
96
#endif