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() const36 LocationType SrcType() const
37 {
38 return src_.GetKind();
39 }
DstType() const40 LocationType DstType() const
41 {
42 return dst_.GetKind();
43 }
SrcValue() const44 auto SrcValue() const
45 {
46 return src_.GetValue();
47 }
DstValue() const48 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() const60 Location GetSrc() const
61 {
62 return src_;
63 }
GetDst() const64 Location GetDst() const
65 {
66 return dst_;
67 }
GetType() const68 DataType::Type GetType() const
69 {
70 return type_;
71 }
GetCommonType() const72 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) const81 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 #ifndef IR_FOR_LIBARK_DEFECT_SCAN_AUX
96 static_assert(sizeof(SpillFillData) <= sizeof(uint64_t));
97 #endif
98
99 namespace sf_data {
100
ToString(const SpillFillData &sf, Arch arch)101 inline auto ToString(const SpillFillData &sf, Arch arch)
102 {
103 std::stringstream ss;
104 sf.Dump(ss, arch);
105 return ss.str();
106 }
107 } // namespace sf_data
108
109 } // namespace panda::compiler
110
111 #endif // COMPILER_OPTIMIZER_IR_SPILL_FILL_DATA_H
112