Return a function pointer from TargetIsa::encode().

Replace the isa::Legalize enumeration with a function pointer. This
allows an ISA to define its own specific legalization actions instead of
relying on the default two.

Generate a LEGALIZE_ACTIONS table for each ISA which contains
legalization function pointers indexed by the legalization codes that
are already in the encoding tables. Include this table in
isa/*/enc_tables.rs.

Give the `Encodings` iterator a reference to the action table and change
its `legalize()` method to return a function pointer instead of an
ISA-specific code.

The Result<> returned from TargetIsa::encode() no longer implements
Debug, so eliminate uses of unwrap and expect on that type.
This commit is contained in:
Jakob Stoklund Olesen
2017-07-27 14:46:56 -07:00
parent d1353bba05
commit 2aca35a9aa
19 changed files with 140 additions and 102 deletions

View File

@@ -479,9 +479,10 @@ impl<'a> Context<'a> {
self.func.dfg.display_inst(pred_inst, self.isa));
// Give it an encoding.
let encoding = self.isa
.encode(&self.func.dfg, &self.func.dfg[inst], ty)
.expect("Can't encode copy");
let encoding = match self.isa.encode(&self.func.dfg, &self.func.dfg[inst], ty) {
Ok(e) => e,
Err(_) => panic!("Can't encode copy.{}", ty),
};
*self.func.encodings.ensure(inst) = encoding;
// Create a live range for the new value.
@@ -525,9 +526,10 @@ impl<'a> Context<'a> {
ty);
// Give it an encoding.
let encoding = self.isa
.encode(&self.func.dfg, &self.func.dfg[inst], ty)
.expect("Can't encode copy");
let encoding = match self.isa.encode(&self.func.dfg, &self.func.dfg[inst], ty) {
Ok(e) => e,
Err(_) => panic!("Can't encode copy.{}", ty),
};
*self.func.encodings.ensure(inst) = encoding;
// Create a live range for the new value.

View File

@@ -220,9 +220,10 @@ impl<'a> Context<'a> {
let reg = dfg.ins(pos).fill(cand.value);
let fill = dfg.value_def(reg).unwrap_inst();
*encodings.ensure(fill) = self.isa
.encode(dfg, &dfg[fill], dfg.value_type(reg))
.expect("Can't encode fill");
match self.isa.encode(dfg, &dfg[fill], dfg.value_type(reg)) {
Ok(e) => *encodings.ensure(fill) = e,
Err(_) => panic!("Can't encode fill {}", cand.value),
}
self.reloads
.insert(ReloadedValue {
@@ -351,9 +352,10 @@ impl<'a> Context<'a> {
.Unary(Opcode::Spill, ty, reg);
// Give it an encoding.
*encodings.ensure(inst) = self.isa
.encode(dfg, &dfg[inst], ty)
.expect("Can't encode spill");
match self.isa.encode(dfg, &dfg[inst], ty) {
Ok(e) => *encodings.ensure(inst) = e,
Err(_) => panic!("Can't encode spill.{}", ty),
}
// Update live ranges.
self.liveness.move_def_locally(stack, inst);

View File

@@ -533,10 +533,10 @@ impl<'a> Context<'a> {
let ty = dfg.value_type(copy);
// Give it an encoding.
let encoding = self.isa
.encode(dfg, &dfg[inst], ty)
.expect("Can't encode copy");
*self.encodings.ensure(inst) = encoding;
match self.isa.encode(dfg, &dfg[inst], ty) {
Ok(e) => *self.encodings.ensure(inst) = e,
Err(_) => panic!("Can't encode {}", dfg.display_inst(inst, self.isa)),
}
// Update live ranges.
self.liveness.create_dead(copy, inst, Affinity::Reg(rci));