blob: d1c768ea0ef65717a4bc0adf86b37398508bf453 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "slang-ir-specialize-matrix-layout.h"
#include "slang-compiler.h"
#include "slang-ir-insts.h"
#include "slang-ir.h"
namespace Slang
{
void visitParent(List<IRMatrixType*>& typeWorkList, IRInst* parent)
{
for (auto child : parent->getChildren())
{
if (auto matrixType = as<IRMatrixType>(child))
{
if (auto constLayout = as<IRIntLit>(matrixType->getLayout()))
{
if (constLayout->getValue() == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)
{
typeWorkList.add(matrixType);
}
}
}
visitParent(typeWorkList, child);
}
}
void specializeMatrixLayout(TargetProgram* target, IRModule* module)
{
List<IRMatrixType*> typeWorkList;
visitParent(typeWorkList, module->getModuleInst());
IRIntegerValue defaultLayout = target->getOptionSet().getMatrixLayoutMode();
if (defaultLayout == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)
defaultLayout = SLANG_MATRIX_LAYOUT_ROW_MAJOR;
IRBuilder builder(module);
for (auto matrixType : typeWorkList)
{
builder.setInsertBefore(matrixType);
auto replacementMatrixType = builder.getMatrixType(
matrixType->getElementType(),
matrixType->getRowCount(),
matrixType->getColumnCount(),
builder.getIntValue(builder.getIntType(), defaultLayout));
matrixType->replaceUsesWith(replacementMatrixType);
}
}
} // namespace Slang
|