Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / linkage.h
index 9fe0218..c5cef5e 100644 (file)
@@ -5,11 +5,10 @@
 #ifndef V8_COMPILER_LINKAGE_H_
 #define V8_COMPILER_LINKAGE_H_
 
-#include "src/v8.h"
-
+#include "src/base/flags.h"
 #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"
@@ -19,80 +18,111 @@ namespace internal {
 namespace compiler {
 
 // Describes the location for a parameter or a return value to a call.
-// TODO(titzer): replace with Radium locations when they are ready.
 class LinkageLocation {
  public:
-  LinkageLocation(MachineType rep, int location)
-      : rep_(rep), location_(location) {}
-
-  inline MachineType representation() const { return rep_; }
+  explicit LinkageLocation(int location) : location_(location) {}
 
   static const int16_t ANY_REGISTER = 32767;
 
+  static LinkageLocation AnyRegister() { return LinkageLocation(ANY_REGISTER); }
+
  private:
   friend class CallDescriptor;
   friend class OperandGenerator;
-  MachineType rep_;
   int16_t location_;  // >= 0 implies register, otherwise stack slot.
 };
 
+typedef Signature<LinkageLocation> LocationSignature;
 
-class CallDescriptor : public ZoneObject {
+// Describes a call to various parts of the compiler. Every call has the notion
+// of a "target", which is the first input to the call.
+class CallDescriptor FINAL : public ZoneObject {
  public:
-  // Describes whether the first parameter is a code object, a JSFunction,
-  // or an address--all of which require different machine sequences to call.
-  enum Kind { kCallCodeObject, kCallJSFunction, kCallAddress };
-
-  enum DeoptimizationSupport { kCanDeoptimize, kCannotDeoptimize };
-
-  CallDescriptor(Kind kind, int8_t return_count, int16_t parameter_count,
-                 int16_t input_count, LinkageLocation* locations,
-                 Operator::Property properties, RegList callee_saved_registers,
-                 DeoptimizationSupport deoptimization_support,
+  // Describes the kind of this call, which determines the target.
+  enum Kind {
+    kCallCodeObject,  // target is a Code object
+    kCallJSFunction,  // target is a JSFunction object
+    kCallAddress      // target is a machine pointer
+  };
+
+  enum Flag {
+    // TODO(jarin) kLazyDeoptimization and kNeedsFrameState should be unified.
+    kNoFlags = 0u,
+    kNeedsFrameState = 1u << 0,
+    kPatchableCallSite = 1u << 1,
+    kNeedsNopAfterCall = 1u << 2,
+    kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall
+  };
+  typedef base::Flags<Flag> Flags;
+
+  CallDescriptor(Kind kind, MachineType target_type, LinkageLocation target_loc,
+                 MachineSignature* machine_sig, LocationSignature* location_sig,
+                 size_t js_param_count, Operator::Properties properties,
+                 RegList callee_saved_registers, Flags flags,
                  const char* debug_name = "")
       : kind_(kind),
-        return_count_(return_count),
-        parameter_count_(parameter_count),
-        input_count_(input_count),
-        locations_(locations),
+        target_type_(target_type),
+        target_loc_(target_loc),
+        machine_sig_(machine_sig),
+        location_sig_(location_sig),
+        js_param_count_(js_param_count),
         properties_(properties),
         callee_saved_registers_(callee_saved_registers),
-        deoptimization_support_(deoptimization_support),
-        debug_name_(debug_name) {}
+        flags_(flags),
+        debug_name_(debug_name) {
+    DCHECK(machine_sig->return_count() == location_sig->return_count());
+    DCHECK(machine_sig->parameter_count() == location_sig->parameter_count());
+  }
+
   // Returns the kind of this call.
   Kind kind() const { return kind_; }
 
   // Returns {true} if this descriptor is a call to a JSFunction.
   bool IsJSFunctionCall() const { return kind_ == kCallJSFunction; }
 
-  // The number of return values from this call, usually 0 or 1.
-  int ReturnCount() const { return return_count_; }
+  // The number of return values from this call.
+  size_t ReturnCount() const { return machine_sig_->return_count(); }
+
+  // The number of JavaScript parameters to this call, including the receiver
+  // object.
+  size_t JSParameterCount() const { return js_param_count_; }
+
+  // The total number of inputs to this call, which includes the target,
+  // receiver, context, etc.
+  // TODO(titzer): this should input the framestate input too.
+  size_t InputCount() const { return 1 + machine_sig_->parameter_count(); }
+
+  size_t FrameStateCount() const { return NeedsFrameState() ? 1 : 0; }
 
-  // The number of JavaScript parameters to this call, including receiver,
-  // but not the context.
-  int ParameterCount() const { return parameter_count_; }
+  Flags flags() const { return flags_; }
 
-  int InputCount() const { return input_count_; }
+  bool NeedsFrameState() const { return flags() & kNeedsFrameState; }
 
-  bool CanLazilyDeoptimize() const {
-    return deoptimization_support_ == kCanDeoptimize;
+  LinkageLocation GetReturnLocation(size_t index) const {
+    return location_sig_->GetReturn(index);
   }
 
-  LinkageLocation GetReturnLocation(int index) {
-    DCHECK(index < return_count_);
-    return locations_[0 + index];  // return locations start at 0.
+  LinkageLocation GetInputLocation(size_t index) const {
+    if (index == 0) return target_loc_;
+    return location_sig_->GetParam(index - 1);
   }
 
-  LinkageLocation GetInputLocation(int index) {
-    DCHECK(index < input_count_ + 1);  // input_count + 1 is the context.
-    return locations_[return_count_ + index];  // inputs start after returns.
+  const MachineSignature* GetMachineSignature() const { return machine_sig_; }
+
+  MachineType GetReturnType(size_t index) const {
+    return machine_sig_->GetReturn(index);
+  }
+
+  MachineType GetInputType(size_t index) const {
+    if (index == 0) return target_type_;
+    return machine_sig_->GetParam(index - 1);
   }
 
   // Operator properties describe how this call can be optimized, if at all.
-  Operator::Property properties() const { return properties_; }
+  Operator::Properties properties() const { return properties_; }
 
   // Get the callee-saved registers, if any, across this call.
-  RegList CalleeSavedRegisters() { return callee_saved_registers_; }
+  RegList CalleeSavedRegisters() const { return callee_saved_registers_; }
 
   const char* debug_name() const { return debug_name_; }
 
@@ -100,16 +130,19 @@ class CallDescriptor : public ZoneObject {
   friend class Linkage;
 
   Kind kind_;
-  int8_t return_count_;
-  int16_t parameter_count_;
-  int16_t input_count_;
-  LinkageLocation* locations_;
-  Operator::Property properties_;
+  MachineType target_type_;
+  LinkageLocation target_loc_;
+  MachineSignature* machine_sig_;
+  LocationSignature* location_sig_;
+  size_t js_param_count_;
+  Operator::Properties properties_;
   RegList callee_saved_registers_;
-  DeoptimizationSupport deoptimization_support_;
+  Flags flags_;
   const char* debug_name_;
 };
 
+DEFINE_OPERATORS_FOR_FLAGS(CallDescriptor::Flags)
+
 OStream& operator<<(OStream& os, const CallDescriptor& d);
 OStream& operator<<(OStream& os, const CallDescriptor::Kind& k);
 
@@ -137,35 +170,35 @@ class Linkage : public ZoneObject {
   CallDescriptor* GetIncomingDescriptor() { return incoming_; }
   CallDescriptor* GetJSCallDescriptor(int parameter_count);
   static CallDescriptor* GetJSCallDescriptor(int parameter_count, Zone* zone);
-  CallDescriptor* GetRuntimeCallDescriptor(
-      Runtime::FunctionId function, int parameter_count,
-      Operator::Property properties,
-      CallDescriptor::DeoptimizationSupport can_deoptimize =
-          CallDescriptor::kCannotDeoptimize);
+  CallDescriptor* GetRuntimeCallDescriptor(Runtime::FunctionId function,
+                                           int parameter_count,
+                                           Operator::Properties properties);
   static CallDescriptor* GetRuntimeCallDescriptor(
       Runtime::FunctionId function, int parameter_count,
-      Operator::Property properties,
-      CallDescriptor::DeoptimizationSupport can_deoptimize, Zone* zone);
+      Operator::Properties properties, Zone* zone);
 
   CallDescriptor* GetStubCallDescriptor(
-      CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count = 0,
-      CallDescriptor::DeoptimizationSupport can_deoptimize =
-          CallDescriptor::kCannotDeoptimize);
+      CallInterfaceDescriptor descriptor, int stack_parameter_count = 0,
+      CallDescriptor::Flags flags = CallDescriptor::kNoFlags);
   static CallDescriptor* GetStubCallDescriptor(
-      CodeStubInterfaceDescriptor* descriptor, int stack_parameter_count,
-      CallDescriptor::DeoptimizationSupport can_deoptimize, Zone* zone);
+      CallInterfaceDescriptor descriptor, int stack_parameter_count,
+      CallDescriptor::Flags flags, Zone* zone);
 
   // Creates a call descriptor for simplified C calls that is appropriate
   // for the host platform. This simplified calling convention only supports
   // integers and pointers of one word size each, i.e. no floating point,
   // structs, pointers to members, etc.
-  static CallDescriptor* GetSimplifiedCDescriptor(
-      Zone* zone, int num_params, MachineType return_type,
-      const MachineType* param_types);
+  static CallDescriptor* GetSimplifiedCDescriptor(Zone* zone,
+                                                  MachineSignature* sig);
 
   // Get the location of an (incoming) parameter to this function.
   LinkageLocation GetParameterLocation(int index) {
-    return incoming_->GetInputLocation(index + 1);
+    return incoming_->GetInputLocation(index + 1);  // + 1 to skip target.
+  }
+
+  // Get the machine type of an (incoming) parameter to this function.
+  MachineType GetParameterType(int index) {
+    return incoming_->GetInputType(index + 1);  // + 1 to skip target.
   }
 
   // Get the location where this function should place its return value.
@@ -173,6 +206,9 @@ class Linkage : public ZoneObject {
     return incoming_->GetReturnLocation(0);
   }
 
+  // Get the machine type of this function's return value.
+  MachineType GetReturnType() { return incoming_->GetReturnType(0); }
+
   // Get the frame offset for a given spill slot. The location depends on the
   // calling convention and the specific frame layout, and may thus be
   // architecture-specific. Negative spill slots indicate arguments on the
@@ -182,12 +218,15 @@ class Linkage : public ZoneObject {
 
   CompilationInfo* info() const { return info_; }
 
+  static bool NeedsFrameState(Runtime::FunctionId function);
+
  private:
   CompilationInfo* info_;
   CallDescriptor* incoming_;
 };
-}
-}
-}  // namespace v8::internal::compiler
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8
 
 #endif  // V8_COMPILER_LINKAGE_H_