35#ifndef V8_CODEGEN_ASSEMBLER_H_
36#define V8_CODEGEN_ASSEMBLER_H_
39#include <forward_list>
44#include <unordered_map>
76class OffHeapInstructionStream;
78class SCTableReference;
114 if (it->first <= to) {
115 max_align = std::max(max_align, it->second);
126 std::cout <<
"align_pos_size:" << std::endl;
128 std::cout <<
"{" << p.first <<
"," << p.second <<
"}"
131 std::cout << std::endl;
133 std::cout <<
"may_optimizable_farjmp:" << std::endl;
136 const auto& jmp_info = p.second;
137 printf(
"{postion:%d, opcode_size:%d, distance:%d, dest:%d}\n",
138 jmp_info.pos, jmp_info.opcode_size, jmp_info.distance,
139 jmp_info.pos + jmp_info.opcode_size + 4 + jmp_info.distance);
141 std::cout << std::endl;
219 bool record_reloc_info_for_serialization =
true;
222 bool enable_root_relative_access =
false;
228 bool isolate_independent_code =
false;
239 bool use_pc_relative_calls_and_jumps_for_mksnapshot =
false;
243 Address code_range_base = 0;
247 bool collect_win64_unwind_info =
false;
251 bool is_wasm =
false;
272 virtual std::unique_ptr<AssemblerBuffer>
Grow(
int new_size)
304#ifdef V8_ENABLE_SANDBOX
336 std::unique_ptr<AssemblerBuffer>);
346 enabled_cpu_features_ = features;
353 return (enabled_cpu_features_ & (
static_cast<uint64_t
>(1) << f)) != 0;
356 enabled_cpu_features_ |= (
static_cast<uint64_t
>(1) << f);
363 return constant_pool_available_ && !
options().isolate_independent_code;
371 return jump_optimization_info_;
374 jump_optimization_info_ = jump_opt;
383 int pc_offset()
const {
return static_cast<int>(
pc_ - buffer_start_); }
386#if defined(V8_TARGET_ARCH_MIPS64) || defined(V8_TARGET_ARCH_LOONG64)
400 std::unique_ptr<AssemblerBuffer> buffer = std::move(
buffer_);
403 buffer_start_ =
nullptr;
422 if (!
v8_flags.code_comments)
return;
423 if (
options().emit_code_comments) {
424 std::string comment_str(comment);
425 if (loc.FileName()) {
426 comment_str +=
" - " + loc.ToString();
428 code_comments_writer_.Add(
pc_offset(), comment_str);
437 if (!
v8_flags.code_comments)
return;
438 if (
options().emit_code_comments) {
439 std::string comment_str(comment);
440 if (loc.FileName()) {
441 comment_str +=
" - " + loc.ToString();
443 code_comments_writer_.Add(
pc_offset(), comment_str);
447#ifdef V8_CODE_COMMENTS
453 template <
typename CommentGen>
455 Assembler* assembler, CommentGen&& comment,
458 if (!
v8_flags.code_comments)
return;
459 if constexpr (std::is_invocable_v<CommentGen>) {
460 Open(comment(), loc);
466 if (!
v8_flags.code_comments)
return;
469 static const int kIndentWidth = 2;
473 void Open(
const std::string& comment,
const SourceLocation& loc);
485 static constexpr int kMinimalBufferSize = 128;
489 static constexpr int kDefaultBufferSize = 4 *
KB;
514 constant_pool_available_ = available;
529 DCHECK(!RelocInfo::IsNoInfo(rmode));
530 if (RelocInfo::IsOnlyForSerializer(rmode) &&
531 !
options().record_reloc_info_for_serialization &&
573#ifdef V8_CODE_COMMENTS
574 int comment_depth_ = 0;
592 CheckPolicy check = kCheckSupported);
597 uint64_t old_enabled_;
607#ifdef V8_CODE_COMMENTS
608#if V8_SUPPORTS_SOURCE_LOCATION
610#define ASM_CODE_COMMENT(asm) ASM_CODE_COMMENT_STRING(asm, "")
612#define ASM_CODE_COMMENT(asm) ASM_CODE_COMMENT_STRING(asm, __func__)
614#define ASM_CODE_COMMENT_STRING(asm, comment) \
615 AssemblerBase::CodeComment UNIQUE_IDENTIFIER(asm_code_comment)(asm, comment)
617#define ASM_CODE_COMMENT(asm)
618#define ASM_CODE_COMMENT_STRING(asm, ...)
625#ifdef V8_ENABLE_DEBUG_CODE
626#define NOOP_UNLESS_DEBUG_CODE
628#define NOOP_UNLESS_DEBUG_CODE \
629 { static_assert(v8_flags.debug_code.value() == false); } \
void set_enabled_cpu_features(uint64_t features)
bool ShouldRecordRelocInfo(RelocInfo::Mode rmode) const
std::unique_ptr< AssemblerBuffer > buffer_
const AssemblerOptions options_
bool IsEnabled(CpuFeature f)
int pc_offset_for_safepoint()
void EnableCpuFeature(CpuFeature f)
void set_jump_optimization_info(JumpOptimizationInfo *jump_opt)
int instruction_size() const
bool is_constant_pool_available() const
uint64_t enabled_cpu_features_
JumpOptimizationInfo * jump_optimization_info_
std::unordered_map< IndirectHandle< HeapObject >, EmbeddedObjectIndex, IndirectHandle< HeapObject >::hash, IndirectHandle< HeapObject >::equal_to > embedded_objects_map_
static void QuietNaN(Tagged< HeapObject > nan)
void FinalizeJumpOptimizationInfo()
std::unique_ptr< AssemblerBuffer > ReleaseBuffer()
std::vector< IndirectHandle< HeapObject > > embedded_objects_
void set_predictable_code_size(bool value)
std::forward_list< HeapNumberRequest > heap_number_requests_
JumpOptimizationInfo * jump_optimization_info()
uint64_t enabled_cpu_features() const
virtual void AbortedCodeGeneration()
size_t EmbeddedObjectIndex
bool predictable_code_size() const
uint8_t * buffer_start() const
CodeCommentsWriter code_comments_writer_
bool predictable_code_size_
V8_INLINE void RecordComment(const char *comment, const SourceLocation &loc=SourceLocation::Current())
V8_INLINE void RecordComment(std::string comment, const SourceLocation &loc=SourceLocation::Current())
const AssemblerOptions & options() const
std::vector< IndirectHandle< Code > > code_targets_
void set_constant_pool_available(bool available)
bool constant_pool_available_
virtual int size() const =0
virtual std::unique_ptr< AssemblerBuffer > Grow(int new_size) V8_WARN_UNUSED_RESULT=0
virtual ~AssemblerBuffer()=default
virtual uint8_t * start() const =0
CpuFeatureScope(AssemblerBase *assembler, CpuFeature f, CheckPolicy check=kCheckSupported)
void set_offset(int offset)
double heap_number() const
HeapNumberRequest(double heap_number, int offset=-1)
static SlotDescriptor ForTrustedPointerSlot(IndirectPointerTag tag)
bool contains_direct_pointer() const
static SlotDescriptor ForCodePointerSlot()
IndirectPointerTag indirect_pointer_tag() const
static SlotDescriptor ForIndirectPointerSlot(IndirectPointerTag tag)
IndirectPointerTag indirect_pointer_tag_
bool contains_indirect_pointer() const
static SlotDescriptor ForDirectPointerSlot()
SlotDescriptor(IndirectPointerTag tag)
base::OwnedVector< uint8_t > buffer_
#define V8_EMBEDDED_CONSTANT_POOL_BOOL
#define USE_SIMULATOR_BOOL
BytecodeAssembler & assembler_
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation trace turbo cfg trace TurboFan s graph trimmer trace TurboFan s control equivalence trace TurboFan s register allocator trace stack load store counters for optimized code in run fuzzing &&concurrent_recompilation trace_turbo trace_turbo_scheduled trace_turbo_stack_accesses verify TurboFan machine graph of code stubs enable FixedArray bounds checks print TurboFan statistics of wasm compilations maximum cumulative size of bytecode considered for inlining scale factor of bytecode size used to calculate the inlining budget * KB
DirectHandle< JSReceiver > options
static V ReadUnalignedValue(Address p)
static void WriteUnalignedValue(Address p, V value)
std::variant< Zone *, AccountingAllocator * > MaybeAssemblerZone
@ kIndirectPointerNullTag
std::unique_ptr< AssemblerBuffer > NewAssemblerBuffer(int size)
V8_EXPORT_PRIVATE FlagValues v8_flags
std::unique_ptr< AssemblerBuffer > ExternalAssemblerBuffer(void *start, int size)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define V8_EXPORT_PRIVATE
std::map< Label *, std::vector< int > > label_farjmp_maps
enum v8::internal::JumpOptimizationInfo::@26 stage
std::map< int, int > align_pos_size
std::vector< JumpInfo > farjmps
bool is_optimizable() const
int MaxAlignInRange(int from, int to)
std::map< int, JumpInfo > may_optimizable_farjmp
bool is_optimizing() const
bool is_collecting() const
#define V8_WARN_UNUSED_RESULT
std::unique_ptr< ValueMirror > value