@@ -17,6 +17,8 @@ public enum Signed: IntegralConstantRepresentation {}
1717public enum Floating : NumericalConstantRepresentation { }
1818/// Represents struct types and operations.
1919public enum Struct : ConstantRepresentation { }
20+ /// Represents vector types and operations.
21+ public enum Vector : ConstantRepresentation { }
2022
2123/// A `Constant` represents a value initialized to a constant. Constant values
2224/// may be manipulated with standard Swift arithmetic operations and used with
@@ -952,6 +954,27 @@ extension Constant where Repr == Struct {
952954 }
953955}
954956
957+ // MARK: Vector Operations
958+
959+ extension Constant where Repr == Vector {
960+ /// Builds a constant operation to construct a permutation of elements
961+ /// from the two given input vectors, returning a vector with the same element
962+ /// type as the inputs and length that is the same as the shuffle mask.
963+ ///
964+ /// - parameter vector1: The first constant vector to shuffle.
965+ /// - parameter vector2: The second constant vector to shuffle.
966+ /// - parameter mask: A constant vector of `i32` values that acts as a mask
967+ /// for the shuffled vectors.
968+ ///
969+ /// - returns: A value representing a constant vector with the same element
970+ /// type as the inputs and length that is the same as the shuffle mask.
971+ public static func buildShuffleVector( _ vector1: Constant , and vector2: Constant , mask: Constant ) -> Constant {
972+ guard let maskTy = mask. type as? VectorType , maskTy. elementType is IntType else {
973+ fatalError ( " Vector shuffle mask's elements must be 32-bit integers " )
974+ }
975+ return Constant ( llvm: LLVMConstShuffleVector ( vector1. asLLVM ( ) , vector2. asLLVM ( ) , mask. asLLVM ( ) ) )
976+ }
977+ }
955978
956979// MARK: Swift Operators
957980
@@ -1384,3 +1407,49 @@ extension Constant where Repr: IntegralConstantRepresentation {
13841407 return Constant ( llvm: LLVMConstNot ( lhs. llvm) )
13851408 }
13861409}
1410+
1411+ // MARK: Undef
1412+
1413+ extension Constant where Repr: IntegralConstantRepresentation {
1414+ /// Returns the special LLVM `undef` value for this type.
1415+ ///
1416+ /// The `undef` value can be used anywhere a constant is expected, and
1417+ /// indicates that the user of the value may receive an unspecified
1418+ /// bit-pattern.
1419+ public static func undef( _ ty: IntType ) -> Constant {
1420+ return Constant < Repr > ( llvm: ty. undef ( ) . asLLVM ( ) )
1421+ }
1422+ }
1423+
1424+ extension Constant where Repr == Floating {
1425+ /// Returns the special LLVM `undef` value for this type.
1426+ ///
1427+ /// The `undef` value can be used anywhere a constant is expected, and
1428+ /// indicates that the user of the value may receive an unspecified
1429+ /// bit-pattern.
1430+ public static func undef( _ ty: FloatType ) -> Constant {
1431+ return Constant ( llvm: ty. undef ( ) . asLLVM ( ) )
1432+ }
1433+ }
1434+
1435+ extension Constant where Repr == Struct {
1436+ /// Returns the special LLVM `undef` value for this type.
1437+ ///
1438+ /// The `undef` value can be used anywhere a constant is expected, and
1439+ /// indicates that the user of the value may receive an unspecified
1440+ /// bit-pattern.
1441+ public static func undef( _ ty: StructType ) -> Constant {
1442+ return Constant ( llvm: ty. undef ( ) . asLLVM ( ) )
1443+ }
1444+ }
1445+
1446+ extension Constant where Repr == Vector {
1447+ /// Returns the special LLVM `undef` value for this type.
1448+ ///
1449+ /// The `undef` value can be used anywhere a constant is expected, and
1450+ /// indicates that the user of the value may receive an unspecified
1451+ /// bit-pattern.
1452+ public static func undef( _ ty: VectorType ) -> Constant {
1453+ return Constant ( llvm: ty. undef ( ) . asLLVM ( ) )
1454+ }
1455+ }
0 commit comments