Skip to content

Expand the managed API for Module, BasicBlock, Target, and instruction flags#265

Merged
tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-managed-module-context
Jul 16, 2026
Merged

Expand the managed API for Module, BasicBlock, Target, and instruction flags#265
tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-managed-module-context

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Expands the high-level managed API (sources/LLVMSharp) to cover the
Phase-1 gaps that don't depend on new native libLLVMSharp helpers, moving
it closer to a faithful reproduction of the LLVM C++ API a real compiler or
JIT needs. Split into four logical commits by area.


Module -- adds a context-scoped ownership registry to LLVMContext so a
Module is a cached, non-owning wrapper (consistent with the other managed
value/type wrappers), and fills out the full accessor set: identity, source
file name, target triple, data-layout string, module inline asm; function and
global lookup/insertion/enumeration; named struct-type lookup; and
print/verify/clone/bitcode. Also exposes ModuleIdentifier,
SourceFileName, and InlineAsm on LLVMModuleRef.

BasicBlock -- parent, terminator, first/last instruction, next/previous
block, instruction enumeration, and move/remove/erase helpers.

Instruction flags + derived accessors -- round-trips the poison-generating
and fast-math flags through the C API instead of native helpers:
HasNoSignedWrap/HasNoUnsignedWrap move onto LLVMGetNSW/GetNUW
with setters, and Exact, disjoint, non-negative, GEP no-wrap, in-bounds,
icmp same-sign, and fast-math flags are added -- each guarded by the owning
instruction kind so a release build never reads the wrong SubclassOptionalData
bits. Also adds the trivially-derived CalledFunction, GEP index/pointer
operands, and load/store pointer/value operands (no new interop).

Target / TargetMachine / DataLayout -- description, JIT/target-machine/
asm-backend queries, and target enumeration on Target; CPU, feature string,
target, and triple on TargetMachine; a target-data constructor plus
call-frame alignment, element offset, and element-containing-offset on
DataLayout. Adds the matching getters on LLVMTargetRef and
LLVMTargetMachineRef.


Builds clean (0 warnings, TreatWarningsAsErrors) with 5 new managed tests;
full suite green. This is the managed half; the native libLLVMSharp helpers
and the managed accessors that consume them follow separately once the native
packages are rebuilt.

tannergooding and others added 4 commits July 15, 2026 17:30
Introduces a context-scoped ownership registry on LLVMContext so a Module is a
cached, non-owning wrapper (matching the other managed value/type wrappers) and
fills out the full accessor surface: identity, source file name, target triple,
data-layout string, and module inline asm; function and global lookup, insertion,
and enumeration; named struct-type lookup; and print/verify/clone/bitcode.

Also exposes ModuleIdentifier, SourceFileName, and InlineAsm on LLVMModuleRef.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fills out BasicBlock to mirror llvm::BasicBlock: parent function, terminator,
first/last instruction, next/previous block, instruction enumeration, and the
move/remove/erase helpers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… API

Round-trips the instruction poison-generating and fast-math flags through the C
API rather than the native helpers: HasNoSignedWrap/HasNoUnsignedWrap move onto
LLVMGetNSW/GetNUW with setters, and Exact, disjoint, non-negative, GEP no-wrap,
in-bounds, icmp same-sign, and fast-math flags are added, each guarded by the
owning instruction kind so a release build never reads the wrong option bits.

Also adds the trivially-derived accessors that need no new interop: CalledFunction,
the GEP index/pointer operands, and the load/store pointer and value operands.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fills the target codegen wrappers to mirror the C++ surface: Target gains
description and JIT/target-machine/asm-backend queries and target enumeration;
TargetMachine gains CPU, feature string, target, and triple; DataLayout gains a
target-data constructor plus call-frame alignment, element offset, and the
element-containing-offset query. Adds the matching getters on LLVMTargetRef and
LLVMTargetMachineRef.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 70ac46d into dotnet:main Jul 16, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-managed-module-context branch July 16, 2026 00:38
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