Skip to content

Commit 016d91c

Browse files
committed
[CallSiteInfo] Handle bundles when updating call site info
This will address the issue: P8198 and P8199 (from D73534). The methods was not handle bundles properly. Differential Revision: https://reviews.llvm.org/D74904
1 parent fa9439f commit 016d91c

16 files changed

+320
-42
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,21 +1006,19 @@ class MachineFunction {
10061006
/// Following functions update call site info. They should be called before
10071007
/// removing, replacing or copying call instruction.
10081008

1009-
/// Move the call site info from \p Old to \New call site info. This function
1010-
/// is used when we are replacing one call instruction with another one to
1011-
/// the same callee.
1012-
void moveCallSiteInfo(const MachineInstr *Old,
1013-
const MachineInstr *New);
1014-
10151009
/// Erase the call site info for \p MI. It is used to remove a call
10161010
/// instruction from the instruction stream.
10171011
void eraseCallSiteInfo(const MachineInstr *MI);
1018-
10191012
/// Copy the call site info from \p Old to \ New. Its usage is when we are
10201013
/// making a copy of the instruction that will be inserted at different point
10211014
/// of the instruction stream.
10221015
void copyCallSiteInfo(const MachineInstr *Old,
10231016
const MachineInstr *New);
1017+
/// Move the call site info from \p Old to \New call site info. This function
1018+
/// is used when we are replacing one call instruction with another one to
1019+
/// the same callee.
1020+
void moveCallSiteInfo(const MachineInstr *Old,
1021+
const MachineInstr *New);
10241022
};
10251023

10261024
//===--------------------------------------------------------------------===//

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,11 @@ class MachineInstr
689689

690690
/// Return true if this is a call instruction that may have an associated
691691
/// call site entry in the debug info.
692-
bool isCandidateForCallSiteEntry() const;
692+
bool isCandidateForCallSiteEntry(QueryType Type = IgnoreBundle) const;
693+
/// Return true if copying, moving, or erasing this instruction requires
694+
/// updating Call Site Info (see \ref copyCallSiteInfo, \ref moveCallSiteInfo,
695+
/// \ref eraseCallSiteInfo).
696+
bool shouldUpdateCallSiteInfo() const;
693697

694698
/// Returns true if the specified instruction stops control flow
695699
/// from executing the instruction immediately following it. Examples include

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
170170

171171
// Update call site info.
172172
std::for_each(MBB->begin(), MBB->end(), [MF](const MachineInstr &MI) {
173-
if (MI.isCandidateForCallSiteEntry())
173+
if (MI.shouldUpdateCallSiteInfo())
174174
MF->eraseCallSiteInfo(&MI);
175175
});
176176
// Remove the block.

