Bug 1699271 - Part 1: Generate MIR Opcodes. r=jandem,iain

Differential Revision: https://phabricator.services.mozilla.com/D111043
This commit is contained in:
carolinecullen 2021-05-27 22:55:30 +00:00
parent 3e5199b524
commit c5a2828bfc
6 changed files with 922 additions and 15 deletions

View File

@ -67,7 +67,7 @@ included_inclnames_to_ignore = set(
"gc/StatsPhasesGenerated.inc", # generated in $OBJDIR
"jit/CacheIROpsGenerated.h", # generated in $OBJDIR
"jit/LOpcodesGenerated.h", # generated in $OBJDIR
"jit/MOpcodesGenerated.h", # generated in $OBJDIR
"jit/MIROpsGenerated.h", # generated in $OBJDIR
"js/ProfilingCategoryList.h", # comes from mozglue/baseprofiler
"jscustomallocator.h", # provided by embedders; allowed to be missing
"js-config.h", # generated in $OBJDIR

View File

@ -0,0 +1,84 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This script generates jit/MIROpsGenerated.h (list of MIR instructions)
# from MIROps.yaml.
import buildconfig
import yaml
import six
from collections import OrderedDict
from mozbuild.preprocessor import Preprocessor
HEADER_TEMPLATE = """\
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef %(includeguard)s
#define %(includeguard)s
/* This file is generated by jit/GenerateMIRFiles.py. Do not edit! */
%(contents)s
#endif // %(includeguard)s
"""
def generate_header(c_out, includeguard, contents):
c_out.write(
HEADER_TEMPLATE
% {
"includeguard": includeguard,
"contents": contents,
}
)
def load_yaml(yaml_path):
# First invoke preprocessor.py so that we can use #ifdef JS_SIMULATOR in
# the YAML file.
pp = Preprocessor()
pp.context.update(buildconfig.defines["ALLDEFINES"])
pp.out = six.StringIO()
pp.do_filter("substitution")
pp.do_include(yaml_path)
contents = pp.out.getvalue()
# Load into an OrderedDict to ensure order is preserved. Note: Python 3.7+
# also preserves ordering for normal dictionaries.
# Code based on https://stackoverflow.com/a/21912744.
class OrderedLoader(yaml.Loader):
pass
def construct_mapping(loader, node):
loader.flatten_mapping(node)
return OrderedDict(loader.construct_pairs(node))
tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
OrderedLoader.add_constructor(tag, construct_mapping)
return yaml.load(contents, OrderedLoader)
def generate_mir_header(c_out, yaml_path):
"""Generate MIROpsGenerated.h from MIROps.yaml. The generated file
has a list of MIR ops.
"""
data = load_yaml(yaml_path)
# MIR_OPCODE_LIST items. Stores the name of each MIR op.
ops_items = []
for op in data:
name = op["name"]
ops_items.append("_({})".format(name))
contents = "#define MIR_OPCODE_LIST(_)\\\n"
contents += "\\\n".join(ops_items)
contents += "\n\n"
generate_header(c_out, "jit_MIROpsGenerated_h", contents)

View File

@ -2,8 +2,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This script generates jit/LOpcodesGenerated.h (list of LIR instructions) and
# jit/MOpcodesGenerated.h (list of MIR instructions) from MIR.h and LIR files.
# This script generates jit/LOpcodesGenerated.h (list of LIR instructions)
# from LIR files.
import re
@ -54,13 +54,6 @@ def generate_header(c_out, inputs, pat, includeguard, listname):
)
def generate_mir_header(c_out, *inputs):
pat = re.compile(
r"^\s*INSTRUCTION_HEADER(_WITHOUT_TYPEPOLICY)?\((?P<name>\w+)\);?$"
)
generate_header(c_out, inputs, pat, "jit_MOpcodesGenerated_h", "MIR_OPCODE_LIST")
def generate_lir_header(c_out, *inputs):
pat = re.compile(r"^\s*LIR_HEADER\((?P<name>\w+)\);?$")
generate_header(c_out, inputs, pat, "jit_LOpcodesGenerated_h", "LIR_OPCODE_LIST")

View File

@ -28,7 +28,7 @@
#include "jit/InlineScriptTree.h"
#include "jit/JitAllocPolicy.h"
#include "jit/MacroAssembler.h"
#include "jit/MOpcodesGenerated.h"
#include "jit/MIROpsGenerated.h"
#include "jit/TypeData.h"
#include "jit/TypePolicy.h"
#include "js/experimental/JitInfo.h" // JSJit{Getter,Setter}Op, JSJitInfo

