diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2022-04-19 13:51:20 -0400 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2022-04-27 18:51:38 -0400 |
commit | 717209763e17c10aaddce9db3faac4ecbf1afd29 (patch) | |
tree | b40d88fb62b216aa06acf2eb67d3cd6cba59b7ac /llvm/tools/llvm-reduce/ReducerWorkItem.cpp | |
parent | 6ff91d17d66da46572e97f9a0b042182762cbe9e (diff) | |
download | llvm-717209763e17c10aaddce9db3faac4ecbf1afd29.zip llvm-717209763e17c10aaddce9db3faac4ecbf1afd29.tar.gz llvm-717209763e17c10aaddce9db3faac4ecbf1afd29.tar.bz2 |
llvm-reduce: Fix incorrect cloning of MachineMemOperands
There were two problems with directly copying the MMOs from the old
function. The MMOs are owned by the function's Allocator, so need to
be reallocated anyways (surprisingly I didn't notice breakage on
this). Second, the PseudoSourceValues are also allocated per function
and need to be reallocated.
Diffstat (limited to 'llvm/tools/llvm-reduce/ReducerWorkItem.cpp')
-rw-r--r-- | llvm/tools/llvm-reduce/ReducerWorkItem.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp index ce2068d..01786a4 100644 --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -127,6 +127,62 @@ static void cloneFrameInfo( } } +static void cloneMemOperands(MachineInstr &DstMI, MachineInstr &SrcMI, + MachineFunction &SrcMF, MachineFunction &DstMF) { + // The new MachineMemOperands should be owned by the new function's + // Allocator. + PseudoSourceValueManager &PSVMgr = DstMF.getPSVManager(); + + // We also need to remap the PseudoSourceValues from the new function's + // PseudoSourceValueManager. + SmallVector<MachineMemOperand *, 2> NewMMOs; + for (MachineMemOperand *OldMMO : SrcMI.memoperands()) { + MachinePointerInfo NewPtrInfo(OldMMO->getPointerInfo()); + if (const PseudoSourceValue *PSV = + NewPtrInfo.V.dyn_cast<const PseudoSourceValue *>()) { + switch (PSV->kind()) { + case PseudoSourceValue::Stack: + NewPtrInfo.V = PSVMgr.getStack(); + break; + case PseudoSourceValue::GOT: + NewPtrInfo.V = PSVMgr.getGOT(); + break; + case PseudoSourceValue::JumpTable: + NewPtrInfo.V = PSVMgr.getJumpTable(); + break; + case PseudoSourceValue::ConstantPool: + NewPtrInfo.V = PSVMgr.getConstantPool(); + break; + case PseudoSourceValue::FixedStack: + NewPtrInfo.V = PSVMgr.getFixedStack( + cast<FixedStackPseudoSourceValue>(PSV)->getFrameIndex()); + break; + case PseudoSourceValue::GlobalValueCallEntry: + NewPtrInfo.V = PSVMgr.getGlobalValueCallEntry( + cast<GlobalValuePseudoSourceValue>(PSV)->getValue()); + break; + case PseudoSourceValue::ExternalSymbolCallEntry: + NewPtrInfo.V = PSVMgr.getExternalSymbolCallEntry( + cast<ExternalSymbolPseudoSourceValue>(PSV)->getSymbol()); + break; + case PseudoSourceValue::TargetCustom: + default: + // FIXME: We have no generic interface for allocating custom PSVs. + report_fatal_error("Cloning TargetCustom PSV not handled"); + } + } + + MachineMemOperand *NewMMO = DstMF.getMachineMemOperand( + NewPtrInfo, OldMMO->getFlags(), OldMMO->getMemoryType(), + OldMMO->getBaseAlign(), OldMMO->getAAInfo(), OldMMO->getRanges(), + OldMMO->getSyncScopeID(), OldMMO->getSuccessOrdering(), + OldMMO->getFailureOrdering()); + NewMMOs.push_back(NewMMO); + } + + DstMI.setMemRefs(DstMF, NewMMOs); +} + static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF, MachineModuleInfo &DestMMI) { auto DstMF = std::make_unique<MachineFunction>( @@ -252,7 +308,8 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF, DstMI->addOperand(DstMO); } - DstMI->setMemRefs(*DstMF, SrcMI.memoperands()); + + cloneMemOperands(*DstMI, SrcMI, *SrcMF, *DstMF); } } |