1 //===-- RegisterAliasing.cpp ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "RegisterAliasing.h"
14 llvm::BitVector
getAliasedBits(const llvm::MCRegisterInfo
&RegInfo
,
15 const llvm::BitVector
&SourceBits
) {
16 llvm::BitVector
AliasedBits(RegInfo
.getNumRegs());
17 for (const size_t PhysReg
: SourceBits
.set_bits()) {
18 using RegAliasItr
= llvm::MCRegAliasIterator
;
19 for (auto Itr
= RegAliasItr(PhysReg
, &RegInfo
, true); Itr
.isValid();
21 AliasedBits
.set(*Itr
);
27 RegisterAliasingTracker::RegisterAliasingTracker(
28 const llvm::MCRegisterInfo
&RegInfo
)
29 : SourceBits(RegInfo
.getNumRegs()), AliasedBits(RegInfo
.getNumRegs()),
30 Origins(RegInfo
.getNumRegs()) {}
32 RegisterAliasingTracker::RegisterAliasingTracker(
33 const llvm::MCRegisterInfo
&RegInfo
, const llvm::BitVector
&ReservedReg
,
34 const llvm::MCRegisterClass
&RegClass
)
35 : RegisterAliasingTracker(RegInfo
) {
36 for (llvm::MCPhysReg PhysReg
: RegClass
)
37 if (!ReservedReg
[PhysReg
]) // Removing reserved registers.
38 SourceBits
.set(PhysReg
);
39 FillOriginAndAliasedBits(RegInfo
, SourceBits
);
42 RegisterAliasingTracker::RegisterAliasingTracker(
43 const llvm::MCRegisterInfo
&RegInfo
, const llvm::MCPhysReg PhysReg
)
44 : RegisterAliasingTracker(RegInfo
) {
45 SourceBits
.set(PhysReg
);
46 FillOriginAndAliasedBits(RegInfo
, SourceBits
);
49 void RegisterAliasingTracker::FillOriginAndAliasedBits(
50 const llvm::MCRegisterInfo
&RegInfo
, const llvm::BitVector
&SourceBits
) {
51 using RegAliasItr
= llvm::MCRegAliasIterator
;
52 for (const size_t PhysReg
: SourceBits
.set_bits()) {
53 for (auto Itr
= RegAliasItr(PhysReg
, &RegInfo
, true); Itr
.isValid();
55 AliasedBits
.set(*Itr
);
56 Origins
[*Itr
] = PhysReg
;
61 RegisterAliasingTrackerCache::RegisterAliasingTrackerCache(
62 const llvm::MCRegisterInfo
&RegInfo
, const llvm::BitVector
&ReservedReg
)
63 : RegInfo(RegInfo
), ReservedReg(ReservedReg
),
64 EmptyRegisters(RegInfo
.getNumRegs()) {}
66 const RegisterAliasingTracker
&
67 RegisterAliasingTrackerCache::getRegister(llvm::MCPhysReg PhysReg
) const {
68 auto &Found
= Registers
[PhysReg
];
70 Found
.reset(new RegisterAliasingTracker(RegInfo
, PhysReg
));
74 const RegisterAliasingTracker
&
75 RegisterAliasingTrackerCache::getRegisterClass(unsigned RegClassIndex
) const {
76 auto &Found
= RegisterClasses
[RegClassIndex
];
77 const auto &RegClass
= RegInfo
.getRegClass(RegClassIndex
);
79 Found
.reset(new RegisterAliasingTracker(RegInfo
, ReservedReg
, RegClass
));
83 } // namespace exegesis