• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef COMPILER_OPTIMIZER_OPTIMIZATIONS_MEMORY_COALESCING_H_
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_MEMORY_COALESCING_H_
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/pass.h"
21 #include "compiler_options.h"
22 
23 namespace panda::compiler {
24 class MemoryCoalescing : public Optimization {
25 public:
26     bool RunImpl() override;
27 
IsEnable()28     bool IsEnable() const override
29     {
30         return options.IsCompilerMemoryCoalescing();
31     }
32 
GetPassName()33     const char *GetPassName() const override
34     {
35         return "MemoryCoalescing";
36     }
37 
38     /**
39      * Types of memory accesses that can be coalesced
40      */
AcceptedType(DataType::Type type)41     static bool AcceptedType(DataType::Type type)
42     {
43         switch (type) {
44             case DataType::UINT32:
45             case DataType::INT32:
46             case DataType::UINT64:
47             case DataType::INT64:
48             case DataType::FLOAT32:
49             case DataType::FLOAT64:
50                 return true;
51             case DataType::REFERENCE:
52                 return options.IsCompilerMemoryCoalescingObjects();
53             default:
54                 return false;
55         }
56     }
57 
58     NO_MOVE_SEMANTIC(MemoryCoalescing);
59     NO_COPY_SEMANTIC(MemoryCoalescing);
60     ~MemoryCoalescing() override = default;
61 };
62 }  // namespace panda::compiler
63 
64 #endif  //  COMPILER_OPTIMIZER_OPTIMIZATIONS_MEMORY_COALESCING_H_
65