Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Unified Diff: src/compiler/code-assembler.h

Issue 1875583003: Separate CodeAssembler and CodeStubAssembler (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix gn build Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler/code-assembler.h
diff --git a/src/compiler/code-stub-assembler.h b/src/compiler/code-assembler.h
similarity index 70%
rename from src/compiler/code-stub-assembler.h
rename to src/compiler/code-assembler.h
index 7c3379e64f2be72417d1b73f99bb64cbe132ad4f..2c528b8aa9c43c80a6e4b5c12a20c7237daca2fc 100644
--- a/src/compiler/code-stub-assembler.h
+++ b/src/compiler/code-assembler.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef V8_COMPILER_CODE_STUB_ASSEMBLER_H_
-#define V8_COMPILER_CODE_STUB_ASSEMBLER_H_
+#ifndef V8_COMPILER_CODE_ASSEMBLER_H_
+#define V8_COMPILER_CODE_ASSEMBLER_H_
#include <map>
@@ -103,6 +103,9 @@ class Schedule;
#define CODE_STUB_ASSEMBLER_UNARY_OP_LIST(V) \
V(Float64Neg) \
V(Float64Sqrt) \
+ V(Float64ExtractLowWord32) \
+ V(Float64ExtractHighWord32) \
+ V(TruncateInt64ToInt32) \
V(ChangeFloat64ToUint32) \
V(ChangeInt32ToFloat64) \
V(ChangeInt32ToInt64) \
@@ -110,35 +113,52 @@ class Schedule;
V(ChangeUint32ToUint64) \
V(Word32Clz)
-class CodeStubAssembler {
+// A "public" interface used by components outside of compiler directory to
+// create code objects with TurboFan's backend. This class is mostly a thin shim
+// around the RawMachineAssembler, and its primary job is to ensure that the
+// innards of the RawMachineAssembler and other compiler implementation details
+// don't leak outside of the the compiler directory..
+//
+// V8 components that need to generate low-level code using this interface
+// should include this header--and this header only--from the compiler directory
+// (this is actually enforced). Since all interesting data structures are
+// forward declared, it's not possible for clients to peek inside the compiler
+// internals.
+//
+// In addition to providing isolation between TurboFan and code generation
+// clients, CodeAssembler also provides an abstraction for creating variables
+// and enhanced Label functionality to merge variable values along paths where
+// they have differing values, including loops.
+class CodeAssembler {
public:
// Create with CallStub linkage.
// |result_size| specifies the number of results returned by the stub.
// TODO(rmcilroy): move result_size to the CallInterfaceDescriptor.
- CodeStubAssembler(Isolate* isolate, Zone* zone,
- const CallInterfaceDescriptor& descriptor,
- Code::Flags flags, const char* name,
- size_t result_size = 1);
+ CodeAssembler(Isolate* isolate, Zone* zone,
+ const CallInterfaceDescriptor& descriptor, Code::Flags flags,
+ const char* name, size_t result_size = 1);
// Create with JSCall linkage.
- CodeStubAssembler(Isolate* isolate, Zone* zone, int parameter_count,
- Code::Flags flags, const char* name);
+ CodeAssembler(Isolate* isolate, Zone* zone, int parameter_count,
+ Code::Flags flags, const char* name);
- virtual ~CodeStubAssembler();
+ virtual ~CodeAssembler();
Handle<Code> GenerateCode();
+ bool Is64();
Benedikt Meurer 2016/04/11 18:12:09 Nit: const
danno 2016/04/18 11:00:04 Done.
+
class Label;
class Variable {
public:
- explicit Variable(CodeStubAssembler* assembler, MachineRepresentation rep);
+ explicit Variable(CodeAssembler* assembler, MachineRepresentation rep);
void Bind(Node* value);
Node* value() const;
MachineRepresentation rep() const;
bool IsBound() const;
private:
- friend class CodeStubAssembler;
+ friend class CodeAssembler;
class Impl;
Impl* impl_;
};
@@ -211,6 +231,9 @@ class CodeStubAssembler {
CODE_STUB_ASSEMBLER_UNARY_OP_LIST(DECLARE_CODE_STUB_ASSEMBER_UNARY_OP)
#undef DECLARE_CODE_STUB_ASSEMBER_UNARY_OP
+ Node* TruncateFloat64ToInt32RoundToZero(Node* a);
+ Node* TruncateFloat64ToInt32JavaScript(Node* a);
+
// Projections
Node* Projection(int index, Node* value);
@@ -271,111 +294,24 @@ class CodeStubAssembler {
// Macros
// ===========================================================================
- // Float64 operations.
- Node* Float64Ceil(Node* x);
- Node* Float64Floor(Node* x);
- Node* Float64Round(Node* x);
- Node* Float64Trunc(Node* x);
-
// Tag a Word as a Smi value.
Benedikt Meurer 2016/04/11 18:12:09 I think those Smi helpers should be in the CodeAss
danno 2016/04/18 11:00:03 As discussed, I see them there too, but I can't mo
Node* SmiTag(Node* value);
// Untag a Smi value as a Word.
Node* SmiUntag(Node* value);
- // Smi conversions.
- Node* SmiToFloat64(Node* value);
- Node* SmiToWord32(Node* value);
-
- // Smi operations.
- Node* SmiAdd(Node* a, Node* b);
- Node* SmiAddWithOverflow(Node* a, Node* b);
- Node* SmiSub(Node* a, Node* b);
- Node* SmiSubWithOverflow(Node* a, Node* b);
- Node* SmiEqual(Node* a, Node* b);
- Node* SmiLessThan(Node* a, Node* b);
- Node* SmiLessThanOrEqual(Node* a, Node* b);
- Node* SmiMin(Node* a, Node* b);
+ // Float64 operations.
+ Node* Float64Ceil(Node* x);
+ Node* Float64Floor(Node* x);
+ Node* Float64Round(Node* x);
+ Node* Float64Trunc(Node* x);
// Load a value from the root array.
Node* LoadRoot(Heap::RootListIndex root_index);
- // Check a value for smi-ness
- Node* WordIsSmi(Node* a);
-
- // Check that the value is a positive smi.
- Node* WordIsPositiveSmi(Node* a);
-
- // Load an object pointer from a buffer that isn't in the heap.
- Node* LoadBufferObject(Node* buffer, int offset,
- MachineType rep = MachineType::AnyTagged());
- // Load a field from an object on the heap.
- Node* LoadObjectField(Node* object, int offset,
- MachineType rep = MachineType::AnyTagged());
- // Load the floating point value of a HeapNumber.
- Node* LoadHeapNumberValue(Node* object);
- // Store the floating point value of a HeapNumber.
- Node* StoreHeapNumberValue(Node* object, Node* value);
- // Truncate the floating point value of a HeapNumber to an Int32.
- Node* TruncateHeapNumberValueToWord32(Node* object);
- // Load the bit field of a Map.
- Node* LoadMapBitField(Node* map);
- // Load bit field 2 of a map.
- Node* LoadMapBitField2(Node* map);
- // Load bit field 3 of a map.
- Node* LoadMapBitField3(Node* map);
- // Load the instance type of a map.
- Node* LoadMapInstanceType(Node* map);
- // Load the instance descriptors of a map.
- Node* LoadMapDescriptors(Node* map);
-
- // Load the hash field of a name.
- Node* LoadNameHash(Node* name);
-
- // Load an array element from a FixedArray.
- Node* LoadFixedArrayElementInt32Index(Node* object, Node* int32_index,
- int additional_offset = 0);
- Node* LoadFixedArrayElementSmiIndex(Node* object, Node* smi_index,
- int additional_offset = 0);
- Node* LoadFixedArrayElementConstantIndex(Node* object, int index);
-
// Allocate an object of the given size.
Node* Allocate(int size, AllocationFlags flags = kNone);
- // Allocate a HeapNumber without initializing its value.
- Node* AllocateHeapNumber();
- // Allocate a HeapNumber with a specific value.
- Node* AllocateHeapNumberWithValue(Node* value);
-
- // Store an array element to a FixedArray.
- Node* StoreFixedArrayElementNoWriteBarrier(Node* object, Node* index,
- Node* value);
- // Load the Map of an HeapObject.
- Node* LoadMap(Node* object);
- // Store the Map of an HeapObject.
- Node* StoreMapNoWriteBarrier(Node* object, Node* map);
- // Load the instance type of an HeapObject.
- Node* LoadInstanceType(Node* object);
-
- // Load the elements backing store of a JSObject.
- Node* LoadElements(Node* object);
- // Load the length of a fixed array base instance.
- Node* LoadFixedArrayBaseLength(Node* array);
-
- // Returns a node that is true if the given bit is set in |word32|.
- template <typename T>
- Node* BitFieldDecode(Node* word32) {
- return BitFieldDecode(word32, T::kShift, T::kMask);
- }
-
- Node* BitFieldDecode(Node* word32, uint32_t shift, uint32_t mask);
-
- // Conversions.
- Node* ChangeFloat64ToTagged(Node* value);
- Node* ChangeInt32ToTagged(Node* value);
- Node* TruncateTaggedToFloat64(Node* context, Node* value);
- Node* TruncateTaggedToWord32(Node* context, Node* value);
// Branching helpers.
- // TODO(danno): Can we be more cleverish wrt. edge-split?
void BranchIf(Node* condition, Label* if_true, Label* if_false);
#define BRANCH_HELPER(name) \
@@ -385,15 +321,6 @@ class CodeStubAssembler {
CODE_STUB_ASSEMBLER_COMPARE_BINARY_OP_LIST(BRANCH_HELPER)
#undef BRANCH_HELPER
- void BranchIfSmiLessThan(Node* a, Node* b, Label* if_true, Label* if_false) {
- BranchIf(SmiLessThan(a, b), if_true, if_false);
- }
-
- void BranchIfSmiLessThanOrEqual(Node* a, Node* b, Label* if_true,
- Label* if_false) {
- BranchIf(SmiLessThanOrEqual(a, b), if_true, if_false);
- }
-
void BranchIfFloat64IsNaN(Node* value, Label* if_true, Label* if_false) {
BranchIfFloat64Equal(value, value, if_false, if_true);
}
@@ -411,18 +338,17 @@ class CodeStubAssembler {
virtual void CallPrologue();
virtual void CallEpilogue();
+ Node* SmiShiftBitsConstant();
+
private:
- friend class CodeStubAssemblerTester;
+ friend class CodeAssemblerTester;
- CodeStubAssembler(Isolate* isolate, Zone* zone,
- CallDescriptor* call_descriptor, Code::Flags flags,
- const char* name);
+ CodeAssembler(Isolate* isolate, Zone* zone, CallDescriptor* call_descriptor,
+ Code::Flags flags, const char* name);
Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args);
Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args);
- Node* SmiShiftBitsConstant();
-
Node* AllocateRawAligned(Node* size_in_bytes, AllocationFlags flags,
Node* top_address, Node* limit_address);
Node* AllocateRawUnaligned(Node* size_in_bytes, AllocationFlags flags,
@@ -434,39 +360,36 @@ class CodeStubAssembler {
bool code_generated_;
ZoneVector<Variable::Impl*> variables_;
- DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler);
+ DISALLOW_COPY_AND_ASSIGN(CodeAssembler);
};
-DEFINE_OPERATORS_FOR_FLAGS(CodeStubAssembler::AllocationFlags);
+DEFINE_OPERATORS_FOR_FLAGS(CodeAssembler::AllocationFlags);
-class CodeStubAssembler::Label {
+class CodeAssembler::Label {
public:
enum Type { kDeferred, kNonDeferred };
- explicit Label(CodeStubAssembler* assembler,
- CodeStubAssembler::Label::Type type =
- CodeStubAssembler::Label::kNonDeferred)
- : CodeStubAssembler::Label(assembler, 0, nullptr, type) {}
- Label(CodeStubAssembler* assembler,
- CodeStubAssembler::Variable* merged_variable,
- CodeStubAssembler::Label::Type type =
- CodeStubAssembler::Label::kNonDeferred)
- : CodeStubAssembler::Label(assembler, 1, &merged_variable, type) {}
- Label(CodeStubAssembler* assembler, int merged_variable_count,
- CodeStubAssembler::Variable** merged_variables,
- CodeStubAssembler::Label::Type type =
- CodeStubAssembler::Label::kNonDeferred);
+ explicit Label(
+ CodeAssembler* assembler,
+ CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
+ : CodeAssembler::Label(assembler, 0, nullptr, type) {}
+ Label(CodeAssembler* assembler, CodeAssembler::Variable* merged_variable,
+ CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
+ : CodeAssembler::Label(assembler, 1, &merged_variable, type) {}
+ Label(CodeAssembler* assembler, int merged_variable_count,
+ CodeAssembler::Variable** merged_variables,
+ CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred);
~Label() {}
private:
- friend class CodeStubAssembler;
+ friend class CodeAssembler;
void Bind();
void MergeVariables();
bool bound_;
size_t merge_count_;
- CodeStubAssembler* assembler_;
+ CodeAssembler* assembler_;
RawMachineLabel* label_;
// Map of variables that need to be merged to their phi nodes (or placeholders
// for those phis).
@@ -480,4 +403,4 @@ class CodeStubAssembler::Label {
} // namespace internal
} // namespace v8
-#endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_
+#endif // V8_COMPILER_CODE_ASSEMBLER_H_

Powered by Google App Engine
This is Rietveld 408576698