Bug 789111 - Add inline path for LIntToString. r=jandem
authorTom Schuster <evilpies@gmail.com>
Thu, 27 Sep 2012 12:41:48 +0200
changeset 108372 978385fba015b69a5efd23763e8c6ca31007de3d
parent 108371 f80cc2f44c27f271a0c8fd2d462c882f91c40899
child 108373 385dbb23bb344d9390a756bb9422fc07b7f29699
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjandem
bugs789111
milestone18.0a1
Bug 789111 - Add inline path for LIntToString. r=jandem
js/src/ion/CodeGenerator.cpp
js/src/ion/LIR-Common.h
js/src/ion/Lowering.cpp
js/src/vm/String.h
--- a/js/src/ion/CodeGenerator.cpp
+++ b/js/src/ion/CodeGenerator.cpp
@@ -192,21 +192,35 @@ CodeGenerator::visitPolyInlineDispatch(L
         }
     }
     return true;
 }
 
 bool
 CodeGenerator::visitIntToString(LIntToString *lir)
 {
+    Register input = ToRegister(lir->input());
+    Register output = ToRegister(lir->output());
+
     typedef JSFlatString *(*pf)(JSContext *, int);
     static const VMFunction IntToStringInfo = FunctionInfo<pf>(Int32ToString);
 
-    pushArg(ToRegister(lir->input()));
-    return callVM(IntToStringInfo, lir);
+    OutOfLineCode *ool = oolCallVM(IntToStringInfo, lir, (ArgList(), input),
+                                   StoreRegisterTo(output));
+    if (!ool)
+        return false;
+
+    masm.branch32(Assembler::AboveOrEqual, input, Imm32(StaticStrings::INT_STATIC_LIMIT),
+                  ool->entry());
+
+    masm.movePtr(ImmWord(&gen->compartment->rt->staticStrings.intStaticTable), output);
+    masm.loadPtr(BaseIndex(output, input, ScalePointer), output);
+
+    masm.bind(ool->rejoin());
+    return true;
 }
 
 bool
 CodeGenerator::visitRegExp(LRegExp *lir)
 {
     JSObject *proto = lir->mir()->getRegExpPrototype();
 
     typedef JSObject *(*pf)(JSContext *, JSObject *, JSObject *);
--- a/js/src/ion/LIR-Common.h
+++ b/js/src/ion/LIR-Common.h
@@ -1608,17 +1608,17 @@ class LTruncateDToInt32 : public LInstru
 
     const LDefinition *tempFloat() {
         return getTemp(0);
     }
 };
 
 // Convert a any input type hosted on one definition to a string with a function
 // call.
-class LIntToString : public LCallInstructionHelper<1, 1, 0>
+class LIntToString : public LInstructionHelper<1, 1, 0>
 {
   public:
     LIR_HEADER(IntToString);
 
     LIntToString(const LAllocation &input) {
         setOperand(0, input);
     }
 
--- a/js/src/ion/Lowering.cpp
+++ b/js/src/ion/Lowering.cpp
@@ -1080,19 +1080,19 @@ LIRGenerator::visitToString(MToString *i
       case MIRType_Double:
       case MIRType_Null:
       case MIRType_Undefined:
       case MIRType_Boolean:
         JS_NOT_REACHED("NYI: Lower MToString");
         break;
 
       case MIRType_Int32: {
-        LIntToString *lir = new LIntToString(useRegisterAtStart(opd));
+        LIntToString *lir = new LIntToString(useRegister(opd));
 
-        if (!defineVMReturn(lir, ins))
+        if (!define(lir, ins))
             return false;
         return assignSafepoint(lir, ins);
       }
 
       default:
         // Objects might be effectful. (see ToPrimitive)
         JS_NOT_REACHED("unexpected type");
         break;
--- a/js/src/vm/String.h
+++ b/js/src/vm/String.h
@@ -677,32 +677,32 @@ namespace js {
 
 class StaticStrings
 {
   private:
     /* Bigger chars cannot be in a length-2 string. */
     static const size_t SMALL_CHAR_LIMIT    = 128U;
     static const size_t NUM_SMALL_CHARS     = 64U;
 
-    static const size_t INT_STATIC_LIMIT    = 256U;
-
     JSAtom *length2StaticTable[NUM_SMALL_CHARS * NUM_SMALL_CHARS];
-    JSAtom *intStaticTable[INT_STATIC_LIMIT];
 
     void clear() {
         PodArrayZero(unitStaticTable);
         PodArrayZero(length2StaticTable);
         PodArrayZero(intStaticTable);
     }
 
   public:
-    /* We keep these public for the methodjit. */
+    /* We keep these public for the JITs. */
     static const size_t UNIT_STATIC_LIMIT   = 256U;
     JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
 
+    static const size_t INT_STATIC_LIMIT    = 256U;
+    JSAtom *intStaticTable[INT_STATIC_LIMIT];
+
     StaticStrings() {
         clear();
     }
 
     bool init(JSContext *cx);
     void trace(JSTracer *trc);
     void finish() {
         clear();