Add native libLLVMSharp helpers for C++ API surface absent from the C-API#271
Merged
tannergooding merged 11 commits intoJul 16, 2026
Merged
Conversation
…-API Add CallBase, CmpInst, GlobalValue, Instruction, Type, and Value helpers that mirror LLVM C++ methods the LLVM-C API does not expose, and remove the now-unused Instruction hasNoSignedWrap/hasNoUnsignedWrap helpers superseded by LLVMGetNSW/GetNUW. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add llvmsharp_OrcCreateObjectLinkingLayer, returning an LLVMOrcObjectLayerRef backed by llvm::orc::ObjectLinkingLayer for use with LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator, so the JIT can run object linking on JITLink instead of RuntimeDyld. Link LLVMOrcJIT and LLVMJITLink to resolve the ObjectLinkingLayer C++ symbols. Resolves dotnet#263 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose ConstantFoldInstruction, ConstantFoldConstant, ConstantFoldCompareInstOperands, and simplifyInstruction from LLVMAnalysis, which the LLVM-C API does not surface. The opcode-based ConstantFoldBinaryOpOperands/ConstantFoldCastOperand folders are deferred since the internal Instruction opcode numbering does not match the C LLVMOpcode enum. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose DominatorTree, PostDominatorTree, LoopInfo, and Loop from LLVMAnalysis behind opaque handles with explicit create/dispose lifetimes, none of which the LLVM-C API surfaces. Loop handles returned by LoopInfo are non-owning and valid for the lifetime of the owning LoopInfo. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose a TargetTransformInfo derived from a TargetMachine and Function behind an opaque handle, along with getInstructionCost, getNumberOfRegisters, and getRegisterBitWidth, which the LLVM-C API does not surface. Requires a local DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, ...) since LLVM keeps its own in the non-public TargetMachineC.cpp. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose CloneFunction and InlineFunction from LLVMTransformUtils, which the LLVM-C API does not surface. InlineFunction returns whether the inline succeeded. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose Mangler::getNameWithPrefix, Value::stripPointerCastsAndAliases, Value::stripInBoundsOffsets, Value::getPointerAlignment, Instruction::comesBefore/moveBefore/moveAfter, and GEPOperator::accumulateConstantOffset, none of which the LLVM-C API surfaces. getNameWithPrefix heap-allocates the mangled name; the caller frees it via llvmsharp_Free. moveBefore uses the iterator overload since the Instruction* overload is deprecated. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The inverse/swapped predicate transforms and the signed/unsigned/true-when-equal/false-when-equal predicate classifications are pure functions of the predicate enum, so they are emulated managed-side from CmpInst.GetPredicate() and don't need a native round-trip. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tannergooding
marked this pull request as ready for review
July 16, 2026 05:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expand the native
libLLVMSharpC++ shim with helpers that exposellvm::C++ API surface which the LLVM-C API does not, so the managed high-level API can faithfully mirror the LLVM C++ class hierarchy. Authored against the LLVM 21.1.8 C++ API, matching the existingunwrap/wrap+out_size/out_bufferconventions in the file.Note
Requires a native rebuild + interop regen before the managed consumers can bind to these. These add native symbols only; the generated interop (
sources/LLVMSharp.Interop/llvmsharp/) is regenerated from the rebuiltlibLLVMSharp. There are no managed consumers in this PR — those follow after thelibLLVMSharp.runtime.*packages are rebuilt.IR helpers —
CmpInst.getPredicateName;Instructionopcode-name /isCommutative/mayHaveSideEffects/mayReadFromMemory/mayWriteToMemory;Type.getPrimitiveSizeInBits(scalable out-param) /getScalarSizeInBits; constant-folding & instruction-simplification; dominator-tree & loop-info analysis;TargetTransformInfocost-model; function cloning & inlining;Valueuse/pointer-strip utilities (stripPointerCasts,getNumUses,isUsedInBasicBlock, ...); IR predicate & speculation-safety; basic-block insertion-point; loop induction-variable & exiting-block.JITLink (resolves #263) —
llvmsharp_OrcCreateObjectLinkingLayer, the JITLinkObjectLinkingLayercreator that the LLVM-C ORC API doesnt expose (the only real path off RtDyld-on-COFF). LinksLLVMOrcJIT+LLVMJITLink`.Cleanup — remove 6 redundant
CmpInstinstance predicate helpers now emulated managed-side from the predicate enum (#270).Cannot be built in-session (no full LLVM install/headers here); helpers are authored against the LLVM 21.1.8 C++ signatures. The one spot to confirm on the native rebuild is the locally-redefined
DEFINE_SIMPLE_CONVERSION_FUNCTIONSfororc::ExecutionSession/orc::ObjectLayer(distinct param types from the IR overloads, so no ambiguity expected).