[DebugInfo][RemoveDIs] Rip out the UseNewDbgInfoFormat flag (#143207)

Start removing debug intrinsics support -- starting with the flag that
controls production of their replacement, debug records. This patch
removes the command-line-flag and with it the ability to switch back to
intrinsics. The module / function / block level "IsNewDbgInfoFormat"
flags get hardcoded to true, I'll to incrementally remove things that
depend on those flags.
This commit is contained in:
Jeremy Morse
2025-06-09 19:36:34 +01:00
committed by GitHub
parent 7f08503a3b
commit 0e4b8b8f81
27 changed files with 69 additions and 263 deletions

View File

@@ -1,8 +1,6 @@
// REQUIRES: asserts
// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | \
// RUN: FileCheck %s
// RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm -mllvm --experimental-debuginfo-iterators=true %s -o - | \
// RUN: FileCheck %s
// This test simply checks that the varargs thunk is created. The failing test
// case asserts.

View File

@@ -1,6 +1,5 @@
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -mllvm --experimental-debuginfo-iterators=true -o - | FileCheck %s --check-prefixes=BOTH,RECORDS
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -mllvm --experimental-debuginfo-iterators=false -o - | FileCheck --check-prefix=LINEONLY %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -mllvm --experimental-debuginfo-iterators=true -o - | FileCheck --check-prefix=LINEONLY %s
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s --check-prefixes=BOTH,RECORDS
! RUN: %flang_fc1 -emit-llvm -debug-info-kind=line-tables-only %s -o - | FileCheck --check-prefix=LINEONLY %s
! This tests checks the debug information for local variables in llvm IR.

View File

@@ -87,8 +87,7 @@ public:
/// Convert variable location debugging information stored in dbg.value
/// intrinsics into DbgMarkers / DbgRecords. Deletes all dbg.values in
/// the process and sets IsNewDbgInfoFormat = true. Only takes effect if
/// the UseNewDbgInfoFormat LLVM command line option is given.
/// the process and sets IsNewDbgInfoFormat = true.
LLVM_ABI void convertToNewDbgValues();
/// Convert variable location debugging information stored in DbgMarkers and

View File

@@ -22,8 +22,6 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PrettyStackTrace.h"
LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
namespace llvm {
template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
@@ -67,7 +65,7 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
// RemoveDIs: if requested, convert debug-info to DbgRecord representation
// for duration of these passes.
ScopedDbgInfoFormatSetter FormatSetter(IR, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(IR, true);
StackTraceEntry Entry(PI, IR);
for (auto &Pass : Passes) {

View File

@@ -64,8 +64,6 @@ static cl::opt<bool> AllowIncompleteIR(
"Allow incomplete IR on a best effort basis (references to unknown "
"metadata will be dropped)"));
LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
static std::string getTypeString(Type *T) {
std::string Result;
raw_string_ostream Tmp(Result);
@@ -443,7 +441,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
UpgradeNVVMAnnotations(*M);
UpgradeSectionAttributes(*M);
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
M->setIsNewDbgInfoFormat(true);
if (!Slots)
return false;

View File

@@ -101,8 +101,6 @@ static cl::opt<bool> ExpandConstantExprs(
cl::desc(
"Expand constant expressions to instructions for testing purposes"));
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
namespace {
enum {
@@ -4481,9 +4479,9 @@ Error BitcodeReader::parseGlobalIndirectSymbolRecord(
Error BitcodeReader::parseModule(uint64_t ResumeBit,
bool ShouldLazyLoadMetadata,
ParserCallbacks Callbacks) {
// In preparation for the deletion of debug-intrinsics, don't allow module
// loading to escape intrinsics being autoupgraded to debug records.
TheModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
// Don't allow modules to use debug-intrinsics: autoupgrading them is now
// mandatory.
TheModule->IsNewDbgInfoFormat = true;
this->ValueTypeCallback = std::move(Callbacks.ValueType);
if (ResumeBit) {

View File

@@ -122,8 +122,6 @@ namespace llvm {
extern FunctionSummary::ForceSummaryHotnessType ForceSummaryEdgesCold;
}
LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
namespace {
/// These are manifest constants used by the bitcode writer. They do not need to

View File

@@ -70,8 +70,6 @@ static cl::opt<bool> SimplifyMIR(
static cl::opt<bool> PrintLocations("mir-debug-loc", cl::Hidden, cl::init(true),
cl::desc("Print MIR debug-locations"));
extern cl::opt<bool> UseNewDbgInfoFormat;
namespace {
/// This structure describes how to print out stack object references.
@@ -967,8 +965,7 @@ void MIRFormatter::printIRValue(raw_ostream &OS, const Value &V,
}
void llvm::printMIR(raw_ostream &OS, const Module &M) {
ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M),
UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M), true);
yaml::Output Out(OS);
Out << const_cast<Module &>(M);
@@ -979,6 +976,6 @@ void llvm::printMIR(raw_ostream &OS, const MachineModuleInfo &MMI,
// RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info
// in dbg.value format.
ScopedDbgInfoFormatSetter FormatSetter(
const_cast<Function &>(MF.getFunction()), UseNewDbgInfoFormat);
const_cast<Function &>(MF.getFunction()), true);
printMF(OS, MMI, MF);
}

View File

@@ -31,30 +31,6 @@ using namespace llvm;
#define DEBUG_TYPE "ir"
STATISTIC(NumInstrRenumberings, "Number of renumberings across all blocks");
// This cl-opt exists to control whether variable-location information is
// produced using intrinsics, or whether DbgRecords are produced. However,
// it's imminently being phased out, so give it a flag-name that is very
// unlikely to be used anywhere.
//
// If you find yourself needing to use this flag for any period longer than
// five minutes, please revert the patch making this change, and make contact
// in this discourse post, where we can discuss any further transition work
// that might be needed to remove debug intrinsics.
//
// https://discourse.llvm.org/t/psa-ir-output-changing-from-debug-intrinsics-to-debug-records/79578
LLVM_ABI cl::opt<bool>
UseNewDbgInfoFormat("dont-pass-this-flag-please-experimental-debuginfo",
cl::Hidden, cl::init(true));
// This cl-opt collects the --experimental-debuginfo-iterators flag and then
// does nothing with it (because the it gets stored into an otherwise unused
// cl-opt), so that we can disable debug-intrinsic production without
// immediately modifying lots of tests. If your tests break because of this
// change, please see the next comment up.
static cl::opt<bool> DeliberatelyUnseenDbgInfoFlag(
"experimental-debuginfo-iterators", cl::Hidden,
cl::init(true));
DbgMarker *BasicBlock::createMarker(Instruction *I) {
assert(IsNewDbgInfoFormat &&
"Tried to create a marker in a non new debug-info block!");
@@ -187,7 +163,7 @@ template class llvm::SymbolTableListTraits<
BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
BasicBlock *InsertBefore)
: Value(Type::getLabelTy(C), Value::BasicBlockVal),
IsNewDbgInfoFormat(UseNewDbgInfoFormat), Parent(nullptr) {
IsNewDbgInfoFormat(true), Parent(nullptr) {
if (NewParent)
insertInto(NewParent, InsertBefore);

View File

@@ -65,8 +65,6 @@ static cl::opt<int> NonGlobalValueMaxNameSize(
"non-global-value-max-name-size", cl::Hidden, cl::init(1024),
cl::desc("Maximum size for the name of non-global values."));
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
void Function::renumberBlocks() {
validateBlockNumbers();
@@ -492,7 +490,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace,
const Twine &name, Module *ParentModule)
: GlobalObject(Ty, Value::FunctionVal, AllocMarker, Linkage, name,
computeAddrSpace(AddrSpace, ParentModule)),
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
NumArgs(Ty->getNumParams()), IsNewDbgInfoFormat(true) {
assert(FunctionType::isValidReturnType(getReturnType()) &&
"invalid return type");
setGlobalObjectSubClassData(0);

View File

@@ -24,8 +24,6 @@
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
namespace {
class PrintModulePassWrapper : public ModulePass {
@@ -42,12 +40,10 @@ public:
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
bool runOnModule(Module &M) override {
ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(M, true);
// Remove intrinsic declarations when printing in the new format.
// TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to
// update test output.
if (UseNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
// TODO: consider removing this as debug-intrinsics are gone.
M.removeDebugIntrinsicDeclarations();
if (llvm::isFunctionInPrintList("*")) {
if (!Banner.empty())
@@ -88,7 +84,7 @@ public:
// This pass just prints a banner followed by the function as it's processed.
bool runOnFunction(Function &F) override {
ScopedDbgInfoFormatSetter FormatSetter(F, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(F, true);
if (isFunctionInPrintList(F.getName())) {
if (forcePrintModuleIR())

View File

@@ -130,8 +130,6 @@ BasicBlock::iterator Instruction::insertInto(BasicBlock *ParentBB,
return getIterator();
}
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
void Instruction::insertBefore(BasicBlock &BB,
InstListType::iterator InsertPos) {
assert(!DebugMarker);

View File

@@ -32,7 +32,6 @@
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
// See PassManagers.h for Pass Manager infrastructure overview.
//===----------------------------------------------------------------------===//
@@ -530,7 +529,7 @@ bool PassManagerImpl::run(Module &M) {
// RemoveDIs: if a command line flag is given, convert to the
// DbgVariableRecord representation of debug-info for the duration of these
// passes.
ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(M, true);
for (ImmutablePass *ImPass : getImmutablePasses())
Changed |= ImPass->doInitialization(M);

View File

@@ -54,8 +54,6 @@
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
//===----------------------------------------------------------------------===//
// Methods to implement the globals and functions lists.
//
@@ -74,7 +72,7 @@ template class LLVM_EXPORT_TEMPLATE llvm::SymbolTableListTraits<GlobalIFunc>;
Module::Module(StringRef MID, LLVMContext &C)
: Context(C), ValSymTab(std::make_unique<ValueSymbolTable>(-1)),
ModuleID(std::string(MID)), SourceFileName(std::string(MID)),
IsNewDbgInfoFormat(UseNewDbgInfoFormat) {
IsNewDbgInfoFormat(true) {
Context.addModule(this);
}

View File

@@ -23,8 +23,6 @@
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
PrintModulePass::PrintModulePass() : OS(dbgs()) {}
PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
bool ShouldPreserveUseListOrder,
@@ -34,12 +32,10 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
EmitSummaryIndex(EmitSummaryIndex) {}
PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) {
ScopedDbgInfoFormatSetter FormatSetter(M, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(M, true);
// Remove intrinsic declarations when printing in the new format.
// TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to
// update test output.
if (UseNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
// TODO: consider removing this now that debug intrinsics are gone.
M.removeDebugIntrinsicDeclarations();
if (llvm::isFunctionInPrintList("*")) {
if (!Banner.empty())
@@ -76,7 +72,7 @@ PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)
PreservedAnalyses PrintFunctionPass::run(Function &F,
FunctionAnalysisManager &) {
ScopedDbgInfoFormatSetter FormatSetter(F, UseNewDbgInfoFormat);
ScopedDbgInfoFormatSetter FormatSetter(F, true);
if (isFunctionInPrintList(F.getName())) {
if (forcePrintModuleIR())

View File

@@ -70,8 +70,6 @@ using namespace object;
#define DEBUG_TYPE "lto"
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
static cl::opt<bool>
DumpThinCGSCCs("dump-thin-cg-sccs", cl::init(false), cl::Hidden,
cl::desc("Dump the SCCs in the ThinLTO index's callgraph"));
@@ -602,7 +600,7 @@ LTO::RegularLTOState::RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
: ParallelCodeGenParallelismLevel(ParallelCodeGenParallelismLevel),
Ctx(Conf), CombinedModule(std::make_unique<Module>("ld-temp.o", Ctx)),
Mover(std::make_unique<IRMover>(*CombinedModule)) {
CombinedModule->IsNewDbgInfoFormat = UseNewDbgInfoFormat;
CombinedModule->IsNewDbgInfoFormat = true;
}
LTO::ThinLTOState::ThinLTOState(ThinBackend BackendParam)

View File

@@ -41,8 +41,6 @@
using namespace llvm;
extern cl::opt<bool> UseNewDbgInfoFormat;
#define DEBUG_TYPE "coro-frame"
namespace {
@@ -842,18 +840,12 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
DILocation::get(DIS->getContext(), LineNum, /*Column=*/1, DIS);
assert(FrameDIVar->isValidLocationForIntrinsic(DILoc));
if (UseNewDbgInfoFormat) {
DbgVariableRecord *NewDVR =
new DbgVariableRecord(ValueAsMetadata::get(Shape.FramePtr), FrameDIVar,
DBuilder.createExpression(), DILoc,
DbgVariableRecord::LocationType::Declare);
BasicBlock::iterator It = Shape.getInsertPtAfterFramePtr();
It->getParent()->insertDbgRecordBefore(NewDVR, It);
} else {
DBuilder.insertDeclare(Shape.FramePtr, FrameDIVar,
DBuilder.createExpression(), DILoc,
Shape.getInsertPtAfterFramePtr());
}
DbgVariableRecord *NewDVR =
new DbgVariableRecord(ValueAsMetadata::get(Shape.FramePtr), FrameDIVar,
DBuilder.createExpression(), DILoc,
DbgVariableRecord::LocationType::Declare);
BasicBlock::iterator It = Shape.getInsertPtAfterFramePtr();
It->getParent()->insertDbgRecordBefore(NewDVR, It);
}
// Build a struct that will keep state for an active coroutine.
@@ -1136,19 +1128,12 @@ static void insertSpills(const FrameDataInfo &FrameData, coro::Shape &Shape) {
// This dbg.declare is preserved for all coro-split function
// fragments. It will be unreachable in the main function, and
// processed by coro::salvageDebugInfo() by the Cloner.
if (UseNewDbgInfoFormat) {
DbgVariableRecord *NewDVR = new DbgVariableRecord(
ValueAsMetadata::get(CurrentReload), DDI->getVariable(),
DDI->getExpression(), DDI->getDebugLoc(),
DbgVariableRecord::LocationType::Declare);
Builder.GetInsertPoint()->getParent()->insertDbgRecordBefore(
NewDVR, Builder.GetInsertPoint());
} else {
DIBuilder(*CurrentBlock->getParent()->getParent(), AllowUnresolved)
.insertDeclare(CurrentReload, DDI->getVariable(),
DDI->getExpression(), DDI->getDebugLoc(),
Builder.GetInsertPoint());
}
DbgVariableRecord *NewDVR = new DbgVariableRecord(
ValueAsMetadata::get(CurrentReload), DDI->getVariable(),
DDI->getExpression(), DDI->getDebugLoc(),
DbgVariableRecord::LocationType::Declare);
Builder.GetInsertPoint()->getParent()->insertDbgRecordBefore(
NewDVR, Builder.GetInsertPoint());
// This dbg.declare is for the main function entry point. It
// will be deleted in all coro-split functions.
coro::salvageDebugInfo(ArgToAllocaMap, *DDI, false /*UseEntryValue*/);

View File

@@ -88,8 +88,6 @@
using namespace llvm;
using namespace llvm::PatternMatch;
extern cl::opt<bool> UseNewDbgInfoFormat;
#define DEBUG_TYPE "local"
STATISTIC(NumRemoved, "Number of unreachable basic blocks removed");
@@ -1691,16 +1689,10 @@ static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV,
DIExpression *DIExpr,
const DebugLoc &NewLoc,
BasicBlock::iterator Instr) {
if (!UseNewDbgInfoFormat) {
Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc, Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
// DbgVariableRecord directly instead of a dbg.value intrinsic.
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
DbgVariableRecord *DV =
new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
Instr->getParent()->insertDbgRecordBefore(DV, Instr);
}
ValueAsMetadata *DVAM = ValueAsMetadata::get(DV);
DbgVariableRecord *DVRec =
new DbgVariableRecord(DVAM, DIVar, DIExpr, NewLoc.get());
Instr->getParent()->insertDbgRecordBefore(DVRec, Instr);
}
static void insertDbgValueOrDbgVariableRecordAfter(
@@ -1838,7 +1830,6 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR,
// then we want to insert a dbg.value for the corresponding fragment.
LLVM_DEBUG(dbgs() << "Failed to convert dbg.declare to dbg.value: " << *DVR
<< '\n');
assert(UseNewDbgInfoFormat);
// For now, when there is a store to parts of the variable (but we do not
// know which part) we insert an dbg.value intrinsic to indicate that we
@@ -1919,7 +1910,6 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgVariableRecord *DVR, LoadInst *LI,
// future if multi-location support is added to the IR, it might be
// preferable to keep tracking both the loaded value and the original
// address in case the alloca can not be elided.
assert(UseNewDbgInfoFormat);
// Create a DbgVariableRecord directly and insert.
ValueAsMetadata *LIVAM = ValueAsMetadata::get(LI);

View File

@@ -66,7 +66,6 @@ static cl::opt<std::string> ClDataLayout("data-layout",
cl::desc("data layout string to use"),
cl::value_desc("layout-string"),
cl::init(""), cl::cat(AsCat));
extern cl::opt<bool> UseNewDbgInfoFormat;
static void WriteOutputFile(const Module *M, const ModuleSummaryIndex *Index) {
// Infer the output filename if needed.
@@ -140,10 +139,8 @@ int main(int argc, char **argv) {
return 1;
}
// Convert to new debug format if requested.
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
if (M->IsNewDbgInfoFormat)
M->removeDebugIntrinsicDeclarations();
M->setIsNewDbgInfoFormat(true);
M->removeDebugIntrinsicDeclarations();
std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);

View File

@@ -96,8 +96,6 @@ static cl::opt<bool> PrintThinLTOIndexOnly(
cl::desc("Only read thinlto index and print the index as LLVM assembly."),
cl::init(false), cl::Hidden, cl::cat(DisCategory));
extern cl::opt<bool> UseNewDbgInfoFormat;
namespace {
static void printDebugLoc(const DebugLoc &DL, formatted_raw_ostream &OS) {
@@ -270,9 +268,8 @@ int main(int argc, char **argv) {
// All that llvm-dis does is write the assembly to a file.
if (!DontPrint) {
if (M) {
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
if (UseNewDbgInfoFormat)
M->removeDebugIntrinsicDeclarations();
M->setIsNewDbgInfoFormat(true);
M->removeDebugIntrinsicDeclarations();
M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);
}
if (Index)

View File

@@ -129,8 +129,6 @@ static cl::opt<bool> IgnoreNonBitcode(
cl::desc("Do not report an error for non-bitcode files in archives"),
cl::Hidden);
extern cl::opt<bool> UseNewDbgInfoFormat;
static ExitOnError ExitOnErr;
// Read the specified bitcode file in and return it. This routine searches the
@@ -531,10 +529,10 @@ int main(int argc, char **argv) {
Composite->removeDebugIntrinsicDeclarations();
};
if (OutputAssembly) {
SetFormat(UseNewDbgInfoFormat);
SetFormat(true);
Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
} else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
SetFormat(UseNewDbgInfoFormat);
SetFormat(true);
WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
}

View File

@@ -24,9 +24,6 @@
using namespace llvm;
using namespace IRSimilarity;
LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
static std::unique_ptr<Module> makeLLVMModule(LLVMContext &Context,
StringRef ModuleStr) {
SMDiagnostic Err;

View File

@@ -27,8 +27,6 @@
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
SMDiagnostic Err;
std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
@@ -241,8 +239,6 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
// Duplicate of above test, but in DbgVariableRecord representation.
TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
LLVMContext C;
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = true;
std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
@@ -285,23 +281,19 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
EXPECT_EQ(DVRs[1]->getNumVariableLocationOps(), 2u);
EXPECT_TRUE(isa<UndefValue>(DVRs[1]->getVariableLocationOp(1)));
EXPECT_TRUE(DVRs[1]->isKillLocation());
UseNewDbgInfoFormat = OldDbgValueMode;
}
// Ensure that the order of dbg.value intrinsics returned by findDbgValues, and
// their corresponding DbgVariableRecord representation, are consistent.
TEST(MetadataTest, OrderingOfDbgVariableRecords) {
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
LLVMContext C;
std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
%b = add i16 %a, 1, !dbg !11
call void @llvm.dbg.value(metadata i16 %b, metadata !9, metadata !DIExpression()), !dbg !11
call void @llvm.dbg.value(metadata i16 %b, metadata !12, metadata !DIExpression()), !dbg !11
#dbg_value(i16 %b, !9, !DIExpression(), !11)
#dbg_value(i16 %b, !12, !DIExpression(), !11)
ret i16 0, !dbg !11
}
declare void @llvm.dbg.value(metadata, metadata, metadata) #0
attributes #0 = { nounwind readnone speculatable willreturn }
!llvm.dbg.cu = !{!0}
@@ -324,33 +316,20 @@ TEST(MetadataTest, OrderingOfDbgVariableRecords) {
SmallVector<DbgValueInst *, 2> DVIs;
SmallVector<DbgVariableRecord *, 2> DVRs;
findDbgValues(DVIs, &I, &DVRs);
ASSERT_EQ(DVIs.size(), 2u);
ASSERT_EQ(DVRs.size(), 0u);
// The correct order of dbg.values is given by their use-list, which becomes
// the reverse order of creation. Thus the dbg.values should come out as
// "bar" and then "foo".
DILocalVariable *Var0 = DVIs[0]->getVariable();
EXPECT_TRUE(Var0->getName() == "bar");
DILocalVariable *Var1 = DVIs[1]->getVariable();
EXPECT_TRUE(Var1->getName() == "foo");
// Now try again, but in DbgVariableRecord form.
DVIs.clear();
M->convertToNewDbgValues();
findDbgValues(DVIs, &I, &DVRs);
ASSERT_EQ(DVIs.size(), 0u);
ASSERT_EQ(DVRs.size(), 2u);
Var0 = DVRs[0]->getVariable();
// The correct order of dbg.values is given by their use-list, which becomes
// the reverse order of creation. Thus the dbg.values should come out as
// "bar" and then "foo".
const DILocalVariable *Var0 = DVRs[0]->getVariable();
EXPECT_TRUE(Var0->getName() == "bar");
Var1 = DVRs[1]->getVariable();
const DILocalVariable *Var1 = DVRs[1]->getVariable();
EXPECT_TRUE(Var1->getName() == "foo");
M->convertFromNewDbgValues();
UseNewDbgInfoFormat = OldDbgValueMode;
}
TEST(DIBuilder, CreateFile) {
@@ -923,8 +902,6 @@ TEST(AssignmentTrackingTest, InstrMethods) {
// dbg.values that have been converted to a non-instruction format.
TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
LLVMContext C;
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -954,6 +931,12 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
!11 = !DILocation(line: 1, column: 1, scope: !6)
)");
// The IR above will be autoupgraded to debug records: but this test is about
// the conversion routines, so convert it back. This test will have value
// going forwards for the purpose of testing the conversion routine, which
// some compatibility tools (DXIL?) wish to use.
M->convertFromNewDbgValues();
// Find the first dbg.value,
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHIIt();
const DILocalVariable *Var = nullptr;
@@ -1099,15 +1082,11 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
// The record of those trailing DbgVariableRecords would dangle and cause an
// assertion failure if it lived until the end of the LLVMContext.
ExitBlock->deleteTrailingDbgRecords();
UseNewDbgInfoFormat = OldDbgValueMode;
}
TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
LLVMContext C;
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -1137,13 +1116,13 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
!11 = !DILocation(line: 1, column: 1, scope: !6)
)");
// For the purpose of this test, set and un-set the command line option
// corresponding to UseNewDbgInfoFormat, but only after parsing, to ensure
// that the IR starts off in the old format.
UseNewDbgInfoFormat = true;
// This test exists to check we can convert back and forth between old and new
// debug info formats (dbg.value intrinsics versus #dbg_value records).
// We're ripping out support for debug intrinsics, but the conversions will
// live on in bitcode autoupgrade and possibly DXIL autodowngrade. Thus, this
// test is still valuable. Begin by starting in the intrinsic format:
M->convertFromNewDbgValues();
// Check that the conversion routines and utilities between dbg.value
// debug-info format and DbgVariableRecords works.
Function *F = M->getFunction("f");
BasicBlock *BB1 = &F->getEntryBlock();
// First instruction should be a dbg.value.
@@ -1245,8 +1224,6 @@ TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
EXPECT_EQ(DVI1->getExpression(), Expr1);
EXPECT_EQ(DVI2->getVariable(), DLV2);
EXPECT_EQ(DVI2->getExpression(), Expr2);
UseNewDbgInfoFormat = OldDbgValueMode;
}
// Test that the hashing function for DISubprograms representing methods produce

View File

@@ -33,8 +33,6 @@
#include "gtest/gtest.h"
#include <memory>
LLVM_ABI extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
namespace llvm {
namespace {
@@ -1452,8 +1450,6 @@ TEST(InstructionsTest, GetSplat) {
TEST(InstructionsTest, SkipDebug) {
LLVMContext C;
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
std::unique_ptr<Module> M = parseIR(C,
R"(
declare void @llvm.dbg.value(metadata, metadata, metadata)
@@ -1480,6 +1476,8 @@ TEST(InstructionsTest, SkipDebug) {
)");
ASSERT_TRUE(M);
Function *F = cast<Function>(M->getNamedValue("f"));
// This test wants to see dbg.values.
F->convertFromNewDbgValues();
BasicBlock &BB = F->front();
// The first non-debug instruction is the terminator.
@@ -1489,7 +1487,6 @@ TEST(InstructionsTest, SkipDebug) {
// After the terminator, there are no non-debug instructions.
EXPECT_EQ(nullptr, Term->getNextNonDebugInstruction());
UseNewDbgInfoFormat = OldDbgValueMode;
}
TEST(InstructionsTest, PhiMightNotBeFPMathOperator) {

View File

@@ -20,8 +20,6 @@
#include "gtest/gtest.h"
using namespace llvm;
LLVM_ABI extern cl::opt<bool> UseNewDbgInfoFormat;
namespace {
TEST(ValueTest, UsedInBasicBlock) {
@@ -256,74 +254,6 @@ TEST(ValueTest, getLocalSlotDeath) {
#endif
TEST(ValueTest, replaceUsesOutsideBlock) {
// Check that Value::replaceUsesOutsideBlock(New, BB) replaces uses outside
// BB, including dbg.* uses of MetadataAsValue(ValueAsMetadata(this)).
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
const auto *IR = R"(
define i32 @f() !dbg !6 {
entry:
%a = add i32 0, 1, !dbg !15
%b = add i32 0, 2, !dbg !15
%c = add i32 %a, 2, !dbg !15
call void @llvm.dbg.value(metadata i32 %a, metadata !9, metadata !DIExpression()), !dbg !15
br label %exit, !dbg !15
exit:
call void @llvm.dbg.value(metadata i32 %a, metadata !11, metadata !DIExpression()), !dbg !16
ret i32 %a, !dbg !16
}
declare void @llvm.dbg.value(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!5}
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "test.ll", directory: "/")
!2 = !{}
!5 = !{i32 2, !"Debug Info Version", i32 3}
!6 = distinct !DISubprogram(name: "f", linkageName: "f", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
!7 = !DISubroutineType(types: !2)
!8 = !{!9, !11}
!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
!10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_signed)
!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 2, type: !12)
!12 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_signed)
!15 = !DILocation(line: 1, column: 1, scope: !6)
!16 = !DILocation(line: 5, column: 1, scope: !6)
)";
LLVMContext Ctx;
SMDiagnostic Err;
std::unique_ptr<Module> M = parseAssemblyString(IR, Err, Ctx);
if (!M)
Err.print("ValueTest", errs());
auto GetNext = [](auto *I) { return &*++I->getIterator(); };
Function *F = M->getFunction("f");
// Entry.
BasicBlock *Entry = &F->front();
Instruction *A = &Entry->front();
Instruction *B = GetNext(A);
Instruction *C = GetNext(B);
auto *EntryDbg = cast<DbgValueInst>(GetNext(C));
// Exit.
BasicBlock *Exit = GetNext(Entry);
auto *ExitDbg = cast<DbgValueInst>(&Exit->front());
Instruction *Ret = GetNext(ExitDbg);
A->replaceUsesOutsideBlock(B, Entry);
// These users are in Entry so shouldn't be changed.
ASSERT_TRUE(C->getOperand(0) == cast<Value>(A));
ASSERT_TRUE(EntryDbg->getValue(0) == cast<Value>(A));
// These users are outside Entry so should be changed.
ASSERT_TRUE(ExitDbg->getValue(0) == cast<Value>(B));
ASSERT_TRUE(Ret->getOperand(0) == cast<Value>(B));
UseNewDbgInfoFormat = OldDbgValueMode;
}
TEST(ValueTest, replaceUsesOutsideBlockDbgVariableRecord) {
// Check that Value::replaceUsesOutsideBlock(New, BB) replaces uses outside
// BB, including DbgVariableRecords.
const auto *IR = R"(

View File

@@ -20,8 +20,6 @@
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
using namespace mlir;
namespace mlir {
@@ -37,10 +35,8 @@ void registerToLLVMIRTranslation() {
// When printing LLVM IR, we should convert the module to the debug info
// format that LLVM expects us to print.
// See https://llvm.org/docs/RemoveDIsDebugInfo.html
llvm::ScopedDbgInfoFormatSetter formatSetter(*llvmModule,
UseNewDbgInfoFormat);
if (UseNewDbgInfoFormat)
llvmModule->removeDebugIntrinsicDeclarations();
llvm::ScopedDbgInfoFormatSetter formatSetter(*llvmModule, true);
llvmModule->removeDebugIntrinsicDeclarations();
llvmModule->print(output, nullptr);
return success();
},

View File

@@ -67,8 +67,6 @@ using namespace mlir;
using namespace mlir::LLVM;
using namespace mlir::LLVM::detail;
extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
namespace {
@@ -2328,7 +2326,7 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
// Once we've finished constructing elements in the module, we should convert
// it to use the debug info format desired by LLVM.
// See https://llvm.org/docs/RemoveDIsDebugInfo.html
translator.llvmModule->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
translator.llvmModule->setIsNewDbgInfoFormat(true);
// Add the necessary debug info module flags, if they were not encoded in MLIR
// beforehand.