Changeset 284341 in webkit
- Timestamp:
- Oct 17, 2021 1:47:30 PM (3 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r284332 r284341 1 2021-10-16 Mark Lam <mark.lam@apple.com> 2 3 Make LLIntAssembly.h more readable. 4 https://bugs.webkit.org/show_bug.cgi?id=231876 5 6 Reviewed by Yusuki Suzuki. 7 8 In this patch, I did the following: 9 10 1. Changed `CodeOrigin` to only dump the filename, and not the full path. 11 12 2. Deferred printing the ".loc" metadata in `$asm.debugAnnotation` till we format 13 the line to dump in `$asm.formatDump`. This enabled the ".loc" metadata to be 14 dumped on the same line as the asm instruction. 15 16 3. Changed `$asm.codeOrigin` to not dump multiple codeOrigin comments. The only 17 times when there appears to be "multiple" codeOrigins for any given instruction 18 is if the instruction before it was elided, thereby leaving the elided 19 instruction's codeOrigin to be mis-attributed to the subsequent instruction. 20 21 4. Moved the MIPS `Assembler.putStr` method to asm.rb. This method was already 22 commonly used in arm.rb and arm64.rb previously. Hence, it belongs in common 23 code. 24 25 Also enhanced it to support indenting by the column width of ".loc" debug 26 annotations if `$enableDebugAnnotations` is true. This keeps the ".loc" column 27 on the left clear of other content, thereby making it easy to visually filter 28 out that column when scanning through the generated asm code. 29 30 5. Changed some code that called `outp.puts` directly to call `$asm.putStr` instead. 31 This yields the nice alignment for easy visual filtering described in (4). 32 33 6. Changed `$preferredCommentStartColumn` to be at column 40 to make the generated 34 asm code more compact. However, if the backend is the C_LOOP, then change it 35 back to 60 because C_LOOP code is more verbose and need the extra space. 36 37 Demo time: 38 Before this patch, LLIntAssembly.h looks like this: 39 ``` 40 #if !OFFLINE_ASM_X86 && !OFFLINE_ASM_X86_WIN && !OFFLINE_ASM_X86_64 && !OFFLINE_ASM_X86_64_WIN && !OFFLINE_ASM_ARMv7 && !OFFLINE_ASM_ARM64 && OFFLINE_ASM_ARM64E && !OFFLINE_ASM_MIPS && !OFFLINE_ASM_RISCV64 && !OFFLINE_ASM_C_LOOP && !OFFLINE_ASM_C_LOOP_WIN && !OFFLINE_ASM_ARMv7k && !OFFLINE_ASM_ARMv7s && OFFLINE_ASM_JSVALUE64 && !OFFLINE_ASM_BIGINT32 && OFFLINE_ASM_GIGACAGE_ENABLED && !OFFLINE_ASM_ASSERT_ENABLED && !OFFLINE_ASM_TRACING && OFFLINE_ASM_ADDRESS64 && OFFLINE_ASM_JIT && OFFLINE_ASM_WEBASSEMBLY && OFFLINE_ASM_HAVE_FAST_TLS && OFFLINE_ASM_WEBASSEMBLY_B3JIT 41 OFFLINE_ASM_BEGIN 42 OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeStart) 43 ".file 1 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter.asm\"\n" 44 ".file 2 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/DerivedSources/JavaScriptCore/InitBytecodes.asm\"\n" 45 ".file 3 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm\"\n" 46 ".file 4 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm\"\n" 47 ".file 5 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/DerivedSources/JavaScriptCore/InitWasm.asm\"\n" 48 ".file 6 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/WebAssembly.asm\"\n" 49 ".file 7 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/usr/local/include/WebKitAdditions/LowLevelInterpreterAdditions.asm\"\n" 50 ".loc 1 1672\n" 51 "\tbrk #0xc471\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1672 52 ".loc 1 1681\n" 53 54 OFFLINE_ASM_GLOBAL_LABEL(vmEntryToJavaScript) 55 ".loc 1 1066\n" 56 "\tpacibsp\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1066 57 ".loc 1 1070\n" 58 "\tstp x29, x30, [sp, #-16]!\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1070 59 ".loc 1 1075\n" 60 "\tmov x29, sp\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1075 61 ".loc 1 1090\n" 62 "\tsub sp, x29, #176\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1090 63 ".loc 3 169\n" 64 "\tmovz x13, #48040, lsl #0\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:169 65 ".loc 3 169\n" 66 "\tadd x17, x1, x13, lsl #0\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:169 67 ".loc 3 169\n" 68 "\tldr w4, [x17, #0]\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:169 69 ".loc 3 170\n" 70 "\tcbnz w4, " LOCAL_LABEL_STRING(_offlineasm_doVMEntry__checkVMEntryPermission) "\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:170 71 ".loc 3 172\n" 72 "\tstr x1, [sp, #0]\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:172 73 74 ... 75 76 ".loc 3 309\n" 77 "\tmov x3, x0\n" // JavaScriptCore/llint/LowLevelInterpreter64.asm:309 78 ".loc 1 1\n" 79 #if OS(DARWIN) 80 "\tL_offlineasm_loh_adrp_1:\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1 81 "\tadrp x2, " LOCAL_REFERENCE(g_config) "@GOTPAGE\n" 82 "\tL_offlineasm_loh_ldr_1:\n" 83 "\tldr x2, [x2, " LOCAL_REFERENCE(g_config) "@GOTPAGEOFF]\n" 84 #elif OS(LINUX) 85 "\tadrp x2, :got:" LOCAL_REFERENCE(g_config) "\n" 86 "\tldr x2, [x2, :got_lo12:" LOCAL_REFERENCE(g_config) "]\n" 87 #else 88 #error Missing globaladdr implementation 89 #endif 90 ".loc 1 1\n" 91 "\tadd x2, x2, #3072\n" // JavaScriptCore/llint/LowLevelInterpreter.asm:1 92 ``` 93 94 After this patch, LLIntAssembly.h looks like this: 95 ``` 96 #if !OFFLINE_ASM_X86 && !OFFLINE_ASM_X86_WIN && !OFFLINE_ASM_X86_64 && !OFFLINE_ASM_X86_64_WIN && !OFFLINE_ASM_ARMv7 && !OFFLINE_ASM_ARM64 && OFFLINE_ASM_ARM64E && !OFFLINE_ASM_MIPS && !OFFLINE_ASM_RISCV64 && !OFFLINE_ASM_C_LOOP && !OFFLINE_ASM_C_LOOP_WIN && !OFFLINE_ASM_ARMv7k && !OFFLINE_ASM_ARMv7s && OFFLINE_ASM_JSVALUE64 && !OFFLINE_ASM_BIGINT32 && OFFLINE_ASM_GIGACAGE_ENABLED && !OFFLINE_ASM_ASSERT_ENABLED && !OFFLINE_ASM_TRACING && OFFLINE_ASM_ADDRESS64 && OFFLINE_ASM_JIT && OFFLINE_ASM_WEBASSEMBLY && OFFLINE_ASM_HAVE_FAST_TLS && OFFLINE_ASM_WEBASSEMBLY_B3JIT 97 98 OFFLINE_ASM_BEGIN 99 OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeStart) 100 ".file 1 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter.asm\"\n" 101 ".file 2 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/DerivedSources/JavaScriptCore/InitBytecodes.asm\"\n" 102 ".file 3 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm\"\n" 103 ".file 4 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm\"\n" 104 ".file 5 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/DerivedSources/JavaScriptCore/InitWasm.asm\"\n" 105 ".file 6 \"/Users/mlam/ws1/OpenSource/Source/JavaScriptCore/llint/WebAssembly.asm\"\n" 106 ".file 7 \"/Users/mlam/ws1/OpenSource/WebKitBuild/Release/usr/local/include/WebKitAdditions/LowLevelInterpreterAdditions.asm\"\n" 107 ".loc 1 1672\n" "brk #0xc471 \n" // LowLevelInterpreter.asm:1672 108 109 ".loc 1 1681\n" OFFLINE_ASM_GLOBAL_LABEL(vmEntryToJavaScript) 110 ".loc 1 1066\n" "pacibsp \n" // LowLevelInterpreter.asm:1066 111 ".loc 1 1070\n" "stp x29, x30, [sp, #-16]! \n" // LowLevelInterpreter.asm:1070 112 ".loc 1 1075\n" "mov x29, sp \n" // LowLevelInterpreter.asm:1075 113 ".loc 1 1090\n" "sub sp, x29, #176 \n" // LowLevelInterpreter.asm:1090 114 ".loc 3 169\n" "movz x13, #48040, lsl #0 \n" // LowLevelInterpreter64.asm:169 115 "add x17, x1, x13, lsl #0 \n" 116 "ldr w4, [x17, #0] \n" 117 ".loc 3 170\n" "cbnz w4, " LOCAL_LABEL_STRING(_offlineasm_doVMEntry__checkVMEntryPermission) " \n" // LowLevelInterpreter64.asm:170 118 ".loc 3 172\n" "str x1, [sp, #0] \n" // LowLevelInterpreter64.asm:172 119 120 ... 121 122 ".loc 3 309\n" "mov x3, x0 \n" // LowLevelInterpreter64.asm:309 123 #if OS(DARWIN) 124 ".loc 1 1\n" "L_offlineasm_loh_adrp_1: \n" // LowLevelInterpreter.asm:1 125 "adrp x2, " LOCAL_REFERENCE(g_config) "@GOTPAGE \n" 126 "L_offlineasm_loh_ldr_1: \n" 127 "ldr x2, [x2, " LOCAL_REFERENCE(g_config) "@GOTPAGEOFF] \n" 128 #elif OS(LINUX) 129 "adrp x2, :got:" LOCAL_REFERENCE(g_config) " \n" 130 "ldr x2, [x2, :got_lo12:" LOCAL_REFERENCE(g_config) "] \n" 131 #else 132 #error Missing globaladdr implementation 133 #endif 134 ".loc 1 1\n" "add x2, x2, #3072 \n" 135 ``` 136 137 * offlineasm/asm.rb: 138 * offlineasm/cloop.rb: 139 * offlineasm/config.rb: 140 * offlineasm/mips.rb: 141 * offlineasm/parser.rb: 142 1 143 2021-10-16 Yusuke Suzuki <ysuzuki@apple.com> 2 144 -
trunk/Source/JavaScriptCore/offlineasm/asm.rb
r282009 r284341 1 1 #!/usr/bin/env ruby 2 2 3 # Copyright (C) 2011 , 2016Apple Inc. All rights reserved.3 # Copyright (C) 2011-2021 Apple Inc. All rights reserved. 4 4 # 5 5 # Redistribution and use in source and binary forms, with or without … … 44 44 45 45 def resetAsm 46 @commentState = :none47 46 @comment = nil 48 47 @internalComment = nil … … 54 53 @deferredNextLabelActions = [] 55 54 @count = 0 55 @debugAnnotationStr = nil 56 @lastDebugAnnotationStr = nil 56 57 57 58 @newlineSpacerState = :none … … 60 61 61 62 def enterAsm 62 @outp.puts "OFFLINE_ASM_BEGIN" if !$emitWinAsm 63 64 if !$emitWinAsm 65 @outp.puts "OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeStart)" 63 @outp.puts "" 64 putStr "OFFLINE_ASM_BEGIN" if !$emitWinAsm 65 66 if !$emitWinAsm 67 putStr "OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeStart)" 66 68 else 67 69 putsProc("llintPCRangeStart", "") … … 75 77 putsProcEndIfNeeded if $emitWinAsm 76 78 if !$emitWinAsm 77 @outp.puts"OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeEnd)"79 putStr "OFFLINE_ASM_GLOBAL_LABEL(llintPCRangeEnd)" 78 80 else 79 81 putsProc("llintPCRangeEnd", "") … … 85 87 action.call() 86 88 } 87 @outp.puts"OFFLINE_ASM_END" if !$emitWinAsm89 putStr "OFFLINE_ASM_END" if !$emitWinAsm 88 90 @state = :cpp 89 91 end … … 122 124 result += "#{@internalComment}" 123 125 end 124 if @codeOrigin and $enableCodeOriginComments 126 if $enableCodeOriginComments and @codeOrigin and @codeOrigin != @lastCodeOrigin 127 @lastCodeOrigin = @codeOrigin 125 128 result += separator if result != "" 126 129 result += "#{@codeOrigin}" … … 131 134 132 135 # Reset all the components that we've just sent to be dumped. 133 @commentState = :none134 136 @comment = nil 135 137 @annotation = nil … … 146 148 147 149 def formatDump(dumpStr, comment, commentColumns=$preferredCommentStartColumn) 150 result = "" 148 151 if comment.length > 0 149 "%-#{commentColumns}s %s" % [dumpStr, comment] 150 else 151 dumpStr 152 end 152 result = "%-#{commentColumns}s %s" % [dumpStr, comment] 153 else 154 result = dumpStr 155 end 156 if $enableDebugAnnotations 157 if @debugAnnotationStr and @debugAnnotationStr != @lastDebugAnnotationStr 158 result = "%-#{$preferredDebugAnnotationColumns}s%s" % [@debugAnnotationStr, result] 159 else 160 result = "%-#{$preferredDebugAnnotationColumns}s%s" % ["", result] 161 end 162 @lastDebugAnnotationStr = @debugAnnotationStr 163 @debugAnnotationStr = nil 164 end 165 result 153 166 end 154 167 … … 177 190 end 178 191 end 179 192 193 def putStr(str) 194 if $enableDebugAnnotations 195 @outp.puts "%-#{$preferredDebugAnnotationColumns}s%s" % ["", str] 196 else 197 @outp.puts str 198 end 199 end 200 180 201 def puts(*line) 181 202 raise unless @state == :asm 182 203 if !$emitWinAsm 183 @outp.puts(formatDump(" \" \\t" + line.join('') + "\\n\"", lastComment))204 @outp.puts(formatDump(" \"" + line.join('') + " \\n\"", lastComment)) 184 205 else 185 206 @outp.puts(formatDump(" " + line.join(''), lastComment)) … … 296 317 297 318 def codeOrigin(text) 298 case @commentState 299 when :none 300 @codeOrigin = text 301 @commentState = :one 302 when :one 303 if $enableCodeOriginComments 304 @outp.puts " " + $commentPrefix + " #{@codeOrigin}" 305 @outp.puts " " + $commentPrefix + " #{text}" 306 end 307 @codeOrigin = nil 308 @commentState = :many 309 when :many 310 @outp.puts $commentPrefix + " #{text}" if $enableCodeOriginComments 311 else 312 raise 313 end 319 @codeOrigin = text 314 320 end 315 321 … … 323 329 324 330 def debugAnnotation(text) 325 @ outp.putstext331 @debugAnnotationStr = text 326 332 end 327 333 end … … 406 412 if backend == "C_LOOP" || backend == "C_LOOP_WIN" 407 413 $enableDebugAnnotations = false 414 $preferredCommentStartColumn = 60 408 415 end 409 416 -
trunk/Source/JavaScriptCore/offlineasm/cloop.rb
r283168 r284341 1 # Copyright (C) 2012-202 0Apple Inc. All rights reserved.1 # Copyright (C) 2012-2021 Apple Inc. All rights reserved. 2 2 # 3 3 # Redistribution and use in source and binary forms, with or without … … 1194 1194 $asm.codeOrigin codeOriginString if $enableCodeOriginComments 1195 1195 $asm.annotation annotation if $enableInstrAnnotations && (opcode != "cloopDo") 1196 $asm.debugAnnotation codeOrigin.debugDirective if $enableDebugAnnotations 1197 end 1198 end 1196 end 1197 end -
trunk/Source/JavaScriptCore/offlineasm/config.rb
r259734 r284341 1 # Copyright (C) 2012-20 18Apple Inc. All rights reserved.1 # Copyright (C) 2012-2021 Apple Inc. All rights reserved. 2 2 # 3 3 # Redistribution and use in source and binary forms, with or without … … 32 32 33 33 34 $preferredCommentStartColumn = 60 34 $preferredCommentStartColumn = 40 35 $preferredDebugAnnotationColumns = 18 35 36 36 37 -
trunk/Source/JavaScriptCore/offlineasm/mips.rb
r279343 r284341 1 # Copyright (C) 2012-20 18Apple Inc. All rights reserved.1 # Copyright (C) 2012-2021 Apple Inc. All rights reserved. 2 2 # Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 3 3 # … … 63 63 # $f16 => (scratch) 64 64 # $f18 => (scratch) 65 66 class Assembler67 def putStr(str)68 @outp.puts str69 end70 end71 65 72 66 class Node -
trunk/Source/JavaScriptCore/offlineasm/parser.rb
r282009 r284341 1 # Copyright (C) 2011 , 2016Apple Inc. All rights reserved.1 # Copyright (C) 2011-2021 Apple Inc. All rights reserved. 2 2 # 3 3 # Redistribution and use in source and binary forms, with or without … … 32 32 @@fileNames = [] 33 33 34 attr_reader :name, : fileNumber34 attr_reader :name, :basename, :fileNumber 35 35 36 36 def SourceFile.outputDotFileList(outp) 37 37 @@fileNames.each_index { 38 38 | index | 39 outp.puts"\".file #{index+1} \\\"#{@@fileNames[index]}\\\"\\n\""39 $asm.putStr "\".file #{index+1} \\\"#{@@fileNames[index]}\\\"\\n\"" 40 40 } 41 41 end … … 43 43 def initialize(fileName) 44 44 @name = Pathname.new(fileName) 45 @basename = File.basename(fileName) 45 46 pathName = "#{@name.realpath}" 46 47 fileNumber = @@fileNames.index(pathName) … … 72 73 73 74 def to_s 74 "#{ fileName}:#{lineNumber}"75 "#{@sourceFile.basename}:#{lineNumber}" 75 76 end 76 77 end
Note: See TracChangeset
for help on using the changeset viewer.