1#pragma once
2
3#include <torch/csrc/jit/ir/ir.h>
4
5namespace torch {
6namespace jit {
7
8// Peephole Optimizes Dict Ops such as len() and __getitem__
9// 1. getitem optimizations
10// Given a function like this:
11// def foo():
12// d = {0 : 1}
13// x = d[0]
14// return x
15// This pass produces (after dead code elimination):
16// def foo(a, b):
17// return 1
18//
19// This optimization can only happen if the dict is not modified
20// and the dict has constant, non overlapping keys.
21//
22// 2. len optimizations
23// Given a function like this:
24// def foo():
25// d = {0 : 1}
26// return len(d)
27// This pass produces (after dead code elimination):
28// def foo():
29// return 1
30//
31// This has the same requirements as the getitem optimizations.
32//
33// Currently this is invoked as part of PeepholeOptimize
34// return true if graph is modified.
35TORCH_API bool PeepholeOptimizeDictIdioms(const std::shared_ptr<Graph>& graph);
36
37} // namespace jit
38} // namespace torch
39