diff options
Diffstat (limited to 'llvm/lib/CodeGen/StackColoring.cpp')
-rw-r--r-- | llvm/lib/CodeGen/StackColoring.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp index b6e81116286f..d720d93c306d 100644 --- a/llvm/lib/CodeGen/StackColoring.cpp +++ b/llvm/lib/CodeGen/StackColoring.cpp @@ -913,6 +913,11 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { assert(To && From && "Invalid allocation object"); Allocas[From] = To; + // If From is before wo, its possible that there is a use of From between + // them. + if (From->comesBefore(To)) + const_cast<AllocaInst*>(To)->moveBefore(const_cast<AllocaInst*>(From)); + // AA might be used later for instruction scheduling, and we need it to be // able to deduce the correct aliasing releationships between pointers // derived from the alloca being remapped and the target of that remapping. @@ -960,6 +965,8 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { } // Remap all instructions to the new stack slots. + std::vector<std::vector<MachineMemOperand *>> SSRefs( + MFI->getObjectIndexEnd()); for (MachineBasicBlock &BB : *MF) for (MachineInstr &I : BB) { // Skip lifetime markers. We'll remove them soon. @@ -1025,6 +1032,16 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { SmallVector<MachineMemOperand *, 2> NewMMOs; bool ReplaceMemOps = false; for (MachineMemOperand *MMO : I.memoperands()) { + // Collect MachineMemOperands which reference + // FixedStackPseudoSourceValues with old frame indices. + if (const auto *FSV = dyn_cast_or_null<FixedStackPseudoSourceValue>( + MMO->getPseudoValue())) { + int FI = FSV->getFrameIndex(); + auto To = SlotRemap.find(FI); + if (To != SlotRemap.end()) + SSRefs[FI].push_back(MMO); + } + // If this memory location can be a slot remapped here, // we remove AA information. bool MayHaveConflictingAAMD = false; @@ -1062,6 +1079,15 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { I.setMemRefs(*MF, NewMMOs); } + // Rewrite MachineMemOperands that reference old frame indices. + for (auto E : enumerate(SSRefs)) + if (!E.value().empty()) { + const PseudoSourceValue *NewSV = + MF->getPSVManager().getFixedStack(SlotRemap.find(E.index())->second); + for (MachineMemOperand *Ref : E.value()) + Ref->setValue(NewSV); + } + // Update the location of C++ catch objects for the MSVC personality routine. if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo()) for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap) @@ -1269,8 +1295,8 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) { SortedSlots[J] = -1; LLVM_DEBUG(dbgs() << "Merging #" << FirstSlot << " and slots #" << SecondSlot << " together.\n"); - unsigned MaxAlignment = std::max(MFI->getObjectAlignment(FirstSlot), - MFI->getObjectAlignment(SecondSlot)); + Align MaxAlignment = std::max(MFI->getObjectAlign(FirstSlot), + MFI->getObjectAlign(SecondSlot)); assert(MFI->getObjectSize(FirstSlot) >= MFI->getObjectSize(SecondSlot) && |