V4 JIT: add IR printer that uses platform register names.
authorErik Verbruggen <erik.verbruggen@digia.com>
Fri, 23 May 2014 13:52:08 +0000 (15:52 +0200)
committerErik Verbruggen <erik.verbruggen@digia.com>
Tue, 24 Jun 2014 07:51:10 +0000 (09:51 +0200)
After running register allocation, the IR is printed one last time (when
the environment variable QV4_SHOW_IR is set). This will now use the
platform defined register names, e.g. "ebx" or "d2".

Change-Id: I2f2f4536d1de940a69690056e5165d38fa7910bb
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/jit/qv4isel_masm.cpp
src/qml/jit/qv4regalloc.cpp
src/qml/jit/qv4registerinfo_p.h

index b35db97..f6c1a03 100644 (file)
@@ -231,8 +231,8 @@ void InstructionSelection::run(int functionIndex)
             // No register allocator available for this platform, or env. var was set, so:
             opt.convertOutOfSSA();
         ConvertTemps().toStackSlots(_function);
+        IR::Optimizer::showMeTheCode(_function);
     }
-    IR::Optimizer::showMeTheCode(_function);
     QSet<IR::Jump *> removableJumps = opt.calculateOptionalJumps();
     qSwap(_removableJumps, removableJumps);
 
index cb24db3..a673cd3 100644 (file)
@@ -95,6 +95,41 @@ protected:
             *out << ": ";
     }
 };
+
+class IRPrinterWithRegisters: public IRPrinterWithPositions
+{
+    const RegisterInformation &_registerInformation;
+    QHash<int, const RegisterInfo *> _infoForRegister;
+
+public:
+    IRPrinterWithRegisters(QTextStream *out, const LifeTimeIntervals::Ptr &intervals,
+                           const RegisterInformation &registerInformation)
+        : IRPrinterWithPositions(out, intervals)
+        , _registerInformation(registerInformation)
+    {
+        for (int i = 0, ei = _registerInformation.size(); i != ei; ++i)
+            _infoForRegister.insert(_registerInformation.at(i).reg<int>(),
+                                    &_registerInformation.at(i));
+    }
+
+protected:
+    void visitTemp(Temp *e)
+    {
+        switch (e->kind) {
+        case Temp::PhysicalRegister: {
+            const RegisterInfo *ri = _infoForRegister.value(e->index, 0);
+            if (ri) {
+                *out << dumpStart(e);
+                *out << ri->prettyName();
+                *out << dumpEnd(e);
+                break;
+            }
+        }
+        default:
+            IRPrinterWithPositions::visitTemp(e);
+        }
+    }
+};
 }
 
 class RegAllocInfo: public IRDecoder
@@ -1237,10 +1272,13 @@ void RegisterAllocator::run(IR::Function *function, const Optimizer &opt)
 
     function->tempCount = *std::max_element(_assignedSpillSlots.begin(), _assignedSpillSlots.end()) + 1;
 
-    if (DebugRegAlloc) {
+    if (DebugRegAlloc)
         qDebug() << "*** Finished regalloc , result:";
+
+    static bool showCode = !qgetenv("QV4_SHOW_IR").isNull();
+    if (showCode) {
         QTextStream qout(stdout, QIODevice::WriteOnly);
-        IRPrinterWithPositions(&qout, _lifeTimeIntervals).print(function);
+        IRPrinterWithRegisters(&qout, _lifeTimeIntervals, _registerInformation).print(function);
     }
 }
 
index b9bef67..b8701d7 100644 (file)
@@ -75,6 +75,7 @@ public:
 
     bool isValid() const { return _reg != InvalidRegister; }
     template <typename T> T reg() const { return static_cast<T>(_reg); }
+    QString prettyName() const { return _prettyName; }
     bool isCallerSaved() const { return _savedBy == CallerSaved; }
     bool isCalleeSaved() const { return _savedBy == CalleeSaved; }
     bool isFloatingPoint() const { return _type == FloatingPointRegister; }