forked from OSchip/llvm-project
unique_ptrify some containers in GlobalISel::RegisterBankInfo
To simplify/clarify memory ownership, make leaks (as one was found/fixed recently) harder to write, etc. (also, while I was there - removed a duplicate lookup in a container) llvm-svn: 293506
This commit is contained in:
parent
7ccb24f8cb
commit
a66696f210
|
@ -378,15 +378,15 @@ protected:
|
||||||
|
|
||||||
/// Keep dynamically allocated PartialMapping in a separate map.
|
/// Keep dynamically allocated PartialMapping in a separate map.
|
||||||
/// This shouldn't be needed when everything gets TableGen'ed.
|
/// This shouldn't be needed when everything gets TableGen'ed.
|
||||||
mutable DenseMap<unsigned, const PartialMapping *> MapOfPartialMappings;
|
mutable DenseMap<unsigned, std::unique_ptr<const PartialMapping>> MapOfPartialMappings;
|
||||||
|
|
||||||
/// Keep dynamically allocated ValueMapping in a separate map.
|
/// Keep dynamically allocated ValueMapping in a separate map.
|
||||||
/// This shouldn't be needed when everything gets TableGen'ed.
|
/// This shouldn't be needed when everything gets TableGen'ed.
|
||||||
mutable DenseMap<unsigned, const ValueMapping *> MapOfValueMappings;
|
mutable DenseMap<unsigned, std::unique_ptr<const ValueMapping> > MapOfValueMappings;
|
||||||
|
|
||||||
/// Keep dynamically allocated array of ValueMapping in a separate map.
|
/// Keep dynamically allocated array of ValueMapping in a separate map.
|
||||||
/// This shouldn't be needed when everything gets TableGen'ed.
|
/// This shouldn't be needed when everything gets TableGen'ed.
|
||||||
mutable DenseMap<unsigned, ValueMapping *> MapOfOperandsMappings;
|
mutable DenseMap<unsigned, std::unique_ptr<ValueMapping[]>> MapOfOperandsMappings;
|
||||||
|
|
||||||
/// Create a RegisterBankInfo that can accomodate up to \p NumRegBanks
|
/// Create a RegisterBankInfo that can accomodate up to \p NumRegBanks
|
||||||
/// RegisterBank instances.
|
/// RegisterBank instances.
|
||||||
|
@ -512,7 +512,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~RegisterBankInfo();
|
virtual ~RegisterBankInfo() = default;
|
||||||
|
|
||||||
/// Get the register bank identified by \p ID.
|
/// Get the register bank identified by \p ID.
|
||||||
const RegisterBank &getRegBank(unsigned ID) const {
|
const RegisterBank &getRegBank(unsigned ID) const {
|
||||||
|
|
|
@ -63,15 +63,6 @@ RegisterBankInfo::RegisterBankInfo(RegisterBank **RegBanks,
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterBankInfo::~RegisterBankInfo() {
|
|
||||||
for (auto It : MapOfPartialMappings)
|
|
||||||
delete It.second;
|
|
||||||
for (auto It : MapOfValueMappings)
|
|
||||||
delete It.second;
|
|
||||||
for (auto It : MapOfOperandsMappings)
|
|
||||||
delete[] It.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RegisterBankInfo::verify(const TargetRegisterInfo &TRI) const {
|
bool RegisterBankInfo::verify(const TargetRegisterInfo &TRI) const {
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
for (unsigned Idx = 0, End = getNumRegBanks(); Idx != End; ++Idx) {
|
for (unsigned Idx = 0, End = getNumRegBanks(); Idx != End; ++Idx) {
|
||||||
|
@ -236,8 +227,8 @@ RegisterBankInfo::getPartialMapping(unsigned StartIdx, unsigned Length,
|
||||||
|
|
||||||
++NumPartialMappingsCreated;
|
++NumPartialMappingsCreated;
|
||||||
|
|
||||||
const PartialMapping *&PartMapping = MapOfPartialMappings[Hash];
|
auto &PartMapping = MapOfPartialMappings[Hash];
|
||||||
PartMapping = new PartialMapping{StartIdx, Length, RegBank};
|
PartMapping = llvm::make_unique<PartialMapping>(StartIdx, Length, RegBank);
|
||||||
return *PartMapping;
|
return *PartMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,8 +261,8 @@ RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
|
||||||
|
|
||||||
++NumValueMappingsCreated;
|
++NumValueMappingsCreated;
|
||||||
|
|
||||||
const ValueMapping *&ValMapping = MapOfValueMappings[Hash];
|
auto &ValMapping = MapOfValueMappings[Hash];
|
||||||
ValMapping = new ValueMapping{BreakDown, NumBreakDowns};
|
ValMapping = llvm::make_unique<ValueMapping>(BreakDown, NumBreakDowns);
|
||||||
return *ValMapping;
|
return *ValMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,9 +275,9 @@ RegisterBankInfo::getOperandsMapping(Iterator Begin, Iterator End) const {
|
||||||
// The addresses of the value mapping are unique.
|
// The addresses of the value mapping are unique.
|
||||||
// Therefore, we can use them directly to hash the operand mapping.
|
// Therefore, we can use them directly to hash the operand mapping.
|
||||||
hash_code Hash = hash_combine_range(Begin, End);
|
hash_code Hash = hash_combine_range(Begin, End);
|
||||||
const auto &It = MapOfOperandsMappings.find(Hash);
|
auto &Res = MapOfOperandsMappings[Hash];
|
||||||
if (It != MapOfOperandsMappings.end())
|
if (Res)
|
||||||
return It->second;
|
return Res.get();
|
||||||
|
|
||||||
++NumOperandsMappingsCreated;
|
++NumOperandsMappingsCreated;
|
||||||
|
|
||||||
|
@ -295,8 +286,7 @@ RegisterBankInfo::getOperandsMapping(Iterator Begin, Iterator End) const {
|
||||||
// mapping, because we use the pointer of the ValueMapping
|
// mapping, because we use the pointer of the ValueMapping
|
||||||
// to hash and we expect them to uniquely identify an instance
|
// to hash and we expect them to uniquely identify an instance
|
||||||
// of value mapping.
|
// of value mapping.
|
||||||
ValueMapping *&Res = MapOfOperandsMappings[Hash];
|
Res = llvm::make_unique<ValueMapping[]>(std::distance(Begin, End));
|
||||||
Res = new ValueMapping[std::distance(Begin, End)];
|
|
||||||
unsigned Idx = 0;
|
unsigned Idx = 0;
|
||||||
for (Iterator It = Begin; It != End; ++It, ++Idx) {
|
for (Iterator It = Begin; It != End; ++It, ++Idx) {
|
||||||
const ValueMapping *ValMap = *It;
|
const ValueMapping *ValMap = *It;
|
||||||
|
@ -304,7 +294,7 @@ RegisterBankInfo::getOperandsMapping(Iterator Begin, Iterator End) const {
|
||||||
continue;
|
continue;
|
||||||
Res[Idx] = *ValMap;
|
Res[Idx] = *ValMap;
|
||||||
}
|
}
|
||||||
return Res;
|
return Res.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const RegisterBankInfo::ValueMapping *RegisterBankInfo::getOperandsMapping(
|
const RegisterBankInfo::ValueMapping *RegisterBankInfo::getOperandsMapping(
|
||||||
|
|
Loading…
Reference in New Issue