1#pragma once
2
3#include <functional>
4#include <string>
5
6namespace taichi::lang {
7
8/**
9 * A unique key of a function.
10 * |func_id| uniquely corresponds to a function template (@ti.func).
11 * |instance_id| is for the template instantiations, i.e., a @ti.func
12 * instantiated multiple times with different ti.template() parameters.
13 * |func_name| is mostly for debugging/visualizing purpose, and doesn't need
14 * to participate in the hash computation.
15 */
16class FunctionKey {
17 public:
18 std::string func_name;
19 int func_id;
20 int instance_id;
21
22 FunctionKey(const std::string &func_name, int func_id, int instance_id);
23
24 bool operator==(const FunctionKey &other_key) const;
25
26 [[nodiscard]] std::string get_full_name() const;
27};
28
29} // namespace taichi::lang
30
31namespace std {
32template <>
33struct hash<taichi::lang::FunctionKey> {
34 std::size_t operator()(const taichi::lang::FunctionKey &key) const noexcept {
35 return key.func_id ^ (key.instance_id << 16);
36 }
37};
38} // namespace std
39