Changeset 281541 in webkit


Ignore:
Timestamp:
Aug 24, 2021 7:34:38 PM (3 years ago)
Author:
mark.lam@apple.com
Message:

[Re-landing] Add some offlineasm enhancements.
https://bugs.webkit.org/show_bug.cgi?id=229332
rdar://82163923

Reviewed by Keith Miller.

  1. Enhance "include" offlineasm Instruction to always attempt to include an asm file from <build-products>/usr/local/include/WebKitAdditions/ first. If the specified file is not available there, then it will attempt to include the file from the same directory as the current source file (which in practice, means Source/JavaScriptCore/llint/).
  1. Enhance "include" offlineasm Instruction to allow an optional file to be included if it exists. For example, the following offlineasm code:

include? LowLevelInterpreterAdditions

... will attempt to include a file LowLevelInterpreterAdditions.asm. If the
file does not exist, this will be a no-op. Note: the "?" after the "include"
means the include is optional.

  1. Enhanced "emit" offlineasm Instruction to be able to take more than one operand.

"emit" used to just copy the string operand that follows into the generated
LLIntAssembly.h. Now, "emit" can take multiple comma separated operands, and
will concatenate all the operands.

Additionally, "emit" can now take a LocalLabelReference as an operand. For
example, this offline asm code:

emit "b ", .done
...

.done:

... will generate this inline asm code in LLIntAssembly.h:

"b " LOCAL_LABEL_STRING(_offlineasm_someLabel_done) "\n"

This makes it easier to emit branches to local labels.

  1. Also fixed LLInt code alignment for ARM_THUMB2 and ARM64.

Previously, it was aligned using ".align 4" which means aligned on a 4
instruction boundary. Note: the interpretation of .align varies for different
target CPU architectures.

Now, we do the alignment using ".balign 4" which means align on a 4 byte
boundary. This is the intended alignment because ARM64 instruction size is
4 bytes, and ARM_THUMB2 instruction size is either 2 bytes or 4 bytes.
Using .align before was potentially wasting some code space.

  • llint/LowLevelInterpreter.asm:
  • llint/LowLevelInterpreter.cpp:
  • offlineasm/ast.rb:
  • offlineasm/parser.rb:
