| 1 |
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -o - %s | FileCheck %s |
| 2 |
|
| 3 |
typedef float float4x4 __attribute__((matrix_type(4,4))); |
| 4 |
typedef int int4x4 __attribute__((matrix_type(4,4))); |
| 5 |
|
| 6 |
typedef float float4 __attribute__((ext_vector_type(4))); |
| 7 |
typedef int int4 __attribute__((ext_vector_type(4))); |
| 8 |
|
| 9 |
export float4 getFloatMatrixDynamic(float4x4 M, int index) { |
| 10 |
// CHECK: FunctionDecl {{.*}} used getFloatMatrixDynamic 'float4 (float4x4, int)' |
| 11 |
// CHECK: ReturnStmt {{.*}} |
| 12 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <LValueToRValue> |
| 13 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<float, 4>' lvalue matrixcomponent |
| 14 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'float4x4':'matrix<float, 4, 4>' lvalue ParmVar {{.*}} 'M' 'float4x4':'matrix<float, 4, 4>' |
| 15 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'index' 'int' |
| 16 |
return M[index]; |
| 17 |
} |
| 18 |
|
| 19 |
export int4 getIntMatrixDynamic(int4x4 M, int index) { |
| 20 |
// CHECK: FunctionDecl {{.*}} used getIntMatrixDynamic 'int4 (int4x4, int)' |
| 21 |
// CHECK: ReturnStmt {{.*}} |
| 22 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue> |
| 23 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<int, 4>' lvalue matrixcomponent |
| 24 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int4x4':'matrix<int, 4, 4>' lvalue ParmVar {{.*}} 'M' 'int4x4':'matrix<int, 4, 4>' |
| 25 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'index' 'int' |
| 26 |
return M[index]; |
| 27 |
} |
| 28 |
|
| 29 |
export float4 AddFloatMatrixConstant(float4x4 M) { |
| 30 |
// CHECK: FunctionDecl {{.*}} used AddFloatMatrixConstant 'float4 (float4x4)' |
| 31 |
// CHECK: ReturnStmt {{.*}} |
| 32 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<float, 4>' '+' |
| 33 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<float, 4>' '+' |
| 34 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<float, 4>' '+' |
| 35 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <LValueToRValue> |
| 36 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<float, 4>' lvalue matrixcomponent |
| 37 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'float4x4':'matrix<float, 4, 4>' lvalue ParmVar {{.*}} 'M' 'float4x4':'matrix<float, 4, 4>' |
| 38 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 39 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <LValueToRValue> |
| 40 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<float, 4>' lvalue matrixcomponent |
| 41 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'float4x4':'matrix<float, 4, 4>' lvalue ParmVar {{.*}} 'M' 'float4x4':'matrix<float, 4, 4>' |
| 42 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 43 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <LValueToRValue> |
| 44 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<float, 4>' lvalue matrixcomponent |
| 45 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'float4x4':'matrix<float, 4, 4>' lvalue ParmVar {{.*}} 'M' 'float4x4':'matrix<float, 4, 4>' |
| 46 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 |
| 47 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<float, 4>' <LValueToRValue> |
| 48 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<float, 4>' lvalue matrixcomponent |
| 49 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'float4x4':'matrix<float, 4, 4>' lvalue ParmVar {{.*}} 'M' 'float4x4':'matrix<float, 4, 4>' |
| 50 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3 |
| 51 |
return M[0] + M[1] + M[2] + M[3]; |
| 52 |
} |
| 53 |
|
| 54 |
export int4 AddIntMatrixConstant(int4x4 M) { |
| 55 |
// CHECK: FunctionDecl {{.*}} used AddIntMatrixConstant 'int4 (int4x4)' |
| 56 |
// CHECK: ReturnStmt {{.*}} |
| 57 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<int, 4>' '+' |
| 58 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<int, 4>' '+' |
| 59 |
// CHECK-NEXT: BinaryOperator {{.*}} 'vector<int, 4>' '+' |
| 60 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue> |
| 61 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<int, 4>' lvalue matrixcomponent |
| 62 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int4x4':'matrix<int, 4, 4>' lvalue ParmVar {{.*}} 'M' 'int4x4':'matrix<int, 4, 4>' |
| 63 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 64 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue> |
| 65 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<int, 4>' lvalue matrixcomponent |
| 66 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int4x4':'matrix<int, 4, 4>' lvalue ParmVar {{.*}} 'M' 'int4x4':'matrix<int, 4, 4>' |
| 67 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1 |
| 68 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue> |
| 69 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<int, 4>' lvalue matrixcomponent |
| 70 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int4x4':'matrix<int, 4, 4>' lvalue ParmVar {{.*}} 'M' 'int4x4':'matrix<int, 4, 4>' |
| 71 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 2 |
| 72 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<int, 4>' <LValueToRValue> |
| 73 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<int, 4>' lvalue matrixcomponent |
| 74 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'int4x4':'matrix<int, 4, 4>' lvalue ParmVar {{.*}} 'M' 'int4x4':'matrix<int, 4, 4>' |
| 75 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 3 |
| 76 |
return M[0] + M[1] + M[2] + M[3]; |
| 77 |
} |
| 78 |
|
| 79 |
export vector<bool, 3> getBoolVecFromTemplateMat(matrix<bool, 2, 3> M) { |
| 80 |
// CHECK: FunctionDecl {{.*}} used getBoolVecFromTemplateMat 'vector<bool, 3> (matrix<bool, 2, 3>)' |
| 81 |
// CHECK-NEXT: ParmVarDecl {{.*}} used M 'matrix<bool, 2, 3>' |
| 82 |
// CHECK-NEXT: CompoundStmt {{.*}} |
| 83 |
// CHECK-NEXT: ReturnStmt {{.*}} |
| 84 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<bool, 3>' <LValueToRValue> |
| 85 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<bool, 3>' lvalue matrixcomponent |
| 86 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'matrix<bool, 2, 3>' lvalue ParmVar {{.*}} 'M' 'matrix<bool, 2, 3>' |
| 87 |
// CHECK-NEXT: IntegerLiteral {{.*}}'int' 0 |
| 88 |
return M[0]; |
| 89 |
} |
| 90 |
|
| 91 |
template<typename T> |
| 92 |
vector<T, 3> getVecFromTemplateMat(matrix<T, 2, 3> M) { |
| 93 |
// CHECK: FunctionTemplateDecl {{.*}} getVecFromTemplateMat |
| 94 |
// CHECK-NEXT: TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T |
| 95 |
// CHECK-NEXT: FunctionDecl {{.*}} getVecFromTemplateMat 'vector<T, 3> (matrix<T, 2, 3>)' |
| 96 |
// CHECK-NEXT: ParmVarDecl {{.*}} referenced M 'matrix<T, 2, 3>' |
| 97 |
// CHECK-NEXT: CompoundStmt {{.*}} |
| 98 |
// CHECK-NEXT: ReturnStmt {{.*}} |
| 99 |
// CHECK-NEXT: MatrixSubscriptExpr {{.*}} '<incomplete matrix index type>' lvalue matrixcomponent |
| 100 |
// CHECK-NEXT: DeclRefExpr {{.*}} 'matrix<T, 2, 3>' lvalue ParmVar {{.*}} 'M' 'matrix<T, 2, 3>' |
| 101 |
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 0 |
| 102 |
// CHECK-NEXT: <<<NULL>>> |
| 103 |
// CHECK-NEXT: FunctionDecl {{.*}} used getVecFromTemplateMat 'vector<bool, 3> (matrix<bool, 2, 3>)' implicit_instantiation instantiated_from {{.*}} |
| 104 |
// CHECK-NEXT: TemplateArgument type 'bool' |
| 105 |
// CHECK-NEXT: BuiltinType {{.*}} 'bool' |
| 106 |
// CHECK-NEXT: ParmVarDecl {{.*}} used M 'matrix<bool, 2, 3>' |
| 107 |
// CHECK-NEXT: CompoundStmt {{.*}} |
| 108 |
// CHECK-NEXT: ReturnStmt {{.*}} |
| 109 |
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'vector<bool, 3>' <LValueToRValue> |
| 110 |
// CHECK-NEXT: MatrixSingleSubscriptExpr {{.*}} 'vector<bool, 3>' lvalue matrixcomponent |
| 111 |
// CHECK-NEXT: DeclRefExpr {{.*}} <col:12> 'matrix<bool, 2, 3>' lvalue ParmVar {{.*}} 'M' 'matrix<bool, 2, 3>' |
| 112 |
// CHECK-NEXT: IntegerLiteral {{.*}} <col:14> 'int' 0 |
| 113 |
// CHECK-NEXT: TypedefDecl {{.*}} referenced bool3 'vector<bool, 3>' |
| 114 |
return M[0]; |
| 115 |
} |
| 116 |
|
| 117 |
typedef bool bool3 __attribute__((ext_vector_type(3))); |
| 118 |
typedef bool bool2x3 __attribute__((matrix_type(2,3))); |
| 119 |
|
| 120 |
export bool3 testTemplatedMatrixAccess(bool2x3 M) { |
| 121 |
return getVecFromTemplateMat(M); |
| 122 |
} |