Add managed Instruction hierarchy accessors#264
Merged
tannergooding merged 1 commit intoJul 15, 2026
Merged
Conversation
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>
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.
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
libLLVMSharpdependency).Added accessors:
Instruction:IsTerminator,Opcode,Parent,SuccessorsCount,Clone(),Get/SetSuccessorCmpInst.GetPredicate()-- the unified nestedPredicate, 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,IsTailCallLoadInst/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:
AtomicOrderingenum (not the rawLLVMAtomicOrdering) for consistency withAtomicRMWInst.BinOpandCmpInst.Predicate.CmpInst.GetPredicate()is a method (with a justifiedCA1024suppression) rather than a property, since a property can't share the nestedPredicatetype's name -- this matches the C++getPredicate()spelling.GetElementPtrInst.IsInBoundsgetter is deferred: this LLVM's C API only exposesLLVMSetIsInBounds, 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 theBasicBlock/Module/Contextsurface (areas F/G) to follow-up PRs.Verified:
dotnet build -c Releaseclean (0 warnings),dotnet test -c Releasegreen -- 2613 unit tests (7 new instruction tests) + 6 Kaleidoscope, 0 failures.