|
39 | 39 | #include "llvm/IR/Constant.h"
|
40 | 40 | #include "llvm/IR/Constants.h"
|
41 | 41 | #include "llvm/IR/DebugInfoMetadata.h"
|
| 42 | +#include "llvm/IR/DebugProgramInstruction.h" |
42 | 43 | #include "llvm/IR/DerivedTypes.h"
|
43 | 44 | #include "llvm/IR/Function.h"
|
44 | 45 | #include "llvm/IR/GlobalAlias.h"
|
@@ -285,6 +286,16 @@ static const Module *getModuleFromVal(const Value *V) {
|
285 | 286 | return nullptr;
|
286 | 287 | }
|
287 | 288 |
|
| 289 | +static const Module *getModuleFromDPI(const DPMarker *Marker) { |
| 290 | + const Function *M = |
| 291 | + Marker->getParent() ? Marker->getParent()->getParent() : nullptr; |
| 292 | + return M ? M->getParent() : nullptr; |
| 293 | +} |
| 294 | + |
| 295 | +static const Module *getModuleFromDPI(const DPValue *DPV) { |
| 296 | + return getModuleFromDPI(DPV->getMarker()); |
| 297 | +} |
| 298 | + |
288 | 299 | static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
|
289 | 300 | switch (cc) {
|
290 | 301 | default: Out << "cc" << cc; break;
|
@@ -2612,6 +2623,8 @@ class AssemblyWriter {
|
2612 | 2623 | void printBasicBlock(const BasicBlock *BB);
|
2613 | 2624 | void printInstructionLine(const Instruction &I);
|
2614 | 2625 | void printInstruction(const Instruction &I);
|
| 2626 | + void printDPMarker(const DPMarker &DPI); |
| 2627 | + void printDPValue(const DPValue &DPI); |
2615 | 2628 |
|
2616 | 2629 | void printUseListOrder(const Value *V, const std::vector<unsigned> &Shuffle);
|
2617 | 2630 | void printUseLists(const Function *F);
|
@@ -3771,6 +3784,9 @@ void AssemblyWriter::printTypeIdentities() {
|
3771 | 3784 |
|
3772 | 3785 | /// printFunction - Print all aspects of a function.
|
3773 | 3786 | void AssemblyWriter::printFunction(const Function *F) {
|
| 3787 | + bool ConvertBack = F->IsNewDbgInfoFormat; |
| 3788 | + if (ConvertBack) |
| 3789 | + const_cast<Function *>(F)->convertFromNewDbgValues(); |
3774 | 3790 | if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out);
|
3775 | 3791 |
|
3776 | 3792 | if (F->isMaterializable())
|
@@ -3913,6 +3929,8 @@ void AssemblyWriter::printFunction(const Function *F) {
|
3913 | 3929 | Out << "}\n";
|
3914 | 3930 | }
|
3915 | 3931 |
|
| 3932 | + if (ConvertBack) |
| 3933 | + const_cast<Function *>(F)->convertToNewDbgValues(); |
3916 | 3934 | Machine.purgeFunction();
|
3917 | 3935 | }
|
3918 | 3936 |
|
@@ -4007,8 +4025,15 @@ void AssemblyWriter::printInfoComment(const Value &V) {
|
4007 | 4025 | if (const auto *Relocate = dyn_cast<GCRelocateInst>(&V))
|
4008 | 4026 | printGCRelocateComment(*Relocate);
|
4009 | 4027 |
|
4010 |
| - if (AnnotationWriter) |
| 4028 | + if (AnnotationWriter) { |
4011 | 4029 | AnnotationWriter->printInfoComment(V, Out);
|
| 4030 | + } else if (const Instruction *I = dyn_cast<Instruction>(&V)) { |
| 4031 | + if (I->DbgMarker) { |
| 4032 | + // In the new, experimental DPValue representation of debug-info, print |
| 4033 | + // out which instructions have DPMarkers and where they are. |
| 4034 | + Out << "; dbgmarker @ " << I->DbgMarker; |
| 4035 | + } |
| 4036 | + } |
4012 | 4037 | }
|
4013 | 4038 |
|
4014 | 4039 | static void maybePrintCallAddrSpace(const Value *Operand, const Instruction *I,
|
@@ -4468,6 +4493,36 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
|
4468 | 4493 | printInfoComment(I);
|
4469 | 4494 | }
|
4470 | 4495 |
|
| 4496 | +void AssemblyWriter::printDPMarker(const DPMarker &Marker) { |
| 4497 | + // There's no formal representation of a DPMarker -- print purely as a |
| 4498 | + // debugging aid. |
| 4499 | + for (const DPValue &DPI2 : Marker.StoredDPValues) { |
| 4500 | + printDPValue(DPI2); |
| 4501 | + Out << "\n"; |
| 4502 | + } |
| 4503 | + |
| 4504 | + Out << " DPMarker -> { "; |
| 4505 | + printInstruction(*Marker.MarkedInstr); |
| 4506 | + Out << " }"; |
| 4507 | + return; |
| 4508 | +} |
| 4509 | + |
| 4510 | +void AssemblyWriter::printDPValue(const DPValue &Value) { |
| 4511 | + // There's no formal representation of a DPValue -- print purely as a |
| 4512 | + // debugging aid. |
| 4513 | + Out << " DPValue { "; |
| 4514 | + auto WriterCtx = getContext(); |
| 4515 | + WriteAsOperandInternal(Out, Value.getRawLocation(), WriterCtx, true); |
| 4516 | + Out << ", "; |
| 4517 | + WriteAsOperandInternal(Out, Value.getVariable(), WriterCtx, true); |
| 4518 | + Out << ", "; |
| 4519 | + WriteAsOperandInternal(Out, Value.getExpression(), WriterCtx, true); |
| 4520 | + Out << ", "; |
| 4521 | + WriteAsOperandInternal(Out, Value.getDebugLoc().get(), WriterCtx, true); |
| 4522 | + Out << " marker @" << Value.getMarker(); |
| 4523 | + Out << " }"; |
| 4524 | +} |
| 4525 | + |
4471 | 4526 | void AssemblyWriter::printMetadataAttachments(
|
4472 | 4527 | const SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs,
|
4473 | 4528 | StringRef Separator) {
|
@@ -4613,11 +4668,19 @@ void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
|
4613 | 4668 |
|
4614 | 4669 | void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
|
4615 | 4670 | bool ShouldPreserveUseListOrder, bool IsForDebug) const {
|
| 4671 | + // RemoveDIs: always print with debug-info in intrinsic format. |
| 4672 | + bool ConvertAfter = IsNewDbgInfoFormat; |
| 4673 | + if (IsNewDbgInfoFormat) |
| 4674 | + const_cast<Module *>(this)->convertFromNewDbgValues(); |
| 4675 | + |
4616 | 4676 | SlotTracker SlotTable(this);
|
4617 | 4677 | formatted_raw_ostream OS(ROS);
|
4618 | 4678 | AssemblyWriter W(OS, SlotTable, this, AAW, IsForDebug,
|
4619 | 4679 | ShouldPreserveUseListOrder);
|
4620 | 4680 | W.printModule(this);
|
| 4681 | + |
| 4682 | + if (ConvertAfter) |
| 4683 | + const_cast<Module *>(this)->convertToNewDbgValues(); |
4621 | 4684 | }
|
4622 | 4685 |
|
4623 | 4686 | void NamedMDNode::print(raw_ostream &ROS, bool IsForDebug) const {
|
@@ -4694,6 +4757,53 @@ static bool isReferencingMDNode(const Instruction &I) {
|
4694 | 4757 | return false;
|
4695 | 4758 | }
|
4696 | 4759 |
|
| 4760 | +void DPMarker::print(raw_ostream &ROS, bool IsForDebug) const { |
| 4761 | + |
| 4762 | + ModuleSlotTracker MST(getModuleFromDPI(this), true); |
| 4763 | + print(ROS, MST, IsForDebug); |
| 4764 | +} |
| 4765 | + |
| 4766 | +void DPValue::print(raw_ostream &ROS, bool IsForDebug) const { |
| 4767 | + |
| 4768 | + ModuleSlotTracker MST(getModuleFromDPI(this), true); |
| 4769 | + print(ROS, MST, IsForDebug); |
| 4770 | +} |
| 4771 | + |
| 4772 | +void DPMarker::print(raw_ostream &ROS, ModuleSlotTracker &MST, |
| 4773 | + bool IsForDebug) const { |
| 4774 | + // There's no formal representation of a DPMarker -- print purely as a |
| 4775 | + // debugging aid. |
| 4776 | + formatted_raw_ostream OS(ROS); |
| 4777 | + SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); |
| 4778 | + SlotTracker &SlotTable = |
| 4779 | + MST.getMachine() ? *MST.getMachine() : EmptySlotTable; |
| 4780 | + auto incorporateFunction = [&](const Function *F) { |
| 4781 | + if (F) |
| 4782 | + MST.incorporateFunction(*F); |
| 4783 | + }; |
| 4784 | + incorporateFunction(getParent() ? getParent()->getParent() : nullptr); |
| 4785 | + AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); |
| 4786 | + W.printDPMarker(*this); |
| 4787 | +} |
| 4788 | + |
| 4789 | +void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST, |
| 4790 | + bool IsForDebug) const { |
| 4791 | + // There's no formal representation of a DPValue -- print purely as a |
| 4792 | + // debugging aid. |
| 4793 | + formatted_raw_ostream OS(ROS); |
| 4794 | + SlotTracker EmptySlotTable(static_cast<const Module *>(nullptr)); |
| 4795 | + SlotTracker &SlotTable = |
| 4796 | + MST.getMachine() ? *MST.getMachine() : EmptySlotTable; |
| 4797 | + auto incorporateFunction = [&](const Function *F) { |
| 4798 | + if (F) |
| 4799 | + MST.incorporateFunction(*F); |
| 4800 | + }; |
| 4801 | + incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent() |
| 4802 | + : nullptr); |
| 4803 | + AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); |
| 4804 | + W.printDPValue(*this); |
| 4805 | +} |
| 4806 | + |
4697 | 4807 | void Value::print(raw_ostream &ROS, bool IsForDebug) const {
|
4698 | 4808 | bool ShouldInitializeAllMetadata = false;
|
4699 | 4809 | if (auto *I = dyn_cast<Instruction>(this))
|
@@ -4939,6 +5049,14 @@ void ModuleSlotTracker::collectMDNodes(MachineMDNodeListType &L, unsigned LB,
|
4939 | 5049 | LLVM_DUMP_METHOD
|
4940 | 5050 | void Value::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; }
|
4941 | 5051 |
|
| 5052 | +// Value::dump - allow easy printing of Values from the debugger. |
| 5053 | +LLVM_DUMP_METHOD |
| 5054 | +void DPMarker::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } |
| 5055 | + |
| 5056 | +// Value::dump - allow easy printing of Values from the debugger. |
| 5057 | +LLVM_DUMP_METHOD |
| 5058 | +void DPValue::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; } |
| 5059 | + |
4942 | 5060 | // Type::dump - allow easy printing of Types from the debugger.
|
4943 | 5061 | LLVM_DUMP_METHOD
|
4944 | 5062 | void Type::dump() const { print(dbgs(), /*IsForDebug=*/true); dbgs() << '\n'; }
|
|
0 commit comments