https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/167628
>From aff57766dd1d9a02cb32b0a5603a1fb028f4bb0a Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Tue, 11 Nov 2025 22:13:57 -0500 Subject: [PATCH 1/9] [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. --- clang/include/clang/Options/Options.td | 5 +++ clang/lib/Driver/ToolChains/Clang.cpp | 11 +++++++ clang/test/Driver/fmatrix-default-layout.c | 38 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 clang/test/Driver/fmatrix-default-layout.c diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index a8fc1c4326cc5..86ce67f6ff237 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -4664,6 +4664,11 @@ def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>, HelpText<"Enable matrix data type and related builtin functions">, MarshallingInfoFlag<LangOpts<"MatrixTypes">, hlsl.KeyPath>; +def fmatrix_default_layout_EQ : Joined<["-"], "fmatrix-default-layout=">, + HelpText<"Set default matrix layout (row-major or column-major)">, + Values<"row-major,column-major">, + Group<f_Group>; + defm raw_string_literals : BoolFOption<"raw-string-literals", LangOpts<"RawStringLiterals">, Default<std#".hasRawStringLiterals()">, PosFlag<SetTrue, [], [], "Enable">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index c5d40c9825fab..a3aabbc35b043 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5692,6 +5692,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-fenable-matrix"); CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-enable-matrix"); + // Only handle default layout if matrix is enabled + if (const Arg *A = + Args.getLastArg(options::OPT_fmatrix_default_layout_EQ)) { + StringRef Val = A->getValue(); + if (Val == "row-major" || Val == "column-major") { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Args.MakeArgString("-matrix-default-layout=" + Val)); + } else { + D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; + } + } } CodeGenOptions::FramePointerKind FPKeepKind = diff --git a/clang/test/Driver/fmatrix-default-layout.c b/clang/test/Driver/fmatrix-default-layout.c new file mode 100644 index 0000000000000..c89396f4452f6 --- /dev/null +++ b/clang/test/Driver/fmatrix-default-layout.c @@ -0,0 +1,38 @@ +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR +// CHECK-COL-MAJOR: -fenable-matrix +// CHECK-COL-MAJOR: -mllvm +// CHECK-COL-MAJOR: -enable-matrix +// CHECK-COL-MAJOR: -mllvm +// CHECK-COL-MAJOR: -matrix-default-layout=column-major + +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR +// CHECK-ROW-MAJOR: -fenable-matrix +// CHECK-ROW-MAJOR: -mllvm +// CHECK-ROW-MAJOR: -enable-matrix +// CHECK-ROW-MAJOR: -mllvm +// CHECK-ROW-MAJOR: -matrix-default-layout=row-major + +// 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 +// CHECK-ERROR-MAJOR: error: invalid value 'error-major' in '-fmatrix-default-layout=error-major' + +// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR-DISABLED +// CHECK-COL-MAJOR-DISABLED-NOT: -fenable-matrix +// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm +// CHECK-COL-MAJOR-DISABLED-NOT: -enable-matrix +// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm +// CHECK-COL-MAJOR-DISABLED-NOT: -matrix-default-layout=column-major + +// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR-DISABLED +// CHECK-ROW-MAJOR-DISABLED-NOT: -fenable-matrix +// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm +// CHECK-ROW-MAJOR-DISABLED-NOT: -enable-matrix +// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm +// CHECK-ROW-MAJOR-DISABLED-NOT: -matrix-default-layout=row-major + +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MATRIX-ENABLED +// CHECK-MATRIX-ENABLED: -fenable-matrix +// CHECK-MATRIX-ENABLED: -mllvm +// CHECK-MATRIX-ENABLED: -enable-matrix +// CHECK-MATRIX-ENABLED-NOT: -mllvm +// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=row-major +// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=column-major >From a025783bb34f443e80423d1846f4f841b6f7b759 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Wed, 12 Nov 2025 18:51:44 -0500 Subject: [PATCH 2/9] add new documentation to address pr concerns --- clang/docs/LanguageExtensions.rst | 5 +++++ clang/docs/MatrixTypes.rst | 5 +++++ clang/docs/ReleaseNotes.rst | 1 + 3 files changed, 11 insertions(+) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index a3db3e5d356b3..88abc270fccf6 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1073,6 +1073,11 @@ The matrix type extension supports explicit casts. Implicit type conversion betw i = static_cast<matrix_5_5<int>>(d); } +The matrix type extension will support column and row major layouts. The flag +to change this behavior is `-fmatrix-default-layout` used like so +`-fmatrix-default-layout=column-major` for column major and like so +`-fmatrix-default-layout=row-major` for row major. + Half-Precision Floating Point ============================= diff --git a/clang/docs/MatrixTypes.rst b/clang/docs/MatrixTypes.rst index b3a2c8cf53670..6c5392149a814 100644 --- a/clang/docs/MatrixTypes.rst +++ b/clang/docs/MatrixTypes.rst @@ -287,6 +287,11 @@ part of the draft specification. The elements of a value of a matrix type are laid out in column-major order without padding. +To change the default order to row major use the `-fmatrix-default-layout` flag. +This flag supports two flag argument values either `column-major` or `row-major` +used like so `-fmatrix-default-layout=column-major`.` This flag controls the +memory layout of matrix types. + We propose to provide a Clang option to override this behavior and allow contraction of those operations (e.g. *-ffp-contract=matrix*). diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 51f07256c5d9f..e03de8198b244 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -327,6 +327,7 @@ New Compiler Flags - New option ``-fsanitize-debug-trap-reasons=`` added to control emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``). - New options for enabling allocation token instrumentation: ``-fsanitize=alloc-token``, ``-falloc-token-max=``, ``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``. - The ``-resource-dir`` option is now displayed in the list of options shown by ``--help``. +- New option ``-fmatrix-default-layout`` added to control the memory layout of Clang matrix types. (e.g. ``-fmatrix-default-layout=column-major`` or ``-fmatrix-default-layout=row-major``). Lanai Support ^^^^^^^^^^^^^^ >From c3e1f76a30dfb9e6ef80a00c364865d2b78b334a Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Fri, 14 Nov 2025 14:57:54 -0500 Subject: [PATCH 3/9] Address pr comments, drop the -mllvm flags make this just about memory layout. So this change actually does something move the lang opt changes into this pr --- clang/docs/LanguageExtensions.rst | 6 +-- clang/docs/MatrixTypes.rst | 5 +-- clang/docs/ReleaseNotes.rst | 2 +- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/LangOptions.h | 7 ++++ clang/include/clang/Options/Options.td | 5 ++- clang/lib/Driver/ToolChains/Clang.cpp | 6 +-- clang/lib/Frontend/CompilerInvocation.cpp | 19 ++++++++++ clang/test/Driver/fmatrix-default-layout.c | 38 ------------------- clang/test/Driver/fmatrix-memory-layout.c | 35 +++++++++++++++++ .../Frontend/CompilerInvocationTest.cpp | 36 ++++++++++++++++++ 11 files changed, 109 insertions(+), 51 deletions(-) delete mode 100644 clang/test/Driver/fmatrix-default-layout.c create mode 100644 clang/test/Driver/fmatrix-memory-layout.c diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 88abc270fccf6..cc5ae719080f0 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1074,9 +1074,9 @@ The matrix type extension supports explicit casts. Implicit type conversion betw } The matrix type extension will support column and row major layouts. The flag -to change this behavior is `-fmatrix-default-layout` used like so -`-fmatrix-default-layout=column-major` for column major and like so -`-fmatrix-default-layout=row-major` for row major. +to change this behavior is `-fmatrix-memory-layout` used like so +`-fmatrix-memory-layout=column-major` for column major and like so +`-fmatrix-memory-layout=row-major` for row major. Half-Precision Floating Point ============================= diff --git a/clang/docs/MatrixTypes.rst b/clang/docs/MatrixTypes.rst index 6c5392149a814..bc36857800aa4 100644 --- a/clang/docs/MatrixTypes.rst +++ b/clang/docs/MatrixTypes.rst @@ -287,10 +287,9 @@ part of the draft specification. The elements of a value of a matrix type are laid out in column-major order without padding. -To change the default order to row major use the `-fmatrix-default-layout` flag. +To change memory layout to row major use the `-fmatrix-default-layout` flag. This flag supports two flag argument values either `column-major` or `row-major` -used like so `-fmatrix-default-layout=column-major`.` This flag controls the -memory layout of matrix types. +used like so `-fmatrix-default-layout=column-major`.` We propose to provide a Clang option to override this behavior and allow contraction of those operations (e.g. *-ffp-contract=matrix*). diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e03de8198b244..bd045d7169c01 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -327,7 +327,7 @@ New Compiler Flags - New option ``-fsanitize-debug-trap-reasons=`` added to control emitting trap reasons into the debug info when compiling with trapping UBSan (e.g. ``-fsanitize-trap=undefined``). - New options for enabling allocation token instrumentation: ``-fsanitize=alloc-token``, ``-falloc-token-max=``, ``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``. - The ``-resource-dir`` option is now displayed in the list of options shown by ``--help``. -- New option ``-fmatrix-default-layout`` added to control the memory layout of Clang matrix types. (e.g. ``-fmatrix-default-layout=column-major`` or ``-fmatrix-default-layout=row-major``). +- New option ``-fmatrix-memory-layout`` added to control the memory layout of Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or ``-fmatrix-memory-layout=row-major``). Lanai Support ^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 40fc66ea12e34..bc2226942f7e4 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -434,6 +434,7 @@ ENUM_LANGOPT(RegisterStaticDestructors, RegisterStaticDestructorsKind, 2, LANGOPT(RegCall4, 1, 0, NotCompatible, "Set __regcall4 as a default calling convention to respect __regcall ABI v.4") LANGOPT(MatrixTypes, 1, 0, NotCompatible, "Enable or disable the builtin matrix type") +ENUM_LANGOPT(DefaultMatrixMemoryLayout, MatrixMemoryLayout, 1, MatrixColMajor, NotCompatible, "Defines the default memory Layout for matrices") VALUE_LANGOPT(MaxMatrixDimension, 32, (1 << 20) - 1, NotCompatible, "maximum allowed matrix dimension") LANGOPT(CXXAssumptions, 1, 1, NotCompatible, "Enable or disable codegen and compile-time checks for C++23's [[assume]] attribute") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 3f042f8ddb5a1..dd1260ed88f9c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -251,6 +251,13 @@ class LangOptionsBase { FEM_UnsetOnCommandLine = 3 }; + enum MatrixMemoryLayout : unsigned { + // Use column-major layout for matrices + MatrixColMajor = 0, + // Use row-major layout for matrices + MatrixRowMajor = 1, + }; + enum ExcessPrecisionKind { FPP_Standard, FPP_Fast, FPP_None }; enum class LaxVectorConversionKind { diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 86ce67f6ff237..08150550ba2a5 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -4664,8 +4664,9 @@ def fenable_matrix : Flag<["-"], "fenable-matrix">, Group<f_Group>, HelpText<"Enable matrix data type and related builtin functions">, MarshallingInfoFlag<LangOpts<"MatrixTypes">, hlsl.KeyPath>; -def fmatrix_default_layout_EQ : Joined<["-"], "fmatrix-default-layout=">, - HelpText<"Set default matrix layout (row-major or column-major)">, +def fmatrix_memory_layout_EQ : Joined<["-"], "fmatrix-memory-layout=">, + Visibility<[ClangOption, CC1Option]>, + HelpText<"Sets the matrix memory layout (row-major or column-major)">, Values<"row-major,column-major">, Group<f_Group>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a3aabbc35b043..c579b4ce72ec9 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5693,12 +5693,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-mllvm"); CmdArgs.push_back("-enable-matrix"); // Only handle default layout if matrix is enabled - if (const Arg *A = - Args.getLastArg(options::OPT_fmatrix_default_layout_EQ)) { + if (const Arg *A = Args.getLastArg(options::OPT_fmatrix_memory_layout_EQ)) { StringRef Val = A->getValue(); if (Val == "row-major" || Val == "column-major") { - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back(Args.MakeArgString("-matrix-default-layout=" + Val)); + CmdArgs.push_back(Args.MakeArgString("-fmatrix-memory-layout=" + Val)); } else { D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index c7c29a91721c0..efd27e89309ab 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3973,6 +3973,13 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, } GenerateArg(Consumer, OPT_falloc_token_mode_EQ, S); } + // Enable options for Matrices + if (Opts.MatrixTypes) { + if (Opts.DefaultMatrixMemoryLayout == LangOptions::MatrixColMajor) + GenerateArg(Consumer, OPT_fmatrix_memory_layout_EQ, "column-major"); + if (Opts.DefaultMatrixMemoryLayout == LangOptions::MatrixRowMajor) + GenerateArg(Consumer, OPT_fmatrix_memory_layout_EQ, "row-major"); + } } bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, @@ -4567,6 +4574,18 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << Arg->getAsString(Args) << S; } + if (Opts.MatrixTypes) { + if (const Arg *A = Args.getLastArg(OPT_fmatrix_memory_layout_EQ)) { + StringRef Val = A->getValue(); + if (Val == "row-major") + Opts.setDefaultMatrixMemoryLayout( + LangOptions::MatrixMemoryLayout::MatrixRowMajor); + else + Opts.setDefaultMatrixMemoryLayout( + LangOptions::MatrixMemoryLayout::MatrixColMajor); + } + } + // Validate options for HLSL if (Opts.HLSL) { // TODO: Revisit restricting SPIR-V to logical once we've figured out how to diff --git a/clang/test/Driver/fmatrix-default-layout.c b/clang/test/Driver/fmatrix-default-layout.c deleted file mode 100644 index c89396f4452f6..0000000000000 --- a/clang/test/Driver/fmatrix-default-layout.c +++ /dev/null @@ -1,38 +0,0 @@ -// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR -// CHECK-COL-MAJOR: -fenable-matrix -// CHECK-COL-MAJOR: -mllvm -// CHECK-COL-MAJOR: -enable-matrix -// CHECK-COL-MAJOR: -mllvm -// CHECK-COL-MAJOR: -matrix-default-layout=column-major - -// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR -// CHECK-ROW-MAJOR: -fenable-matrix -// CHECK-ROW-MAJOR: -mllvm -// CHECK-ROW-MAJOR: -enable-matrix -// CHECK-ROW-MAJOR: -mllvm -// CHECK-ROW-MAJOR: -matrix-default-layout=row-major - -// 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 -// CHECK-ERROR-MAJOR: error: invalid value 'error-major' in '-fmatrix-default-layout=error-major' - -// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR-DISABLED -// CHECK-COL-MAJOR-DISABLED-NOT: -fenable-matrix -// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm -// CHECK-COL-MAJOR-DISABLED-NOT: -enable-matrix -// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm -// CHECK-COL-MAJOR-DISABLED-NOT: -matrix-default-layout=column-major - -// RUN: %clang --target=x86_64-linux-gnu -fmatrix-default-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR-DISABLED -// CHECK-ROW-MAJOR-DISABLED-NOT: -fenable-matrix -// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm -// CHECK-ROW-MAJOR-DISABLED-NOT: -enable-matrix -// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm -// CHECK-ROW-MAJOR-DISABLED-NOT: -matrix-default-layout=row-major - -// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MATRIX-ENABLED -// CHECK-MATRIX-ENABLED: -fenable-matrix -// CHECK-MATRIX-ENABLED: -mllvm -// CHECK-MATRIX-ENABLED: -enable-matrix -// CHECK-MATRIX-ENABLED-NOT: -mllvm -// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=row-major -// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=column-major diff --git a/clang/test/Driver/fmatrix-memory-layout.c b/clang/test/Driver/fmatrix-memory-layout.c new file mode 100644 index 0000000000000..b6ed6ac9d9061 --- /dev/null +++ b/clang/test/Driver/fmatrix-memory-layout.c @@ -0,0 +1,35 @@ +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR +// CHECK-COL-MAJOR: -fenable-matrix +// CHECK-COL-MAJOR: -mllvm +// CHECK-COL-MAJOR: -enable-matrix +// CHECK-COL-MAJOR: -fmatrix-memory-layout=column-major + +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR +// CHECK-ROW-MAJOR: -fenable-matrix +// CHECK-ROW-MAJOR: -mllvm +// CHECK-ROW-MAJOR: -enable-matrix +// CHECK-ROW-MAJOR: -fmatrix-memory-layout=row-major + +// RUN: not %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=error-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR-MAJOR +// CHECK-ERROR-MAJOR: error: invalid value 'error-major' in '-fmatrix-memory-layout=error-major' + +// RUN: %clang --target=x86_64-linux-gnu -fmatrix-memory-layout=column-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-COL-MAJOR-DISABLED +// CHECK-COL-MAJOR-DISABLED: clang: warning: argument unused during compilation: '-fmatrix-memory-layout=column-major' +// CHECK-COL-MAJOR-DISABLED-NOT: -fenable-matrix +// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm +// CHECK-COL-MAJOR-DISABLED-NOT: -enable-matrix +// CHECK-COL-MAJOR-DISABLED-NOT: -fmatrix-memory-layout=column-major + +// RUN: %clang --target=x86_64-linux-gnu -fmatrix-memory-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR-DISABLED +// CHECK-ROW-MAJOR-DISABLED: clang: warning: argument unused during compilation: '-fmatrix-memory-layout=row-major' +// CHECK-ROW-MAJOR-DISABLED-NOT: -fenable-matrix +// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm +// CHECK-ROW-MAJOR-DISABLED-NOT: -enable-matrix +// CHECK-ROW-MAJOR-DISABLED-NOT: -fmatrix-memory-layout=row-major + +// RUN: %clang --target=x86_64-linux-gnu -fenable-matrix %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MATRIX-ENABLED +// CHECK-MATRIX-ENABLED: -fenable-matrix +// CHECK-MATRIX-ENABLED: -mllvm +// CHECK-MATRIX-ENABLED: -enable-matrix +// CHECK-MATRIX-ENABLED-NOT: -fmatrix-memory-layout=row-major +// CHECK-MATRIX-ENABLED-NOT: -fmatrix-memory-layout=column-major diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 1332422688fe6..f03e1db6644be 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -738,6 +738,18 @@ TEST_F(CommandLineTest, ConditionalParsingIfHLSLFlagPresent) { CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_EQ(Invocation.getLangOpts().MaxMatrixDimension, 4u); + ASSERT_EQ(Invocation.getLangOpts().getDefaultMatrixMemoryLayout(), + LangOptions::MatrixColMajor); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); +} + +TEST_F(CommandLineTest, ConditionalParsingHLSLRowMajor) { + const char *Args[] = {"-xhlsl", "-fmatrix-memory-layout=row-major"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_EQ(Invocation.getLangOpts().getDefaultMatrixMemoryLayout(), + LangOptions::MatrixRowMajor); Invocation.generateCC1CommandLine(GeneratedArgs, *this); } @@ -748,6 +760,30 @@ TEST_F(CommandLineTest, ConditionalParsingIfHLSLFlagNotPresent) { CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_EQ(Invocation.getLangOpts().MaxMatrixDimension, 1048575u); + ASSERT_EQ(Invocation.getLangOpts().getDefaultMatrixMemoryLayout(), + LangOptions::MatrixColMajor); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); +} + +TEST_F(CommandLineTest, ConditionalParsingClangRowMajor) { + const char *Args[] = {"-fenable-matrix", "-fmatrix-memory-layout=row-major"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_EQ(Invocation.getLangOpts().getDefaultMatrixMemoryLayout(), + LangOptions::MatrixRowMajor); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); +} + +TEST_F(CommandLineTest, ConditionalParsingIgnoreRowMajorIfMatrixNotEnabled) { + const char *Args[] = {"-fmatrix-memory-layout=row-major"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_EQ(Invocation.getLangOpts().getDefaultMatrixMemoryLayout(), + LangOptions::MatrixColMajor); Invocation.generateCC1CommandLine(GeneratedArgs, *this); } >From c918e06ee722fbf309884a33bbf9d2de2beea0f6 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Mon, 17 Nov 2025 12:07:14 -0500 Subject: [PATCH 4/9] Update comments in CompilerInvocation.cpp --- clang/lib/Frontend/CompilerInvocation.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index efd27e89309ab..cafbf08f071e7 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3973,7 +3973,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, } GenerateArg(Consumer, OPT_falloc_token_mode_EQ, S); } - // Enable options for Matrices + // Generate args for Matrices if (Opts.MatrixTypes) { if (Opts.DefaultMatrixMemoryLayout == LangOptions::MatrixColMajor) GenerateArg(Consumer, OPT_fmatrix_memory_layout_EQ, "column-major"); @@ -4574,6 +4574,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << Arg->getAsString(Args) << S; } + // Enable options for Matrices if (Opts.MatrixTypes) { if (const Arg *A = Args.getLastArg(OPT_fmatrix_memory_layout_EQ)) { StringRef Val = A->getValue(); >From 94487a1530fc13cfb6e42d5ad8caedf36222ada2 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Fri, 21 Nov 2025 09:20:47 -0500 Subject: [PATCH 5/9] Apply suggestions from code review Improve documentation and comments. Co-authored-by: Florian Hahn <[email protected]> --- clang/docs/LanguageExtensions.rst | 6 ++---- clang/lib/Frontend/CompilerInvocation.cpp | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index cc5ae719080f0..824fb84a9e53b 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1073,10 +1073,8 @@ The matrix type extension supports explicit casts. Implicit type conversion betw i = static_cast<matrix_5_5<int>>(d); } -The matrix type extension will support column and row major layouts. The flag -to change this behavior is `-fmatrix-memory-layout` used like so -`-fmatrix-memory-layout=column-major` for column major and like so -`-fmatrix-memory-layout=row-major` for row major. +The matrix type extension supports column and row major memory layouts, but not all builtins are supported with row-major layout. +The layout defaults to column major and can be specified using `-fmatrix-memory-layout`. To enable column major layout, use `-fmatrix-memory-layout=column-major`, and for row major layout use `-fmatrix-memory-layout=row-major` Half-Precision Floating Point ============================= diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index cafbf08f071e7..9d71734065d9c 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3973,7 +3973,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, } GenerateArg(Consumer, OPT_falloc_token_mode_EQ, S); } - // Generate args for Matrices + // Generate args for matrix types. if (Opts.MatrixTypes) { if (Opts.DefaultMatrixMemoryLayout == LangOptions::MatrixColMajor) GenerateArg(Consumer, OPT_fmatrix_memory_layout_EQ, "column-major"); @@ -4574,7 +4574,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << Arg->getAsString(Args) << S; } - // Enable options for Matrices + // Enable options for matrix types. if (Opts.MatrixTypes) { if (const Arg *A = Args.getLastArg(OPT_fmatrix_memory_layout_EQ)) { StringRef Val = A->getValue(); >From 61b2bfe3c771ddd44139a221d4a93bd003da3bd7 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Fri, 21 Nov 2025 09:48:21 -0500 Subject: [PATCH 6/9] conform rst files to 80 column limit --- clang/docs/LanguageExtensions.rst | 7 +++++-- clang/docs/MatrixTypes.rst | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 824fb84a9e53b..9c6aca662bb80 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1073,8 +1073,11 @@ The matrix type extension supports explicit casts. Implicit type conversion betw i = static_cast<matrix_5_5<int>>(d); } -The matrix type extension supports column and row major memory layouts, but not all builtins are supported with row-major layout. -The layout defaults to column major and can be specified using `-fmatrix-memory-layout`. To enable column major layout, use `-fmatrix-memory-layout=column-major`, and for row major layout use `-fmatrix-memory-layout=row-major` +The matrix type extension supports column and row major memory layouts, but not +all builtins are supported with row-major layout. The layout defaults to column +major and can be specified using `-fmatrix-memory-layout`. To enable column +major layout, use `-fmatrix-memory-layout=column-major`, and for row major +layout use `-fmatrix-memory-layout=row-major` Half-Precision Floating Point ============================= diff --git a/clang/docs/MatrixTypes.rst b/clang/docs/MatrixTypes.rst index bc36857800aa4..1caf4bde28117 100644 --- a/clang/docs/MatrixTypes.rst +++ b/clang/docs/MatrixTypes.rst @@ -288,8 +288,8 @@ The elements of a value of a matrix type are laid out in column-major order without padding. To change memory layout to row major use the `-fmatrix-default-layout` flag. -This flag supports two flag argument values either `column-major` or `row-major` -used like so `-fmatrix-default-layout=column-major`.` +This flag supports two flag argument values either `column-major` or +`row-major` used like so `-fmatrix-default-layout=column-major`.` We propose to provide a Clang option to override this behavior and allow contraction of those operations (e.g. *-ffp-contract=matrix*). >From 966a3d7bd2320b819ee9af3786f050cd86ce24ec Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Wed, 26 Nov 2025 09:55:17 -0500 Subject: [PATCH 7/9] Fix typo in docs after flag name changed in driver. --- clang/docs/MatrixTypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/docs/MatrixTypes.rst b/clang/docs/MatrixTypes.rst index 1caf4bde28117..8701baa2d0f1c 100644 --- a/clang/docs/MatrixTypes.rst +++ b/clang/docs/MatrixTypes.rst @@ -287,9 +287,9 @@ part of the draft specification. The elements of a value of a matrix type are laid out in column-major order without padding. -To change memory layout to row major use the `-fmatrix-default-layout` flag. +To change memory layout to row major use the `-fmatrix-memory-layout` flag. This flag supports two flag argument values either `column-major` or -`row-major` used like so `-fmatrix-default-layout=column-major`.` +`row-major` used like so `-fmatrix-memory-layout=column-major`.` We propose to provide a Clang option to override this behavior and allow contraction of those operations (e.g. *-ffp-contract=matrix*). >From 1ecfa5a8036f7e588ab5c544dfd08ad4459d0cba Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Wed, 26 Nov 2025 13:35:49 -0500 Subject: [PATCH 8/9] add back the -mllvm flags. Force the opt flags and clang flags to match. Force clang builtins to error if the wrong major order is selected --- .../clang/Basic/DiagnosticDriverKinds.td | 3 +++ .../include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Driver/ToolChains/Clang.cpp | 3 +++ clang/lib/Frontend/CompilerInvocation.cpp | 10 ++++++++-- clang/lib/Sema/SemaChecking.cpp | 17 +++++++++++++++++ clang/test/Driver/fmatrix-memory-layout.c | 14 ++++++++++++++ .../Sema/matrix-col-major-builtin-disable.c | 13 +++++++++++++ 7 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 clang/test/Sema/matrix-col-major-builtin-disable.c diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index f262db55a0d92..3ba05ffd10807 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -792,6 +792,9 @@ def err_cc1_round_trip_mismatch : Error< def err_cc1_unbounded_vscale_min : Error< "minimum vscale must be an unsigned integer greater than 0">; +def err_conflicting_matrix_layout_flags: Error< + "-fmatrix-memory-layout=%0 conflicts with -mllvm -matrix-default-layout=%1">; + def err_drv_using_omit_rtti_component_without_no_rtti : Error< "-fexperimental-omit-vtable-rtti call only be used with -fno-rtti">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 53aa86a7dabde..cf06e31403039 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13006,6 +13006,8 @@ def err_builtin_trivially_relocate_invalid_arg_type: Error < def err_builtin_matrix_disabled: Error< "matrix types extension is disabled. Pass -fenable-matrix to enable it">; +def err_builtin_matrix_major_order_disabled: Error< + "matrix %select{row|column}0 major %select{load|store}1 is disabled. Pass -fmatrix-memory-layout=%select{row|column}0-major to enable it">; def err_matrix_index_not_integer: Error< "matrix %select{row|column}0 index is not an integer">; def err_matrix_index_outside_range: Error< diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index c579b4ce72ec9..c03a92c623f8c 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5697,6 +5697,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, StringRef Val = A->getValue(); if (Val == "row-major" || Val == "column-major") { CmdArgs.push_back(Args.MakeArgString("-fmatrix-memory-layout=" + Val)); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back(Args.MakeArgString("-matrix-default-layout=" + Val)); + } else { D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 9d71734065d9c..27b23a4958af3 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4577,13 +4577,19 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, // Enable options for matrix types. if (Opts.MatrixTypes) { if (const Arg *A = Args.getLastArg(OPT_fmatrix_memory_layout_EQ)) { - StringRef Val = A->getValue(); - if (Val == "row-major") + StringRef ClangValue = A->getValue(); + if (ClangValue == "row-major") Opts.setDefaultMatrixMemoryLayout( LangOptions::MatrixMemoryLayout::MatrixRowMajor); else Opts.setDefaultMatrixMemoryLayout( LangOptions::MatrixMemoryLayout::MatrixColMajor); + + for (Arg *A : Args.filtered(options::OPT_mllvm)) { + StringRef OptValue = A->getValue(); + if (OptValue.consume_front("-matrix-default-layout=") && ClangValue != OptValue) + Diags.Report(diag::err_conflicting_matrix_layout_flags) << ClangValue << OptValue; + } } } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index f4e58de91286b..851ceed5ce3fc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -16342,6 +16342,12 @@ ExprResult Sema::BuiltinMatrixColumnMajorLoad(CallExpr *TheCall, return ExprError(); } + if(getLangOpts().getDefaultMatrixMemoryLayout() != LangOptions::MatrixColMajor) { + Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) + << /*column*/1 << /*load*/ 0; + return ExprError(); + } + if (checkArgCount(TheCall, 4)) return ExprError(); @@ -16454,6 +16460,17 @@ ExprResult Sema::BuiltinMatrixColumnMajorLoad(CallExpr *TheCall, ExprResult Sema::BuiltinMatrixColumnMajorStore(CallExpr *TheCall, ExprResult CallResult) { + if (!getLangOpts().MatrixTypes) { + Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_disabled); + return ExprError(); + } + + if(getLangOpts().getDefaultMatrixMemoryLayout() != LangOptions::MatrixColMajor) { + Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) + << /*column*/1 << /*store*/ 1; + return ExprError(); + } + if (checkArgCount(TheCall, 3)) return ExprError(); diff --git a/clang/test/Driver/fmatrix-memory-layout.c b/clang/test/Driver/fmatrix-memory-layout.c index b6ed6ac9d9061..f05cd8f26c004 100644 --- a/clang/test/Driver/fmatrix-memory-layout.c +++ b/clang/test/Driver/fmatrix-memory-layout.c @@ -3,12 +3,16 @@ // CHECK-COL-MAJOR: -mllvm // CHECK-COL-MAJOR: -enable-matrix // CHECK-COL-MAJOR: -fmatrix-memory-layout=column-major +// CHECK-COL-MAJOR: -mllvm +// CHECK-COL-MAJOR: -matrix-default-layout=column-major // RUN: %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR // CHECK-ROW-MAJOR: -fenable-matrix // CHECK-ROW-MAJOR: -mllvm // CHECK-ROW-MAJOR: -enable-matrix // CHECK-ROW-MAJOR: -fmatrix-memory-layout=row-major +// CHECK-ROW-MAJOR: -mllvm +// CHECK-ROW-MAJOR: -matrix-default-layout=row-major // RUN: not %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=error-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR-MAJOR // CHECK-ERROR-MAJOR: error: invalid value 'error-major' in '-fmatrix-memory-layout=error-major' @@ -19,6 +23,8 @@ // CHECK-COL-MAJOR-DISABLED-NOT: -mllvm // CHECK-COL-MAJOR-DISABLED-NOT: -enable-matrix // CHECK-COL-MAJOR-DISABLED-NOT: -fmatrix-memory-layout=column-major +// CHECK-COL-MAJOR-DISABLED-NOT: -mllvm +// CHECK-COL-MAJOR-DISABLED-NOT: -matrix-default-layout=column-major // RUN: %clang --target=x86_64-linux-gnu -fmatrix-memory-layout=row-major %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ROW-MAJOR-DISABLED // CHECK-ROW-MAJOR-DISABLED: clang: warning: argument unused during compilation: '-fmatrix-memory-layout=row-major' @@ -26,6 +32,8 @@ // CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm // CHECK-ROW-MAJOR-DISABLED-NOT: -enable-matrix // CHECK-ROW-MAJOR-DISABLED-NOT: -fmatrix-memory-layout=row-major +// CHECK-ROW-MAJOR-DISABLED-NOT: -mllvm +// CHECK-ROW-MAJOR-DISABLED-NOT: -matrix-default-layout=row-major // RUN: %clang --target=x86_64-linux-gnu -fenable-matrix %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MATRIX-ENABLED // CHECK-MATRIX-ENABLED: -fenable-matrix @@ -33,3 +41,9 @@ // CHECK-MATRIX-ENABLED: -enable-matrix // CHECK-MATRIX-ENABLED-NOT: -fmatrix-memory-layout=row-major // CHECK-MATRIX-ENABLED-NOT: -fmatrix-memory-layout=column-major +// CHECK-MATRIX-ENABLED-NOT: -mllvm +// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=row-major +// CHECK-MATRIX-ENABLED-NOT: -matrix-default-layout=column-major + +// RUN: not %clang --target=x86_64-linux-gnu -fenable-matrix -fmatrix-memory-layout=column-major -mllvm -matrix-default-layout=row-major %s -fsyntax-only 2>&1 | FileCheck %s --check-prefix=CHECK-MISMATCH-MAJOR +// CHECK-MISMATCH-MAJOR: error: -fmatrix-memory-layout=column-major conflicts with -mllvm -matrix-default-layout=row-major diff --git a/clang/test/Sema/matrix-col-major-builtin-disable.c b/clang/test/Sema/matrix-col-major-builtin-disable.c new file mode 100644 index 0000000000000..0be010b30c286 --- /dev/null +++ b/clang/test/Sema/matrix-col-major-builtin-disable.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 %s -fenable-matrix -fmatrix-memory-layout=row-major -pedantic -verify -triple=x86_64-apple-darwin9 + +typedef float sx5x10_t __attribute__((matrix_type(5, 10))); + +void column_major_load(float *p1) { + sx5x10_t a1 = __builtin_matrix_column_major_load(p1, 5, 11, 5); + // expected-error@-1 {{matrix column major load is disabled. Pass -fmatrix-memory-layout=column-major to enable it}} +} + +void column_major_store(sx5x10_t *m1, float *p1) { + __builtin_matrix_column_major_store(*m1, p1, 1); + // expected-error@-1 {{matrix column major store is disabled. Pass -fmatrix-memory-layout=column-major to enable it}} +} \ No newline at end of file >From 6fd2afed6a28819558ae262cf8578074be18c2ef Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <[email protected]> Date: Wed, 26 Nov 2025 13:44:11 -0500 Subject: [PATCH 9/9] fix formatting --- clang/lib/Driver/ToolChains/Clang.cpp | 2 +- clang/lib/Frontend/CompilerInvocation.cpp | 8 +++++--- clang/lib/Sema/SemaChecking.cpp | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index c03a92c623f8c..5e4cb434f3485 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5699,7 +5699,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString("-fmatrix-memory-layout=" + Val)); CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString("-matrix-default-layout=" + Val)); - + } else { D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 27b23a4958af3..0ce60c21c565f 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4584,11 +4584,13 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, else Opts.setDefaultMatrixMemoryLayout( LangOptions::MatrixMemoryLayout::MatrixColMajor); - + for (Arg *A : Args.filtered(options::OPT_mllvm)) { StringRef OptValue = A->getValue(); - if (OptValue.consume_front("-matrix-default-layout=") && ClangValue != OptValue) - Diags.Report(diag::err_conflicting_matrix_layout_flags) << ClangValue << OptValue; + if (OptValue.consume_front("-matrix-default-layout=") && + ClangValue != OptValue) + Diags.Report(diag::err_conflicting_matrix_layout_flags) + << ClangValue << OptValue; } } } diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 851ceed5ce3fc..39fc262735d51 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -16342,9 +16342,10 @@ ExprResult Sema::BuiltinMatrixColumnMajorLoad(CallExpr *TheCall, return ExprError(); } - if(getLangOpts().getDefaultMatrixMemoryLayout() != LangOptions::MatrixColMajor) { - Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) - << /*column*/1 << /*load*/ 0; + if (getLangOpts().getDefaultMatrixMemoryLayout() != + LangOptions::MatrixColMajor) { + Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) + << /*column*/ 1 << /*load*/ 0; return ExprError(); } @@ -16464,13 +16465,14 @@ ExprResult Sema::BuiltinMatrixColumnMajorStore(CallExpr *TheCall, Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_disabled); return ExprError(); } - - if(getLangOpts().getDefaultMatrixMemoryLayout() != LangOptions::MatrixColMajor) { - Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) - << /*column*/1 << /*store*/ 1; + + if (getLangOpts().getDefaultMatrixMemoryLayout() != + LangOptions::MatrixColMajor) { + Diag(TheCall->getBeginLoc(), diag::err_builtin_matrix_major_order_disabled) + << /*column*/ 1 << /*store*/ 1; return ExprError(); } - + if (checkArgCount(TheCall, 3)) return ExprError(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
