Skip to content

Commit 2eea502

Browse files
committed
Add binding to retrieve the scalarType of a vector
1 parent 8a4e694 commit 2eea502

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/LLVM/IRType.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public extension IRType {
3434
var context: Context {
3535
return Context(llvm: LLVMGetTypeContext(asLLVM()))
3636
}
37+
38+
/// If this is a vector type, return the element type, otherwise
39+
/// return `self`.
40+
var scalarType: IRType {
41+
guard let vecTy = self as? VectorType else {
42+
return self
43+
}
44+
return vecTy.elementType
45+
}
3746
}
3847

3948
internal func convertType(_ type: LLVMTypeRef) -> IRType {

0 commit comments

Comments
 (0)