830
js/src/jit/MIROps.yaml Normal file
View File

@ -0,0 +1,830 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# [SMDOC] MIR Opcodes
# =======================
# This file defines all MIR opcodes.
#
# name
# ====
# Opcode name.
#
- name: Start
- name: OsrEntry
- name: Nop
- name: LimitedTruncate
- name: Constant
- name: WasmNullConstant
- name: WasmFloatConstant
- name: Parameter
- name: Callee
- name: IsConstructing
- name: TableSwitch
- name: Goto
- name: Test
- name: Return
- name: Throw
- name: NewArray
- name: NewArrayDynamicLength
- name: NewTypedArray
- name: NewTypedArrayDynamicLength
- name: NewTypedArrayFromArray
- name: NewTypedArrayFromArrayBuffer
- name: NewObject
- name: NewPlainObject
- name: NewArrayObject
- name: NewIterator
- name: ObjectState
- name: ArrayState
- name: MutateProto
- name: InitPropGetterSetter
- name: InitElemGetterSetter
- name: Call
- name: ApplyArgs
- name: ApplyArgsObj
- name: ApplyArray
- name: ConstructArray
- name: Bail
- name: Unreachable
- name: EncodeSnapshot
- name: AssertRecoveredOnBailout
- name: AssertFloat32
- name: Compare
- name: SameValueDouble
- name: SameValue
- name: Box
- name: Unbox
- name: AssertRange
- name: AssertClass
- name: AssertShape
- name: CreateThisWithTemplate
- name: CreateThis
- name: CreateArgumentsObject
- name: CreateInlinedArgumentsObject
- name: GetInlinedArgument
- name: GetArgumentsObjectArg
- name: SetArgumentsObjectArg
- name: LoadArgumentsObjectArg
- name: ArgumentsObjectLength
- name: GuardArgumentsObjectFlags
- name: ReturnFromCtor
- name: ToDouble
- name: ToFloat32
- name: WasmUnsignedToDouble
- name: WasmUnsignedToFloat32
- name: WrapInt64ToInt32
- name: ExtendInt32ToInt64
- name: WasmBuiltinTruncateToInt64
- name: WasmTruncateToInt64
- name: WasmTruncateToInt32
- name: WasmBoxValue
- name: WasmAnyRefFromJSObject
- name: Int32ToIntPtr
- name: NonNegativeIntPtrToInt32
- name: IntPtrToDouble
- name: AdjustDataViewLength
- name: Int64ToFloatingPoint
- name: BuiltinInt64ToFloatingPoint
- name: ToNumberInt32
- name: ToIntegerInt32
- name: TruncateToInt32
- name: WasmBuiltinTruncateToInt32
- name: ToBigInt
- name: ToInt64
- name: TruncateBigIntToInt64
- name: Int64ToBigInt
- name: ToString
- name: BitNot
- name: TypeOf
- name: ToAsyncIter
- name: ToPropertyKeyCache
- name: BitAnd
- name: BitOr
- name: BitXor
- name: Lsh
- name: Rsh
- name: Ursh
- name: SignExtendInt32
- name: SignExtendInt64
- name: MinMax
- name: MinMaxArray
- name: Abs
- name: Clz
- name: Ctz
- name: Popcnt
- name: Sqrt
- name: CopySign
- name: Atan2
- name: Hypot
- name: Pow
- name: PowHalf
- name: Random
- name: Sign
- name: MathFunction
- name: Add
- name: Sub
- name: Mul
- name: Div
- name: WasmBuiltinDivI64
- name: Mod
- name: WasmBuiltinModD
- name: WasmBuiltinModI64
- name: BigIntAdd
- name: BigIntSub
- name: BigIntMul
- name: BigIntDiv
- name: BigIntMod
- name: BigIntPow
- name: BigIntBitAnd
- name: BigIntBitOr
- name: BigIntBitXor
- name: BigIntLsh
- name: BigIntRsh
- name: BigIntIncrement
- name: BigIntDecrement
- name: BigIntNegate
- name: BigIntBitNot
- name: Concat
- name: CharCodeAt
- name: FromCharCode
- name: FromCodePoint
- name: StringConvertCase
- name: StringSplit
- name: BoxNonStrictThis
- name: ImplicitThis
- name: ArrowNewTarget
- name: Phi
- name: Beta
- name: NaNToZero
- name: OsrValue
- name: OsrEnvironmentChain
- name: OsrArgumentsObject
- name: OsrReturnValue
- name: BinaryCache
- name: UnaryCache
- name: CheckOverRecursed
- name: InterruptCheck
- name: WasmInterruptCheck
- name: WasmTrap
- name: LexicalCheck
- name: ThrowRuntimeLexicalError
- name: ThrowMsg
- name: GlobalDeclInstantiation
- name: RegExp
- name: RegExpMatcher
- name: RegExpSearcher
- name: RegExpTester
- name: RegExpPrototypeOptimizable
- name: RegExpInstanceOptimizable
- name: GetFirstDollarIndex
- name: StringReplace
- name: Substr
- name: ModuleMetadata
- name: DynamicImport
- name: Lambda
- name: LambdaArrow
- name: FunctionWithProto
- name: SetFunName
- name: Slots
- name: Elements
- name: InitializedLength
- name: SetInitializedLength
- name: ArrayLength
- name: SetArrayLength
- name: FunctionLength
- name: FunctionName
- name: GetNextEntryForIterator
- name: ArrayBufferByteLength
- name: ArrayBufferViewLength
- name: ArrayBufferViewByteOffset
- name: ArrayBufferViewElements
- name: TypedArrayElementSize
- name: GuardHasAttachedArrayBuffer
- name: GuardNumberToIntPtrIndex
- name: KeepAliveObject
- name: Not
- name: BoundsCheck
- name: BoundsCheckLower
- name: SpectreMaskIndex
- name: LoadElement
- name: LoadElementAndUnbox
- name: LoadElementHole
- name: StoreElement
- name: StoreHoleValueElement
- name: StoreElementHole
- name: ArrayPopShift
- name: ArrayPush
- name: ArraySlice
- name: ArrayJoin
- name: LoadUnboxedScalar
- name: LoadDataViewElement
- name: LoadTypedArrayElementHole
- name: StoreUnboxedScalar
- name: StoreDataViewElement
- name: StoreTypedArrayElementHole
- name: EffectiveAddress
- name: ClampToUint8
- name: LoadFixedSlot
- name: LoadFixedSlotAndUnbox
- name: LoadDynamicSlotAndUnbox
- name: StoreFixedSlot
- name: GetPropertyCache
- name: HomeObjectSuperBase
- name: GetPropSuperCache
- name: BindNameCache
- name: CallBindVar
- name: GuardShape
- name: GuardProto
- name: GuardNullProto
- name: GuardIsNativeObject
- name: GuardIsProxy
- name: GuardIsNotProxy
- name: GuardIsNotDOMProxy
- name: ProxyGet
- name: ProxyGetByValue
- name: ProxyHasProp
- name: ProxySet
- name: ProxySetByValue
- name: CallSetArrayLength
- name: MegamorphicLoadSlot
- name: MegamorphicLoadSlotByValue
- name: MegamorphicStoreSlot
- name: MegamorphicHasProp
- name: GuardIsNotArrayBufferMaybeShared
- name: GuardIsTypedArray
- name: NurseryObject
- name: GuardValue
- name: GuardNullOrUndefined
- name: GuardFunctionFlags
- name: GuardFunctionIsNonBuiltinCtor
- name: GuardFunctionKind
- name: GuardFunctionScript
- name: GuardObjectIdentity
- name: GuardSpecificFunction
- name: GuardSpecificAtom
- name: GuardSpecificSymbol
- name: GuardStringToIndex
- name: GuardStringToInt32
- name: GuardStringToDouble
- name: GuardNoDenseElements
- name: GuardTagNotEqual
- name: LoadDynamicSlot
- name: FunctionEnvironment
- name: NewLexicalEnvironmentObject
- name: NewClassBodyEnvironmentObject
- name: CopyLexicalEnvironmentObject
- name: HomeObject
- name: AddAndStoreSlot
- name: AllocateAndStoreSlot
- name: StoreDynamicSlot
- name: GetNameCache
- name: CallGetIntrinsicValue
- name: DeleteProperty
- name: DeleteElement
- name: SetPropertyCache
- name: CallSetElement
- name: SetDOMProperty
- name: GetDOMProperty
- name: GetDOMMember
- name: LoadDOMExpandoValue
- name: LoadDOMExpandoValueGuardGeneration
- name: LoadDOMExpandoValueIgnoreGeneration
- name: GuardDOMExpandoMissingOrGuardShape
- name: StringLength
- name: Floor
- name: Ceil
- name: Round
- name: Trunc
- name: NearbyInt
- name: GetIteratorCache
- name: OptimizeSpreadCallCache
- name: IteratorMore
- name: IsNoIter
- name: IteratorEnd
- name: InCache
- name: InArray
- name: GuardElementNotHole
- name: CheckPrivateFieldCache
- name: HasOwnCache
- name: InstanceOf
- name: InstanceOfCache
- name: ArgumentsLength
- name: GetFrameArgument
- name: NewTarget
- name: Rest
- name: PostWriteBarrier
- name: PostWriteElementBarrier
- name: NewNamedLambdaObject
- name: NewCallObject
- name: NewStringObject
- name: IsCallable
- name: IsConstructor
- name: IsCrossRealmArrayConstructor
- name: IsObject
- name: IsNullOrUndefined
- name: HasClass
- name: GuardToClass
- name: IsArray
- name: IsTypedArray
- name: ObjectClassToString
- name: CheckReturn
- name: CheckThis
- name: AsyncResolve
- name: GeneratorReturn
- name: AsyncAwait
- name: CheckThisReinit
- name: Generator
- name: CanSkipAwait
- name: MaybeExtractAwaitValue
- name: IncrementWarmUpCounter
- name: AtomicIsLockFree
- name: CompareExchangeTypedArrayElement
- name: AtomicExchangeTypedArrayElement
- name: AtomicTypedArrayElementBinop
- name: Debugger
- name: CheckIsObj
- name: CheckObjCoercible
- name: CheckClassHeritage
- name: DebugCheckSelfHosted
- name: FinishBoundFunctionInit
- name: IsPackedArray
- name: GuardArrayIsPacked
- name: GetPrototypeOf
- name: ObjectWithProto
- name: ObjectStaticProto
- name: BuiltinObject
- name: SuperFunction
- name: InitHomeObject
- name: IsTypedArrayConstructor
- name: LoadValueTag
- name: LoadWrapperTarget
- name: GuardHasGetterSetter
- name: GuardIsExtensible
- name: GuardInt32IsNonNegative
- name: GuardIndexGreaterThanDenseInitLength
- name: GuardIndexIsValidUpdateOrAdd
- name: CallAddOrUpdateSparseElement
- name: CallGetSparseElement
- name: CallNativeGetElement
- name: CallObjectHasSparseElement
- name: BigIntAsIntN
- name: BigIntAsUintN
- name: WasmNeg
- name: WasmLoadTls
- name: WasmHeapBase
- name: WasmBoundsCheck
- name: WasmExtendU32Index
- name: WasmWrapU32Index
- name: WasmAddOffset
- name: WasmAlignmentCheck
- name: WasmLoad
- name: WasmStore
- name: AsmJSLoadHeap
- name: AsmJSStoreHeap
- name: WasmFence
- name: WasmCompareExchangeHeap
- name: WasmAtomicExchangeHeap
- name: WasmAtomicBinopHeap
- name: WasmLoadGlobalVar
- name: WasmLoadGlobalCell
- name: WasmStoreGlobalVar
- name: WasmStoreGlobalCell
- name: WasmStoreStackResult
- name: WasmDerivedPointer
- name: WasmStoreRef
- name: WasmParameter
- name: WasmReturn
- name: WasmReturnVoid
- name: WasmStackArg
- name: WasmRegisterResult
- name: WasmFloatRegisterResult
- name: WasmRegister64Result
- name: WasmStackResultArea
- name: WasmStackResult
- name: WasmCall
- name: WasmSelect
- name: WasmReinterpret
- name: Rotate
- name: WasmBitselectSimd128
- name: WasmBinarySimd128
- name: WasmBinarySimd128WithConstant
- name: WasmShiftSimd128
- name: WasmShuffleSimd128
- name: WasmReplaceLaneSimd128
- name: WasmUnarySimd128
- name: WasmScalarToSimd128
- name: WasmReduceSimd128
- name: WasmLoadLaneSimd128
- name: WasmStoreLaneSimd128
- name: UnreachableResult
- name: IonToWasmCall

View File

@ -234,12 +234,12 @@ elif CONFIG["JS_CODEGEN_MIPS32"] or CONFIG["JS_CODEGEN_MIPS64"]:
UNIFIED_SOURCES += ["mips64/Simulator-mips64.cpp"]
# Generate jit/MOpcodesGenerated.h from jit/MIR.h
# Generate jit/MIROpsGenerated.h from jit/MIROps.yaml
GeneratedFile(
"MOpcodesGenerated.h",
script="GenerateOpcodeFiles.py",
"MIROpsGenerated.h",
script="GenerateMIRFiles.py",
entry_point="generate_mir_header",
inputs=["MIR.h"],
inputs=["MIROps.yaml"],
)
# Generate jit/LOpcodesGenerated.h from jit/LIR.h, jit/shared/LIR-shared.h, and