Add PPC AsmPrinter handling for target-specific form of
authorDale Johannesen <dalej@apple.com>
Mon, 26 Apr 2010 20:05:01 +0000 (20:05 +0000)
committerDale Johannesen <dalej@apple.com>
Mon, 26 Apr 2010 20:05:01 +0000 (20:05 +0000)
DBG_VALUE, and a cautionary comment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102371 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp

index db1a15b534c602ad07aa0c8ff60309ce85b4d6a7..79ecbf83719c17360fca3e164c03706709209ad4 100644 (file)
@@ -367,6 +367,9 @@ public:
   /// normally be lowered the same way as other addresses on the target,
   /// e.g. in load instructions.  For targets that do not support this
   /// the debug info is simply lost.
+  /// If you add this for a target you should handle this DBG_VALUE in the
+  /// target-specific AsmPrinter code as well; you will probably get invalid
+  /// assembly output if you don't.
   virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
                                                  unsigned FrameIx,
                                                  uint64_t Offset,
index 17446b0dcd6dae5305ea99c9316293239b445ce7..f85ebae8decca5977424240ae4c25218f2904b8b 100644 (file)
@@ -21,6 +21,7 @@
 #include "PPCPredicates.h"
 #include "PPCTargetMachine.h"
 #include "PPCSubtarget.h"
+#include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
@@ -535,6 +536,23 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
   SmallString<128> Str;
   raw_svector_ostream O(Str);
 
+  if (MI->getOpcode() == TargetOpcode::DBG_VALUE) {
+    unsigned NOps = MI->getNumOperands();
+    assert(NOps==4);
+    O << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
+    // cast away const; DIetc do not take const operands for some reason.
+    DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps-1).getMetadata()));
+    O << V.getName();
+    O << " <- ";
+    // Frame address.  Currently handles register +- offset only.
+    assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm());
+    O << '['; printOperand(MI, 0, O); O << '+'; printOperand(MI, 1, O);
+    O << ']';
+    O << "+";
+    printOperand(MI, NOps-2, O);
+    OutStreamer.EmitRawText(O.str());
+    return;
+  }
   // Check for slwi/srwi mnemonics.
   if (MI->getOpcode() == PPC::RLWINM) {
     unsigned char SH = MI->getOperand(2).getImm();