Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code for PR #6044 #35

Open
wants to merge 3 commits into
base: aleino/1-matrices
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ typedef uint32_t SlangSizeT;
EmitSpirvMethod, // enum SlangEmitSpirvMethod

EmitReflectionJSON, // bool

SkipMatrixDimensionValidation, // bool, don't validate that matrix dimensions are > 1 when
// set

CountOf,
};

Expand Down
1 change: 1 addition & 0 deletions source/slang-record-replay/util/emum-to-string.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ static Slang::String CompilerOptionNameToString(const slang::CompilerOptionName
CASE(VulkanBindShiftAll);
CASE(GenerateWholeProgram);
CASE(UseUpToDateBinaryModule);
CASE(SkipMatrixDimensionValidation);
CASE(CountOf);
default:
Slang::StringBuilder str;
Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,6 +2625,12 @@ bool CodeGenContext::shouldValidateIR()
return getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::ValidateIr);
}

bool CodeGenContext::shouldSkipMatrixDimensionValidation()
{
return getTargetProgram()->getOptionSet().getBoolOption(
CompilerOptionName::SkipMatrixDimensionValidation);
}

bool CodeGenContext::shouldSkipSPIRVValidation()
{
return getTargetProgram()->getOptionSet().getBoolOption(
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,7 @@ struct CodeGenContext
IRDumpOptions getIRDumpOptions();

bool shouldValidateIR();
bool shouldSkipMatrixDimensionValidation();
bool shouldDumpIR();
bool shouldReportCheckpointIntermediates();

Expand Down
6 changes: 6 additions & 0 deletions source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,12 @@ DIAGNOSTIC(
overloadedParameterToHigherOrderFunction,
"passing overloaded functions to higher order functions is not supported")

DIAGNOSTIC(
39999,
Error,
matrixColumnOrRowCountIsOne,
"matrix of type '$0' has column or row count of 1")

// 38xxx

DIAGNOSTIC(
Expand Down
22 changes: 22 additions & 0 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,24 @@ static void unexportNonEmbeddableIR(CodeGenTarget target, IRModule* irModule)
}
}

static void validateMatrixDimensions(DiagnosticSink* sink, IRInst* inst)
{
if (auto matrixType = as<IRMatrixType>(inst->getDataType()))
{
auto colCount = as<IRIntLit>(matrixType->getColumnCount());
auto rowCount = as<IRIntLit>(matrixType->getRowCount());

if ((rowCount && (rowCount->getValue() == 1)) || (colCount && (colCount->getValue() == 1)))
{
sink->diagnose(inst->sourceLoc, Diagnostics::matrixColumnOrRowCountIsOne, matrixType);
}
}
for (auto child : inst->getModifiableChildren())
{
validateMatrixDimensions(sink, child);
}
};

Result linkAndOptimizeIR(
CodeGenContext* codeGenContext,
LinkingAndOptimizationOptions const& options,
Expand Down Expand Up @@ -1504,6 +1522,10 @@ Result linkAndOptimizeIR(
#endif
validateIRModuleIfEnabled(codeGenContext, irModule);

// Make sure there are no matrices with 1 row/column
if (!codeGenContext->shouldSkipMatrixDimensionValidation())
validateMatrixDimensions(sink, irModule->getModuleInst());

// The resource-based specialization pass above
// may create specialized versions of functions, but
// it does not try to completely eliminate the original
Expand Down
5 changes: 5 additions & 0 deletions source/slang/slang-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ void initCommandOptions(CommandOptions& options)
"Serialize the IR between front-end and back-end."},
{OptionKind::SkipCodeGen, "-skip-codegen", nullptr, "Skip the code generation phase."},
{OptionKind::ValidateIr, "-validate-ir", nullptr, "Validate the IR between the phases."},
{OptionKind::SkipMatrixDimensionValidation,
"-skip-matrix-dimension-validation",
nullptr,
"Skip matrix dimension validation."},
{OptionKind::VerbosePaths,
"-verbose-paths",
nullptr,
Expand Down Expand Up @@ -2150,6 +2154,7 @@ SlangResult OptionsParser::_parse(int argc, char const* const* argv)
case OptionKind::LoopInversion:
case OptionKind::UnscopedEnum:
case OptionKind::PreserveParameters:
case OptionKind::SkipMatrixDimensionValidation:
linkage->m_optionSet.set(optionKind, true);
break;
case OptionKind::MatrixLayoutRow:
Expand Down
Loading