mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-05-22 15:06:05 +00:00

Summary: This allows us to test each backend pass under the presence of debug info using pre-existing tests. The tests should not fail as a result of this so long as it's true that debug info does not affect CodeGen. In practice, a few tests are sensitive to this: * Tests that check the pass structure (e.g. O0-pipeline.ll) * Tests that check --debug output. Specifically instruction dumps containing MMO's (e.g. prelegalizercombiner-extends.ll) * Tests that contain debugify metadata as mir-strip-debug will remove it (e.g. fastisel-debugvalue-undef.ll) * Tests with partial debug info (e.g. patchable-function-entry-empty.mir had debug info but no !llvm.dbg.cu) * Tests that check optimization remarks overly strictly (e.g. prologue-epilogue-remarks.mir) * Tests that would inject the pass in an unsafe region (e.g. seqpairspill.mir would inject between register alloc and virt reg rewriter) In all cases, the checks can either be updated or --debugify-and-strip-all-safe=0 can be used to avoid being affected by something like llvm-lit -Dllc='llc --debugify-and-strip-all-safe' I tested this without the lost debug locations verifier to confirm that AArch64 behaviour is unaffected (with the fixes in this patch) and with it to confirm it finds the problems without the additional RUN lines we had before. Depends on D77886, D77887, D77747 Reviewers: aprantl, vsk, bogner Subscribers: qcolombet, kristof.beyls, hiraditya, danielkiss, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77888
86 lines
2.9 KiB
C++
86 lines
2.9 KiB
C++
//===- MachineDebugify.cpp - Attach synthetic debug info to everything ----===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file This pass attaches synthetic debug info to everything. It can be used
|
|
/// to create targeted tests for debug info preservation.
|
|
///
|
|
/// This isn't intended to have feature parity with Debugify.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/IR/DIBuilder.h"
|
|
#include "llvm/IR/DebugInfo.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/Transforms/Utils/Debugify.h"
|
|
|
|
#define DEBUG_TYPE "mir-debugify"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI,
|
|
DIBuilder &DIB, Function &F) {
|
|
MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
|
|
|
|
DISubprogram *SP = F.getSubprogram();
|
|
assert(SP && "IR Debugify just created it?");
|
|
|
|
LLVMContext &Ctx = F.getParent()->getContext();
|
|
unsigned NextLine = SP->getLine();
|
|
|
|
for (MachineBasicBlock &MBB : MF) {
|
|
for (MachineInstr &MI : MBB) {
|
|
// This will likely emit line numbers beyond the end of the imagined
|
|
// source function and into subsequent ones. We don't do anything about
|
|
// that as it doesn't really matter to the compiler where the line is in
|
|
// the imaginary source code.
|
|
MI.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// ModulePass for attaching synthetic debug info to everything, used with the
|
|
/// legacy module pass manager.
|
|
struct DebugifyMachineModule : public ModulePass {
|
|
bool runOnModule(Module &M) override {
|
|
MachineModuleInfo &MMI =
|
|
getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
|
|
return applyDebugifyMetadata(
|
|
M, M.functions(),
|
|
"ModuleDebugify: ", [&](DIBuilder &DIB, Function &F) -> bool {
|
|
return applyDebugifyMetadataToMachineFunction(MMI, DIB, F);
|
|
});
|
|
}
|
|
|
|
DebugifyMachineModule() : ModulePass(ID) {}
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.addRequired<MachineModuleInfoWrapperPass>();
|
|
AU.addPreserved<MachineModuleInfoWrapperPass>();
|
|
AU.setPreservesCFG();
|
|
}
|
|
|
|
static char ID; // Pass identification.
|
|
};
|
|
char DebugifyMachineModule::ID = 0;
|
|
|
|
} // end anonymous namespace
|
|
|
|
INITIALIZE_PASS_BEGIN(DebugifyMachineModule, DEBUG_TYPE,
|
|
"Machine Debugify Module", false, false)
|
|
INITIALIZE_PASS_END(DebugifyMachineModule, DEBUG_TYPE,
|
|
"Machine Debugify Module", false, false)
|
|
|
|
ModulePass *llvm::createDebugifyMachineModulePass() {
|
|
return new DebugifyMachineModule();
|
|
}
|