blob: 11bb400b0ae5faee0ea6095f4329abf912961943 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// slang-ir-lower-generics.cpp
#include "slang-ir-lower-generics.h"
#include "slang-ir-any-value-marshalling.h"
#include "slang-ir-augment-make-existential.h"
#include "slang-ir-generics-lowering-context.h"
#include "slang-ir-lower-existential.h"
#include "slang-ir-lower-generic-function.h"
#include "slang-ir-lower-generic-call.h"
#include "slang-ir-lower-generic-type.h"
#include "slang-ir-specialize-dispatch.h"
#include "slang-ir-witness-table-wrapper.h"
#include "slang-ir-ssa.h"
#include "slang-ir-dce.h"
namespace Slang
{
void lowerGenerics(
TargetRequest* targetReq,
IRModule* module,
DiagnosticSink* sink)
{
SharedGenericsLoweringContext sharedContext;
sharedContext.targetReq = targetReq;
sharedContext.module = module;
sharedContext.sink = sink;
// Replace all `makeExistential` insts with `makeExistentialWithRTTI`
// before making any other changes. This is necessary because a parameter of
// generic type will be lowered into `AnyValueType`, and after that we can no longer
// access the original generic type parameter from the lowered parameter value.
// This steps ensures that the generic type parameter is available via an
// explicit operand in `makeExistentialWithRTTI`, so that type parameter
// can be translated into an RTTI object during `lower-generic-type`,
// and used to create a tuple representing the existential value.
augmentMakeExistentialInsts(module);
lowerGenericFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
return;
lowerGenericType(&sharedContext);
if (sink->getErrorCount() != 0)
return;
lowerExistentials(&sharedContext);
if (sink->getErrorCount() != 0)
return;
lowerGenericCalls(&sharedContext);
if (sink->getErrorCount() != 0)
return;
generateWitnessTableWrapperFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
return;
generateAnyValueMarshallingFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
return;
specializeDispatchFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
return;
// We might have generated new temporary variables during lowering.
// An SSA pass can clean up unnecessary load/stores.
constructSSA(module);
eliminateDeadCode(module);
}
} // namespace Slang
|