Commit 5f072169 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[nci] Refactor optimized compilation info flags

... for more consistent naming and less boilerplate.

Getters now use the `lower_case_flag()` style. Setters now use the
`set_lower_case_flag()` style.

Bug: v8:8888
Change-Id: I5af35b13a013bf303c4ca8d86f926754af28bfce
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2237139
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68293}
parent 0817d7ee
......@@ -751,7 +751,7 @@ void InsertCodeIntoOptimizedCodeCache(
// Function context specialization folds-in the function context,
// so no sharing can occur.
if (compilation_info->is_function_context_specializing()) {
if (compilation_info->function_context_specializing()) {
// Native context specialized code is not shared, so make sure the optimized
// code cache is clear.
ClearOptimizedCodeCache(compilation_info);
......
......@@ -32,7 +32,7 @@ OptimizedCompilationInfo::OptimizedCompilationInfo(
// is active, to be able to get more precise source positions at the price of
// more memory consumption.
if (isolate->NeedsDetailedOptimizedCodeLineInfo()) {
MarkAsSourcePositionsEnabled();
set_source_positions();
}
SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
......@@ -53,59 +53,82 @@ OptimizedCompilationInfo::OptimizedCompilationInfo(Code::Kind code_kind,
ConfigureFlags();
}
#ifdef DEBUG
bool OptimizedCompilationInfo::FlagSetIsValid(Flag flag) const {
switch (flag) {
case kPoisonRegisterArguments:
return untrusted_code_mitigations();
default:
return true;
}
UNREACHABLE();
}
bool OptimizedCompilationInfo::FlagGetIsValid(Flag flag) const {
switch (flag) {
case kPoisonRegisterArguments:
if (!GetFlag(kPoisonRegisterArguments)) return true;
return untrusted_code_mitigations() && called_with_code_start_register();
default:
return true;
}
UNREACHABLE();
}
#endif // DEBUG
void OptimizedCompilationInfo::ConfigureFlags() {
if (FLAG_untrusted_code_mitigations) SetFlag(kUntrustedCodeMitigations);
if (FLAG_untrusted_code_mitigations) set_untrusted_code_mitigations();
switch (code_kind_) {
case Code::OPTIMIZED_FUNCTION:
SetFlag(kCalledWithCodeStartRegister);
SetFlag(kSwitchJumpTableEnabled);
set_called_with_code_start_register();
set_switch_jump_table();
if (FLAG_function_context_specialization) {
MarkAsFunctionContextSpecializing();
set_function_context_specializing();
}
if (FLAG_turbo_splitting) {
MarkAsSplittingEnabled();
set_splitting();
}
if (FLAG_untrusted_code_mitigations) {
MarkAsPoisoningRegisterArguments();
set_poison_register_arguments();
}
if (FLAG_analyze_environment_liveness) {
// TODO(yangguo): Disable this in case of debugging for crbug.com/826613
MarkAsAnalyzeEnvironmentLiveness();
set_analyze_environment_liveness();
}
break;
case Code::BYTECODE_HANDLER:
SetFlag(kCalledWithCodeStartRegister);
set_called_with_code_start_register();
if (FLAG_turbo_splitting) {
MarkAsSplittingEnabled();
set_splitting();
}
break;
case Code::BUILTIN:
case Code::STUB:
if (FLAG_turbo_splitting) {
MarkAsSplittingEnabled();
set_splitting();
}
#if ENABLE_GDB_JIT_INTERFACE && DEBUG
MarkAsSourcePositionsEnabled();
set_source_positions();
#endif // ENABLE_GDB_JIT_INTERFACE && DEBUG
break;
case Code::WASM_FUNCTION:
case Code::WASM_TO_CAPI_FUNCTION:
SetFlag(kSwitchJumpTableEnabled);
set_switch_jump_table();
break;
default:
break;
}
if (FLAG_turbo_control_flow_aware_allocation) {
MarkAsTurboControlFlowAwareAllocation();
set_turbo_control_flow_aware_allocation();
} else {
MarkAsTurboPreprocessRanges();
set_turbo_preprocess_ranges();
}
}
OptimizedCompilationInfo::~OptimizedCompilationInfo() {
if (GetFlag(kDisableFutureOptimization) && has_shared_info()) {
if (disable_future_optimization() && has_shared_info()) {
shared_info()->DisableOptimization(bailout_reason());
}
}
......@@ -134,12 +157,12 @@ void OptimizedCompilationInfo::AbortOptimization(BailoutReason reason) {
if (bailout_reason_ == BailoutReason::kNoReason) {
bailout_reason_ = reason;
}
SetFlag(kDisableFutureOptimization);
set_disable_future_optimization();
}
void OptimizedCompilationInfo::RetryOptimization(BailoutReason reason) {
DCHECK_NE(reason, BailoutReason::kNoReason);
if (GetFlag(kDisableFutureOptimization)) return;
if (disable_future_optimization()) return;
bailout_reason_ = reason;
}
......@@ -225,11 +248,11 @@ int OptimizedCompilationInfo::AddInlinedFunction(
void OptimizedCompilationInfo::SetTracingFlags(bool passes_filter) {
if (!passes_filter) return;
if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);
if (FLAG_trace_turbo_alloc) SetFlag(kTraceTurboAllocation);
if (FLAG_trace_heap_broker) SetFlag(kTraceHeapBroker);
if (FLAG_trace_turbo) set_trace_turbo_json();
if (FLAG_trace_turbo_graph) set_trace_turbo_graph();
if (FLAG_trace_turbo_scheduled) set_trace_turbo_scheduled();
if (FLAG_trace_turbo_alloc) set_trace_turbo_allocation();
if (FLAG_trace_heap_broker) set_trace_heap_broker();
}
OptimizedCompilationInfo::InlinedFunctionHolder::InlinedFunctionHolder(
......
......@@ -44,31 +44,58 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
public:
// Various configuration flags for a compilation, as well as some properties
// of the compiled code produced by a compilation.
#define FLAGS(V) \
V(FunctionContextSpecializing, function_context_specializing, 0) \
V(Inlining, inlining, 1) \
V(DisableFutureOptimization, disable_future_optimization, 2) \
V(Splitting, splitting, 3) \
V(SourcePositions, source_positions, 4) \
V(BailoutOnUninitialized, bailout_on_uninitialized, 5) \
V(LoopPeeling, loop_peeling, 6) \
V(UntrustedCodeMitigations, untrusted_code_mitigations, 7) \
V(SwitchJumpTable, switch_jump_table, 8) \
V(CalledWithCodeStartRegister, called_with_code_start_register, 9) \
V(PoisonRegisterArguments, poison_register_arguments, 10) \
V(AllocationFolding, allocation_folding, 11) \
V(AnalyzeEnvironmentLiveness, analyze_environment_liveness, 12) \
V(TraceTurboJson, trace_turbo_json, 13) \
V(TraceTurboGraph, trace_turbo_graph, 14) \
V(TraceTurboScheduled, trace_turbo_scheduled, 15) \
V(TraceTurboAllocation, trace_turbo_allocation, 16) \
V(TraceHeapBroker, trace_heap_broker, 17) \
V(WasmRuntimeExceptionSupport, wasm_runtime_exception_support, 18) \
V(TurboControlFlowAwareAllocation, turbo_control_flow_aware_allocation, 19) \
V(TurboPreprocessRanges, turbo_preprocess_ranges, 20) \
V(ConcurrentInlining, concurrent_inlining, 21)
enum Flag {
kFunctionContextSpecializing = 1 << 0,
kInliningEnabled = 1 << 1,
kDisableFutureOptimization = 1 << 2,
kSplittingEnabled = 1 << 3,
kSourcePositionsEnabled = 1 << 4,
kBailoutOnUninitialized = 1 << 5,
kLoopPeelingEnabled = 1 << 6,
kUntrustedCodeMitigations = 1 << 7,
kSwitchJumpTableEnabled = 1 << 8,
kCalledWithCodeStartRegister = 1 << 9,
kPoisonRegisterArguments = 1 << 10,
kAllocationFoldingEnabled = 1 << 11,
kAnalyzeEnvironmentLiveness = 1 << 12,
kTraceTurboJson = 1 << 13,
kTraceTurboGraph = 1 << 14,
kTraceTurboScheduled = 1 << 15,
kTraceTurboAllocation = 1 << 16,
kTraceHeapBroker = 1 << 17,
kWasmRuntimeExceptionSupport = 1 << 18,
kTurboControlFlowAwareAllocation = 1 << 19,
kTurboPreprocessRanges = 1 << 20,
kConcurrentInlining = 1 << 21,
#define DEF_ENUM(Camel, Lower, Bit) k##Camel = 1 << Bit,
FLAGS(DEF_ENUM)
#undef DEF_ENUM
};
#define DEF_GETTER(Camel, Lower, Bit) \
bool Lower() const { \
DCHECK(FlagGetIsValid(k##Camel)); \
return GetFlag(k##Camel); \
}
FLAGS(DEF_GETTER)
#undef DEF_GETTER
#define DEF_SETTER(Camel, Lower, Bit) \
void set_##Lower() { \
DCHECK(FlagSetIsValid(k##Camel)); \
SetFlag(k##Camel); \
}
FLAGS(DEF_SETTER)
#undef DEF_SETTER
#ifdef DEBUG
bool FlagGetIsValid(Flag flag) const;
bool FlagSetIsValid(Flag flag) const;
#endif // DEBUG
// Construct a compilation info for optimized compilation.
OptimizedCompilationInfo(Zone* zone, Isolate* isolate,
Handle<SharedFunctionInfo> shared,
......@@ -93,38 +120,6 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
BailoutId osr_offset() const { return osr_offset_; }
JavaScriptFrame* osr_frame() const { return osr_frame_; }
// Flags used by optimized compilation.
void MarkAsConcurrentInlining() { SetFlag(kConcurrentInlining); }
bool is_concurrent_inlining() const { return GetFlag(kConcurrentInlining); }
void MarkAsTurboControlFlowAwareAllocation() {
SetFlag(kTurboControlFlowAwareAllocation);
}
bool is_turbo_control_flow_aware_allocation() const {
return GetFlag(kTurboControlFlowAwareAllocation);
}
void MarkAsTurboPreprocessRanges() { SetFlag(kTurboPreprocessRanges); }
bool is_turbo_preprocess_ranges() const {
return GetFlag(kTurboPreprocessRanges);
}
void MarkAsFunctionContextSpecializing() {
SetFlag(kFunctionContextSpecializing);
}
bool is_function_context_specializing() const {
return GetFlag(kFunctionContextSpecializing);
}
void MarkAsSourcePositionsEnabled() { SetFlag(kSourcePositionsEnabled); }
bool is_source_positions_enabled() const {
return GetFlag(kSourcePositionsEnabled);
}
void MarkAsInliningEnabled() { SetFlag(kInliningEnabled); }
bool is_inlining_enabled() const { return GetFlag(kInliningEnabled); }
void SetPoisoningMitigationLevel(PoisoningMitigationLevel poisoning_level) {
poisoning_level_ = poisoning_level;
}
......@@ -132,75 +127,6 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
return poisoning_level_;
}
void MarkAsSplittingEnabled() { SetFlag(kSplittingEnabled); }
bool is_splitting_enabled() const { return GetFlag(kSplittingEnabled); }
void MarkAsBailoutOnUninitialized() { SetFlag(kBailoutOnUninitialized); }
bool is_bailout_on_uninitialized() const {
return GetFlag(kBailoutOnUninitialized);
}
void MarkAsLoopPeelingEnabled() { SetFlag(kLoopPeelingEnabled); }
bool is_loop_peeling_enabled() const { return GetFlag(kLoopPeelingEnabled); }
bool has_untrusted_code_mitigations() const {
return GetFlag(kUntrustedCodeMitigations);
}
bool switch_jump_table_enabled() const {
return GetFlag(kSwitchJumpTableEnabled);
}
bool called_with_code_start_register() const {
bool enabled = GetFlag(kCalledWithCodeStartRegister);
return enabled;
}
void MarkAsPoisoningRegisterArguments() {
DCHECK(has_untrusted_code_mitigations());
SetFlag(kPoisonRegisterArguments);
}
bool is_poisoning_register_arguments() const {
bool enabled = GetFlag(kPoisonRegisterArguments);
DCHECK_IMPLIES(enabled, has_untrusted_code_mitigations());
DCHECK_IMPLIES(enabled, called_with_code_start_register());
return enabled;
}
void MarkAsAllocationFoldingEnabled() { SetFlag(kAllocationFoldingEnabled); }
bool is_allocation_folding_enabled() const {
return GetFlag(kAllocationFoldingEnabled);
}
void MarkAsAnalyzeEnvironmentLiveness() {
SetFlag(kAnalyzeEnvironmentLiveness);
}
bool is_analyze_environment_liveness() const {
return GetFlag(kAnalyzeEnvironmentLiveness);
}
void SetWasmRuntimeExceptionSupport() {
SetFlag(kWasmRuntimeExceptionSupport);
}
bool wasm_runtime_exception_support() {
return GetFlag(kWasmRuntimeExceptionSupport);
}
bool trace_turbo_json_enabled() const { return GetFlag(kTraceTurboJson); }
bool trace_turbo_graph_enabled() const { return GetFlag(kTraceTurboGraph); }
bool trace_turbo_allocation_enabled() const {
return GetFlag(kTraceTurboAllocation);
}
bool trace_turbo_scheduled_enabled() const {
return GetFlag(kTraceTurboScheduled);
}
bool trace_heap_broker_enabled() const { return GetFlag(kTraceHeapBroker); }
// Code getters and setters.
void SetCode(Handle<Code> code) { code_ = code; }
......@@ -240,10 +166,6 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
BailoutReason bailout_reason() const { return bailout_reason_; }
bool is_disable_future_optimization() const {
return GetFlag(kDisableFutureOptimization);
}
int optimization_id() const {
DCHECK(IsOptimizing());
return optimization_id_;
......
......@@ -162,7 +162,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleDeoptimizerCall(
DeoptimizeReason deoptimization_reason = exit->reason();
Address deopt_entry =
Deoptimizer::GetDeoptimizationEntry(tasm()->isolate(), deopt_kind);
if (info()->is_source_positions_enabled()) {
if (info()->source_positions()) {
tasm()->RecordDeoptReason(deoptimization_reason, exit->pos(),
deoptimization_id);
}
......@@ -192,7 +192,7 @@ void CodeGenerator::AssembleCode() {
// the frame (that is done in AssemblePrologue).
FrameScope frame_scope(tasm(), StackFrame::MANUAL);
if (info->is_source_positions_enabled()) {
if (info->source_positions()) {
AssembleSourcePosition(start_source_position());
}
offsets_info_.code_start_register_check = tasm()->pc_offset();
......@@ -243,7 +243,7 @@ void CodeGenerator::AssembleCode() {
unwinding_info_writer_.SetNumberOfInstructionBlocks(
instructions()->InstructionBlockCount());
if (info->trace_turbo_json_enabled()) {
if (info->trace_turbo_json()) {
block_starts_.assign(instructions()->instruction_blocks().size(), -1);
instr_starts_.assign(instructions()->instructions().size(), {});
}
......@@ -254,7 +254,7 @@ void CodeGenerator::AssembleCode() {
if (block->ShouldAlign() && !tasm()->jump_optimization_info()) {
tasm()->CodeTargetAlign();
}
if (info->trace_turbo_json_enabled()) {
if (info->trace_turbo_json()) {
block_starts_[block->rpo_number().ToInt()] = tasm()->pc_offset();
}
// Bind a label for a block.
......@@ -723,7 +723,7 @@ RpoNumber CodeGenerator::ComputeBranchInfo(BranchInfo* branch,
CodeGenerator::CodeGenResult CodeGenerator::AssembleInstruction(
int instruction_index, const InstructionBlock* block) {
Instruction* instr = instructions()->InstructionAt(instruction_index);
if (info()->trace_turbo_json_enabled()) {
if (info()->trace_turbo_json()) {
instr_starts_[instruction_index].gap_pc_offset = tasm()->pc_offset();
}
int first_unused_stack_slot;
......@@ -743,14 +743,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleInstruction(
if (instr->IsJump() && block->must_deconstruct_frame()) {
AssembleDeconstructFrame();
}
if (info()->trace_turbo_json_enabled()) {
if (info()->trace_turbo_json()) {
instr_starts_[instruction_index].arch_instr_pc_offset = tasm()->pc_offset();
}
// Assemble architecture-specific code for the instruction.
CodeGenResult result = AssembleArchInstruction(instr);
if (result != kSuccess) return result;
if (info()->trace_turbo_json_enabled()) {
if (info()->trace_turbo_json()) {
instr_starts_[instruction_index].condition_pc_offset = tasm()->pc_offset();
}
......@@ -834,7 +834,7 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) {
buffer << "-- ";
// Turbolizer only needs the source position, as it can reconstruct
// the inlining stack from other information.
if (info->trace_turbo_json_enabled() || !tasm()->isolate() ||
if (info->trace_turbo_json() || !tasm()->isolate() ||
tasm()->isolate()->concurrent_recompilation_enabled()) {
buffer << source_position;
} else {
......@@ -1331,7 +1331,7 @@ void CodeGenerator::InitializeSpeculationPoison() {
if (info()->called_with_code_start_register()) {
tasm()->RecordComment("-- Prologue: generate speculation poison --");
GenerateSpeculationPoisonFromCodeStartRegister();
if (info()->is_poisoning_register_arguments()) {
if (info()->poison_register_arguments()) {
AssembleRegisterArgumentPoisoning();
}
} else {
......
......@@ -429,8 +429,7 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
// always hold true.
CHECK(shared_info->is_compiled());
if (!broker()->is_concurrent_inlining() &&
info_->is_source_positions_enabled()) {
if (!broker()->is_concurrent_inlining() && info_->source_positions()) {
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate(),
shared_info->object());
}
......@@ -462,10 +461,10 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
Graph::SubgraphScope scope(graph());
BytecodeGraphBuilderFlags flags(
BytecodeGraphBuilderFlag::kSkipFirstStackCheck);
if (info_->is_analyze_environment_liveness()) {
if (info_->analyze_environment_liveness()) {
flags |= BytecodeGraphBuilderFlag::kAnalyzeEnvironmentLiveness;
}
if (info_->is_bailout_on_uninitialized()) {
if (info_->bailout_on_uninitialized()) {
flags |= BytecodeGraphBuilderFlag::kBailoutOnUninitialized;
}
{
......
This diff is collapsed.
......@@ -6894,18 +6894,17 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
OptimizedCompilationInfo info(GetDebugName(&zone, func_index), &zone,
Code::WASM_FUNCTION);
if (env->runtime_exception_support) {
info.SetWasmRuntimeExceptionSupport();
info.set_wasm_runtime_exception_support();
}
if (info.trace_turbo_json_enabled()) {
if (info.trace_turbo_json()) {
TurboCfgFile tcf;
tcf << AsC1VCompilation(&info);
}
NodeOriginTable* node_origins = info.trace_turbo_json_enabled()
? new (&zone)
NodeOriginTable(mcgraph->graph())
: nullptr;
NodeOriginTable* node_origins =
info.trace_turbo_json() ? new (&zone) NodeOriginTable(mcgraph->graph())
: nullptr;
SourcePositionTable* source_positions =
new (mcgraph->zone()) SourcePositionTable(mcgraph->graph());
if (!BuildGraphForWasmFunction(wasm_engine->allocator(), env, func_body,
......
......@@ -257,8 +257,8 @@ i::Handle<i::JSFunction> Optimize(
i::OptimizedCompilationInfo info(zone, isolate, shared, function);
if (flags & i::OptimizedCompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
if (flags & i::OptimizedCompilationInfo::kInlining) {
info.set_inlining();
}
CHECK(info.shared_info()->HasBytecodeArray());
......
......@@ -25,7 +25,7 @@ FunctionTester::FunctionTester(const char* source, uint32_t flags)
function((FLAG_allow_natives_syntax = true, NewFunction(source))),
flags_(flags) {
Compile(function);
const uint32_t supported_flags = OptimizedCompilationInfo::kInliningEnabled;
const uint32_t supported_flags = OptimizedCompilationInfo::kInlining;
CHECK_EQ(0u, flags_ & ~supported_flags);
}
......
......@@ -37,12 +37,12 @@ SerializerTester::SerializerTester(const char* source)
function_string += " })();";
Handle<JSFunction> function = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(function_string.c_str()))));
uint32_t flags = i::OptimizedCompilationInfo::kInliningEnabled |
uint32_t flags = i::OptimizedCompilationInfo::kInlining |
i::OptimizedCompilationInfo::kFunctionContextSpecializing |
i::OptimizedCompilationInfo::kLoopPeelingEnabled |
i::OptimizedCompilationInfo::kLoopPeeling |
i::OptimizedCompilationInfo::kBailoutOnUninitialized |
i::OptimizedCompilationInfo::kAllocationFoldingEnabled |
i::OptimizedCompilationInfo::kSplittingEnabled |
i::OptimizedCompilationInfo::kAllocationFolding |
i::OptimizedCompilationInfo::kSplitting |
i::OptimizedCompilationInfo::kAnalyzeEnvironmentLiveness;
Optimize(function, main_zone(), main_isolate(), flags, &broker_);
function_ = JSFunctionRef(broker(), function);
......
......@@ -10,7 +10,7 @@ namespace v8 {
namespace internal {
namespace compiler {
uint32_t flags = OptimizedCompilationInfo::kInliningEnabled;
uint32_t flags = OptimizedCompilationInfo::kInlining;
TEST(Call) {
FunctionTester T("(function(a,b) { return %_Call(b, a, 1, 2, 3); })", flags);
......
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