Skip to content

[DebugInfo][RemoveDIs] Remove scoped-dbg-format-setter #143450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,25 +692,6 @@ getDbgRecordRange(DbgMarker *DebugMarker) {

DEFINE_ISA_CONVERSION_FUNCTIONS(DbgRecord, LLVMDbgRecordRef)

/// Used to temporarily set the debug info format of a function, module, or
/// basic block for the duration of this object's lifetime, after which the
/// prior state will be restored.
template <typename T> class ScopedDbgInfoFormatSetter {
T &Obj;
bool OldState;

public:
ScopedDbgInfoFormatSetter(T &Obj, bool NewState)
: Obj(Obj), OldState(Obj.IsNewDbgInfoFormat) {
Obj.setIsNewDbgInfoFormat(NewState);
}
~ScopedDbgInfoFormatSetter() { Obj.setIsNewDbgInfoFormat(OldState); }
};

template <typename T>
ScopedDbgInfoFormatSetter(T &Obj,
bool NewState) -> ScopedDbgInfoFormatSetter<T>;

} // namespace llvm

#endif // LLVM_IR_DEBUGPROGRAMINSTRUCTION_H
4 changes: 0 additions & 4 deletions llvm/include/llvm/IR/PassManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
detail::getAnalysisResult<PassInstrumentationAnalysis>(
AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));

// RemoveDIs: if requested, convert debug-info to DbgRecord representation
// for duration of these passes.
ScopedDbgInfoFormatSetter FormatSetter(IR, true);

StackTraceEntry Entry(PI, IR);
for (auto &Pass : Passes) {
Entry.setPass(&*Pass);
Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
using namespace llvm;

PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
M.removeDebugIntrinsicDeclarations();

const ModuleSummaryIndex *Index =
EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
Expand Down Expand Up @@ -51,9 +49,7 @@ namespace {
StringRef getPassName() const override { return "Bitcode Writer"; }

bool runOnModule(Module &M) override {
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
M.removeDebugIntrinsicDeclarations();

WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
/*EmitModuleHash=*/false);
Expand Down
6 changes: 0 additions & 6 deletions llvm/lib/CodeGen/MIRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,17 +965,11 @@ void MIRFormatter::printIRValue(raw_ostream &OS, const Value &V,
}

void llvm::printMIR(raw_ostream &OS, const Module &M) {
ScopedDbgInfoFormatSetter FormatSetter(const_cast<Module &>(M), true);

yaml::Output Out(OS);
Out << const_cast<Module &>(M);
}

void llvm::printMIR(raw_ostream &OS, const MachineModuleInfo &MMI,
const MachineFunction &MF) {
// RemoveDIs: as there's no textual form for DbgRecords yet, print debug-info
// in dbg.value format.
ScopedDbgInfoFormatSetter FormatSetter(
const_cast<Function &>(MF.getFunction()), true);
printMF(OS, MMI, MF);
}
3 changes: 0 additions & 3 deletions llvm/lib/IR/IRPrintingPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PrintModulePassWrapper : public ModulePass {
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}

bool runOnModule(Module &M) override {
ScopedDbgInfoFormatSetter FormatSetter(M, true);
// Remove intrinsic declarations when printing in the new format.
// TODO: consider removing this as debug-intrinsics are gone.
M.removeDebugIntrinsicDeclarations();
Expand Down Expand Up @@ -84,8 +83,6 @@ class PrintFunctionPassWrapper : public FunctionPass {

// This pass just prints a banner followed by the function as it's processed.
bool runOnFunction(Function &F) override {
ScopedDbgInfoFormatSetter FormatSetter(F, true);

if (isFunctionInPrintList(F.getName())) {
if (forcePrintModuleIR())
OS << Banner << " (function: " << F.getName() << ")\n"
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/IR/LegacyPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,6 @@ bool PassManagerImpl::run(Module &M) {
dumpArguments();
dumpPasses();

// 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, true);

for (ImmutablePass *ImPass : getImmutablePasses())
Changed |= ImPass->doInitialization(M);

Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/IRPrinter/IRPrintingPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
EmitSummaryIndex(EmitSummaryIndex) {}

PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &AM) {
ScopedDbgInfoFormatSetter FormatSetter(M, true);
// Remove intrinsic declarations when printing in the new format.
// TODO: consider removing this now that debug intrinsics are gone.
M.removeDebugIntrinsicDeclarations();
Expand Down Expand Up @@ -72,8 +71,6 @@ PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)

PreservedAnalyses PrintFunctionPass::run(Function &F,
FunctionAnalysisManager &) {
ScopedDbgInfoFormatSetter FormatSetter(F, true);

if (isFunctionInPrintList(F.getName())) {
if (forcePrintModuleIR())
OS << Banner << " (function: " << F.getName() << ")\n" << *F.getParent();
Expand Down
3 changes: 0 additions & 3 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,6 @@ Error IRLinker::run() {
if (Error Err = SrcM->getMaterializer()->materializeMetadata())
return Err;

// Convert source module to match dest for the duration of the link.
ScopedDbgInfoFormatSetter FormatSetter(*SrcM, DstM.IsNewDbgInfoFormat);

// Inherit the target data from the source module if the destination
// module doesn't have one already.
if (DstM.getDataLayout().isDefault())
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,7 @@ llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
FunctionAnalysisManager &FAM =
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();

ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat);
if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
M.removeDebugIntrinsicDeclarations();

bool Changed = writeThinLTOBitcode(
OS, ThinLinkOS,
Expand Down
4 changes: 0 additions & 4 deletions mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ void registerToLLVMIRTranslation() {
if (!llvmModule)
return failure();

// 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, true);
llvmModule->removeDebugIntrinsicDeclarations();
llvmModule->print(output, nullptr);
return success();
Expand Down