Revision: 23490
Author:   tit...@chromium.org
Date:     Thu Aug 28 13:17:38 2014 UTC
Log: Add MachineSignature, which is an encapsulation of the machine types for parameters and return values in a graph.

This utility will be used to simplify Linkage and fix representation inference
to work with graphs where parameters and return values are something other
than tagged. It will also make testing representation inference a lot
easier, since we can then exactly nail down the machine types of parameters
and returns.

This CL also adds c-signature.h, which demonstrates how to convert C function
signatures into MachineSignatures. The CSignatures will be used in tests to
make it easier and simpler to codegen tests.

R=ja...@chromium.org
BUG=

Review URL: https://codereview.chromium.org/515173002
https://code.google.com/p/v8/source/detail?r=23490

Added:
 /branches/bleeding_edge/test/cctest/compiler/c-signature.h
Modified:
 /branches/bleeding_edge/src/compiler/change-lowering.cc
 /branches/bleeding_edge/src/compiler/linkage-impl.h
 /branches/bleeding_edge/src/compiler/linkage.h
 /branches/bleeding_edge/src/compiler/machine-operator.h
 /branches/bleeding_edge/src/compiler/machine-type.h
 /branches/bleeding_edge/src/compiler/raw-machine-assembler.h
 /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc
 /branches/bleeding_edge/src/compiler/structured-machine-assembler.h
 /branches/bleeding_edge/test/cctest/cctest.gyp
 /branches/bleeding_edge/test/cctest/compiler/codegen-tester.h
 /branches/bleeding_edge/test/cctest/compiler/instruction-selector-tester.h
 /branches/bleeding_edge/test/cctest/compiler/test-run-machops.cc
 /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc
/branches/bleeding_edge/test/cctest/compiler/test-structured-ifbuilder-fuzzer.cc /branches/bleeding_edge/test/cctest/compiler/test-structured-machine-assembler.cc

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/cctest/compiler/c-signature.h Thu Aug 28 13:17:38 2014 UTC
@@ -0,0 +1,133 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_COMPILER_C_SIGNATURE_H_
+#define V8_COMPILER_C_SIGNATURE_H_
+
+#include "src/compiler/machine-type.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+template <typename T>
+inline MachineType MachineTypeForC() {
+  CHECK(false);  // Instantiated with invalid type.
+  return kMachNone;
+}
+
+template <>
+inline MachineType MachineTypeForC<void>() {
+  return kMachNone;
+}
+
+template <>
+inline MachineType MachineTypeForC<int8_t>() {
+  return kMachInt8;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint8_t>() {
+  return kMachUint8;
+}
+
+template <>
+inline MachineType MachineTypeForC<int16_t>() {
+  return kMachInt16;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint16_t>() {
+  return kMachUint16;
+}
+
+template <>
+inline MachineType MachineTypeForC<int32_t>() {
+  return kMachInt32;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint32_t>() {
+  return kMachUint32;
+}
+
+template <>
+inline MachineType MachineTypeForC<int64_t>() {
+  return kMachInt64;
+}
+
+template <>
+inline MachineType MachineTypeForC<uint64_t>() {
+  return kMachUint64;
+}
+
+template <>
+inline MachineType MachineTypeForC<double>() {
+  return kMachFloat64;
+}
+
+template <>
+inline MachineType MachineTypeForC<Object*>() {
+  return kMachAnyTagged;
+}
+
+template <typename Ret, uint16_t kParamCount>
+class CSignatureOf : public MachineSignature {
+ protected:
+  MachineType storage_[1 + kParamCount];
+
+  CSignatureOf()
+      : MachineSignature(MachineTypeForC<Ret>() != kMachNone ? 1 : 0,
+                         kParamCount,
+                         reinterpret_cast<MachineType*>(&storage_)) {
+    if (return_count_ == 1) storage_[0] = MachineTypeForC<Ret>();
+  }
+  void Set(int index, MachineType type) {
+    DCHECK(index >= 0 && index < kParamCount);
+    reps_[return_count_ + index] = type;
+  }
+};
+
+// Helper classes for instantiating Signature objects to be callable from C.
+template <typename Ret>
+class CSignature0 : public CSignatureOf<Ret, 0> {
+ public:
+  CSignature0() : CSignatureOf<Ret, 0>() {}
+};
+
+template <typename Ret, typename P1>
+class CSignature1 : public CSignatureOf<Ret, 1> {
+ public:
+  CSignature1() : CSignatureOf<Ret, 1>() {
+    this->Set(0, MachineTypeForC<P1>());
+  }
+};
+
+template <typename Ret, typename P1, typename P2>
+class CSignature2 : public CSignatureOf<Ret, 2> {
+ public:
+  CSignature2() : CSignatureOf<Ret, 2>() {
+    this->Set(0, MachineTypeForC<P1>());
+    this->Set(1, MachineTypeForC<P2>());
+  }
+};
+
+template <typename Ret, typename P1, typename P2, typename P3>
+class CSignature3 : public CSignatureOf<Ret, 3> {
+ public:
+  CSignature3() : CSignatureOf<Ret, 3>() {
+    this->Set(0, MachineTypeForC<P1>());
+    this->Set(1, MachineTypeForC<P2>());
+    this->Set(2, MachineTypeForC<P3>());
+  }
+};
+
+static const CSignature2<int32_t, int32_t, int32_t> int32_int32_to_int32;
+static const CSignature2<uint32_t, uint32_t, uint32_t> uint32_uint32_to_uint32; +static const CSignature2<double, double, double> float64_float64_to_float64;
+}
+}
+}  // namespace v8::internal::compiler
+
+#endif  // V8_COMPILER_C_SIGNATURE_H_
=======================================
--- /branches/bleeding_edge/src/compiler/change-lowering.cc Wed Aug 27 13:49:30 2014 UTC +++ /branches/bleeding_edge/src/compiler/change-lowering.cc Thu Aug 28 13:17:38 2014 UTC
@@ -3,6 +3,7 @@
 // found in the LICENSE file.

 #include "src/compiler/change-lowering.h"
