Skip to content

Commit e3b7620

Browse files
committed
[GC] Use MapVector for GCStrategyMap
Use `MapVector`, so `GCStrategyMap` can support forward and reverse iterator, which is required in `AsmPrinter`.
1 parent cf0efb3 commit e3b7620

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

llvm/include/llvm/CodeGen/GCMetadata.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define LLVM_CODEGEN_GCMETADATA_H
3434

3535
#include "llvm/ADT/DenseMap.h"
36+
#include "llvm/ADT/MapVector.h"
3637
#include "llvm/ADT/SmallVector.h"
3738
#include "llvm/ADT/StringMap.h"
3839
#include "llvm/ADT/StringRef.h"
@@ -151,9 +152,9 @@ class GCFunctionInfo {
151152
size_t live_size(const iterator &p) const { return roots_size(); }
152153
};
153154

154-
struct GCStrategyMap {
155-
StringMap<std::unique_ptr<GCStrategy>> StrategyMap;
156-
155+
class GCStrategyMap : public MapVector<std::string, std::unique_ptr<GCStrategy>,
156+
StringMap<unsigned>> {
157+
public:
157158
GCStrategyMap() = default;
158159
GCStrategyMap(GCStrategyMap &&) = default;
159160

llvm/lib/CodeGen/GCMetadata.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool GCStrategyMap::invalidate(Module &M, const PreservedAnalyses &PA,
2626
for (const auto &F : M) {
2727
if (F.isDeclaration() || !F.hasGC())
2828
continue;
29-
if (!StrategyMap.contains(F.getGC()))
29+
if (!contains(F.getGC()))
3030
return true;
3131
}
3232
return false;
@@ -36,17 +36,16 @@ AnalysisKey CollectorMetadataAnalysis::Key;
3636

3737
CollectorMetadataAnalysis::Result
3838
CollectorMetadataAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
39-
Result R;
40-
auto &Map = R.StrategyMap;
39+
Result StrategyMap;
4140
for (auto &F : M) {
4241
if (F.isDeclaration() || !F.hasGC())
4342
continue;
4443
auto GCName = F.getGC();
45-
auto [It, Inserted] = Map.try_emplace(GCName);
44+
auto [It, Inserted] = StrategyMap.try_emplace(GCName);
4645
if (Inserted)
4746
It->second = getGCStrategy(GCName);
4847
}
49-
return R;
48+
return StrategyMap;
5049
}
5150

5251
AnalysisKey GCFunctionAnalysis::Key;
@@ -61,8 +60,7 @@ GCFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
6160
MAMProxy.cachedResultExists<CollectorMetadataAnalysis>(*F.getParent()) &&
6261
"This pass need module analysis `collector-metadata`!");
6362
auto &Map =
64-
MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent())
65-
->StrategyMap;
63+
*MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent());
6664
GCFunctionInfo Info(F, *Map[F.getGC()]);
6765
return Info;
6866
}

0 commit comments

Comments
 (0)