Commit 3b16f676 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[runtime] Cleanup SharedFunctionInfo fields definitions (4).

Define compiler hints bits as bit fields but not as enum.
This eases adding new bit fields to the compiler hints field.

TBR=marja@chromium.org

Bug: v8:6470
Change-Id: Ia023bab25b925847924c45d5a57f85a14c8f1971
Reviewed-on: https://chromium-review.googlesource.com/529044
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45825}
parent be113513
......@@ -2418,8 +2418,8 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
// We need to convert the receiver for non-native sloppy mode functions.
Label done_convert;
__ TestAndBranchIfAnySet(w3,
(1 << SharedFunctionInfo::kNative) |
(1 << SharedFunctionInfo::kStrictModeFunction),
(1 << SharedFunctionInfo::kNativeBit) |
(1 << SharedFunctionInfo::kStrictModeBit),
&done_convert);
{
// ----------- S t a t e -------------
......
......@@ -103,8 +103,7 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewClosure(Node* shared_info,
STATIC_ASSERT(FunctionKind::kNormalFunction == 0);
Node* is_not_normal =
Word32And(compiler_hints,
Int32Constant(SharedFunctionInfo::kAllFunctionKindBitsMask));
DecodeWord32<SharedFunctionInfo::FunctionKindBits>(compiler_hints);
GotoIfNot(is_not_normal, &if_normal);
Node* is_generator = Word32And(
......
......@@ -5482,10 +5482,10 @@ void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) {
FieldMemOperand(result, SharedFunctionInfo::kCompilerHintsOffset));
// Do not transform the receiver to object for strict mode functions.
__ Tbnz(result, SharedFunctionInfo::kStrictModeFunction, &copy_receiver);
__ Tbnz(result, SharedFunctionInfo::kStrictModeBit, &copy_receiver);
// Do not transform the receiver to object for builtins.
__ Tbnz(result, SharedFunctionInfo::kNative, &copy_receiver);
__ Tbnz(result, SharedFunctionInfo::kNativeBit, &copy_receiver);
}
// Normal function. Replace undefined or null with global receiver.
......
......@@ -36,9 +36,9 @@ ACCESSORS(SharedFunctionInfo, function_identifier, Object,
BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type,
is_named_expression,
SharedFunctionInfo::IsNamedExpressionBits)
SharedFunctionInfo::IsNamedExpressionBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
SharedFunctionInfo::IsTopLevelBits)
SharedFunctionInfo::IsTopLevelBit)
INT_ACCESSORS(SharedFunctionInfo, length, kLengthOffset)
INT_ACCESSORS(SharedFunctionInfo, internal_formal_parameter_count,
......@@ -75,35 +75,39 @@ AbstractCode* SharedFunctionInfo::abstract_code() {
}
}
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, allows_lazy_compilation,
kAllowLazyCompilation)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, uses_arguments,
kUsesArguments)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, has_duplicate_parameters,
kHasDuplicateParameters)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, asm_function, kIsAsmFunction)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_declaration,
kIsDeclaration)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, marked_for_tier_up,
kMarkedForTierUp)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints,
has_concurrent_optimization_job, kHasConcurrentOptimizationJob)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, needs_home_object,
kNeedsHomeObject)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, native, kNative)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, force_inline, kForceInline)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, must_use_ignition_turbo,
kMustUseIgnitionTurbo)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_asm_wasm_broken,
kIsAsmWasmBroken)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, optimization_disabled,
kOptimizationDisabled)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, allows_lazy_compilation,
SharedFunctionInfo::AllowLazyCompilationBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, uses_arguments,
SharedFunctionInfo::UsesArgumentsBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints,
has_duplicate_parameters,
SharedFunctionInfo::HasDuplicateParametersBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, asm_function,
SharedFunctionInfo::IsAsmFunctionBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, is_declaration,
SharedFunctionInfo::IsDeclarationBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, marked_for_tier_up,
SharedFunctionInfo::MarkedForTierUpBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints,
has_concurrent_optimization_job,
SharedFunctionInfo::HasConcurrentOptimizationJobBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, needs_home_object,
SharedFunctionInfo::NeedsHomeObjectBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, native,
SharedFunctionInfo::IsNativeBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, force_inline,
SharedFunctionInfo::ForceInlineBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, must_use_ignition_turbo,
SharedFunctionInfo::MustUseIgnitionTurboBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, is_asm_wasm_broken,
SharedFunctionInfo::IsAsmWasmBrokenBit)
BIT_FIELD_ACCESSORS(SharedFunctionInfo, compiler_hints, optimization_disabled,
SharedFunctionInfo::OptimizationDisabledBit)
LanguageMode SharedFunctionInfo::language_mode() {
STATIC_ASSERT(LANGUAGE_END == 2);
return construct_language_mode(
BooleanBit::get(compiler_hints(), kStrictModeFunction));
return construct_language_mode(IsStrictBit::decode(compiler_hints()));
}
void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) {
......@@ -112,7 +116,7 @@ void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) {
// again or go up in the chain:
DCHECK(is_sloppy(this->language_mode()) || is_strict(language_mode));
int hints = compiler_hints();
hints = BooleanBit::set(hints, kStrictModeFunction, is_strict(language_mode));
hints = IsStrictBit::update(hints, is_strict(language_mode));
set_compiler_hints(hints);
}
......
......@@ -500,40 +500,42 @@ class SharedFunctionInfo : public HeapObject {
kLastPointerFieldOffset + kPointerSize, kSize>
BodyDescriptorWeakCode;
// Bit fields in |start_position_and_type|.
typedef BitField<bool, 0, 1> IsNamedExpressionBits;
typedef BitField<bool, IsNamedExpressionBits::kNext, 1> IsTopLevelBits;
typedef BitField<int, IsTopLevelBits::kNext, 30> StartPositionBits;
// TODO(ishell): turn this into a set of BitFields.
// Bit positions in compiler_hints.
enum CompilerHints {
// byte 0
kAllowLazyCompilation,
kMarkedForTierUp,
kOptimizationDisabled,
kHasDuplicateParameters,
kNative,
kStrictModeFunction,
kUsesArguments,
kNeedsHomeObject,
// byte 1
kForceInline,
kIsAsmFunction,
kMustUseIgnitionTurbo,
kIsDeclaration,
kIsAsmWasmBroken,
kHasConcurrentOptimizationJob,
kUnused1, // Unused fields.
kUnused2,
// byte 2
kFunctionKind,
// rest of byte 2 and first two bits of byte 3 are used by FunctionKind
// byte 3
kCompilerHintsCount = kFunctionKind + 10, // Pseudo entry
};
// Bit fields in |start_position_and_type|.
#define START_POSITION_AND_TYPE_BIT_FIELDS(V, _) \
V(IsNamedExpressionBit, bool, 1, _) \
V(IsTopLevelBit, bool, 1, _) \
V(StartPositionBits, int, 30, _)
DEFINE_BIT_FIELDS(START_POSITION_AND_TYPE_BIT_FIELDS)
// Bit positions in |compiler_hints|.
#define COMPILER_HINTS_BIT_FIELDS(V, _) \
/* byte 0 */ \
V(AllowLazyCompilationBit, bool, 1, _) \
V(MarkedForTierUpBit, bool, 1, _) \
V(OptimizationDisabledBit, bool, 1, _) \
V(HasDuplicateParametersBit, bool, 1, _) \
V(IsNativeBit, bool, 1, _) \
V(IsStrictBit, bool, 1, _) \
V(UsesArgumentsBit, bool, 1, _) \
V(NeedsHomeObjectBit, bool, 1, _) \
/* byte 1 */ \
V(ForceInlineBit, bool, 1, _) \
V(IsAsmFunctionBit, bool, 1, _) \
V(MustUseIgnitionTurboBit, bool, 1, _) \
V(IsDeclarationBit, bool, 1, _) \
V(IsAsmWasmBrokenBit, bool, 1, _) \
V(HasConcurrentOptimizationJobBit, bool, 1, _) \
/* Bits 14-15 are unused. */ \
V(UnusedBits1, int, 2, _) \
/* byte 2 */ \
V(FunctionKindBits, FunctionKind, 10, _) \
/* Bits 27-31 are unused. */
DEFINE_BIT_FIELDS(COMPILER_HINTS_BIT_FIELDS)
STATIC_ASSERT(ForceInlineBit::kShift == kBitsPerByte);
STATIC_ASSERT(FunctionKindBits::kShift == kBitsPerByte * 2);
// Bit positions in |debugger_hints|.
enum DebuggerHints {
......@@ -547,11 +549,6 @@ class SharedFunctionInfo : public HeapObject {
kHasReportedBinaryCoverage
};
// kFunctionKind has to be byte-aligned
STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0);
class FunctionKindBits : public BitField<FunctionKind, kFunctionKind, 10> {};
// Bit fields in |counters|.
typedef BitField<int, 0, 4> DeoptCountBits;
typedef BitField<int, DeoptCountBits::kNext, 18> OptReenableTriesBits;
......@@ -567,22 +564,18 @@ class SharedFunctionInfo : public HeapObject {
inline int length() const;
static const int kCompilerHintsSize = kIntSize;
STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
public:
// Constants for optimizing codegen for strict mode function and
// native tests when using integer-width instructions.
static const int kStrictModeBit = kStrictModeFunction;
static const int kNativeBit = kNative;
static const int kHasDuplicateParametersBit = kHasDuplicateParameters;
// TODO(ishell): use respective bit field definition directly.
static const int kStrictModeBit = IsStrictBit::kShift;
static const int kNativeBit = IsNativeBit::kShift;
static const int kHasDuplicateParametersBit =
HasDuplicateParametersBit::kShift;
static const int kFunctionKindShift = kFunctionKind;
static const int kAllFunctionKindBitsMask = FunctionKindBits::kMask;
static const int kFunctionKindShift = FunctionKindBits::kShift;
static const int kMarkedForTierUpBit = kMarkedForTierUp;
static const int kMarkedForTierUpBit = MarkedForTierUpBit::kShift;
// Constants for optimizing codegen for strict mode function and
// native tests.
......@@ -613,12 +606,16 @@ class SharedFunctionInfo : public HeapObject {
#else
#error Unknown byte ordering
#endif
static const int kStrictModeByteOffset = BYTE_OFFSET(kStrictModeFunction);
static const int kNativeByteOffset = BYTE_OFFSET(kNative);
static const int kFunctionKindByteOffset = BYTE_OFFSET(kFunctionKind);
static const int kStrictModeByteOffset = BYTE_OFFSET(IsStrictBit::kShift);
static const int kNativeByteOffset = BYTE_OFFSET(IsNativeBit::kShift);
// FunctionKind bit field has to be byte-aligned
STATIC_ASSERT((FunctionKindBits::kShift % kBitsPerByte) == 0);
static const int kFunctionKindByteOffset =
BYTE_OFFSET(FunctionKindBits::kShift);
static const int kHasDuplicateParametersByteOffset =
BYTE_OFFSET(kHasDuplicateParameters);
static const int kMarkedForTierUpByteOffset = BYTE_OFFSET(kMarkedForTierUp);
BYTE_OFFSET(kHasDuplicateParametersBit);
static const int kMarkedForTierUpByteOffset =
BYTE_OFFSET(MarkedForTierUpBit::kShift);
#undef BYTE_OFFSET
private:
......
......@@ -135,7 +135,7 @@ ParseInfo* ParseInfo::AllocateWithoutScript(Handle<SharedFunctionInfo> shared) {
DeclarationScope* ParseInfo::scope() const { return literal()->scope(); }
bool ParseInfo::is_declaration() const {
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0;
return SharedFunctionInfo::IsDeclarationBit::decode(compiler_hints_);
}
FunctionKind ParseInfo::function_kind() const {
......
......@@ -2660,7 +2660,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Only sets fields in compiler_hints that are currently used.
int compiler_hints = SharedFunctionInfo::FunctionKindBits::encode(kind);
if (function_type == FunctionLiteral::kDeclaration) {
compiler_hints |= 1 << SharedFunctionInfo::kIsDeclaration;
compiler_hints |= SharedFunctionInfo::IsDeclarationBit::encode(true);
}
should_use_parse_task = compiler_dispatcher_->Enqueue(
source_, start_pos, source_->length(), language_mode,
......
......@@ -327,6 +327,41 @@ class BitField : public BitFieldBase<T, shift, size, uint32_t> { };
template<class T, int shift, int size>
class BitField64 : public BitFieldBase<T, shift, size, uint64_t> { };
// Helper macros for defining a contiguous sequence of bit fields. Example:
// (backslashes at the ends of respective lines of this multi-line macro
// definition are omitted here to please the compiler)
//
// #define MAP_BIT_FIELD1(V, _)
// V(IsAbcBit, bool, 1, _)
// V(IsBcdBit, bool, 1, _)
// V(CdeBits, int, 5, _)
// V(DefBits, MutableMode, 1, _)
//
// DEFINE_BIT_FIELDS(MAP_BIT_FIELD1)
// or
// DEFINE_BIT_FIELDS_64(MAP_BIT_FIELD1)
//
#define DEFINE_BIT_FIELD_RANGE_TYPE(Name, Type, Size, _) \
k##Name##Start, k##Name##End = k##Name##Start + Size - 1,
#define DEFINE_BIT_RANGESS(LIST_MACRO) \
struct LIST_MACRO##_Ranges { \
enum { LIST_MACRO(DEFINE_BIT_FIELD_RANGE_TYPE, _) }; \
};
#define DEFINE_BIT_FIELD_TYPE(Name, Type, Size, RangesName) \
typedef BitField<Type, RangesName::k##Name##Start, Size> Name;
#define DEFINE_BIT_FIELD_64_TYPE(Name, Type, Size, RangesName) \
typedef BitField64<Type, RangesName::k##Name##Start, Size> Name;
#define DEFINE_BIT_FIELDS(LIST_MACRO) \
DEFINE_BIT_RANGESS(LIST_MACRO) \
LIST_MACRO(DEFINE_BIT_FIELD_TYPE, LIST_MACRO##_Ranges)
#define DEFINE_BIT_FIELDS_64(LIST_MACRO) \
DEFINE_BIT_RANGESS(LIST_MACRO) \
LIST_MACRO(DEFINE_BIT_FIELD_64_TYPE, LIST_MACRO##_Ranges)
// ----------------------------------------------------------------------------
// BitSetComputer is a help template for encoding and decoding information for
......
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