+#include "src/compiler/machine-operator.h"

 #include "src/compiler/js-graph.h"

=======================================
--- /branches/bleeding_edge/src/compiler/linkage-impl.h Thu Aug 21 11:56:46 2014 UTC +++ /branches/bleeding_edge/src/compiler/linkage-impl.h Thu Aug 28 13:17:38 2014 UTC
@@ -21,8 +21,7 @@
   }

   static inline LinkageLocation WordRegisterLocation(Register reg) {
-    return LinkageLocation(MachineOperatorBuilder::pointer_rep(),
-                           Register::ToAllocationIndex(reg));
+    return LinkageLocation(kMachPtr, Register::ToAllocationIndex(reg));
   }

   static LinkageLocation UnconstrainedRegister(MachineType rep) {
@@ -180,8 +179,7 @@
     int index = 0;
     locations[index++] =
         TaggedRegisterLocation(LinkageTraits::ReturnValueReg());
-    locations[index++] = LinkageHelper::UnconstrainedRegister(
-        MachineOperatorBuilder::pointer_rep());
+    locations[index++] = LinkageHelper::UnconstrainedRegister(kMachPtr);
     // TODO(dcarney): test with lots of parameters.
     int i = 0;
for (; i < LinkageTraits::CRegisterParametersLength() && i < num_params;
=======================================
--- /branches/bleeding_edge/src/compiler/linkage.h Thu Aug 21 11:56:46 2014 UTC +++ /branches/bleeding_edge/src/compiler/linkage.h Thu Aug 28 13:17:38 2014 UTC
@@ -9,7 +9,7 @@

 #include "src/code-stubs.h"
 #include "src/compiler/frame.h"
-#include "src/compiler/machine-operator.h"
+#include "src/compiler/machine-type.h"
 #include "src/compiler/node.h"
 #include "src/compiler/operator.h"
 #include "src/zone.h"
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator.h Wed Aug 20 04:01:00 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator.h Thu Aug 28 13:17:38 2014 UTC
@@ -31,7 +31,7 @@
 // for generating code to run on architectures such as ia32, x64, arm, etc.
 class MachineOperatorBuilder {
  public:
- explicit MachineOperatorBuilder(Zone* zone, MachineType word = pointer_rep())
+  explicit MachineOperatorBuilder(Zone* zone, MachineType word = kMachPtr)
       : zone_(zone), word_(word) {
     CHECK(word == kRepWord32 || word == kRepWord64);
   }
@@ -155,10 +155,6 @@
   inline bool is32() const { return word_ == kRepWord32; }
   inline bool is64() const { return word_ == kRepWord64; }
   inline MachineType word() const { return word_; }
-
-  static inline MachineType pointer_rep() {
-    return kPointerSize == 8 ? kRepWord64 : kRepWord32;
-  }

 #undef WORD_SIZE
 #undef UNOP
=======================================
--- /branches/bleeding_edge/src/compiler/machine-type.h Tue Aug 26 08:29:12 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-type.h Thu Aug 28 13:17:38 2014 UTC
@@ -108,6 +108,32 @@
   }
 }

+// Describes the inputs and outputs of a function or call in terms of machine
+// types.
+class MachineSignature {
+ public:
+  MachineSignature(uint8_t return_count, uint16_t param_count,
+                   MachineType* reps)
+ : return_count_(return_count), param_count_(param_count), reps_(reps) {}
+
+  int GetReturnCount() const { return return_count_; }
+  int GetParamCount() const { return param_count_; }
+
+  MachineType GetParameterType(int index) const {
+    DCHECK(index >= 0 && index < param_count_);
+    return reps_[return_count_ + index];
+  }
+
+  MachineType GetReturnType(int index = 0) const {
+    DCHECK(index >= 0 && index < return_count_);
+    return reps_[index];
+  }
+
+ protected:
+  uint8_t return_count_;
+  uint16_t param_count_;
+  MachineType* reps_;
+};
 }  // namespace compiler
 }  // namespace internal
 }  // namespace v8
