Skip to content

Commit fd63d4c

Browse files
committed
[Matrix] Add a row\col major toggle in the clang driver
fixes #167621 - define the new options in `Options.td` limit the naming to row-major or column-major. - In `ToolChains/Clang.cpp` limit the opt usage to only when `-fenable-matrix` is used. - make sure we set the flags llvm needs for the lower-matrix-intrinsics pass.
1 parent ea10026 commit fd63d4c

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

clang/include/clang/Options/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4642,6 +4642,11 @@ def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>,
46424642
HelpText<"Enable matrix data type and related builtin functions">,
46434643
MarshallingInfoFlag<LangOpts<"MatrixTypes">, hlsl.KeyPath>;
46444644

4645+
def fmatrix_default_layout_EQ : Joined<["-"], "fmatrix-default-layout=">,
4646+
HelpText<"Set default matrix layout (row-major or column-major)">,
4647+
Values<"row-major,column-major">,
4648+
Group<f_Group>;
4649+
46454650
defm raw_string_literals : BoolFOption<"raw-string-literals",
46464651
LangOpts<"RawStringLiterals">, Default<std#".hasRawStringLiterals()">,
46474652
PosFlag<SetTrue, [], [], "Enable">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5692,6 +5692,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56925692
CmdArgs.push_back("-fenable-matrix");
56935693
CmdArgs.push_back("-mllvm");
56945694
CmdArgs.push_back("-enable-matrix");
5695+
// Only handle default layout if matrix is enabled
5696+
if (const Arg *A =
5697+
Args.getLastArg(options::OPT_fmatrix_default_layout_EQ)) {
5698+
StringRef Val = A->getValue();
5699+
if (Val == "row-major" || Val == "column-major") {
5700+
CmdArgs.push_back("-mllvm");
5701+
CmdArgs.push_back(Args.MakeArgString("-matrix-default-layout=" + Val));
5702+
} else {
5703+
D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
5704+
}
5705+
}
56955706
}
56965707

56975708
CodeGenOptions::FramePointerKind FPKeepKind =
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR
2+
// CHECK-COL-MAJOR: -fenable-matrix
3+
// CHECK-COL-MAJOR: -mllvm
4+
// CHECK-COL-MAJOR: -enable-matrix
5+
// CHECK-COL-MAJOR: -mllvm
6+
// CHECK-COL-MAJOR: -matrix-default-layout=column-major
7+
8+
// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR
9+
// CHECK-ROW-MAJOR: -fenable-matrix
10+
// CHECK-ROW-MAJOR: -mllvm
11+
// CHECK-ROW-MAJOR: -enable-matrix
12+
// CHECK-ROW-MAJOR: -mllvm
13+
// CHECK-ROW-MAJOR: -matrix-default-layout=row-major
14+
15+
// RUN: not %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=error-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR-MAJOR
16+
// CHECK-ERROR-MAJOR: error: invalid value 'error-major' in '-fmatrix-default-layout=error-major'
17+
18+
// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR-DISABLED
19+
// CHECK-COL-MAJOR-DISABLED-NOT: -fenable-matrix
20+
// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm
21+
// CHECK-COL-MAJOR-DISABLED-NOT: -enable-matrix
22+
// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm
23+
// CHECK-COL-MAJOR-DISABLED-NOT: -matrix-default-layout=column-major
24+
25+
// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR-DISABLED
26+
// CHECK-ROW-MAJOR-DISABLED-NOT: -fenable-matrix
27+
// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm
28+
// CHECK-ROW-MAJOR-DISABLED-NOT: -enable-matrix
29+
// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm
30+
// CHECK-ROW-MAJOR-DISABLED-NOT: -matrix-default-layout=row-major
31+
32+
// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MATRIX-ENABLED
33+
// CHECK-MATRIX-ENABLED: -fenable-matrix
34+
// CHECK-MATRIX-ENABLED: -mllvm
35+
// CHECK-MATRIX-ENABLED: -enable-matrix
36+
// CHECK-MATRIX-ENABLED-NOT: -mllvm
37+
// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=row-major
38+
// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=column-major

0 commit comments

Comments
 (0)