Commit 4711e6d6 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[compiler] Replace some MachineType by MachineRepresentation

For determining whether unaligned memory accessed is allowed, it is
actually sufficient to pass the MachineRepresentation instead of the
MachineType.
As the MachineRepresentation is an enum, this allows to store the set
of unsupported types as an EnumSet instead of std::vector.

R=mstarzinger@chromium.org

Change-Id: Ibe44717bae3a6034bae683057e80bd40d92e70ae
Reviewed-on: https://chromium-review.googlesource.com/598790
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47123}
parent 744b901d
......@@ -274,8 +274,8 @@ TF_BUILTIN(TypedArrayInitialize, TypedArrayBuiltinsAssembler) {
Node* elements;
if (UnalignedLoadSupported(MachineType::Float64()) &&
UnalignedStoreSupported(MachineType::Float64())) {
if (UnalignedLoadSupported(MachineRepresentation::kFloat64) &&
UnalignedStoreSupported(MachineRepresentation::kFloat64)) {
elements = AllocateInNewSpace(var_total_size.value());
} else {
elements = AllocateInNewSpace(var_total_size.value(), kDoubleAlignment);
......
......@@ -2716,9 +2716,9 @@ InstructionSelector::SupportedMachineOperatorFlags() {
// static
MachineOperatorBuilder::AlignmentRequirements
InstructionSelector::AlignmentRequirements() {
Vector<MachineType> req_aligned = Vector<MachineType>::New(2);
req_aligned[0] = MachineType::Float32();
req_aligned[1] = MachineType::Float64();
EnumSet<MachineRepresentation> req_aligned;
req_aligned.Add(MachineRepresentation::kFloat32);
req_aligned.Add(MachineRepresentation::kFloat64);
return MachineOperatorBuilder::AlignmentRequirements::
SomeUnalignedAccessUnsupported(req_aligned, req_aligned);
}
......
......@@ -801,13 +801,11 @@ void CodeAssembler::Switch(Node* index, Label* default_label,
labels, case_count);
}
bool CodeAssembler::UnalignedLoadSupported(
const MachineType& machineType) const {
return raw_assembler()->machine()->UnalignedLoadSupported(machineType);
bool CodeAssembler::UnalignedLoadSupported(MachineRepresentation rep) const {
return raw_assembler()->machine()->UnalignedLoadSupported(rep);
}
bool CodeAssembler::UnalignedStoreSupported(
const MachineType& machineType) const {
return raw_assembler()->machine()->UnalignedStoreSupported(machineType);
bool CodeAssembler::UnalignedStoreSupported(MachineRepresentation rep) const {
return raw_assembler()->machine()->UnalignedStoreSupported(rep);
}
// RawMachineAssembler delegate helpers:
......
......@@ -452,8 +452,8 @@ class V8_EXPORT_PRIVATE CodeAssembler {
void BreakOnNode(int node_id);
bool UnalignedLoadSupported(const MachineType& machineType) const;
bool UnalignedStoreSupported(const MachineType& machineType) const;
bool UnalignedLoadSupported(MachineRepresentation rep) const;
bool UnalignedStoreSupported(MachineRepresentation rep) const;
protected:
void RegisterCallGenerationCallbacks(
......
......@@ -9,6 +9,7 @@
#include "src/base/flags.h"
#include "src/globals.h"
#include "src/machine-type.h"
#include "src/utils.h"
namespace v8 {
namespace internal {
......@@ -167,12 +168,12 @@ class V8_EXPORT_PRIVATE MachineOperatorBuilder final
public:
enum UnalignedAccessSupport { kNoSupport, kSomeSupport, kFullSupport };
bool IsUnalignedLoadSupported(const MachineType& machineType) const {
return IsUnalignedSupported(unalignedLoadUnsupportedTypes_, machineType);
bool IsUnalignedLoadSupported(MachineRepresentation rep) const {
return IsUnalignedSupported(unalignedLoadUnsupportedTypes_, rep);
}
bool IsUnalignedStoreSupported(const MachineType& machineType) const {
return IsUnalignedSupported(unalignedStoreUnsupportedTypes_, machineType);
bool IsUnalignedStoreSupported(MachineRepresentation rep) const {
return IsUnalignedSupported(unalignedStoreUnsupportedTypes_, rep);
}
static AlignmentRequirements FullUnalignedAccessSupport() {
......@@ -182,8 +183,8 @@ class V8_EXPORT_PRIVATE MachineOperatorBuilder final
return AlignmentRequirements(kNoSupport);
}
static AlignmentRequirements SomeUnalignedAccessUnsupported(
const Vector<MachineType>& unalignedLoadUnsupportedTypes,
const Vector<MachineType>& unalignedStoreUnsupportedTypes) {
EnumSet<MachineRepresentation> unalignedLoadUnsupportedTypes,
EnumSet<MachineRepresentation> unalignedStoreUnsupportedTypes) {
return AlignmentRequirements(kSomeSupport, unalignedLoadUnsupportedTypes,
unalignedStoreUnsupportedTypes);
}
......@@ -191,35 +192,32 @@ class V8_EXPORT_PRIVATE MachineOperatorBuilder final
private:
explicit AlignmentRequirements(
AlignmentRequirements::UnalignedAccessSupport unalignedAccessSupport,
Vector<MachineType> unalignedLoadUnsupportedTypes =
Vector<MachineType>(NULL, 0),
Vector<MachineType> unalignedStoreUnsupportedTypes =
Vector<MachineType>(NULL, 0))
EnumSet<MachineRepresentation> unalignedLoadUnsupportedTypes =
EnumSet<MachineRepresentation>(),
EnumSet<MachineRepresentation> unalignedStoreUnsupportedTypes =
EnumSet<MachineRepresentation>())
: unalignedSupport_(unalignedAccessSupport),
unalignedLoadUnsupportedTypes_(unalignedLoadUnsupportedTypes),
unalignedStoreUnsupportedTypes_(unalignedStoreUnsupportedTypes) {}
bool IsUnalignedSupported(const Vector<MachineType>& unsupported,
const MachineType& machineType) const {
bool IsUnalignedSupported(EnumSet<MachineRepresentation> unsupported,
MachineRepresentation rep) const {
// All accesses of bytes in memory are aligned.
DCHECK_NE(machineType.representation(), MachineRepresentation::kWord8);
if (unalignedSupport_ == kFullSupport) {
return true;
} else if (unalignedSupport_ == kNoSupport) {
return false;
} else {
for (MachineType m : unsupported) {
if (m == machineType) {
return false;
}
}
return true;
DCHECK_NE(MachineRepresentation::kWord8, rep);
switch (unalignedSupport_) {
case kFullSupport:
return true;
case kNoSupport:
return false;
case kSomeSupport:
return !unsupported.Contains(rep);
}
UNREACHABLE();
}
const AlignmentRequirements::UnalignedAccessSupport unalignedSupport_;
const Vector<MachineType> unalignedLoadUnsupportedTypes_;
const Vector<MachineType> unalignedStoreUnsupportedTypes_;
const EnumSet<MachineRepresentation> unalignedLoadUnsupportedTypes_;
const EnumSet<MachineRepresentation> unalignedStoreUnsupportedTypes_;
};
explicit MachineOperatorBuilder(
......@@ -632,12 +630,12 @@ class V8_EXPORT_PRIVATE MachineOperatorBuilder final
bool Is64() const { return word() == MachineRepresentation::kWord64; }
MachineRepresentation word() const { return word_; }
bool UnalignedLoadSupported(const MachineType& machineType) {
return alignment_requirements_.IsUnalignedLoadSupported(machineType);
bool UnalignedLoadSupported(MachineRepresentation rep) {
return alignment_requirements_.IsUnalignedLoadSupported(rep);
}
bool UnalignedStoreSupported(const MachineType& machineType) {
return alignment_requirements_.IsUnalignedStoreSupported(machineType);
bool UnalignedStoreSupported(MachineRepresentation rep) {
return alignment_requirements_.IsUnalignedStoreSupported(rep);
}
// Pseudo operators that translate to 32/64-bit operators depending on the
......
......@@ -139,14 +139,14 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
Node* Retain(Node* value) { return AddNode(common()->Retain(), value); }
// Unaligned memory operations
Node* UnalignedLoad(MachineType rep, Node* base) {
return UnalignedLoad(rep, base, IntPtrConstant(0));
Node* UnalignedLoad(MachineType type, Node* base) {
return UnalignedLoad(type, base, IntPtrConstant(0));
}
Node* UnalignedLoad(MachineType rep, Node* base, Node* index) {
if (machine()->UnalignedLoadSupported(rep)) {
return AddNode(machine()->Load(rep), base, index);
Node* UnalignedLoad(MachineType type, Node* base, Node* index) {
if (machine()->UnalignedLoadSupported(type.representation())) {
return AddNode(machine()->Load(type), base, index);
} else {
return AddNode(machine()->UnalignedLoad(rep), base, index);
return AddNode(machine()->UnalignedLoad(type), base, index);
}
}
Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* value) {
......@@ -154,8 +154,7 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
}
Node* UnalignedStore(MachineRepresentation rep, Node* base, Node* index,
Node* value) {
MachineType t = MachineType::TypeForRepresentation(rep);
if (machine()->UnalignedStoreSupported(t)) {
if (machine()->UnalignedStoreSupported(rep)) {
return AddNode(machine()->Store(StoreRepresentation(
rep, WriteBarrierKind::kNoWriteBarrier)),
base, index, value);
......@@ -167,8 +166,8 @@ class V8_EXPORT_PRIVATE RawMachineAssembler {
}
// Atomic memory operations.
Node* AtomicLoad(MachineType rep, Node* base, Node* index) {
return AddNode(machine()->AtomicLoad(rep), base, index);
Node* AtomicLoad(MachineType type, Node* base, Node* index) {
return AddNode(machine()->AtomicLoad(type), base, index);
}
Node* AtomicStore(MachineRepresentation rep, Node* base, Node* index,
Node* value) {
......
......@@ -3190,8 +3190,7 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index,
const Operator* WasmGraphBuilder::GetSafeStoreOperator(int offset,
wasm::ValueType type) {
int alignment = offset % (1 << ElementSizeLog2Of(type));
if (alignment == 0 || jsgraph()->machine()->UnalignedStoreSupported(
MachineType::TypeForRepresentation(type))) {
if (alignment == 0 || jsgraph()->machine()->UnalignedStoreSupported(type)) {
StoreRepresentation rep(type, WriteBarrierKind::kNoWriteBarrier);
return jsgraph()->machine()->Store(rep);
}
......@@ -3211,7 +3210,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
}
if (memtype.representation() == MachineRepresentation::kWord8 ||
jsgraph()->machine()->UnalignedLoadSupported(memtype)) {
jsgraph()->machine()->UnalignedLoadSupported(memtype.representation())) {
if (FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED) {
DCHECK(FLAG_wasm_guard_pages);
Node* position_node = jsgraph()->Int32Constant(position);
......@@ -3267,7 +3266,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
#endif
if (memtype.representation() == MachineRepresentation::kWord8 ||
jsgraph()->machine()->UnalignedStoreSupported(memtype)) {
jsgraph()->machine()->UnalignedStoreSupported(memtype.representation())) {
if (FLAG_wasm_trap_handler && V8_TRAP_HANDLER_SUPPORTED) {
Node* position_node = jsgraph()->Int32Constant(position);
store = graph()->NewNode(
......
......@@ -1119,8 +1119,8 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) {
const MemoryAccessImm2 memacc = GetParam();
TRACED_FOREACH(int32_t, index, memacc.immediates) {
StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer());
bool unaligned_store_supported = m.machine()->UnalignedStoreSupported(
MachineType::TypeForRepresentation(memacc.type.representation()));
bool unaligned_store_supported =
m.machine()->UnalignedStoreSupported(memacc.type.representation());
m.UnalignedStore(memacc.type.representation(), m.Parameter(0),
m.Int32Constant(index), m.Int32Constant(0));
m.Return(m.Int32Constant(0));
......
......@@ -1561,8 +1561,8 @@ TEST_P(InstructionSelectorMemoryAccessUnalignedImmTest, StoreZero) {
const MemoryAccessImm2 memacc = GetParam();
TRACED_FOREACH(int32_t, index, memacc.immediates) {
StreamBuilder m(this, MachineType::Int32(), MachineType::Pointer());
bool unaligned_store_supported = m.machine()->UnalignedStoreSupported(
MachineType::TypeForRepresentation(memacc.type.representation()));
bool unaligned_store_supported =
m.machine()->UnalignedStoreSupported(memacc.type.representation());
m.UnalignedStore(memacc.type.representation(), m.Parameter(0),
m.Int32Constant(index), m.Int32Constant(0));
m.Return(m.Int32Constant(0));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment