• 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_IR_SPILL_FILL_DATA_H
17 #define COMPILER_OPTIMIZER_IR_SPILL_FILL_DATA_H
18 
19 #include "datatype.h"
20 #include "constants.h"
21 #include "locations.h"
22 
23 namespace panda::compiler {
24 
25 using LocationType = Location::Kind;
26 
27 class SpillFillData {
28 public:
29     SpillFillData() = default;
SpillFillData(LocationType src_type,LocationType dst_type,unsigned src_val,unsigned dst_val,DataType::Type tp)30     SpillFillData(LocationType src_type, LocationType dst_type, unsigned src_val, unsigned dst_val, DataType::Type tp)
31         : src_(src_type, src_val), dst_(dst_type, dst_val), type_(tp)
32     {
33     }
SpillFillData(Location src,Location dst,DataType::Type type)34     SpillFillData(Location src, Location dst, DataType::Type type) : src_(src), dst_(dst), type_(type) {}
35 
SrcType()36     LocationType SrcType() const
37     {
38         return src_.GetKind();
39     }
DstType()40     LocationType DstType() const
41     {
42         return dst_.GetKind();
43     }
SrcValue()44     auto SrcValue() const
45     {
46         return src_.GetValue();
47     }
DstValue()48     auto DstValue() const
49     {
50         return dst_.GetValue();
51     }
SetSrc(Location loc)52     void SetSrc(Location loc)
53     {
54         src_ = loc;
55     }
SetDst(Location loc)56     void SetDst(Location loc)
57     {
58         dst_ = loc;
59     }
GetSrc()60     Location GetSrc() const
61     {
62         return src_;
63     }
GetDst()64     Location GetDst() const
65     {
66         return dst_;
67     }
GetType()68     DataType::Type GetType() const
69     {
70         return type_;
71     }
GetCommonType()72     DataType::Type GetCommonType() const
73     {
74         return DataType::GetCommonType(type_);
75     }
SetType(DataType::Type type)76     void SetType(DataType::Type type)
77     {
78         type_ = type;
79     }
80 
Dump(std::ostream & stm,Arch arch)81     void Dump(std::ostream &stm, Arch arch) const
82     {
83         GetSrc().Dump(stm, arch);
84         stm << " -> ";
85         GetDst().Dump(stm, arch);
86         stm << " [" << ToString(GetType()) << "]";
87     }
88 
89 private:
90     Location src_;
91     Location dst_;
92     DataType::Type type_ {DataType::NO_TYPE};
93 };
94 
95 static_assert(sizeof(SpillFillData) <= sizeof(uint64_t));
96 
97 namespace sf_data {
98 
ToString(const SpillFillData & sf,Arch arch)99 inline auto ToString(const SpillFillData &sf, Arch arch)
100 {
101     std::stringstream ss;
102     sf.Dump(ss, arch);
103     return ss.str();
104 }
105 }  // namespace sf_data
106 
107 }  // namespace panda::compiler
108 
109 #endif  // COMPILER_OPTIMIZER_IR_SPILL_FILL_DATA_H
110