gisel-ab 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gisel_ab/__init__.py +120 -0
- gisel_ab/__main__.py +8 -0
- gisel_ab/baseline.py +145 -0
- gisel_ab/bugreport.py +113 -0
- gisel_ab/cli.py +150 -0
- gisel_ab/cohort.py +704 -0
- gisel_ab/cpp/aarch64_generated_ctor.cpp +23 -0
- gisel_ab/cpp/aarch64_query_runner.cpp +380 -0
- gisel_ab/cpp/arm_generated_ctor.cpp +18 -0
- gisel_ab/cpp/arm_query_runner.cpp +58 -0
- gisel_ab/cpp/m68k_generated_ctor.cpp +21 -0
- gisel_ab/cpp/m68k_query_runner.cpp +43 -0
- gisel_ab/cpp/mips_generated_ctor.cpp +16 -0
- gisel_ab/cpp/mips_query_runner.cpp +52 -0
- gisel_ab/cpp/ppc_generated_ctor.cpp +16 -0
- gisel_ab/cpp/ppc_query_runner.cpp +46 -0
- gisel_ab/cpp/query-recovery.h +229 -0
- gisel_ab/cpp/query_runner.cpp +419 -0
- gisel_ab/cpp/query_runner_common.h +417 -0
- gisel_ab/cpp/riscv_generated_ctor.cpp +25 -0
- gisel_ab/cpp/riscv_query_runner.cpp +379 -0
- gisel_ab/cpp/spirv_generated_ctor.cpp +24 -0
- gisel_ab/cpp/spirv_query_runner.cpp +98 -0
- gisel_ab/cpp/wasm_generated_ctor.cpp +17 -0
- gisel_ab/cpp/wasm_query_runner.cpp +52 -0
- gisel_ab/cpp/x86_generated_ctor.cpp +24 -0
- gisel_ab/data/aarch64-contract.json +102 -0
- gisel_ab/data/baseline-2026-11-12.json +1684 -0
- gisel_ab/data/closure/aarch64-D.json +156 -0
- gisel_ab/data/closure/aarch64-G.json +75 -0
- gisel_ab/data/closure/arm-D.json +50 -0
- gisel_ab/data/closure/arm-G.json +57 -0
- gisel_ab/data/closure/m68k-D.json +46 -0
- gisel_ab/data/closure/m68k-G.json +54 -0
- gisel_ab/data/closure/mips-D.json +50 -0
- gisel_ab/data/closure/mips-G.json +87 -0
- gisel_ab/data/closure/ppc-D.json +49 -0
- gisel_ab/data/closure/ppc-G.json +56 -0
- gisel_ab/data/closure/riscv-D.json +59 -0
- gisel_ab/data/closure/riscv-G.json +66 -0
- gisel_ab/data/closure/spirv-D.json +58 -0
- gisel_ab/data/closure/spirv-G.json +58 -0
- gisel_ab/data/closure/wasm-D.json +56 -0
- gisel_ab/data/closure/wasm-G.json +62 -0
- gisel_ab/data/closure/x86-D.json +60 -0
- gisel_ab/data/closure/x86-G.json +66 -0
- gisel_ab/data/domain.json +139 -0
- gisel_ab/data/mir-configs.json +444 -0
- gisel_ab/data/mir-shapes.jsonc +1168 -0
- gisel_ab/data/riscv-contract.json +102 -0
- gisel_ab/data/suite/README.md +81 -0
- gisel_ab/data/suite/aarch64/official.answers.jsonl +12559 -0
- gisel_ab/data/suite/aarch64/queries.jsonl +12559 -0
- gisel_ab/data/suite/aarch64/suite.json +43 -0
- gisel_ab/data/suite/m68k/official.answers.jsonl +35 -0
- gisel_ab/data/suite/m68k/queries.jsonl +35 -0
- gisel_ab/data/suite/m68k/suite.json +24 -0
- gisel_ab/data/suite/riscv/official.answers.jsonl +6086 -0
- gisel_ab/data/suite/riscv/queries.jsonl +6086 -0
- gisel_ab/data/suite/riscv/suite.json +41 -0
- gisel_ab/data/suite/x86/official.answers.jsonl +3014 -0
- gisel_ab/data/suite/x86/queries.jsonl +3014 -0
- gisel_ab/data/suite/x86/suite.json +33 -0
- gisel_ab/data/targets/aarch64.json +39 -0
- gisel_ab/data/targets/arm.json +39 -0
- gisel_ab/data/targets/m68k.json +39 -0
- gisel_ab/data/targets/mips.json +39 -0
- gisel_ab/data/targets/ppc.json +39 -0
- gisel_ab/data/targets/riscv.json +39 -0
- gisel_ab/data/targets/schema.json +266 -0
- gisel_ab/data/targets/spirv.json +39 -0
- gisel_ab/data/targets/wasm.json +39 -0
- gisel_ab/data/targets/x86-ctor.json +39 -0
- gisel_ab/data/targets/x86.json +39 -0
- gisel_ab/data/x86-contract.json +93 -0
- gisel_ab/doctor.py +320 -0
- gisel_ab/domain_plan.py +130 -0
- gisel_ab/evidence.py +892 -0
- gisel_ab/l0/__init__.py +0 -0
- gisel_ab/l0/attribute.py +286 -0
- gisel_ab/l0/closure.py +255 -0
- gisel_ab/l0/diff.py +388 -0
- gisel_ab/l0/g_attribution.py +93 -0
- gisel_ab/l0/inject_opcode.py +123 -0
- gisel_ab/l0/inject_predicate.py +150 -0
- gisel_ab/l0/queries.py +215 -0
- gisel_ab/l0/run.py +688 -0
- gisel_ab/l0/swap.py +257 -0
- gisel_ab/l0/u_attribution.py +192 -0
- gisel_ab/l3.py +271 -0
- gisel_ab/mir/__init__.py +0 -0
- gisel_ab/mir/config_check.py +144 -0
- gisel_ab/mir/from_query.py +717 -0
- gisel_ab/mir/libs.py +252 -0
- gisel_ab/mir/replay.py +548 -0
- gisel_ab/paths.py +151 -0
- gisel_ab/refresh_counts.py +80 -0
- gisel_ab/replay_frozen.py +154 -0
- gisel_ab/setup.py +92 -0
- gisel_ab/suite.py +390 -0
- gisel_ab/targets.py +287 -0
- gisel_ab/vertical.py +654 -0
- gisel_ab-0.9.0.dist-info/METADATA +349 -0
- gisel_ab-0.9.0.dist-info/RECORD +107 -0
- gisel_ab-0.9.0.dist-info/WHEEL +5 -0
- gisel_ab-0.9.0.dist-info/entry_points.txt +2 -0
- gisel_ab-0.9.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
//===- query_runner_common.h - one JSONL query -> getAction(), any target -===//
|
|
2
|
+
//
|
|
3
|
+
// Included exactly once by a per-target runner. The including file must
|
|
4
|
+
// define, before the include:
|
|
5
|
+
//
|
|
6
|
+
// using TargetSubtarget = <Target>Subtarget;
|
|
7
|
+
// using TargetLegalizer = <Target>LegalizerInfo;
|
|
8
|
+
//
|
|
9
|
+
// and, after it:
|
|
10
|
+
//
|
|
11
|
+
// static ArrayRef<Config> configs();
|
|
12
|
+
// static void initializeTarget();
|
|
13
|
+
// static std::unique_ptr<TargetLegalizer>
|
|
14
|
+
// makeLegalizer(const TargetSubtarget &, TargetMachine &);
|
|
15
|
+
//
|
|
16
|
+
// Everything else -- config expansion, LLT spelling, mem/imms decoding, the
|
|
17
|
+
// answer JSON -- is identical for every target. A new target is a ~30 line
|
|
18
|
+
// file plus a build script, not another 360 line copy.
|
|
19
|
+
//
|
|
20
|
+
// Both sides of an A/B run are the same runner: `ours` links a replacement
|
|
21
|
+
// constructor object first, so the class the runner names resolves to the
|
|
22
|
+
// generated body for that binary and to the library's body for `official`.
|
|
23
|
+
//===----------------------------------------------------------------------===//
|
|
24
|
+
|
|
25
|
+
#ifndef GISEL_AB_QUERY_RUNNER_COMMON_H
|
|
26
|
+
#define GISEL_AB_QUERY_RUNNER_COMMON_H
|
|
27
|
+
|
|
28
|
+
#include "llvm/ADT/ArrayRef.h"
|
|
29
|
+
#include "llvm/ADT/SmallVector.h"
|
|
30
|
+
#include "llvm/ADT/StringMap.h"
|
|
31
|
+
#include "llvm/ADT/StringSwitch.h"
|
|
32
|
+
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
|
|
33
|
+
#include "llvm/CodeGen/TargetOpcodes.h"
|
|
34
|
+
#include "llvm/IR/Function.h"
|
|
35
|
+
#include "llvm/IR/LLVMContext.h"
|
|
36
|
+
#include "llvm/IR/Module.h"
|
|
37
|
+
#include "llvm/MC/TargetRegistry.h"
|
|
38
|
+
#include "llvm/Support/AtomicOrdering.h"
|
|
39
|
+
#include "llvm/Support/JSON.h"
|
|
40
|
+
#include "llvm/Support/raw_ostream.h"
|
|
41
|
+
#include "llvm/Target/TargetMachine.h"
|
|
42
|
+
#include "llvm/Target/TargetOptions.h"
|
|
43
|
+
#include "llvm/TargetParser/Triple.h"
|
|
44
|
+
|
|
45
|
+
#include <fstream>
|
|
46
|
+
#include <memory>
|
|
47
|
+
#include <optional>
|
|
48
|
+
#include <string>
|
|
49
|
+
#include <vector>
|
|
50
|
+
|
|
51
|
+
#include "query-recovery.h"
|
|
52
|
+
using namespace llvm;
|
|
53
|
+
using namespace TargetOpcode;
|
|
54
|
+
using namespace LegalizeActions;
|
|
55
|
+
|
|
56
|
+
namespace {
|
|
57
|
+
|
|
58
|
+
struct Config {
|
|
59
|
+
const char *ID;
|
|
60
|
+
const char *Triple;
|
|
61
|
+
const char *CPU;
|
|
62
|
+
const char *Features;
|
|
63
|
+
std::optional<CodeModel::Model> CM;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
struct Sigma {
|
|
67
|
+
std::unique_ptr<TargetMachine> TM;
|
|
68
|
+
const TargetSubtarget *STI = nullptr;
|
|
69
|
+
std::unique_ptr<TargetLegalizer> L;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Provided by the per-target file after this header.
|
|
73
|
+
static ArrayRef<Config> configs();
|
|
74
|
+
static void initializeTarget();
|
|
75
|
+
static std::unique_ptr<TargetLegalizer>
|
|
76
|
+
makeLegalizer(const TargetSubtarget &ST, TargetMachine &TM);
|
|
77
|
+
|
|
78
|
+
// Optional per-target adjustment applied to the freshly created subtarget,
|
|
79
|
+
// before the legalizer is built. Most targets keep the no-op below. SPIRV
|
|
80
|
+
// needs it because its execution environment and extension set are not
|
|
81
|
+
// encoded in the triple, so two configurations can share one triple.
|
|
82
|
+
// A runner that provides a real one defines GISEL_AB_TWEAK_SUBTARGET before
|
|
83
|
+
// including this header and defines `tweakSubtarget` after it.
|
|
84
|
+
#ifdef GISEL_AB_TWEAK_SUBTARGET
|
|
85
|
+
static void tweakSubtarget(const Config &, TargetSubtarget &);
|
|
86
|
+
#else
|
|
87
|
+
static void tweakSubtarget(const Config &, TargetSubtarget &) {}
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
static std::optional<AtomicOrdering> parseOrdering(StringRef Text) {
|
|
91
|
+
return StringSwitch<std::optional<AtomicOrdering>>(Text)
|
|
92
|
+
.Case("NotAtomic", AtomicOrdering::NotAtomic)
|
|
93
|
+
.Case("Unordered", AtomicOrdering::Unordered)
|
|
94
|
+
.Case("Monotonic", AtomicOrdering::Monotonic)
|
|
95
|
+
.Case("Acquire", AtomicOrdering::Acquire)
|
|
96
|
+
.Case("Release", AtomicOrdering::Release)
|
|
97
|
+
.Case("AcquireRelease", AtomicOrdering::AcquireRelease)
|
|
98
|
+
.Case("SequentiallyConsistent", AtomicOrdering::SequentiallyConsistent)
|
|
99
|
+
.Default(std::nullopt);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static std::string jsonString(StringRef S) {
|
|
103
|
+
std::string Out = "\"";
|
|
104
|
+
for (char C : S) {
|
|
105
|
+
if (C == '"' || C == '\\') {
|
|
106
|
+
Out += '\\';
|
|
107
|
+
Out += C;
|
|
108
|
+
} else if (C == '\n') {
|
|
109
|
+
Out += "\\n";
|
|
110
|
+
} else {
|
|
111
|
+
Out += C;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
Out += '"';
|
|
115
|
+
return Out;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Core IR spelling, kind-preserving: s32 / i32 / f32 / bf16 / p0:32 /
|
|
119
|
+
// v4s32 / nxv4s32. LLT::print drops the pointer width ("p0"), which would
|
|
120
|
+
// make ILP32 and LP64 configurations indistinguishable at p0.
|
|
121
|
+
static std::string lltStr(LLT Ty) {
|
|
122
|
+
if (!Ty.isValid())
|
|
123
|
+
return "LLT_invalid";
|
|
124
|
+
if (Ty.isPointer())
|
|
125
|
+
return "p" + std::to_string(Ty.getAddressSpace()) + ":" +
|
|
126
|
+
std::to_string(Ty.getSizeInBits());
|
|
127
|
+
if (Ty.isVector()) {
|
|
128
|
+
std::string Elem = lltStr(Ty.getElementType());
|
|
129
|
+
return (Ty.isScalable() ? "nxv" : "v") +
|
|
130
|
+
std::to_string(Ty.getElementCount().getKnownMinValue()) + Elem;
|
|
131
|
+
}
|
|
132
|
+
if (Ty.isBFloat16())
|
|
133
|
+
return "bf16";
|
|
134
|
+
if (Ty.isFloat())
|
|
135
|
+
return "f" + std::to_string(Ty.getScalarSizeInBits());
|
|
136
|
+
if (Ty.isInteger())
|
|
137
|
+
return "i" + std::to_string(Ty.getScalarSizeInBits());
|
|
138
|
+
return "s" + std::to_string(Ty.getScalarSizeInBits());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static const char *actionName(LegalizeAction A) {
|
|
142
|
+
switch (A) {
|
|
143
|
+
case Legal: return "Legal";
|
|
144
|
+
case NarrowScalar: return "NarrowScalar";
|
|
145
|
+
case WidenScalar: return "WidenScalar";
|
|
146
|
+
case FewerElements: return "FewerElements";
|
|
147
|
+
case MoreElements: return "MoreElements";
|
|
148
|
+
case Bitcast: return "Bitcast";
|
|
149
|
+
case Lower: return "Lower";
|
|
150
|
+
case Libcall: return "Libcall";
|
|
151
|
+
case Unsupported: return "Unsupported";
|
|
152
|
+
case Custom: return "Custom";
|
|
153
|
+
default: return "?";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static unsigned opcodeFor(StringRef Name) {
|
|
158
|
+
#undef HANDLE_TARGET_OPCODE
|
|
159
|
+
#undef HANDLE_TARGET_OPCODE_MARKER
|
|
160
|
+
return StringSwitch<unsigned>(Name)
|
|
161
|
+
#define HANDLE_TARGET_OPCODE(OPC) .Case(#OPC, TargetOpcode::OPC)
|
|
162
|
+
#define HANDLE_TARGET_OPCODE_MARKER(IDENT, OP)
|
|
163
|
+
#include "llvm/Support/TargetOpcodes.def"
|
|
164
|
+
#undef HANDLE_TARGET_OPCODE
|
|
165
|
+
#undef HANDLE_TARGET_OPCODE_MARKER
|
|
166
|
+
.Default(0);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// `p0:*` is the configuration-dependent pointer width; the subtarget decides
|
|
170
|
+
// it, exactly as it does for every other configuration axis.
|
|
171
|
+
static std::optional<LLT> parseLLT(StringRef S, unsigned PointerBits = 0) {
|
|
172
|
+
if (S == "bf16")
|
|
173
|
+
return LLT::bfloat16();
|
|
174
|
+
if (S.starts_with("nxv") || S.starts_with("v")) {
|
|
175
|
+
bool Scalable = S.starts_with("nxv");
|
|
176
|
+
S = S.drop_front(Scalable ? 3 : 1);
|
|
177
|
+
size_t I = 0;
|
|
178
|
+
while (I < S.size() && S[I] >= '0' && S[I] <= '9')
|
|
179
|
+
++I;
|
|
180
|
+
unsigned N = 0;
|
|
181
|
+
if (I == 0 || S.substr(0, I).getAsInteger(10, N))
|
|
182
|
+
return std::nullopt;
|
|
183
|
+
auto Elem = parseLLT(S.drop_front(I), PointerBits);
|
|
184
|
+
if (!Elem)
|
|
185
|
+
return std::nullopt;
|
|
186
|
+
return LLT::vector(Scalable ? ElementCount::getScalable(N)
|
|
187
|
+
: ElementCount::getFixed(N), *Elem);
|
|
188
|
+
}
|
|
189
|
+
if (S.starts_with("p")) {
|
|
190
|
+
size_t Colon = S.find(':');
|
|
191
|
+
unsigned AS = 0;
|
|
192
|
+
if (Colon == StringRef::npos ||
|
|
193
|
+
S.substr(1, Colon - 1).getAsInteger(10, AS))
|
|
194
|
+
return std::nullopt;
|
|
195
|
+
if (S.drop_front(Colon + 1) == "*") {
|
|
196
|
+
if (!PointerBits)
|
|
197
|
+
return std::nullopt;
|
|
198
|
+
return LLT::pointer(AS, PointerBits);
|
|
199
|
+
}
|
|
200
|
+
unsigned Bits = 0;
|
|
201
|
+
if (S.drop_front(Colon + 1).getAsInteger(10, Bits))
|
|
202
|
+
return std::nullopt;
|
|
203
|
+
return LLT::pointer(AS, Bits);
|
|
204
|
+
}
|
|
205
|
+
char Kind = S.empty() ? '?' : S[0];
|
|
206
|
+
unsigned Bits = 0;
|
|
207
|
+
if (S.drop_front().getAsInteger(10, Bits))
|
|
208
|
+
return std::nullopt;
|
|
209
|
+
switch (Kind) {
|
|
210
|
+
case 's': return LLT::scalar(Bits);
|
|
211
|
+
case 'i': return LLT::integer(Bits);
|
|
212
|
+
case 'f': return LLT::floatIEEE(Bits);
|
|
213
|
+
default: return std::nullopt;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static bool makeSigma(const Config &C, Sigma &S) {
|
|
218
|
+
Triple TT(C.Triple);
|
|
219
|
+
std::string Err;
|
|
220
|
+
const Target *T = TargetRegistry::lookupTarget("", TT, Err);
|
|
221
|
+
if (!T) {
|
|
222
|
+
errs() << "no target for " << C.ID << " (" << C.Triple << "): " << Err
|
|
223
|
+
<< "\n";
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
TargetOptions Opts;
|
|
227
|
+
S.TM.reset(T->createTargetMachine(TT, C.CPU, C.Features, Opts,
|
|
228
|
+
std::nullopt, C.CM));
|
|
229
|
+
if (!S.TM) {
|
|
230
|
+
errs() << "no target machine for " << C.ID << "\n";
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
static LLVMContext Ctx;
|
|
234
|
+
static Module M("t", Ctx);
|
|
235
|
+
if (!M.getFunction("f"))
|
|
236
|
+
Function::Create(FunctionType::get(Type::getVoidTy(Ctx), false),
|
|
237
|
+
Function::ExternalLinkage, "f", &M);
|
|
238
|
+
S.STI = static_cast<const TargetSubtarget *>(
|
|
239
|
+
S.TM->getSubtargetImpl(*M.getFunction("f")));
|
|
240
|
+
if (!S.STI) {
|
|
241
|
+
errs() << "no subtarget for " << C.ID << "\n";
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
// The subtarget comes back const because TargetMachine hands out a const
|
|
245
|
+
// interface, but the machine owns it and is the only writer; a per-target
|
|
246
|
+
// hook may need to finish configuring it (see tweakSubtarget above).
|
|
247
|
+
tweakSubtarget(C, const_cast<TargetSubtarget &>(*S.STI));
|
|
248
|
+
S.L = makeLegalizer(*S.STI, *S.TM);
|
|
249
|
+
return bool(S.L);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static int answerLine(StringRef Line, const StringMap<Sigma *> &Sigmas,
|
|
253
|
+
raw_ostream &Out) {
|
|
254
|
+
Expected<json::Value> Parsed = json::parse(Line);
|
|
255
|
+
if (!Parsed)
|
|
256
|
+
return 2;
|
|
257
|
+
json::Object *Obj = Parsed->getAsObject();
|
|
258
|
+
if (!Obj)
|
|
259
|
+
return 2;
|
|
260
|
+
auto ConfigName = Obj->getString("config");
|
|
261
|
+
auto Name = Obj->getString("name");
|
|
262
|
+
json::Array *TypeArr = Obj->getArray("types");
|
|
263
|
+
if (!ConfigName || !Name || !TypeArr)
|
|
264
|
+
return 2;
|
|
265
|
+
auto It = Sigmas.find(*ConfigName);
|
|
266
|
+
if (It == Sigmas.end())
|
|
267
|
+
return 2;
|
|
268
|
+
Sigma &S = *It->second;
|
|
269
|
+
unsigned PtrBits = S.TM->createDataLayout().getPointerSizeInBits(0);
|
|
270
|
+
SmallVector<LLT, 4> Types;
|
|
271
|
+
// Keep the caller's spelling: a target without extended LLT (RISC-V) maps
|
|
272
|
+
// `f16` and `s16` to the same scalar(16), so re-spelling the parsed type
|
|
273
|
+
// would collapse two distinct query keys in the answer file.
|
|
274
|
+
SmallVector<std::string, 4> TypeText;
|
|
275
|
+
for (const json::Value &V : *TypeArr) {
|
|
276
|
+
auto Text = V.getAsString();
|
|
277
|
+
if (!Text)
|
|
278
|
+
return 2;
|
|
279
|
+
auto Ty = parseLLT(*Text, PtrBits);
|
|
280
|
+
if (!Ty)
|
|
281
|
+
return 2;
|
|
282
|
+
Types.push_back(*Ty);
|
|
283
|
+
TypeText.push_back(Text->str());
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Immediate operands are part of the query: a rule may read Q.Immediates
|
|
287
|
+
// (e.g. LegalizePredicates::immIs). Dropping them makes the rule index the
|
|
288
|
+
// empty array and abort, which would look like an answer difference.
|
|
289
|
+
SmallVector<int64_t, 2> Imms;
|
|
290
|
+
if (json::Array *ImmArr = Obj->getArray("imms"))
|
|
291
|
+
for (const json::Value &V : *ImmArr) {
|
|
292
|
+
auto I = V.getAsInteger();
|
|
293
|
+
if (!I)
|
|
294
|
+
return 2;
|
|
295
|
+
Imms.push_back(*I);
|
|
296
|
+
}
|
|
297
|
+
std::string ImmsText = "[";
|
|
298
|
+
for (size_t I = 0; I != Imms.size(); ++I) {
|
|
299
|
+
if (I)
|
|
300
|
+
ImmsText += ",";
|
|
301
|
+
ImmsText += std::to_string(Imms[I]);
|
|
302
|
+
}
|
|
303
|
+
ImmsText += "]";
|
|
304
|
+
|
|
305
|
+
SmallVector<LegalityQuery::MemDesc, 1> MMOs;
|
|
306
|
+
std::string MemText = "null";
|
|
307
|
+
if (json::Array *Mem = Obj->getArray("mem")) {
|
|
308
|
+
if (Mem->size() != 2 && Mem->size() != 4)
|
|
309
|
+
return 2;
|
|
310
|
+
auto TyText = (*Mem)[0].getAsString();
|
|
311
|
+
auto Align = (*Mem)[1].getAsInteger();
|
|
312
|
+
if (!TyText || !Align)
|
|
313
|
+
return 2;
|
|
314
|
+
auto Ty = parseLLT(*TyText, PtrBits);
|
|
315
|
+
if (!Ty)
|
|
316
|
+
return 2;
|
|
317
|
+
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
|
|
318
|
+
AtomicOrdering Failure = AtomicOrdering::NotAtomic;
|
|
319
|
+
std::optional<StringRef> OrderingText;
|
|
320
|
+
std::optional<StringRef> FailureText;
|
|
321
|
+
if (Mem->size() == 4) {
|
|
322
|
+
OrderingText = (*Mem)[2].getAsString();
|
|
323
|
+
FailureText = (*Mem)[3].getAsString();
|
|
324
|
+
auto ParsedOrdering = OrderingText ? parseOrdering(*OrderingText)
|
|
325
|
+
: std::nullopt;
|
|
326
|
+
auto ParsedFailure = FailureText ? parseOrdering(*FailureText)
|
|
327
|
+
: std::nullopt;
|
|
328
|
+
if (!ParsedOrdering || !ParsedFailure)
|
|
329
|
+
return 2;
|
|
330
|
+
Ordering = *ParsedOrdering;
|
|
331
|
+
Failure = *ParsedFailure;
|
|
332
|
+
}
|
|
333
|
+
MMOs.push_back(LegalityQuery::MemDesc(*Ty, *Align, Ordering, Failure));
|
|
334
|
+
MemText = "[" + jsonString(*TyText) + "," + std::to_string(*Align);
|
|
335
|
+
if (Mem->size() == 4)
|
|
336
|
+
MemText += "," + jsonString(*OrderingText) + "," +
|
|
337
|
+
jsonString(*FailureText);
|
|
338
|
+
MemText += "]";
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
unsigned Opcode = opcodeFor(*Name);
|
|
342
|
+
if (!Opcode)
|
|
343
|
+
return 2;
|
|
344
|
+
LegalityQuery Q(Opcode, Types, MMOs, Imms);
|
|
345
|
+
LegalizeActionStep Step = S.L->getAction(Q);
|
|
346
|
+
Out << "{\"config\":" << jsonString(*ConfigName)
|
|
347
|
+
<< ",\"name\":" << jsonString(*Name) << ",\"types\":[";
|
|
348
|
+
for (size_t I = 0; I != Types.size(); ++I) {
|
|
349
|
+
if (I)
|
|
350
|
+
Out << ',';
|
|
351
|
+
Out << jsonString(TypeText[I]);
|
|
352
|
+
}
|
|
353
|
+
Out << "],\"mem\":" << MemText << ",\"imms\":" << ImmsText
|
|
354
|
+
<< ",\"action\":" << jsonString(actionName(Step.Action))
|
|
355
|
+
<< ",\"type_idx\":" << (unsigned)Step.TypeIdx
|
|
356
|
+
<< ",\"new_type\":" << jsonString(lltStr(Step.NewType)) << "}\n";
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
} // namespace
|
|
361
|
+
|
|
362
|
+
int main(int Argc, char **Argv) {
|
|
363
|
+
ab::disableCoreDumps();
|
|
364
|
+
StringRef Queries;
|
|
365
|
+
for (int I = 1; I < Argc; ++I) {
|
|
366
|
+
StringRef A(Argv[I]);
|
|
367
|
+
if (A == "--queries" && I + 1 < Argc)
|
|
368
|
+
Queries = Argv[++I];
|
|
369
|
+
else if (A == "-h" || A == "--help")
|
|
370
|
+
return 0;
|
|
371
|
+
else
|
|
372
|
+
return 2;
|
|
373
|
+
}
|
|
374
|
+
if (Queries.empty())
|
|
375
|
+
return 2;
|
|
376
|
+
|
|
377
|
+
initializeTarget();
|
|
378
|
+
|
|
379
|
+
StringMap<Sigma *> Sigmas;
|
|
380
|
+
std::vector<std::unique_ptr<Sigma>> Storage;
|
|
381
|
+
for (const Config &C : configs()) {
|
|
382
|
+
auto S = std::make_unique<Sigma>();
|
|
383
|
+
if (!makeSigma(C, *S))
|
|
384
|
+
return 2;
|
|
385
|
+
Sigmas[C.ID] = S.get();
|
|
386
|
+
Storage.push_back(std::move(S));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
std::ifstream In(Queries.str());
|
|
390
|
+
if (!In)
|
|
391
|
+
return 2;
|
|
392
|
+
std::string Line;
|
|
393
|
+
unsigned N = 0;
|
|
394
|
+
while (std::getline(In, Line)) {
|
|
395
|
+
if (Line.empty())
|
|
396
|
+
continue;
|
|
397
|
+
int Rc = 0;
|
|
398
|
+
if (!ab::runQuery([&] { Rc = answerLine(Line, Sigmas, outs()); })) {
|
|
399
|
+
// The query aborted inside LLVM. The legalizer is built and const, so
|
|
400
|
+
// the only loss is memory allocated by the abandoned call.
|
|
401
|
+
ab::writeUnanswerable(Line, outs());
|
|
402
|
+
outs().flush();
|
|
403
|
+
++N;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (Rc)
|
|
407
|
+
return Rc;
|
|
408
|
+
// Flush per answer: a real crash would still lose a buffered tail, and
|
|
409
|
+
// run-queries.py restarts after it.
|
|
410
|
+
outs().flush();
|
|
411
|
+
++N;
|
|
412
|
+
}
|
|
413
|
+
errs() << "answered " << N << " queries\n";
|
|
414
|
+
return 0;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
#endif
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The RISC-V A/B ours build replaces only the legalizer constructor. The
|
|
2
|
+
// remaining target library, including custom legalization, stays official.
|
|
3
|
+
|
|
4
|
+
#include "RISCVSubtarget.h"
|
|
5
|
+
#include "GISel/RISCVLegalizerInfo.h"
|
|
6
|
+
#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
|
|
7
|
+
#include "llvm/CodeGen/TargetLowering.h"
|
|
8
|
+
#include "llvm/CodeGen/TargetOpcodes.h"
|
|
9
|
+
#include "llvm/Target/TargetMachine.h"
|
|
10
|
+
|
|
11
|
+
using namespace llvm;
|
|
12
|
+
using namespace LegalizeActions;
|
|
13
|
+
using namespace LegalizeMutations;
|
|
14
|
+
using namespace LegalityPredicates;
|
|
15
|
+
using namespace MIPatternMatch;
|
|
16
|
+
|
|
17
|
+
// The generated fragment uses the same locals as the handwritten constructor:
|
|
18
|
+
// `ST` (the parameter), the `STI`/`XLen`/`sXLen` members, and `sDoubleXLen`/`p0`.
|
|
19
|
+
RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
|
|
20
|
+
: STI(ST), XLen(STI.getXLen()), sXLen(LLT::scalar(XLen)) {
|
|
21
|
+
using namespace TargetOpcode;
|
|
22
|
+
const LLT sDoubleXLen = LLT::scalar(2 * XLen);
|
|
23
|
+
const LLT p0 = LLT::pointer(0, XLen);
|
|
24
|
+
#include "RISCVLegalizerInfo.inc"
|
|
25
|
+
}
|