Skip to content

Commit 9767ba6

Browse files
committed
Revert "[DebugInfo][RemoveDIs] Remove a swathe of debug-intrinsic code (llvm#144389)"
This reverts commit 9eb0020.
1 parent 719fd29 commit 9767ba6

39 files changed

+347
-96
lines changed

llvm/include/llvm/Analysis/IRSimilarityIdentifier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ struct IRInstructionMapper {
545545
// dependent.
546546
InstrType visitLandingPadInst(LandingPadInst &LPI) { return Illegal; }
547547
InstrType visitFuncletPadInst(FuncletPadInst &FPI) { return Illegal; }
548+
// DebugInfo should be included in the regions, but should not be
549+
// analyzed for similarity as it has no bearing on the outcome of the
550+
// program.
551+
InstrType visitDbgInfoIntrinsic(DbgInfoIntrinsic &DII) { return Invisible; }
548552
InstrType visitIntrinsicInst(IntrinsicInst &II) {
549553
// These are disabled due to complications in the CodeExtractor when
550554
// outlining these instructions. For instance, It is unclear what we

llvm/include/llvm/Analysis/PtrUseVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class PtrUseVisitor : protected InstVisitor<DerivedT>,
285285

286286
// No-op intrinsics which we know don't escape the pointer to logic in
287287
// some other function.
288+
void visitDbgInfoIntrinsic(DbgInfoIntrinsic &I) {}
288289
void visitMemIntrinsic(MemIntrinsic &I) {}
289290
void visitIntrinsicInst(IntrinsicInst &II) {
290291
switch (II.getIntrinsicID()) {

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,12 @@ handleUnreachableTerminator(Instruction *I,
394394
SmallVectorImpl<Value *> &PoisonedValues);
395395

396396
/// Remove all instructions from a basic block other than its terminator
397-
/// and any present EH pad instructions. Returns the number of instructions
397+
/// and any present EH pad instructions. Returns a pair where the first element
398+
/// is the number of instructions (excluding debug info intrinsics) that have
399+
/// been removed, and the second element is the number of debug info intrinsics
398400
/// that have been removed.
399-
LLVM_ABI unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
401+
LLVM_ABI std::pair<unsigned, unsigned>
402+
removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB);
400403

401404
/// Insert an unreachable instruction before the specified
402405
/// instruction, making it and the rest of the code in the block dead.

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ void AliasSetTracker::add(AnyMemTransferInst *MTI) {
343343
}
344344

345345
void AliasSetTracker::addUnknown(Instruction *Inst) {
346+
if (isa<DbgInfoIntrinsic>(Inst))
347+
return; // Ignore DbgInfo Intrinsics.
348+
346349
if (auto *II = dyn_cast<IntrinsicInst>(Inst)) {
347350
// These intrinsics will show up as affecting memory, but they are just
348351
// markers.

llvm/lib/Analysis/CallGraph.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ CallGraph::CallGraph(Module &M)
3434
CallsExternalNode(std::make_unique<CallGraphNode>(this, nullptr)) {
3535
// Add every interesting function to the call graph.
3636
for (Function &F : M)
37-
addToCallGraph(&F);
37+
if (!isDbgInfoIntrinsic(F.getIntrinsicID()))
38+
addToCallGraph(&F);
3839
}
3940

4041
CallGraph::CallGraph(CallGraph &&Arg)
@@ -100,7 +101,7 @@ void CallGraph::populateCallGraphNode(CallGraphNode *Node) {
100101
const Function *Callee = Call->getCalledFunction();
101102
if (!Callee)
102103
Node->addCalledFunction(Call, CallsExternalNode.get());
103-
else
104+
else if (!isDbgInfoIntrinsic(Callee->getIntrinsicID()))
104105
Node->addCalledFunction(Call, getOrInsertFunction(Callee));
105106

106107
// Add reference to callback functions.

llvm/lib/Analysis/DemandedBits.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ using namespace llvm::PatternMatch;
4646
#define DEBUG_TYPE "demanded-bits"
4747

4848
static bool isAlwaysLive(Instruction *I) {
49-
return I->isTerminator() || I->isEHPad() || I->mayHaveSideEffects();
49+
return I->isTerminator() || isa<DbgInfoIntrinsic>(I) || I->isEHPad() ||
50+
I->mayHaveSideEffects();
5051
}
5152

5253
void DemandedBits::determineLiveOperandBits(

llvm/lib/Analysis/Loads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ bool llvm::isSafeToLoadUnconditionally(Value *V, Align Alignment, const APInt &S
434434
// If we see a free or a call which may write to memory (i.e. which might do
435435
// a free) the pointer could be marked invalid.
436436
if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
437-
!isa<LifetimeIntrinsic>(BBI))
437+
!isa<LifetimeIntrinsic>(BBI) && !isa<DbgInfoIntrinsic>(BBI))
438438
return false;
439439

440440
Value *AccessedPtr;

llvm/lib/Analysis/MemoryDependenceAnalysis.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ MemDepResult MemoryDependenceResults::getCallDependencyFrom(
188188
// Walk backwards through the block, looking for dependencies.
189189
while (ScanIt != BB->begin()) {
190190
Instruction *Inst = &*--ScanIt;
191+
// Debug intrinsics don't cause dependences and should not affect Limit
192+
if (isa<DbgInfoIntrinsic>(Inst))
193+
continue;
191194

192195
// Limit the amount of scanning we do so we don't end up with quadratic
193196
// running time on extreme testcases.
@@ -429,6 +432,11 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
429432
while (ScanIt != BB->begin()) {
430433
Instruction *Inst = &*--ScanIt;
431434

435+
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
436+
// Debug intrinsics don't (and can't) cause dependencies.
437+
if (isa<DbgInfoIntrinsic>(II))
438+
continue;
439+
432440
// Limit the amount of scanning we do so we don't end up with quadratic
433441
// running time on extreme testcases.
434442
--*Limit;

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7846,6 +7846,8 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(
78467846
iterator_range<BasicBlock::const_iterator> Range, unsigned ScanLimit) {
78477847
assert(ScanLimit && "scan limit must be non-zero");
78487848
for (const Instruction &I : Range) {
7849+
if (isa<DbgInfoIntrinsic>(I))
7850+
continue;
78497851
if (--ScanLimit == 0)
78507852
return false;
78517853
if (!isGuaranteedToTransferExecutionToSuccessor(&I))
@@ -8048,6 +8050,8 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
80488050
// well-defined operands.
80498051

80508052
for (const auto &I : make_range(Begin, End)) {
8053+
if (isa<DbgInfoIntrinsic>(I))
8054+
continue;
80518055
if (--ScanLimit == 0)
80528056
break;
80538057

@@ -8072,6 +8076,8 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
80728076

80738077
while (true) {
80748078
for (const auto &I : make_range(Begin, End)) {
8079+
if (isa<DbgInfoIntrinsic>(I))
8080+
continue;
80758081
if (--ScanLimit == 0)
80768082
return false;
80778083
if (mustTriggerUB(&I, YieldsPoison))

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,12 @@ BasicBlock *CodeGenPrepare::findDestBlockOfMergeableEmptyBlock(BasicBlock *BB) {
896896
BasicBlock::iterator BBI = BI->getIterator();
897897
if (BBI != BB->begin()) {
898898
--BBI;
899-
if (!isa<PHINode>(BBI))
899+
while (isa<DbgInfoIntrinsic>(BBI)) {
900+
if (BBI == BB->begin())
901+
break;
902+
--BBI;
903+
}
904+
if (!isa<DbgInfoIntrinsic>(BBI) && !isa<PHINode>(BBI))
900905
return nullptr;
901906
}
902907

@@ -2976,9 +2981,10 @@ bool CodeGenPrepare::dupRetToEnableTailCallOpts(BasicBlock *BB,
29762981
// Make sure there are no instructions between the first instruction
29772982
// and return.
29782983
BasicBlock::const_iterator BI = BB->getFirstNonPHIIt();
2979-
// Skip over pseudo-probes and the bitcast.
2980-
while (&*BI == BCI || &*BI == EVI || isa<PseudoProbeInst>(BI) ||
2981-
isLifetimeEndOrBitCastFor(&*BI) || isFakeUse(&*BI))
2984+
// Skip over debug and the bitcast.
2985+
while (isa<DbgInfoIntrinsic>(BI) || &*BI == BCI || &*BI == EVI ||
2986+
isa<PseudoProbeInst>(BI) || isLifetimeEndOrBitCastFor(&*BI) ||
2987+
isFakeUse(&*BI))
29822988
BI = std::next(BI);
29832989
if (&*BI != RetI)
29842990
return false;

0 commit comments

Comments
 (0)