aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/AsmWriter.cpp75
-rw-r--r--llvm/lib/IR/BasicBlock.cpp4
-rw-r--r--llvm/lib/IR/IRPrintingPasses.cpp32
-rw-r--r--llvm/lib/IR/Module.cpp22
4 files changed, 70 insertions, 63 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index fba404c..a3da6ca 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -861,7 +861,7 @@ private:
/// Add all of the metadata from an instruction.
void processInstructionMetadata(const Instruction &I);
- /// Add all of the metadata from an instruction.
+ /// Add all of the metadata from a DbgRecord.
void processDbgRecordMetadata(const DbgRecord &DPV);
};
@@ -1140,6 +1140,9 @@ void SlotTracker::processFunctionMetadata(const Function &F) {
void SlotTracker::processDbgRecordMetadata(const DbgRecord &DR) {
if (const DPValue *DPV = dyn_cast<const DPValue>(&DR)) {
+ // Process metadata used by DbgRecords; we only specifically care about the
+ // DILocalVariable, DILocation, and DIAssignID fields, as the Value and
+ // Expression fields should only be printed inline and so do not use a slot.
CreateMetadataSlot(DPV->getVariable());
if (DPV->isDbgAssign())
CreateMetadataSlot(DPV->getAssignID());
@@ -2703,6 +2706,7 @@ public:
void printDPValue(const DPValue &DPI);
void printDPLabel(const DPLabel &DPL);
void printDbgRecord(const DbgRecord &DPI);
+ void printDbgRecordLine(const DbgRecord &DPI);
void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle);
void printUseLists(const Function *F);
@@ -3885,9 +3889,6 @@ void AssemblyWriter::printTypeIdentities() {
/// printFunction - Print all aspects of a function.
void AssemblyWriter::printFunction(const Function *F) {
- bool ConvertBack = F->IsNewDbgInfoFormat;
- if (ConvertBack)
- const_cast<Function *>(F)->convertFromNewDbgValues();
if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
if (F->isMaterializable())
@@ -4030,8 +4031,6 @@ void AssemblyWriter::printFunction(const Function *F) {
Out << "}\n";
}
- if (ConvertBack)
- const_cast<Function *>(F)->convertToNewDbgValues();
Machine.purgeFunction();
}
@@ -4098,6 +4097,8 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
// Output all of the instructions in the basic block...
for (const Instruction &I : *BB) {
+ for (const DbgRecord &DR : I.getDbgValueRange())
+ printDbgRecordLine(DR);
printInstructionLine(I);
}
@@ -4611,12 +4612,10 @@ void AssemblyWriter::printDbgRecord(const DbgRecord &DR) {
llvm_unreachable("Unexpected DbgRecord kind");
}
-void AssemblyWriter::printDPValue(const DPValue &Value) {
- // There's no formal representation of a DPValue -- print purely as a
- // debugging aid.
- Out << " DPValue ";
-
- switch (Value.getType()) {
+void AssemblyWriter::printDPValue(const DPValue &DPV) {
+ auto WriterCtx = getContext();
+ Out << "#dbg_";
+ switch (DPV.getType()) {
case DPValue::LocationType::Value:
Out << "value";
break;
@@ -4629,35 +4628,39 @@ void AssemblyWriter::printDPValue(const DPValue &Value) {
default:
llvm_unreachable("Tried to print a DPValue with an invalid LocationType!");
}
- Out << " { ";
- auto WriterCtx = getContext();
- WriteAsOperandInternal(Out, Value.getRawLocation(), WriterCtx, true);
+ Out << "(";
+ WriteAsOperandInternal(Out, DPV.getRawLocation(), WriterCtx, true);
Out << ", ";
- WriteAsOperandInternal(Out, Value.getVariable(), WriterCtx, true);
+ WriteAsOperandInternal(Out, DPV.getVariable(), WriterCtx, true);
Out << ", ";
- WriteAsOperandInternal(Out, Value.getExpression(), WriterCtx, true);
+ WriteAsOperandInternal(Out, DPV.getExpression(), WriterCtx, true);
Out << ", ";
- if (Value.isDbgAssign()) {
- WriteAsOperandInternal(Out, Value.getAssignID(), WriterCtx, true);
+ if (DPV.isDbgAssign()) {
+ WriteAsOperandInternal(Out, DPV.getAssignID(), WriterCtx, true);
Out << ", ";
- WriteAsOperandInternal(Out, Value.getRawAddress(), WriterCtx, true);
+ WriteAsOperandInternal(Out, DPV.getRawAddress(), WriterCtx, true);
Out << ", ";
- WriteAsOperandInternal(Out, Value.getAddressExpression(), WriterCtx, true);
+ WriteAsOperandInternal(Out, DPV.getAddressExpression(), WriterCtx, true);
Out << ", ";
}
- WriteAsOperandInternal(Out, Value.getDebugLoc().get(), WriterCtx, true);
- Out << " marker @" << Value.getMarker();
- Out << " }";
+ WriteAsOperandInternal(Out, DPV.getDebugLoc().getAsMDNode(), WriterCtx, true);
+ Out << ")";
+}
+
+/// printDbgRecordLine - Print a DbgRecord with indentation and a newline
+/// character.
+void AssemblyWriter::printDbgRecordLine(const DbgRecord &DR) {
+ // Print lengthier indentation to bring out-of-line with instructions.
+ Out << " ";
+ printDbgRecord(DR);
+ Out << '\n';
}
void AssemblyWriter::printDPLabel(const DPLabel &Label) {
- // There's no formal representation of a DPLabel -- print purely as
- // a debugging aid.
- Out << " DPLabel { ";
auto WriterCtx = getContext();
+ Out << "#dbg_label(";
WriteAsOperandInternal(Out, Label.getLabel(), WriterCtx, true);
- Out << " marker @" << Label.getMarker();
- Out << " }";
+ Out << ")";
}
void AssemblyWriter::printMetadataAttachments(
@@ -4805,19 +4808,11 @@ void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
bool ShouldPreserveUseListOrder, bool IsForDebug) const {
- // RemoveDIs: always print with debug-info in intrinsic format.
- bool ConvertAfter = IsNewDbgInfoFormat;
- if (IsNewDbgInfoFormat)
- const_cast<Module *>(this)->convertFromNewDbgValues();
-
SlotTracker SlotTable(this);
formatted_raw_ostream OS(ROS);
AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug,
ShouldPreserveUseListOrder);
W.printModule(this);
-
- if (ConvertAfter)
- const_cast<Module *>(this)->convertToNewDbgValues();
}
void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const {
@@ -4908,8 +4903,6 @@ void DPValue::print(raw_ostream &ROS, bool IsForDebug) const {
void DPMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
- // There's no formal representation of a DPMarker -- print purely as a
- // debugging aid.
formatted_raw_ostream OS(ROS);
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
SlotTracker &SlotTable =
@@ -4931,8 +4924,6 @@ void DPLabel::print(raw_ostream &ROS, bool IsForDebug) const {
void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
- // There's no formal representation of a DPValue -- print purely as a
- // debugging aid.
formatted_raw_ostream OS(ROS);
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
SlotTracker &SlotTable =
@@ -4950,8 +4941,6 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST,
void DPLabel::print(raw_ostream &ROS, ModuleSlotTracker &MST,
bool IsForDebug) const {
- // There's no formal representation of a DbgLabelRecord -- print purely as
- // a debugging aid.
formatted_raw_ostream OS(ROS);
SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr));
SlotTracker &SlotTable =
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 6ea876f..c110c4c 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -61,10 +61,6 @@ DPMarker *BasicBlock::createMarker(InstListType::iterator It) {
}
void BasicBlock::convertToNewDbgValues() {
- // Is the command line option set?
- if (!UseNewDbgInfoFormat)
- return;
-
IsNewDbgInfoFormat = true;
// Iterate over all instructions in the instruction list, collecting dbg.value
diff --git a/llvm/lib/IR/IRPrintingPasses.cpp b/llvm/lib/IR/IRPrintingPasses.cpp
index b19210e..84fb8e6 100644
--- a/llvm/lib/IR/IRPrintingPasses.cpp
+++ b/llvm/lib/IR/IRPrintingPasses.cpp
@@ -23,6 +23,11 @@
using namespace llvm;
+cl::opt<bool> WriteNewDbgInfoFormat(
+ "write-experimental-debuginfo",
+ cl::desc("Write debug info in the new non-intrinsic format"),
+ cl::init(false));
+
namespace {
class PrintModulePassWrapper : public ModulePass {
@@ -39,11 +44,14 @@ public:
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
bool runOnModule(Module &M) override {
- // RemoveDIs: there's no textual representation of the DPValue debug-info,
- // convert to dbg.values before writing out.
- bool IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
- if (IsNewDbgInfoFormat)
- M.convertFromNewDbgValues();
+ // RemoveDIs: Regardless of the format we've processed this module in, use
+ // `WriteNewDbgInfoFormat` to determine which format we use to write it.
+ ScopedDbgInfoFormatSetter FormatSetter(M, WriteNewDbgInfoFormat);
+ // Remove intrinsic declarations when printing in the new format.
+ // TODO: Move this into Module::setIsNewDbgInfoFormat when we're ready to
+ // update test output.
+ if (WriteNewDbgInfoFormat)
+ M.removeDebugIntrinsicDeclarations();
if (llvm::isFunctionInPrintList("*")) {
if (!Banner.empty())
@@ -62,9 +70,6 @@ public:
}
}
- if (IsNewDbgInfoFormat)
- M.convertToNewDbgValues();
-
return false;
}
@@ -87,11 +92,9 @@ public:
// This pass just prints a banner followed by the function as it's processed.
bool runOnFunction(Function &F) override {
- // RemoveDIs: there's no textual representation of the DPValue debug-info,
- // convert to dbg.values before writing out.
- bool IsNewDbgInfoFormat = F.IsNewDbgInfoFormat;
- if (IsNewDbgInfoFormat)
- F.convertFromNewDbgValues();
+ // RemoveDIs: Regardless of the format we've processed this function in, use
+ // `WriteNewDbgInfoFormat` to determine which format we use to write it.
+ ScopedDbgInfoFormatSetter FormatSetter(F, WriteNewDbgInfoFormat);
if (isFunctionInPrintList(F.getName())) {
if (forcePrintModuleIR())
@@ -101,9 +104,6 @@ public:
OS << Banner << '\n' << static_cast<Value &>(F);
}
- if (IsNewDbgInfoFormat)
- F.convertToNewDbgValues();
-
return false;
}
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 1946db2..a8696ed 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -85,6 +85,28 @@ Module::~Module() {
IFuncList.clear();
}
+void Module::removeDebugIntrinsicDeclarations() {
+ auto *DeclareIntrinsicFn =
+ Intrinsic::getDeclaration(this, Intrinsic::dbg_declare);
+ assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug declare intrinsic should have had uses removed.");
+ DeclareIntrinsicFn->eraseFromParent();
+ auto *ValueIntrinsicFn =
+ Intrinsic::getDeclaration(this, Intrinsic::dbg_value);
+ assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug value intrinsic should have had uses removed.");
+ ValueIntrinsicFn->eraseFromParent();
+ auto *AssignIntrinsicFn =
+ Intrinsic::getDeclaration(this, Intrinsic::dbg_assign);
+ assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
+ "Debug assign intrinsic should have had uses removed.");
+ AssignIntrinsicFn->eraseFromParent();
+ auto *LabelntrinsicFn = Intrinsic::getDeclaration(this, Intrinsic::dbg_label);
+ assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
+ "Debug label intrinsic should have had uses removed.");
+ LabelntrinsicFn->eraseFromParent();
+}
+
std::unique_ptr<RandomNumberGenerator>
Module::createRNG(const StringRef Name) const {
SmallString<32> Salt(Name);