blob: 8247363d83b25b395edb86338939ee08b36d28cd (
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# SPDX-License-Identifier: GPL-3.0-or-later
if(NOT DEFINED TOOL OR NOT DEFINED INPUT OR NOT DEFINED WORK_DIRECTORY)
message(FATAL_ERROR "MIR tool stage test is missing a required path")
endif()
file(REMOVE_RECURSE "${WORK_DIRECTORY}")
file(MAKE_DIRECTORY "${WORK_DIRECTORY}")
set(
Stages
prelegalizer-mir
legalized-mir
regbank-mir
selected-mir
post-ssa-mir
post-ra-mir
final-mir
)
foreach(Stage IN LISTS Stages)
set(StageOutput "${WORK_DIRECTORY}/${Stage}.mir")
set(RepeatedOutput "${WORK_DIRECTORY}/${Stage}.repeat.mir")
set(CanonicalOutput "${WORK_DIRECTORY}/${Stage}.canonical.mir")
execute_process(
COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${StageOutput}"
RESULT_VARIABLE StageResult
ERROR_VARIABLE StageDiagnostics
)
if(NOT StageResult EQUAL 0)
message(FATAL_ERROR "${Stage} production failed: ${StageDiagnostics}")
endif()
execute_process(
COMMAND "${TOOL}" --input "${INPUT}" --emit "${Stage}" --output "${RepeatedOutput}"
RESULT_VARIABLE RepeatedResult
ERROR_VARIABLE RepeatedDiagnostics
)
if(NOT RepeatedResult EQUAL 0)
message(FATAL_ERROR "repeated ${Stage} production failed: ${RepeatedDiagnostics}")
endif()
execute_process(
COMMAND "${CMAKE_COMMAND}" -E compare_files "${StageOutput}" "${RepeatedOutput}"
RESULT_VARIABLE DeterminismResult
)
if(NOT DeterminismResult EQUAL 0)
message(FATAL_ERROR "${Stage} output is not deterministic")
endif()
execute_process(
COMMAND "${TOOL}" --verify --input "${StageOutput}" --output "${CanonicalOutput}"
RESULT_VARIABLE VerifyResult
ERROR_VARIABLE VerifyDiagnostics
)
if(NOT VerifyResult EQUAL 0)
message(FATAL_ERROR "${Stage} output failed strict MIR reload: ${VerifyDiagnostics}")
endif()
execute_process(
COMMAND "${CMAKE_COMMAND}" -E compare_files "${StageOutput}" "${CanonicalOutput}"
RESULT_VARIABLE CanonicalResult
)
if(NOT CanonicalResult EQUAL 0)
message(FATAL_ERROR "${Stage} output is not canonical after strict reload")
endif()
endforeach()
set(NoPassOutput "${WORK_DIRECTORY}/none.mir")
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --run-pass=none --emit final-mir --output "${NoPassOutput}"
RESULT_VARIABLE NoPassResult
ERROR_VARIABLE NoPassDiagnostics
)
if(NOT NoPassResult EQUAL 0)
message(FATAL_ERROR "LLVM-compatible none pass failed: ${NoPassDiagnostics}")
endif()
execute_process(
COMMAND "${CMAKE_COMMAND}" -E compare_files "${NoPassOutput}"
"${WORK_DIRECTORY}/prelegalizer-mir.mir"
RESULT_VARIABLE NoPassComparisonResult
)
if(NOT NoPassComparisonResult EQUAL 0)
message(FATAL_ERROR "LLVM-compatible none pass changed canonical MIR")
endif()
set(PassList "${WORK_DIRECTORY}/passes.txt")
execute_process(
COMMAND "${TOOL}" --list-passes --input "${INPUT}" --output "${PassList}"
RESULT_VARIABLE ListResult
ERROR_VARIABLE ListDiagnostics
)
if(NOT ListResult EQUAL 0)
message(FATAL_ERROR "pass listing failed: ${ListDiagnostics}")
endif()
file(READ "${PassList}" PassListText)
foreach(RequiredPass IN ITEMS Legalizer RegisterBankSelect InstructionSelect PrologueEpilogueInsertion)
if(NOT PassListText MATCHES "(^|\n)${RequiredPass}(\n|$)")
message(FATAL_ERROR "canonical pass list is missing ${RequiredPass}")
endif()
endforeach()
set(LegalizedOutput "${WORK_DIRECTORY}/run-pass.mir")
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --run-pass Legalizer --emit legalized-mir --output
"${LegalizedOutput}"
RESULT_VARIABLE RunPassResult
ERROR_VARIABLE RunPassDiagnostics
)
if(NOT RunPassResult EQUAL 0)
message(FATAL_ERROR "single-pass execution failed: ${RunPassDiagnostics}")
endif()
set(RegBankOutput "${WORK_DIRECTORY}/passes.mir")
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --passes Legalizer,RegisterBankSelect --emit regbank-mir
--output "${RegBankOutput}"
RESULT_VARIABLE PassesResult
ERROR_VARIABLE PassesDiagnostics
)
if(NOT PassesResult EQUAL 0)
message(FATAL_ERROR "explicit pass pipeline failed: ${PassesDiagnostics}")
endif()
set(StoppedOutput "${WORK_DIRECTORY}/stopped.mir")
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --stop-after Legalizer --emit final-mir --output
"${StoppedOutput}"
RESULT_VARIABLE StopResult
ERROR_VARIABLE StopDiagnostics
)
if(NOT StopResult EQUAL 0)
message(FATAL_ERROR "stop-after control failed: ${StopDiagnostics}")
endif()
execute_process(
COMMAND "${TOOL}" --verify --input "${StoppedOutput}"
RESULT_VARIABLE StopVerifyResult
ERROR_VARIABLE StopVerifyDiagnostics
)
if(NOT StopVerifyResult EQUAL 0)
message(FATAL_ERROR "stop-after output failed strict reload: ${StopVerifyDiagnostics}")
endif()
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --emit legalized-mir --print-before Legalizer --print-after
Legalizer --output "${WORK_DIRECTORY}/printed.mir"
RESULT_VARIABLE PrintResult
ERROR_VARIABLE PrintDiagnostics
)
if(NOT PrintResult EQUAL 0)
message(FATAL_ERROR "pass snapshot controls failed: ${PrintDiagnostics}")
endif()
if(NOT PrintDiagnostics MATCHES "[*][*][*] prelegalizer-mir Legalizer#1" OR
NOT PrintDiagnostics MATCHES "[*][*][*] legalized-mir Legalizer#1")
message(FATAL_ERROR "before/after pass snapshots are incomplete")
endif()
execute_process(
COMMAND
"${TOOL}" --input "${INPUT}" --emit final-mir --stage-snapshots --output
"${WORK_DIRECTORY}/snapshot-final.mir"
RESULT_VARIABLE SnapshotResult
ERROR_VARIABLE SnapshotDiagnostics
)
if(NOT SnapshotResult EQUAL 0)
message(FATAL_ERROR "stage snapshot execution failed: ${SnapshotDiagnostics}")
endif()
foreach(Stage IN LISTS Stages)
if(NOT SnapshotDiagnostics MATCHES "[*][*][*] ${Stage}")
message(FATAL_ERROR "stage snapshots are missing ${Stage}")
endif()
endforeach()
file(REMOVE_RECURSE "${WORK_DIRECTORY}")
|