Location:
trunk/Source/JavaScriptCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r281534 r281541  
     12021-08-24  Mark Lam  <mark.lam@apple.com>
     2
     3        [Re-landing] Add some offlineasm enhancements.
     4        https://bugs.webkit.org/show_bug.cgi?id=229332
     5        rdar://82163923
     6
     7        Reviewed by Keith Miller.
     8
     9        1. Enhance "include" offlineasm Instruction to always attempt to include an asm
     10           file from <build-products>/usr/local/include/WebKitAdditions/ first.  If the
     11           specified file is not available there, then it will attempt to include the file
     12           from the same directory as the current source file (which in practice, means
     13           Source/JavaScriptCore/llint/).
     14
     15        2. Enhance "include" offlineasm Instruction to allow an optional file to be
     16           included if it exists.  For example, the following offlineasm code:
     17
     18                include? LowLevelInterpreterAdditions
     19
     20           ... will attempt to include a file LowLevelInterpreterAdditions.asm.  If the
     21           file does not exist, this will be a no-op.  Note: the "?" after the "include"
     22           means the include is optional.
     23
     24        3. Enhanced "emit" offlineasm Instruction to be able to take more than one operand.
     25
     26           "emit" used to just copy the string operand that follows into the generated
     27           LLIntAssembly.h.  Now, "emit" can take multiple comma separated operands, and
     28           will concatenate all the operands.
     29
     30           Additionally, "emit" can now take a LocalLabelReference as an operand.  For
     31           example, this offline asm code:
     32
     33                   emit "b ", .done
     34                   ...
     35                .done:
     36
     37           ... will generate this inline asm code in LLIntAssembly.h:
     38
     39                "b " LOCAL_LABEL_STRING(_offlineasm_someLabel_done) "\n"
     40
     41           This makes it easier to emit branches to local labels.
     42
     43        4. Also fixed LLInt code alignment for ARM_THUMB2 and ARM64.
     44
     45           Previously, it was aligned using ".align 4" which means aligned on a 4
     46           instruction boundary.  Note: the interpretation of .align varies for different
     47           target CPU architectures.
     48
     49           Now, we do the alignment using ".balign 4" which means align on a 4 byte
     50           boundary.  This is the intended alignment because ARM64 instruction size is
     51           4 bytes, and ARM_THUMB2 instruction size is either 2 bytes or 4 bytes.
     52           Using .align before was potentially wasting some code space.
     53
     54        * llint/LowLevelInterpreter.asm:
     55        * llint/LowLevelInterpreter.cpp:
     56        * offlineasm/ast.rb:
     57        * offlineasm/parser.rb:
     58
    1592021-08-24  Mark Lam  <mark.lam@apple.com>
    260
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter.asm

    r281523 r281541  
    25512551
    25522552end
     2553
     2554include? LowLevelInterpreterAdditions
  • trunk/Source/JavaScriptCore/llint/LowLevelInterpreter.cpp

    r281496 r281541  
    496496#define OFFLINE_ASM_GLOBAL_LABEL(label)          \
    497497    ".text\n"                                    \
    498     ".align 4\n"                                 \
     498    ".balign 4\n"                                 \
    499499    ".globl " SYMBOL_STRING(label) "\n"          \
    500500    HIDE_SYMBOL(label) "\n"                      \
     
    505505#define OFFLINE_ASM_GLOBAL_LABEL(label)         \
    506506    ".text\n"                                   \
    507     ".align 4\n"                                \
     507    ".balign 4\n"                                \
    508508    ".globl " SYMBOL_STRING(label) "\n"         \
    509509    HIDE_SYMBOL(label) "\n"                     \
  • trunk/Source/JavaScriptCore/offlineasm/ast.rb

    r281496 r281541  
    945945            $asm.putGlobalAnnotation
    946946        when "emit"
    947             $asm.puts "#{operands[0].dump}"
     947            str = "";
     948            for operand in operands do
     949                if (operand.is_a? LocalLabelReference)
     950                    str += operand.asmLabel
     951                else
     952                    str += "#{operand.dump}"
     953                end
     954            end
     955            $asm.puts "#{str}"
    948956        when "tagCodePtr", "tagReturnAddress", "untagReturnAddress", "removeCodePtrTag", "untagArrayPtr", "removeArrayPtrTag"
    949957        else
  • trunk/Source/JavaScriptCore/offlineasm/parser.rb

    r281496 r281541  
    201201        when /\A".*"/
    202202            result << Token.new(CodeOrigin.new(file, lineNumber), $&)
     203        when /\?/
     204            result << Token.new(CodeOrigin.new(file, lineNumber), $&)
    203205        else
    204206            raise "Lexer error at #{CodeOrigin.new(file, lineNumber).to_s}, unexpected sequence #{str[0..20].inspect}"
     
    262264        @idx = 0
    263265        @annotation = nil
     266        # FIXME: CMake does not currently set BUILT_PRODUCTS_DIR.
     267        # https://bugs.webkit.org/show_bug.cgi?id=229340
     268        @buildProductsDirectory = ENV['BUILT_PRODUCTS_DIR'];
    264269    end
    265270   
     
    818823            elsif @tokens[@idx] == "include"
    819824                @idx += 1
     825                isOptional = false
     826                if @tokens[@idx] == "?"
     827                    isOptional = true
     828                    @idx += 1
     829                end
    820830                parseError unless isIdentifier(@tokens[@idx])
    821831                moduleName = @tokens[@idx].string
    822                 fileName = IncludeFile.new(moduleName, @tokens[@idx].codeOrigin.fileName.dirname).fileName
    823                 @idx += 1
    824                 list << parse(fileName)
     832                @idx += 1
     833                additionsDirectoryName = "#{@buildProductsDirectory}/usr/local/include/WebKitAdditions/"
     834                fileName = IncludeFile.new(moduleName, additionsDirectoryName).fileName
     835                if not File.exists?(fileName)
     836                    fileName = IncludeFile.new(moduleName, @tokens[@idx].codeOrigin.fileName.dirname).fileName
     837                end
     838                fileExists = File.exists?(fileName)
     839                raise "File not found: #{fileName}" if not fileExists and not isOptional
     840                list << parse(fileName) if fileExists
    825841            else
    826842                parseError "Expecting terminal #{final} #{comment}"
     
    839855            elsif @tokens[@idx] == "include"
    840856                @idx += 1
     857                isOptional = false
     858                if @tokens[@idx] == "?"
     859                    isOptional = true
     860                    @idx += 1
     861                end
    841862                parseError unless isIdentifier(@tokens[@idx])
    842863                moduleName = @tokens[@idx].string
    843                 fileName = IncludeFile.new(moduleName, @tokens[@idx].codeOrigin.fileName.dirname).fileName
    844                 @idx += 1
    845                
    846                 fileList << fileName
     864                @idx += 1
     865                additionsDirectoryName = "#{@buildProductsDirectory}/usr/local/include/WebKitAdditions/"
     866                fileName = IncludeFile.new(moduleName, additionsDirectoryName).fileName
     867                if not File.exists?(fileName)
     868                    fileName = IncludeFile.new(moduleName, @tokens[@idx].codeOrigin.fileName.dirname).fileName
     869                end
     870                fileExists = File.exists?(fileName)
     871                raise "File not found: #{fileName}" if not fileExists and not isOptional
     872                fileList << fileName if fileExists
    847873            else
    848874                @idx += 1
Note: See TracChangeset for help on using the changeset viewer.