llvm/lib/CodeGen/IfConversion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,7 @@ bool IfConverter::IfConvertDiamondCommon(
18511851
while (NumDups1 != 0) {
18521852
// Since this instruction is going to be deleted, update call
18531853
// site info state if the instruction is call instruction.
1854-
if (DI2->isCandidateForCallSiteEntry())
1854+
if (DI2->shouldUpdateCallSiteInfo())
18551855
MBB2.getParent()->eraseCallSiteInfo(&*DI2);
18561856

18571857
++DI2;
@@ -1900,7 +1900,7 @@ bool IfConverter::IfConvertDiamondCommon(
19001900

19011901
// Since this instruction is going to be deleted, update call
19021902
// site info state if the instruction is call instruction.
1903-
if (DI1->isCandidateForCallSiteEntry())
1903+
if (DI1->shouldUpdateCallSiteInfo())
19041904
MBB1.getParent()->eraseCallSiteInfo(&*DI1);
19051905

19061906
// skip dbg_value instructions

llvm/lib/CodeGen/LiveRangeEdit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
232232
LLVM_DEBUG(dbgs() << " folded: " << *FoldMI);
233233
LIS.ReplaceMachineInstrInMaps(*UseMI, *FoldMI);
234234
// Update the call site info.
235-
if (UseMI->isCandidateForCallSiteEntry())
235+
if (UseMI->shouldUpdateCallSiteInfo())
236236
UseMI->getMF()->moveCallSiteInfo(UseMI, FoldMI);
237237
UseMI->eraseFromParent();
238238
DefMI->addRegisterDead(LI->reg, nullptr);

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
393393
// be triggered during the implementation of support for the
394394
// call site info of a new architecture. If the assertion is triggered,
395395
// back trace will tell where to insert a call to updateCallSiteInfo().
396-
assert((!MI->isCall(MachineInstr::IgnoreBundle) ||
396+
assert((!MI->isCandidateForCallSiteEntry() ||
397397
CallSitesInfo.find(MI) == CallSitesInfo.end()) &&
398398
"Call site info was not updated!");
399399
// Strip it for parts. The operand array and the MI object itself are
@@ -871,48 +871,68 @@ MachineFunction::getCallSiteInfo(const MachineInstr *MI) {
871871
return CallSitesInfo.find(MI);
872872
}
873873

874-
void MachineFunction::moveCallSiteInfo(const MachineInstr *Old,
875-
const MachineInstr *New) {
876-
assert(Old->isCandidateForCallSiteEntry() &&
877-
"Call site info refers only to call (MI) candidates");
878-
879-
if (!New->isCandidateForCallSiteEntry())
880-
return eraseCallSiteInfo(Old);
874+
/// Return the call machine instruction or find a call within bundle.
875+
static const MachineInstr *getCallInstr(const MachineInstr *MI) {
876+
if (!MI->isBundle())
877+
return MI;
881878

882-
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
883-
if (CSIt == CallSitesInfo.end())
884-
return;
879+
for (auto &BMI : make_range(getBundleStart(MI->getIterator()),
880+
getBundleEnd(MI->getIterator())))
881+
if (BMI.isCandidateForCallSiteEntry())
882+
return &BMI;
885883

886-
CallSiteInfo CSInfo = std::move(CSIt->second);
887-
CallSitesInfo.erase(CSIt);
888-
CallSitesInfo[New] = CSInfo;
884+
llvm_unreachable("Unexpected bundle without a call site candidate");
889885
}
890886

891887
void MachineFunction::eraseCallSiteInfo(const MachineInstr *MI) {
892-
assert(MI->isCandidateForCallSiteEntry() &&
893-
"Call site info refers only to call (MI) candidates");
894-
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(MI);
888+
assert(MI->shouldUpdateCallSiteInfo() &&
889+
"Call site info refers only to call (MI) candidates or "
890+
"candidates inside bundles");
891+
892+
const MachineInstr *CallMI = getCallInstr(MI);
893+
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(CallMI);
895894
if (CSIt == CallSitesInfo.end())
896895
return;
897896
CallSitesInfo.erase(CSIt);
898897
}
899898

900899
void MachineFunction::copyCallSiteInfo(const MachineInstr *Old,
901900
const MachineInstr *New) {
902-
assert(Old->isCandidateForCallSiteEntry() &&
903-
"Call site info refers only to call (MI) candidates");
901+
assert(Old->shouldUpdateCallSiteInfo() &&
902+
"Call site info refers only to call (MI) candidates or "
903+
"candidates inside bundles");
904904

905905
if (!New->isCandidateForCallSiteEntry())
906906
return eraseCallSiteInfo(Old);
907907

908-
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(Old);
908+
const MachineInstr *OldCallMI = getCallInstr(Old);
909+
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI);
909910
if (CSIt == CallSitesInfo.end())
910911
return;
911912

912913
CallSiteInfo CSInfo = CSIt->second;
913914
CallSitesInfo[New] = CSInfo;
914915
}
915916

917+
void MachineFunction::moveCallSiteInfo(const MachineInstr *Old,
918+
const MachineInstr *New) {
919+
assert(Old->shouldUpdateCallSiteInfo() &&
920+
"Call site info refers only to call (MI) candidates or "
921+
"candidates inside bundles");
922+
923+
if (!New->isCandidateForCallSiteEntry())
924+
return eraseCallSiteInfo(Old);
925+
926+
const MachineInstr *OldCallMI = getCallInstr(Old);
927+
CallSiteInfoMap::iterator CSIt = getCallSiteInfo(OldCallMI);
928+
if (CSIt == CallSitesInfo.end())
929+
return;
930+
931+
CallSiteInfo CSInfo = std::move(CSIt->second);
932+
CallSitesInfo.erase(CSIt);
933+
CallSitesInfo[New] = CSInfo;
934+
}
935+
916936
/// \}
917937

918938
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ void MachineInstr::eraseFromBundle() {
697697
getParent()->erase_instr(this);
698698
}
699699

700-
bool MachineInstr::isCandidateForCallSiteEntry() const {
701-
if (!isCall(MachineInstr::IgnoreBundle))
700+
bool MachineInstr::isCandidateForCallSiteEntry(QueryType Type) const {
701+
if (!isCall(Type))
702702
return false;
703703
switch (getOpcode()) {
704704
case TargetOpcode::PATCHABLE_EVENT_CALL:
@@ -711,6 +711,12 @@ bool MachineInstr::isCandidateForCallSiteEntry() const {
711711
return true;
712712
}
713713

714+
bool MachineInstr::shouldUpdateCallSiteInfo() const {
715+
if (isBundle())
716+
return isCandidateForCallSiteEntry(MachineInstr::AnyInBundle);
717+
return isCandidateForCallSiteEntry();
718+
}
719+
714720
unsigned MachineInstr::getNumExplicitOperands() const {
715721
unsigned NumOperands = MCID->getNumOperands();
716722
if (!MCID->isVariadic())

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ MachineInstr *MachineLICMBase::ExtractHoistableLoad(MachineInstr *MI) {
13691369
// Otherwise we successfully unfolded a load that we can hoist.
13701370

13711371
// Update the call site info.
1372-
if (MI->isCandidateForCallSiteEntry())
1372+
if (MI->shouldUpdateCallSiteInfo())
13731373
MF.eraseCallSiteInfo(MI);
13741374

13751375
MI->eraseFromParent();

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ bool MachineOutliner::outline(Module &M,
12601260
MOP.getReg(), true, /* isDef = true */
12611261
true /* isImp = true */));
12621262
}
1263-
if (MI.isCandidateForCallSiteEntry())
1263+
if (MI.shouldUpdateCallSiteInfo())
12641264
MI.getMF()->eraseCallSiteInfo(&MI);
12651265
};
12661266
// Copy over the defs in the outlined range.

llvm/lib/CodeGen/PeepholeOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
17771777
LocalMIs.erase(DefMI);
17781778
LocalMIs.insert(FoldMI);
17791779
// Update the call site info.
1780-
if (MI->isCandidateForCallSiteEntry())
1780+
if (MI->shouldUpdateCallSiteInfo())
17811781
MI->getMF()->moveCallSiteInfo(MI, FoldMI);
17821782
MI->eraseFromParent();
17831783
DefMI->eraseFromParent();

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ void TailDuplicator::removeDeadBlock(
10181018
MachineFunction *MF = MBB->getParent();
10191019
// Update the call site info.
10201020
std::for_each(MBB->begin(), MBB->end(), [MF](const MachineInstr &MI) {
1021-
if (MI.isCandidateForCallSiteEntry())
1021+
if (MI.shouldUpdateCallSiteInfo())
10221022
MF->eraseCallSiteInfo(&MI);
10231023
});
10241024

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ TargetInstrInfo::ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
143143
// from the end of MBB.
144144
while (Tail != MBB->end()) {
145145
auto MI = Tail++;
146-
if (MI->isCandidateForCallSiteEntry())
146+
if (MI->shouldUpdateCallSiteInfo())
147147
MBB->getParent()->eraseCallSiteInfo(&*MI);
148148
MBB->erase(MI);
149149
}

llvm/lib/CodeGen/UnreachableBlockElim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
151151
for (unsigned i = 0, e = DeadBlocks.size(); i != e; ++i) {
152152
// Remove any call site information for calls in the block.
153153
for (auto &I : DeadBlocks[i]->instrs())
154-
if (I.isCandidateForCallSiteEntry())
154+
if (I.shouldUpdateCallSiteInfo())
155155
DeadBlocks[i]->getParent()->eraseCallSiteInfo(&I);
156156

157157
DeadBlocks[i]->eraseFromParent();

llvm/lib/CodeGen/XRayInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void XRayInstrumentation::replaceRetWithPatchableRet(
111111
for (auto &MO : T.operands())
112112
MIB.add(MO);
113113
Terminators.push_back(&T);
114-
if (T.isCandidateForCallSiteEntry())
114+
if (T.shouldUpdateCallSiteInfo())
115115
MF.eraseCallSiteInfo(&T);
116116
}
117117
}

llvm/lib/Target/AArch64/AArch64CleanupLocalDynamicTLSPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct LDTLSCleanup : public MachineFunctionPass {
106106
.addReg(TLSBaseAddrReg);
107107

108108
// Update the call site info.
109-
if (I.isCandidateForCallSiteEntry())
109+
if (I.shouldUpdateCallSiteInfo())
110110
I.getMF()->eraseCallSiteInfo(&I);
111111

112112
// Erase the TLS_base_addr instruction.

0 commit comments

Comments
 (0)