2017-12-09 05:57:28 +08:00
|
|
|
//===- Debugify.cpp - Attach synthetic debug info to everything -----------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-12-09 05:57:28 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file This pass attaches synthetic debug info to everything. It can be used
|
|
|
|
/// to create targeted tests for debug info preservation.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-11-15 07:15:48 +08:00
|
|
|
#include "llvm/Transforms/Utils/Debugify.h"
|
2017-12-09 05:57:28 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/IR/DIBuilder.h"
|
|
|
|
#include "llvm/IR/DebugInfo.h"
|
|
|
|
#include "llvm/IR/InstIterator.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Pass.h"
|
2019-11-15 07:15:48 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-06-07 03:05:41 +08:00
|
|
|
cl::opt<bool> Quiet("debugify-quiet",
|
|
|
|
cl::desc("Suppress verbose debugify output"));
|
|
|
|
|
|
|
|
raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
|
|
|
|
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
|
|
|
|
return Ty->isSized() ? M.getDataLayout().getTypeAllocSizeInBits(Ty) : 0;
|
|
|
|
}
|
|
|
|
|
2018-02-16 05:28:38 +08:00
|
|
|
bool isFunctionSkipped(Function &F) {
|
|
|
|
return F.isDeclaration() || !F.hasExactDefinition();
|
|
|
|
}
|
|
|
|
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
/// Find the basic block's terminating instruction.
|
2018-06-05 08:56:07 +08:00
|
|
|
///
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
/// Special care is needed to handle musttail and deopt calls, as these behave
|
|
|
|
/// like (but are in fact not) terminators.
|
|
|
|
Instruction *findTerminatingInstruction(BasicBlock &BB) {
|
2018-06-05 08:56:07 +08:00
|
|
|
if (auto *I = BB.getTerminatingMustTailCall())
|
|
|
|
return I;
|
|
|
|
if (auto *I = BB.getTerminatingDeoptimizeCall())
|
|
|
|
return I;
|
|
|
|
return BB.getTerminator();
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
bool applyDebugifyMetadata(Module &M,
|
|
|
|
iterator_range<Module::iterator> Functions,
|
|
|
|
StringRef Banner) {
|
2017-12-09 05:57:28 +08:00
|
|
|
// Skip modules with debug info.
|
|
|
|
if (M.getNamedMetadata("llvm.dbg.cu")) {
|
2018-06-07 03:05:41 +08:00
|
|
|
dbg() << Banner << "Skipping module with debug info\n";
|
2017-12-09 05:57:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIBuilder DIB(M);
|
|
|
|
LLVMContext &Ctx = M.getContext();
|
|
|
|
|
|
|
|
// Get a DIType which corresponds to Ty.
|
|
|
|
DenseMap<uint64_t, DIType *> TypeCache;
|
|
|
|
auto getCachedDIType = [&](Type *Ty) -> DIType * {
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
uint64_t Size = getAllocSizeInBits(M, Ty);
|
2017-12-09 05:57:28 +08:00
|
|
|
DIType *&DTy = TypeCache[Size];
|
|
|
|
if (!DTy) {
|
|
|
|
std::string Name = "ty" + utostr(Size);
|
|
|
|
DTy = DIB.createBasicType(Name, Size, dwarf::DW_ATE_unsigned);
|
|
|
|
}
|
|
|
|
return DTy;
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned NextLine = 1;
|
|
|
|
unsigned NextVar = 1;
|
|
|
|
auto File = DIB.createFile(M.getName(), "/");
|
2018-06-05 08:56:07 +08:00
|
|
|
auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C, File, "debugify",
|
|
|
|
/*isOptimized=*/true, "", 0);
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
// Visit each instruction.
|
2018-05-15 08:29:27 +08:00
|
|
|
for (Function &F : Functions) {
|
2018-02-16 05:28:38 +08:00
|
|
|
if (isFunctionSkipped(F))
|
2017-12-09 05:57:28 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
|
2018-11-20 02:29:28 +08:00
|
|
|
DISubprogram::DISPFlags SPFlags =
|
|
|
|
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
|
|
|
|
if (F.hasPrivateLinkage() || F.hasInternalLinkage())
|
|
|
|
SPFlags |= DISubprogram::SPFlagLocalToUnit;
|
|
|
|
auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
|
|
|
|
SPType, NextLine, DINode::FlagZero, SPFlags);
|
2017-12-09 05:57:28 +08:00
|
|
|
F.setSubprogram(SP);
|
|
|
|
for (BasicBlock &BB : F) {
|
|
|
|
// Attach debug locations.
|
|
|
|
for (Instruction &I : BB)
|
|
|
|
I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
|
|
|
|
|
2018-06-04 06:50:22 +08:00
|
|
|
// Inserting debug values into EH pads can break IR invariants.
|
|
|
|
if (BB.isEHPad())
|
|
|
|
continue;
|
|
|
|
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
// Find the terminating instruction, after which no debug values are
|
|
|
|
// attached.
|
|
|
|
Instruction *LastInst = findTerminatingInstruction(BB);
|
|
|
|
assert(LastInst && "Expected basic block with a terminator");
|
2018-06-04 11:33:01 +08:00
|
|
|
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
// Maintain an insertion point which can't be invalidated when updates
|
|
|
|
// are made.
|
|
|
|
BasicBlock::iterator InsertPt = BB.getFirstInsertionPt();
|
|
|
|
assert(InsertPt != BB.end() && "Expected to find an insertion point");
|
|
|
|
Instruction *InsertBefore = &*InsertPt;
|
2018-06-04 11:33:01 +08:00
|
|
|
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
// Attach debug values.
|
|
|
|
for (Instruction *I = &*BB.begin(); I != LastInst; I = I->getNextNode()) {
|
2017-12-09 05:57:28 +08:00
|
|
|
// Skip void-valued instructions.
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
if (I->getType()->isVoidTy())
|
2017-12-09 05:57:28 +08:00
|
|
|
continue;
|
|
|
|
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
// Phis and EH pads must be grouped at the beginning of the block.
|
|
|
|
// Only advance the insertion point when we finish visiting these.
|
|
|
|
if (!isa<PHINode>(I) && !I->isEHPad())
|
|
|
|
InsertBefore = I->getNextNode();
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
std::string Name = utostr(NextVar++);
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
const DILocation *Loc = I->getDebugLoc().get();
|
2017-12-09 05:57:28 +08:00
|
|
|
auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
getCachedDIType(I->getType()),
|
2017-12-09 05:57:28 +08:00
|
|
|
/*AlwaysPreserve=*/true);
|
[Debugify] Move debug value intrinsics closer to their operand defs
Before this patch, debugify would insert debug value intrinsics before the
terminating instruction in a block. This had the advantage of being simple,
but was a bit too simple/unrealistic.
This patch teaches debugify to insert debug values immediately after their
operand defs. This enables better testing of the compiler.
For example, with this patch, `opt -debugify-each` is able to identify a
vectorizer DI-invariance bug fixed in llvm.org/PR32761. In this bug, the
vectorizer produced different output with/without debug info present.
Reverting Davide's bugfix locally, I see:
$ ~/scripts/opt-check-dbg-invar.sh ./bin/opt \
.../SLPVectorizer/AArch64/spillcost-di.ll -slp-vectorizer
Comparing: -slp-vectorizer .../SLPVectorizer/AArch64/spillcost-di.ll
Baseline: /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.iYYeL1kf
With DI : /var/folders/j8/t4w0bp8j6x1g6fpghkcb4sjm0000gp/T/tmp.sQtQSeet
9,11c9,11
< %5 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
< %6 = bitcast i64* %4 to <2 x i64>*
< %7 = load <2 x i64>, <2 x i64>* %6, align 8, !tbaa !0
---
> %5 = load i64, i64* %4, align 8, !tbaa !0
> %6 = getelementptr inbounds %0, %0* %2, i64 %0, i32 1
> %7 = load i64, i64* %6, align 8, !tbaa !5
12a13
> store i64 %5, i64* %8, align 8, !tbaa !0
14,15c15
< %10 = bitcast i64* %8 to <2 x i64>*
< store <2 x i64> %7, <2 x i64>* %10, align 8, !tbaa !0
---
> store i64 %7, i64* %9, align 8, !tbaa !5
:: Found a test case ^
Running this over the *.ll files in tree, I found four additional examples
which compile differently with/without DI present. I plan on filing bugs for
these.
llvm-svn: 334118
2018-06-07 03:05:42 +08:00
|
|
|
DIB.insertDbgValueIntrinsic(I, LocalVar, DIB.createExpression(), Loc,
|
|
|
|
InsertBefore);
|
2017-12-09 05:57:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
DIB.finalizeSubprogram(SP);
|
|
|
|
}
|
|
|
|
DIB.finalize();
|
|
|
|
|
|
|
|
// Track the number of distinct lines and variables.
|
|
|
|
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
|
|
|
|
auto *IntTy = Type::getInt32Ty(Ctx);
|
|
|
|
auto addDebugifyOperand = [&](unsigned N) {
|
|
|
|
NMD->addOperand(MDNode::get(
|
|
|
|
Ctx, ValueAsMetadata::getConstant(ConstantInt::get(IntTy, N))));
|
|
|
|
};
|
|
|
|
addDebugifyOperand(NextLine - 1); // Original number of lines.
|
|
|
|
addDebugifyOperand(NextVar - 1); // Original number of variables.
|
2018-05-15 08:29:27 +08:00
|
|
|
assert(NMD->getNumOperands() == 2 &&
|
|
|
|
"llvm.debugify should have exactly 2 operands!");
|
2018-05-25 07:00:23 +08:00
|
|
|
|
|
|
|
// Claim that this synthetic debug info is valid.
|
|
|
|
StringRef DIVersionKey = "Debug Info Version";
|
|
|
|
if (!M.getModuleFlag(DIVersionKey))
|
|
|
|
M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
|
|
|
|
|
2017-12-09 05:57:28 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
/// Return true if a mis-sized diagnostic is issued for \p DVI.
|
|
|
|
bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
|
|
|
|
// The size of a dbg.value's value operand should match the size of the
|
|
|
|
// variable it corresponds to.
|
|
|
|
//
|
|
|
|
// TODO: This, along with a check for non-null value operands, should be
|
|
|
|
// promoted to verifier failures.
|
|
|
|
Value *V = DVI->getValue();
|
|
|
|
if (!V)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// For now, don't try to interpret anything more complicated than an empty
|
|
|
|
// DIExpression. Eventually we should try to handle OP_deref and fragments.
|
|
|
|
if (DVI->getExpression()->getNumElements())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Type *Ty = V->getType();
|
|
|
|
uint64_t ValueOperandSize = getAllocSizeInBits(M, Ty);
|
2018-06-27 08:47:52 +08:00
|
|
|
Optional<uint64_t> DbgVarSize = DVI->getFragmentSizeInBits();
|
|
|
|
if (!ValueOperandSize || !DbgVarSize)
|
|
|
|
return false;
|
|
|
|
|
2018-07-07 01:32:40 +08:00
|
|
|
bool HasBadSize = false;
|
|
|
|
if (Ty->isIntegerTy()) {
|
|
|
|
auto Signedness = DVI->getVariable()->getSignedness();
|
|
|
|
if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
|
|
|
|
HasBadSize = ValueOperandSize < *DbgVarSize;
|
|
|
|
} else {
|
|
|
|
HasBadSize = ValueOperandSize != *DbgVarSize;
|
|
|
|
}
|
|
|
|
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
if (HasBadSize) {
|
|
|
|
dbg() << "ERROR: dbg.value operand has size " << ValueOperandSize
|
2018-06-27 08:47:52 +08:00
|
|
|
<< ", but its variable has size " << *DbgVarSize << ": ";
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
DVI->print(dbg());
|
|
|
|
dbg() << "\n";
|
|
|
|
}
|
|
|
|
return HasBadSize;
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
bool checkDebugifyMetadata(Module &M,
|
|
|
|
iterator_range<Module::iterator> Functions,
|
2018-06-05 08:56:07 +08:00
|
|
|
StringRef NameOfWrappedPass, StringRef Banner,
|
2018-07-24 08:41:29 +08:00
|
|
|
bool Strip, DebugifyStatsMap *StatsMap) {
|
2017-12-09 05:57:28 +08:00
|
|
|
// Skip modules without debugify metadata.
|
|
|
|
NamedMDNode *NMD = M.getNamedMetadata("llvm.debugify");
|
2018-05-15 08:29:27 +08:00
|
|
|
if (!NMD) {
|
2018-06-07 03:05:41 +08:00
|
|
|
dbg() << Banner << "Skipping module without debugify metadata\n";
|
2018-05-15 08:29:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
|
|
|
|
return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
|
|
|
|
->getZExtValue();
|
|
|
|
};
|
2018-05-15 08:29:27 +08:00
|
|
|
assert(NMD->getNumOperands() == 2 &&
|
|
|
|
"llvm.debugify should have exactly 2 operands!");
|
2017-12-09 05:57:28 +08:00
|
|
|
unsigned OriginalNumLines = getDebugifyOperand(0);
|
|
|
|
unsigned OriginalNumVars = getDebugifyOperand(1);
|
|
|
|
bool HasErrors = false;
|
|
|
|
|
2018-07-24 08:41:29 +08:00
|
|
|
// Track debug info loss statistics if able.
|
|
|
|
DebugifyStatistics *Stats = nullptr;
|
|
|
|
if (StatsMap && !NameOfWrappedPass.empty())
|
|
|
|
Stats = &StatsMap->operator[](NameOfWrappedPass);
|
|
|
|
|
2017-12-09 05:57:28 +08:00
|
|
|
BitVector MissingLines{OriginalNumLines, true};
|
2018-05-15 08:29:27 +08:00
|
|
|
BitVector MissingVars{OriginalNumVars, true};
|
|
|
|
for (Function &F : Functions) {
|
2018-02-16 05:28:38 +08:00
|
|
|
if (isFunctionSkipped(F))
|
|
|
|
continue;
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
// Find missing lines.
|
2017-12-09 05:57:28 +08:00
|
|
|
for (Instruction &I : instructions(F)) {
|
|
|
|
if (isa<DbgValueInst>(&I))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto DL = I.getDebugLoc();
|
2018-05-15 08:29:27 +08:00
|
|
|
if (DL && DL.getLine() != 0) {
|
2017-12-09 05:57:28 +08:00
|
|
|
MissingLines.reset(DL.getLine() - 1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-29 02:21:11 +08:00
|
|
|
if (!DL) {
|
|
|
|
dbg() << "ERROR: Instruction with empty DebugLoc in function ";
|
|
|
|
dbg() << F.getName() << " --";
|
|
|
|
I.print(dbg());
|
|
|
|
dbg() << "\n";
|
|
|
|
HasErrors = true;
|
|
|
|
}
|
2017-12-09 05:57:28 +08:00
|
|
|
}
|
2018-02-16 05:28:38 +08:00
|
|
|
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
// Find missing variables and mis-sized debug values.
|
2017-12-09 05:57:28 +08:00
|
|
|
for (Instruction &I : instructions(F)) {
|
|
|
|
auto *DVI = dyn_cast<DbgValueInst>(&I);
|
|
|
|
if (!DVI)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned Var = ~0U;
|
|
|
|
(void)to_integer(DVI->getVariable()->getName(), Var, 10);
|
|
|
|
assert(Var <= OriginalNumVars && "Unexpected name for DILocalVariable");
|
[Debugify] Diagnose mis-sized dbg.values
Report an error in -check-debugify when the size of a dbg.value operand
doesn't match up with the size of the variable it describes.
Eventually this check should be moved into the IR verifier. For the
moment, it's useful to include the check in -check-debugify as a means
of catching regressions and finding existing bugs.
Here are some instances of bugs the new check finds in the -O2 pipeline
(all in InstCombine):
1) A float is used where a double is expected:
ERROR: dbg.value operand has size 32, but its variable has size 64:
call void @llvm.dbg.value(metadata float %expf, metadata !12, metadata
!DIExpression()), !dbg !15
2) An i8 is used where an i32 is expected:
ERROR: dbg.value operand has size 8, but its variable has size 32:
call void @llvm.dbg.value(metadata i8 %t4, metadata !14, metadata
!DIExpression()), !dbg !24
3) A <4 x i32> is used where something twice as large is expected
(perhaps a <4 x i64>, I haven't double-checked):
ERROR: dbg.value operand has size 128, but its variable has size 256:
call void @llvm.dbg.value(metadata <4 x i32> %4, metadata !40, metadata
!DIExpression()), !dbg !95
Differential Revision: https://reviews.llvm.org/D48408
llvm-svn: 335682
2018-06-27 06:46:41 +08:00
|
|
|
bool HasBadSize = diagnoseMisSizedDbgValue(M, DVI);
|
|
|
|
if (!HasBadSize)
|
|
|
|
MissingVars.reset(Var - 1);
|
|
|
|
HasErrors |= HasBadSize;
|
2017-12-09 05:57:28 +08:00
|
|
|
}
|
|
|
|
}
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
// Print the results.
|
|
|
|
for (unsigned Idx : MissingLines.set_bits())
|
2018-06-07 03:05:41 +08:00
|
|
|
dbg() << "WARNING: Missing line " << Idx + 1 << "\n";
|
2018-05-15 08:29:27 +08:00
|
|
|
|
2017-12-09 05:57:28 +08:00
|
|
|
for (unsigned Idx : MissingVars.set_bits())
|
2018-06-27 02:54:10 +08:00
|
|
|
dbg() << "WARNING: Missing variable " << Idx + 1 << "\n";
|
2017-12-09 05:57:28 +08:00
|
|
|
|
2018-07-24 08:41:29 +08:00
|
|
|
// Update DI loss statistics.
|
|
|
|
if (Stats) {
|
|
|
|
Stats->NumDbgLocsExpected += OriginalNumLines;
|
|
|
|
Stats->NumDbgLocsMissing += MissingLines.count();
|
|
|
|
Stats->NumDbgValuesExpected += OriginalNumVars;
|
|
|
|
Stats->NumDbgValuesMissing += MissingVars.count();
|
|
|
|
}
|
|
|
|
|
2018-06-07 03:05:41 +08:00
|
|
|
dbg() << Banner;
|
2018-05-25 07:00:22 +08:00
|
|
|
if (!NameOfWrappedPass.empty())
|
2018-06-07 03:05:41 +08:00
|
|
|
dbg() << " [" << NameOfWrappedPass << "]";
|
|
|
|
dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
// Strip the Debugify Metadata if required.
|
|
|
|
if (Strip) {
|
|
|
|
StripDebugInfo(M);
|
|
|
|
M.eraseNamedMetadata(NMD);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2017-12-09 05:57:28 +08:00
|
|
|
}
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
/// ModulePass for attaching synthetic debug info to everything, used with the
|
|
|
|
/// legacy module pass manager.
|
|
|
|
struct DebugifyModulePass : public ModulePass {
|
|
|
|
bool runOnModule(Module &M) override {
|
|
|
|
return applyDebugifyMetadata(M, M.functions(), "ModuleDebugify: ");
|
|
|
|
}
|
2017-12-09 05:57:28 +08:00
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
DebugifyModulePass() : ModulePass(ID) {}
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification.
|
|
|
|
};
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
/// FunctionPass for attaching synthetic debug info to instructions within a
|
|
|
|
/// single function, used with the legacy module pass manager.
|
|
|
|
struct DebugifyFunctionPass : public FunctionPass {
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
Module &M = *F.getParent();
|
|
|
|
auto FuncIt = F.getIterator();
|
|
|
|
return applyDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
|
2018-06-05 08:56:07 +08:00
|
|
|
"FunctionDebugify: ");
|
2018-05-15 08:29:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DebugifyFunctionPass() : FunctionPass(ID) {}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ModulePass for checking debug info inserted by -debugify, used with the
|
|
|
|
/// legacy module pass manager.
|
|
|
|
struct CheckDebugifyModulePass : public ModulePass {
|
2017-12-09 05:57:28 +08:00
|
|
|
bool runOnModule(Module &M) override {
|
2018-05-16 07:38:05 +08:00
|
|
|
return checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
|
2018-07-24 08:41:29 +08:00
|
|
|
"CheckModuleDebugify", Strip, StatsMap);
|
2017-12-09 05:57:28 +08:00
|
|
|
}
|
|
|
|
|
2018-07-24 08:41:29 +08:00
|
|
|
CheckDebugifyModulePass(bool Strip = false, StringRef NameOfWrappedPass = "",
|
|
|
|
DebugifyStatsMap *StatsMap = nullptr)
|
|
|
|
: ModulePass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
|
|
|
|
StatsMap(StatsMap) {}
|
2018-05-15 08:29:27 +08:00
|
|
|
|
2018-06-05 05:43:28 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
static char ID; // Pass identification.
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool Strip;
|
2018-05-16 07:38:05 +08:00
|
|
|
StringRef NameOfWrappedPass;
|
2018-07-24 08:41:29 +08:00
|
|
|
DebugifyStatsMap *StatsMap;
|
2018-05-15 08:29:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// FunctionPass for checking debug info inserted by -debugify-function, used
|
|
|
|
/// with the legacy module pass manager.
|
|
|
|
struct CheckDebugifyFunctionPass : public FunctionPass {
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
Module &M = *F.getParent();
|
|
|
|
auto FuncIt = F.getIterator();
|
|
|
|
return checkDebugifyMetadata(M, make_range(FuncIt, std::next(FuncIt)),
|
2018-05-25 07:00:23 +08:00
|
|
|
NameOfWrappedPass, "CheckFunctionDebugify",
|
2018-07-24 08:41:29 +08:00
|
|
|
Strip, StatsMap);
|
2018-05-15 08:29:27 +08:00
|
|
|
}
|
|
|
|
|
2018-05-25 07:00:23 +08:00
|
|
|
CheckDebugifyFunctionPass(bool Strip = false,
|
2018-07-24 08:41:29 +08:00
|
|
|
StringRef NameOfWrappedPass = "",
|
|
|
|
DebugifyStatsMap *StatsMap = nullptr)
|
|
|
|
: FunctionPass(ID), Strip(Strip), NameOfWrappedPass(NameOfWrappedPass),
|
|
|
|
StatsMap(StatsMap) {}
|
2017-12-09 05:57:28 +08:00
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ID; // Pass identification.
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool Strip;
|
2018-05-16 07:38:05 +08:00
|
|
|
StringRef NameOfWrappedPass;
|
2018-07-24 08:41:29 +08:00
|
|
|
DebugifyStatsMap *StatsMap;
|
2017-12-09 05:57:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2018-06-05 08:56:07 +08:00
|
|
|
ModulePass *createDebugifyModulePass() { return new DebugifyModulePass(); }
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
FunctionPass *createDebugifyFunctionPass() {
|
|
|
|
return new DebugifyFunctionPass();
|
|
|
|
}
|
2018-01-24 04:43:50 +08:00
|
|
|
|
2018-02-16 05:14:36 +08:00
|
|
|
PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
|
2018-05-15 08:29:27 +08:00
|
|
|
applyDebugifyMetadata(M, M.functions(), "ModuleDebugify: ");
|
2018-02-16 05:14:36 +08:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2018-06-04 08:11:47 +08:00
|
|
|
ModulePass *createCheckDebugifyModulePass(bool Strip,
|
2018-07-24 08:41:29 +08:00
|
|
|
StringRef NameOfWrappedPass,
|
|
|
|
DebugifyStatsMap *StatsMap) {
|
|
|
|
return new CheckDebugifyModulePass(Strip, NameOfWrappedPass, StatsMap);
|
2018-05-15 08:29:27 +08:00
|
|
|
}
|
|
|
|
|
2018-06-04 08:11:47 +08:00
|
|
|
FunctionPass *createCheckDebugifyFunctionPass(bool Strip,
|
2018-07-24 08:41:29 +08:00
|
|
|
StringRef NameOfWrappedPass,
|
|
|
|
DebugifyStatsMap *StatsMap) {
|
|
|
|
return new CheckDebugifyFunctionPass(Strip, NameOfWrappedPass, StatsMap);
|
2018-05-15 08:29:27 +08:00
|
|
|
}
|
2018-01-24 04:43:50 +08:00
|
|
|
|
2018-02-16 05:14:36 +08:00
|
|
|
PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
|
|
|
|
ModuleAnalysisManager &) {
|
2018-07-24 08:41:29 +08:00
|
|
|
checkDebugifyMetadata(M, M.functions(), "", "CheckModuleDebugify", false,
|
|
|
|
nullptr);
|
2018-02-16 05:14:36 +08:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
char DebugifyModulePass::ID = 0;
|
|
|
|
static RegisterPass<DebugifyModulePass> DM("debugify",
|
2018-06-04 08:11:47 +08:00
|
|
|
"Attach debug info to everything");
|
2017-12-09 05:57:28 +08:00
|
|
|
|
2018-05-15 08:29:27 +08:00
|
|
|
char CheckDebugifyModulePass::ID = 0;
|
2018-06-04 08:11:47 +08:00
|
|
|
static RegisterPass<CheckDebugifyModulePass>
|
|
|
|
CDM("check-debugify", "Check debug info from -debugify");
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
char DebugifyFunctionPass::ID = 0;
|
|
|
|
static RegisterPass<DebugifyFunctionPass> DF("debugify-function",
|
2018-06-04 08:11:47 +08:00
|
|
|
"Attach debug info to a function");
|
2018-05-15 08:29:27 +08:00
|
|
|
|
|
|
|
char CheckDebugifyFunctionPass::ID = 0;
|
2018-06-04 08:11:47 +08:00
|
|
|
static RegisterPass<CheckDebugifyFunctionPass>
|
|
|
|
CDF("check-debugify-function", "Check debug info from -debugify-function");
|