-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform.py
48 lines (36 loc) · 1.17 KB
/
transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Definition of a code transformation that can be applied to functions
for intra-procedural optimizations.
"""
from abc import ABC, abstractmethod
from bril.core.ir import Function
# Name assigned to the dead code elimination transform.
DEAD_CODE_ELIMINATION: str = "dce"
# Name assigned to the global dead code elimination transform.
GLOBAL_DEAD_CODE_ELIMINATION: str = "global-dce"
# Name assigned to the redundant store elimination transform.
REDUNDANT_STORE_ELIMINATION: str = "rse"
# Name assigned to local value numbering.
LOCAL_VALUE_NUMBERING: str = "lvn"
# Whether or not to enable debug mode when running optimizations to display
# verbose information.
ENABLE_OPTIMIZATION_DEBUG_MODE: bool = True
class Transform(ABC):
"""
A transform is any class that implements the `run` method to process
Bril functions.
"""
@abstractmethod
def __init__(self, name: str):
self.name = name
@abstractmethod
def run(self, function: Function):
pass
class Identity(Transform):
"""
Identity transformation is a no op pass.
"""
def __init__(self):
super().__init__("identity")
def run(self, _: Function):
pass