Skip to content

Complete vector and aggregate indexing instructions #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2017
Merged
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
35 changes: 33 additions & 2 deletions Sources/LLVM/IRBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ public class IRBuilder {
return LLVMSizeOf(val.asLLVM())
}

// MARK: Vector Instructions
// MARK: Aggregate Instructions

/// Builds an instruction to insert a value into a member field in an
/// aggregate value.
Expand All @@ -958,12 +958,31 @@ public class IRBuilder {
return LLVMBuildInsertValue(llvm, aggregate.asLLVM(), element.asLLVM(), UInt32(index), name)
}

/// Builds an instruction to extract a value from a member field in an
/// aggregate value.
///
/// An `extract value` instruction differs from a `get element pointer`
/// instruction because the value being indexed is not a pointer and the first
/// index is unnecessary (as it is assumed to be zero).
///
/// - parameter aggregate: A value of array or structure type.
/// - parameter index: The index at which at which to extract a value.
/// - parameter name: The name for the newly inserted instruction.
///
/// - returns: A value representing an aggregate that has been updated with
/// the given value at the given index.
func buildExtractValue(aggregate: IRValue, index: Int, name: String = "") -> IRValue {
return LLVMBuildExtractValue(llvm, aggregate.asLLVM(), UInt32(index), name)
}

// MARK: Vector Instructions

/// Builds a vector insert instruction to nondestructively insert the given
/// value into the given vector.
///
/// - parameter vector: A value of vector type.
/// - parameter element: The value to insert.
/// - parameter index: The index at which at which to insert the value.
/// - parameter index: The index at which to insert the value.
/// - parameter name: The name for the newly inserted instruction.
///
/// - returns: A value representing a vector that has been updated with
Expand All @@ -972,6 +991,18 @@ public class IRBuilder {
return LLVMBuildInsertElement(llvm, vector.asLLVM(), element.asLLVM(), index.asLLVM(), name)
}

/// Builds an instruction to extract a single scalar element from a vector at
/// a specified index.
///
/// - parameter vector: A value of vector type.
/// - parameter index: The index at which to insert the value.
/// - parameter name: The name for the newly inserted instruction.
///
/// - returns: A value representing a scalar at the given index.
public func buildExtractElement(vector: IRValue, index: IRValue, name: String = "") -> IRValue {
return LLVMBuildExtractElement(llvm, vector.asLLVM(), index.asLLVM(), name)
}

// MARK: Global Variable Instructions

/// Build a named global of the given type.
Expand Down