Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions sources/LLVMSharp.Interop/Extensions/LLVMValueRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public readonly uint Alignment
}
}

public readonly LLVMTypeRef AllocatedType => (IsAAllocaInst != null) ? LLVM.GetAllocatedType(this) : default;

public readonly uint ArgOperandsCount => ((IsACallInst != null) || (IsAInvokeInst != null) || (IsACallBrInst != null)) ? LLVM.GetNumArgOperands(this) : default;

public readonly LLVMAtomicRMWBinOp AtomicRMWBinOp
{
get
Expand All @@ -58,6 +62,36 @@ public readonly LLVMAtomicRMWBinOp AtomicRMWBinOp

public readonly LLVMValueRef BlockAddressFunction => (IsABlockAddress != null) ? LLVM.GetBlockAddressFunction(this) : default;

public readonly LLVMTypeRef CalledFunctionType => ((IsACallInst != null) || (IsAInvokeInst != null) || (IsACallBrInst != null)) ? LLVM.GetCalledFunctionType(this) : default;

public readonly LLVMValueRef CalledValue => ((IsACallInst != null) || (IsAInvokeInst != null) || (IsACallBrInst != null)) ? LLVM.GetCalledValue(this) : default;

public readonly LLVMAtomicOrdering CmpXchgFailureOrdering
{
get
{
return (IsAAtomicCmpXchgInst != null) ? LLVM.GetCmpXchgFailureOrdering(this) : default;
}

set
{
LLVM.SetCmpXchgFailureOrdering(this, value);
}
}

public readonly LLVMAtomicOrdering CmpXchgSuccessOrdering
{
get
{
return (IsAAtomicCmpXchgInst != null) ? LLVM.GetCmpXchgSuccessOrdering(this) : default;
}

set
{
LLVM.SetCmpXchgSuccessOrdering(this, value);
}
}

public readonly LLVMValueRef Condition
{
get
Expand Down Expand Up @@ -167,6 +201,8 @@ public readonly string GC
}
}

public readonly LLVMTypeRef GEPSourceElementType => (IsAGetElementPtrInst != null) ? LLVM.GetGEPSourceElementType(this) : default;

public readonly LLVMValueRef GlobalIFuncResolver
{
get
Expand Down Expand Up @@ -570,10 +606,27 @@ public readonly string Name

public readonly LLVMValueRef NextParam => (IsAArgument != null) ? LLVM.GetNextParam(this) : default;

public readonly LLVMBasicBlockRef NormalDest => (IsAInvokeInst != null) ? LLVM.GetNormalDest(this) : default;

public readonly uint NumClauses => (IsALandingPadInst != null) ? LLVM.GetNumClauses(this) : default;

public readonly LLVMOpcode Opcode => Kind is LLVMValueKind.LLVMInstructionValueKind ? InstructionOpcode : ConstOpcode;

public readonly int OperandCount => ((Kind == LLVMValueKind.LLVMMetadataAsValueValueKind) || (IsAUser != null)) ? LLVM.GetNumOperands(this) : default;

public readonly LLVMAtomicOrdering Ordering
{
get
{
return ((IsALoadInst != null) || (IsAStoreInst != null) || (IsAFenceInst != null) || (IsAAtomicRMWInst != null)) ? LLVM.GetOrdering(this) : default;
}

set
{
LLVM.SetOrdering(this, value);
}
}

public readonly uint ParamsCount => (IsAFunction != null) ? LLVM.CountParams(this) : default;

public readonly LLVMValueRef ParamParent => (IsAArgument != null) ? LLVM.GetParamParent(this) : default;
Expand Down Expand Up @@ -679,6 +732,8 @@ public readonly LLVMUnnamedAddr UnnamedAddress
}
}

public readonly LLVMBasicBlockRef UnwindDest => ((IsAInvokeInst != null) || (IsACatchSwitchInst != null) || (IsACleanupReturnInst != null)) ? LLVM.GetUnwindDest(this) : default;

public readonly LLVMValueUsesEnumerable Uses => new LLVMValueUsesEnumerable(this);

public readonly LLVMVisibility Visibility
Expand Down Expand Up @@ -1235,6 +1290,10 @@ public readonly double GetConstRealDouble(out bool losesInfo)

public readonly LLVMValueRef GetAggregateElement(uint idx) => LLVM.GetAggregateElement(this, idx);

public readonly LLVMValueRef GetArgOperand(uint index) => LLVM.GetArgOperand(this, index);

public readonly LLVMValueRef GetClause(uint index) => LLVM.GetClause(this, index);

[Obsolete("Use GetAggregateElement instead")]
public readonly LLVMValueRef GetElementAsConstant(uint idx) => LLVM.GetElementAsConstant(this, idx);

Expand Down
2 changes: 2 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/AllocaInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public uint Alignment
Handle.SetAlignment(value);
}
}

public Type AllocatedType => Context.GetOrCreate(Handle.AllocatedType);
}
56 changes: 56 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/AtomicCmpXchgInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,60 @@ public sealed class AtomicCmpXchgInst : Instruction
internal AtomicCmpXchgInst(LLVMValueRef handle) : base(handle.IsAAtomicCmpXchgInst)
{
}

public AtomicOrdering FailureOrdering
{
get
{
return (AtomicOrdering)Handle.CmpXchgFailureOrdering;
}

set
{
var handle = Handle;
handle.CmpXchgFailureOrdering = (LLVMAtomicOrdering)value;
}
}

public AtomicOrdering SuccessOrdering
{
get
{
return (AtomicOrdering)Handle.CmpXchgSuccessOrdering;
}

set
{
var handle = Handle;
handle.CmpXchgSuccessOrdering = (LLVMAtomicOrdering)value;
}
}

public bool Volatile
{
get
{
return Handle.Volatile;
}

set
{
var handle = Handle;
handle.Volatile = value;
}
}

public bool Weak
{
get
{
return Handle.Weak;
}

set
{
var handle = Handle;
handle.Weak = value;
}
}
}
42 changes: 42 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/AtomicRMWInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,46 @@ public sealed partial class AtomicRMWInst : Instruction
internal AtomicRMWInst(LLVMValueRef handle) : base(handle.IsAAtomicRMWInst)
{
}

public BinOp Operation
{
get
{
return (BinOp)Handle.AtomicRMWBinOp;
}

set
{
var handle = Handle;
handle.AtomicRMWBinOp = (LLVMAtomicRMWBinOp)value;
}
}

public AtomicOrdering Ordering
{
get
{
return (AtomicOrdering)Handle.Ordering;
}

set
{
var handle = Handle;
handle.Ordering = (LLVMAtomicOrdering)value;
}
}

public bool Volatile
{
get
{
return Handle.Volatile;
}

set
{
var handle = Handle;
handle.Volatile = value;
}
}
}
4 changes: 4 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/BranchInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public sealed class BranchInst : Instruction
internal BranchInst(LLVMValueRef handle) : base(handle.IsABranchInst)
{
}

public Value Condition => Context.GetOrCreate(Handle.Condition);

public bool IsConditional => Handle.IsConditional;
}
8 changes: 8 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/CallBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ private protected CallBase(LLVMValueRef handle) : base(handle)
{
}

public uint ArgOperandsCount => Handle.ArgOperandsCount;

public LLVMCallConv CallingConvention
{
get
Expand Down Expand Up @@ -43,4 +45,10 @@ public Attribute[] GetAttributesAtIndex(LLVMAttributeIndex index)

return attributes;
}

public FunctionType CalledFunctionType => Context.GetOrCreate<FunctionType>(Handle.CalledFunctionType);

public Value CalledOperand => Context.GetOrCreate(Handle.CalledValue);

public Value GetArgOperand(uint index) => Context.GetOrCreate(Handle.GetArgOperand(index));
}
14 changes: 14 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/CallInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ private protected CallInst(LLVMValueRef handle) : base(handle.IsACallInst)
{
}

public bool IsTailCall
{
get
{
return Handle.IsTailCall;
}

set
{
var handle = Handle;
handle.IsTailCall = value;
}
}

internal static new CallInst Create(LLVMValueRef handle) => handle switch
{
_ when handle.IsAIntrinsicInst != null => IntrinsicInst.Create(handle),
Expand Down
4 changes: 4 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/CmpInst.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System.Diagnostics.CodeAnalysis;
using LLVMSharp.Interop;

namespace LLVMSharp;
Expand All @@ -10,6 +11,9 @@ private protected CmpInst(LLVMValueRef handle) : base(handle.IsACmpInst)
{
}

[SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "Mirrors C++ CmpInst::getPredicate(); the 'Predicate' name is the nested predicate enum type.")]
public Predicate GetPredicate() => (Handle.IsAICmpInst != null) ? (Predicate)Handle.ICmpPredicate : (Predicate)Handle.FCmpPredicate;

internal static new CmpInst Create(LLVMValueRef handle) => handle switch
{
_ when handle.IsAFCmpInst != null => new FCmpInst(handle),
Expand Down
14 changes: 14 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/FenceInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ public sealed class FenceInst : Instruction
internal FenceInst(LLVMValueRef handle) : base(handle.IsAFenceInst)
{
}

public AtomicOrdering Ordering
{
get
{
return (AtomicOrdering)Handle.Ordering;
}

set
{
var handle = Handle;
handle.Ordering = (LLVMAtomicOrdering)value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public sealed class GetElementPtrInst : Instruction
internal GetElementPtrInst(LLVMValueRef handle) : base(handle.IsAGetElementPtrInst)
{
}

public Type SourceElementType => Context.GetOrCreate(Handle.GEPSourceElementType);
}
19 changes: 19 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/Instruction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using LLVMSharp.Interop;

namespace LLVMSharp;
Expand All @@ -10,10 +11,28 @@ private protected Instruction(LLVMValueRef handle) : base(handle.IsAInstruction,
{
}

public bool IsTerminator => Handle.IsATerminatorInst != null;

public LLVMOpcode Opcode => Handle.InstructionOpcode;

public BasicBlock Parent => Context.GetOrCreate(Handle.InstructionParent);

public uint SuccessorsCount => Handle.SuccessorsCount;

public Instruction Clone() => Context.GetOrCreate<Instruction>(Handle.InstructionClone);

public void EraseFromParent() => Handle.InstructionEraseFromParent();

public BasicBlock GetSuccessor(uint index) => Context.GetOrCreate(Handle.GetSuccessor(index));

public void RemoveFromParent() => Handle.InstructionRemoveFromParent();

public void SetSuccessor(uint index, BasicBlock block)
{
ArgumentNullException.ThrowIfNull(block);
Handle.SetSuccessor(index, block.Handle);
}

internal static new Instruction Create(LLVMValueRef handle) => handle switch
{
_ when handle.IsAUnaryOperator != null => new UnaryOperator(handle),
Expand Down
4 changes: 4 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/InvokeInst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public sealed class InvokeInst : CallBase
internal InvokeInst(LLVMValueRef handle) : base(handle.IsAInvokeInst)
{
}

public BasicBlock NormalDest => Context.GetOrCreate(Handle.NormalDest);

public BasicBlock UnwindDest => Context.GetOrCreate(Handle.UnwindDest);
}
25 changes: 25 additions & 0 deletions sources/LLVMSharp/Values/Users/Instructions/LandingPadInst.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using LLVMSharp.Interop;

namespace LLVMSharp;
Expand All @@ -9,4 +10,28 @@ public sealed class LandingPadInst : Instruction
internal LandingPadInst(LLVMValueRef handle) : base(handle.IsALandingPadInst)
{
}

public bool IsCleanup
{
get
{
return Handle.IsCleanup;
}

set
{
var handle = Handle;
handle.IsCleanup = value;
}
}

public uint NumClauses => Handle.NumClauses;

public void AddClause(Constant clauseVal)
{
ArgumentNullException.ThrowIfNull(clauseVal);
Handle.AddClause(clauseVal.Handle);
}

public Constant GetClause(uint index) => Context.GetOrCreate<Constant>(Handle.GetClause(index));
}
Loading
Loading