Skip to content

xls/jit: Make JitRuntime layout queries lock-free and avoid redundant mask ops. - #5534

Draft
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1028359539
Draft

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1028359539

Conversation

@copybara-service

Copy link
Copy Markdown

xls/jit: Make JitRuntime layout queries lock-free and avoid redundant mask ops.

JitRuntime previously guarded an internal LLVMContext and
LlvmTypeConverter with an absl::Mutex on every GetTypeByteSize,
GetTypeAlignment, PackArgs, UnpackBuffer, and BlitValueToBuffer call
because querying composite struct layouts on llvm::DataLayout mutates its
internal layout map. That lock serialized concurrent callers and recomputed
nested tuple layouts repeatedly. Separately, LlvmTypeConverter emitted
multi-instruction sign-extension sequences and redundant padding-mask and
instructions on power-of-two bit widths that already match their LLVM integer
container width.

Extract immutable target alignment and endianness parameters into
TargetLayoutInfo during JIT and AOT compilation (using the compiler's existing
LLVMContext), emit TargetLayoutProto in AotPackageEntrypointsProto so AOT
wrappers and proc runtimes instantiate JitRuntime directly from serialized
layout metadata without a process-global cache or DataLayout parsing, and
evaluate all layout queries, value blitting, and buffer unpacking lock-free with
single-pass tuple offset advancement. Temporarily retain a deprecated
JitRuntime::data_layout() accessor (ABSL_DEPRECATED) populated only by the
llvm::DataLayout constructors (live JIT runtimes) for legacy JIT callers
migrating off direct llvm::DataLayout inspection. Simplify
LlvmTypeConverter::AsSignedValue to a shift pair and elide no-op
ClearPaddingBits masks when the XLS bit width equals the LLVM integer width.

… mask ops.

`JitRuntime` previously guarded an internal `LLVMContext` and
`LlvmTypeConverter` with an `absl::Mutex` on every `GetTypeByteSize`,
`GetTypeAlignment`, `PackArgs`, `UnpackBuffer`, and `BlitValueToBuffer` call
because querying composite struct layouts on `llvm::DataLayout` mutates its
internal layout map. That lock serialized concurrent callers and recomputed
nested tuple layouts repeatedly. Separately, `LlvmTypeConverter` emitted
multi-instruction sign-extension sequences and redundant padding-mask `and`
instructions on power-of-two bit widths that already match their LLVM integer
container width.

Extract immutable target alignment and endianness parameters into
`TargetLayoutInfo` during JIT and AOT compilation (using the compiler's existing
`LLVMContext`), emit `TargetLayoutProto` in `AotPackageEntrypointsProto` so AOT
wrappers and proc runtimes instantiate `JitRuntime` directly from serialized
layout metadata without a process-global cache or `DataLayout` parsing, and
evaluate all layout queries, value blitting, and buffer unpacking lock-free with
single-pass tuple offset advancement. Temporarily retain a deprecated
`JitRuntime::data_layout()` accessor (`ABSL_DEPRECATED`) populated only by the
`llvm::DataLayout` constructors (live JIT runtimes) for legacy JIT callers
migrating off direct `llvm::DataLayout` inspection. Simplify
`LlvmTypeConverter::AsSignedValue` to a shift pair and elide no-op
`ClearPaddingBits` masks when the XLS bit width equals the LLVM integer width.

PiperOrigin-RevId: 1028359539

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant