From: Nikita Popov Date: Fri, 15 Jul 2022 14:36:46 +0000 (+0200) Subject: [GlobalOpt] Add struct for parts during GlobalSRA (NFC) X-Git-Tag: upstream/17.0.6~16777 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d9d855a073a496540d4e40e67945b6f09d3aea7;p=platform%2Fupstream%2Fllvm.git [GlobalOpt] Add struct for parts during GlobalSRA (NFC) This is in preparation for https://reviews.llvm.org/D129857. --- diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 11621d9..435f38f 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -335,10 +335,14 @@ static bool CleanupConstantGlobalUsers(GlobalVariable *GV, return Changed; } +struct GlobalPart { + Type *Ty; +}; + /// Look at all uses of the global and determine which (offset, type) pairs it /// can be split into. -static bool collectSRATypes(DenseMap &Types, GlobalValue *GV, - const DataLayout &DL) { +static bool collectSRATypes(DenseMap &Parts, + GlobalValue *GV, const DataLayout &DL) { SmallVector Worklist; SmallPtrSet Visited; auto AppendUses = [&](Value *V) { @@ -373,8 +377,8 @@ static bool collectSRATypes(DenseMap &Types, GlobalValue *GV, // TODO: We currently require that all accesses at a given offset must // use the same type. This could be relaxed. Type *Ty = getLoadStoreType(V); - auto It = Types.try_emplace(Offset.getZExtValue(), Ty).first; - if (Ty != It->second) + auto It = Parts.try_emplace(Offset.getZExtValue(), GlobalPart{Ty}).first; + if (Ty != It->second.Ty) return false; // Scalable types not currently supported. @@ -459,21 +463,22 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { assert(GV->hasLocalLinkage()); // Collect types to split into. - DenseMap Types; - if (!collectSRATypes(Types, GV, DL) || Types.empty()) + DenseMap Parts; + if (!collectSRATypes(Parts, GV, DL) || Parts.empty()) return nullptr; // Make sure we don't SRA back to the same type. - if (Types.size() == 1 && Types.begin()->second == GV->getValueType()) + if (Parts.size() == 1 && Parts.begin()->second.Ty == GV->getValueType()) return nullptr; // Don't perform SRA if we would have to split into many globals. - if (Types.size() > 16) + if (Parts.size() > 16) return nullptr; // Sort by offset. SmallVector, 16> TypesVector; - append_range(TypesVector, Types); + for (const auto &Pair : Parts) + TypesVector.push_back({Pair.first, Pair.second.Ty}); sort(TypesVector, llvm::less_first()); // Check that the types are non-overlapping. @@ -493,7 +498,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) { // Collect initializers for new globals. Constant *OrigInit = GV->getInitializer(); DenseMap Initializers; - for (const auto &Pair : Types) { + for (const auto &Pair : TypesVector) { Constant *NewInit = ConstantFoldLoadFromConst(OrigInit, Pair.second, APInt(64, Pair.first), DL); if (!NewInit) {