From 2b209c791db1bbefddb53f6777b52794dab76e9f Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 10 Mar 2017 09:23:55 -0800 Subject: [PATCH] Add value_opnums and imm_opnums fields to Instruction. These two tuples contain operand indexes of the explicit value operands and immediate operands respectively. We can no longer use the instruction format value_operands field. --- lib/cretonne/meta/cdsl/instructions.py | 11 ++++++++++- lib/cretonne/meta/cdsl/operands.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/cretonne/meta/cdsl/instructions.py b/lib/cretonne/meta/cdsl/instructions.py index fcce1684fd..861e6f0883 100644 --- a/lib/cretonne/meta/cdsl/instructions.py +++ b/lib/cretonne/meta/cdsl/instructions.py @@ -104,9 +104,18 @@ class Instruction(object): self.ins = self._to_operand_tuple(ins) self.outs = self._to_operand_tuple(outs) self.format = InstructionFormat.lookup(self.ins, self.outs) - # Indexes into outs for value results. Others are `variable_args`. + + # Indexes into `self.outs` for value results. + # Other results are `variable_args`. self.value_results = tuple( i for i, o in enumerate(self.outs) if o.is_value()) + # Indexes into `self.ins` for value operands. + self.value_opnums = tuple( + i for i, o in enumerate(self.ins) if o.is_value()) + # Indexes into `self.ins` for non-value operands. + self.imm_opnums = tuple( + i for i, o in enumerate(self.ins) if o.is_immediate()) + self._verify_polymorphic() for attr in Instruction.ATTRIBS: setattr(self, attr, not not kwargs.get(attr, False)) diff --git a/lib/cretonne/meta/cdsl/operands.py b/lib/cretonne/meta/cdsl/operands.py index 277f2597b0..dafa18de35 100644 --- a/lib/cretonne/meta/cdsl/operands.py +++ b/lib/cretonne/meta/cdsl/operands.py @@ -157,3 +157,14 @@ class Operand(object): Is this an SSA value operand? """ return self.kind is VALUE + + def is_immediate(self): + # type: () -> bool + """ + Is this an immediate operand? + + Note that this includes both `ImmediateKind` operands *and* entity + references. It is any operand that doesn't represent a value + dependency. + """ + return self.kind is not VALUE and self.kind is not VARIABLE_ARGS