Skip to content

Add managed Instruction hierarchy accessors#264

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-managed-instruction-hierarchy
Jul 15, 2026
Merged

Add managed Instruction hierarchy accessors#264
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-managed-instruction-hierarchy

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Phase 1, PR2 of the effort to fill gaps in the high-level managed (C++-mirroring) API. Follows #261 (areas A-D: types/values/constants/globals).

This PR covers area E -- the Instruction hierarchy, which was a set of near-empty subclass skeletons. Everything here is reachable through the pure LLVM-C surface (no native libLLVMSharp dependency).

Added accessors:

  • Instruction: IsTerminator, Opcode, Parent, SuccessorsCount, Clone(), Get/SetSuccessor
  • CmpInst.GetPredicate() -- the unified nested Predicate, mirroring C++ CmpInst::getPredicate()
  • BranchInst (Condition/IsConditional), SwitchInst (Condition/DefaultDest/AddCase), SelectInst (Condition/TrueValue/FalseValue), ReturnInst.ReturnValue, PHINode (IncomingCount/AddIncoming/GetIncomingBlock/GetIncomingValue)
  • CallBase/CallInst: ArgOperandsCount, CalledOperand, CalledFunctionType, GetArgOperand, IsTailCall
  • LoadInst/StoreInst (Ordering/Volatile), AllocaInst.AllocatedType, GetElementPtrInst.SourceElementType, AtomicRMWInst (Operation/Ordering/Volatile), AtomicCmpXchgInst (Success/FailureOrdering/Volatile/Weak), FenceInst.Ordering, LandingPadInst (IsCleanup/NumClauses/AddClause/GetClause), InvokeInst (NormalDest/UnwindDest)

The corresponding layer-2 enablers were added to Extensions/LLVMValueRef.cs.


Notes:

  • Orderings are exposed as the managed AtomicOrdering enum (not the raw LLVMAtomicOrdering) for consistency with AtomicRMWInst.BinOp and CmpInst.Predicate.
  • CmpInst.GetPredicate() is a method (with a justified CA1024 suppression) rather than a property, since a property can't share the nested Predicate type's name -- this matches the C++ getPredicate() spelling.
  • GetElementPtrInst.IsInBounds getter is deferred: this LLVM's C API only exposes LLVMSetIsInBounds, so a set-only property would be asymmetric.

Deferred to later phases (unchanged from the plan): native-dependent flags (HasNoSignedWrap/HasNoUnsignedWrap, opcode/predicate names) to Phase 3, and the BasicBlock/Module/Context surface (areas F/G) to follow-up PRs.

Verified: dotnet build -c Release clean (0 warnings), dotnet test -c Release green -- 2613 unit tests (7 new instruction tests) + 6 Kaleidoscope, 0 failures.

Fills in the high-level Instruction subclasses, which were near-empty
skeletons, with the C++-mirroring accessors reachable through the pure
LLVM-C surface: opcode/terminator/parent/successors on the base, the
unified CmpInst predicate, branch/switch/select/return/phi operands and
destinations, call arg operands and called operand/type, and the
load/store/alloca/GEP/atomic/landingpad/invoke accessors. Orderings use
the managed AtomicOrdering enum for consistency with AtomicRMWInst.BinOp
and CmpInst.Predicate.

Native-dependent flags (nsw/nuw, opcode/predicate names) and the
BasicBlock/Module/Context surface remain deferred to later phases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit d525c9e into dotnet:main Jul 15, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-managed-instruction-hierarchy branch July 15, 2026 20:56
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