=======================================
--- /branches/bleeding_edge/src/compiler/raw-machine-assembler.h Wed Aug 27 15:56:11 2014 UTC +++ /branches/bleeding_edge/src/compiler/raw-machine-assembler.h Thu Aug 28 13:17:38 2014 UTC
@@ -47,7 +47,7 @@

   RawMachineAssembler(Graph* graph,
MachineCallDescriptorBuilder* call_descriptor_builder, - MachineType word = MachineOperatorBuilder::pointer_rep());
+                      MachineType word = kMachPtr);
   virtual ~RawMachineAssembler() {}

   Isolate* isolate() const { return zone()->isolate(); }
=======================================
--- /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc Wed Aug 27 14:47:50 2014 UTC +++ /branches/bleeding_edge/src/compiler/simplified-operator-reducer.cc Thu Aug 28 13:17:38 2014 UTC
@@ -4,6 +4,7 @@

 #include "src/compiler/generic-node-inl.h"
 #include "src/compiler/js-graph.h"
+#include "src/compiler/machine-operator.h"
 #include "src/compiler/node-matchers.h"
 #include "src/compiler/simplified-operator-reducer.h"

=======================================
--- /branches/bleeding_edge/src/compiler/structured-machine-assembler.h Tue Aug 26 13:09:08 2014 UTC +++ /branches/bleeding_edge/src/compiler/structured-machine-assembler.h Thu Aug 28 13:17:38 2014 UTC
@@ -63,7 +63,7 @@

   StructuredMachineAssembler(
       Graph* graph, MachineCallDescriptorBuilder* call_descriptor_builder,
-      MachineType word = MachineOperatorBuilder::pointer_rep());
+      MachineType word = kMachPtr);
   virtual ~StructuredMachineAssembler() {}

   Isolate* isolate() const { return zone()->isolate(); }
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.gyp Fri Aug 22 08:52:40 2014 UTC +++ /branches/bleeding_edge/test/cctest/cctest.gyp Thu Aug 28 13:17:38 2014 UTC
@@ -44,6 +44,7 @@
       ],
       'sources': [  ### gcmole(all) ###
         '<(generated_file)',
+        'compiler/c-signature.h',
         'compiler/codegen-tester.cc',
         'compiler/codegen-tester.h',
         'compiler/function-tester.h',
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/codegen-tester.h Thu Aug 14 09:19:54 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/codegen-tester.h Thu Aug 28 13:17:38 2014 UTC
@@ -30,7 +30,7 @@
         MachineAssembler(new (main_zone()) Graph(main_zone()),
ToCallDescriptorBuilder(main_zone(), return_type, p0,
                                                  p1, p2, p3, p4),
-                         MachineOperatorBuilder::pointer_rep()) {}
+                         kMachPtr) {}

Node* LoadFromPointer(void* address, MachineType rep, int32_t offset = 0) {
     return this->Load(rep, this->PointerConstant(address),
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/instruction-selector-tester.h Thu Aug 14 09:19:54 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/instruction-selector-tester.h Thu Aug 28 13:17:38 2014 UTC
@@ -40,7 +40,7 @@
             new (main_zone()) Graph(main_zone()),
             new (main_zone()) MachineCallDescriptorBuilder(
kMachInt32, kParameterCount, BuildParameterArray(main_zone())),
-            MachineOperatorBuilder::pointer_rep()) {}
+            kMachPtr) {}

   void SelectInstructions(CpuFeature feature) {
     SelectInstructions(InstructionSelector::Features(feature));
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-run-machops.cc Tue Aug 26 09:19:24 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-run-machops.cc Thu Aug 28 13:17:38 2014 UTC
@@ -3534,10 +3534,9 @@
     RawMachineAssemblerTester<int32_t> m;
     Node** args = NULL;
     MachineType* arg_types = NULL;
-    Node* function =
-        call_direct ? m.PointerConstant(function_address)
-                    : m.LoadFromPointer(&function_address,
- MachineOperatorBuilder::pointer_rep());
+    Node* function = call_direct
+                         ? m.PointerConstant(function_address)
+                         : m.LoadFromPointer(&function_address, kMachPtr);
     m.Return(m.CallC(function, kMachInt32, arg_types, args, 0));

     CHECK_EQ(7, m.Call());
@@ -3554,10 +3553,9 @@
     RawMachineAssemblerTester<int32_t> m(kMachInt32);
     Node* args[] = {m.Parameter(0)};
     MachineType arg_types[] = {kMachInt32};
-    Node* function =
-        call_direct ? m.PointerConstant(function_address)
-                    : m.LoadFromPointer(&function_address,
- MachineOperatorBuilder::pointer_rep());
+    Node* function = call_direct
+                         ? m.PointerConstant(function_address)
+                         : m.LoadFromPointer(&function_address, kMachPtr);
     m.Return(m.CallC(function, kMachInt32, arg_types, args, 1));

     FOR_INT32_INPUTS(i) {
@@ -3577,10 +3575,9 @@
     RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32);
     Node* args[] = {m.Parameter(0), m.Parameter(1)};
     MachineType arg_types[] = {kMachInt32, kMachInt32};
-    Node* function =
-        call_direct ? m.PointerConstant(function_address)
-                    : m.LoadFromPointer(&function_address,
- MachineOperatorBuilder::pointer_rep());
+    Node* function = call_direct
+                         ? m.PointerConstant(function_address)
+                         : m.LoadFromPointer(&function_address, kMachPtr);
     m.Return(m.CallC(function, kMachInt32, arg_types, args, 2));

     FOR_INT32_INPUTS(i) {
@@ -3819,8 +3816,7 @@

 static void IntPtrCompare(intptr_t left, intptr_t right) {
   for (int test = 0; test < 7; test++) {
- RawMachineAssemblerTester<bool> m(MachineOperatorBuilder::pointer_rep(), - MachineOperatorBuilder::pointer_rep());
+    RawMachineAssemblerTester<bool> m(kMachPtr, kMachPtr);
     Node* p0 = m.Parameter(0);
     Node* p1 = m.Parameter(1);
     Node* res = NULL;
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc Tue Aug 26 09:19:24 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-simplified-lowering.cc Thu Aug 28 13:17:38 2014 UTC
@@ -72,9 +72,8 @@

 FieldAccess ForArrayBufferBackingStore() {
   FieldAccess access = {
- kTaggedBase, JSArrayBuffer::kBackingStoreOffset,
-      Handle<Name>(),                        Type::UntaggedPtr(),
-      MachineOperatorBuilder::pointer_rep(),
+ kTaggedBase, JSArrayBuffer::kBackingStoreOffset, Handle<Name>(),
+      Type::UntaggedPtr(), kMachPtr,
   };
   return access;
 }
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-structured-ifbuilder-fuzzer.cc Tue Aug 26 09:19:24 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-structured-ifbuilder-fuzzer.cc Thu Aug 28 13:17:38 2014 UTC
@@ -267,9 +267,7 @@
class IfBuilderGenerator : public StructuredMachineAssemblerTester<int32_t> {
  public:
   IfBuilderGenerator()
-      : StructuredMachineAssemblerTester<int32_t>(
-            MachineOperatorBuilder::pointer_rep(),
-            MachineOperatorBuilder::pointer_rep()),
+      : StructuredMachineAssemblerTester<int32_t>(kMachPtr, kMachPtr),
         var_(NewVariable(Int32Constant(kInitalVar))),
         c_(this),
         m_(this->zone()),
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-structured-machine-assembler.cc Tue Aug 26 09:19:24 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-structured-machine-assembler.cc Thu Aug 28 13:17:38 2014 UTC
@@ -878,9 +878,8 @@
 class QuicksortHelper : public StructuredMachineAssemblerTester<int32_t> {
  public:
   QuicksortHelper()
-      : StructuredMachineAssemblerTester<int32_t>(
-            MachineOperatorBuilder::pointer_rep(), kMachInt32,
-            MachineOperatorBuilder::pointer_rep(), kMachInt32),
+      : StructuredMachineAssemblerTester<int32_t>(kMachPtr, kMachInt32,
+                                                  kMachPtr, kMachInt32),
         input_(NULL),
         stack_limit_(NULL),
         one_(Int32Constant(1)),

--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to