Check an instruction.
(&mut self, block: Block, inst: Inst)
| 344 | |
| 345 | /// Check an instruction. |
| 346 | fn check_inst(&mut self, block: Block, inst: Inst) -> Result<()> { |
| 347 | // These are temporary for the scope of this instruction. |
| 348 | self.early_fixed.clear(); |
| 349 | self.late_fixed.clear(); |
| 350 | self.reuse_targets.clear(); |
| 351 | |
| 352 | let operands = self.func.inst_operands(inst); |
| 353 | ensure!( |
| 354 | operands.len() <= MAX_INST_OPERANDS, |
| 355 | "{inst}: Too many operands: {} (max: {MAX_INST_OPERANDS})", |
| 356 | operands.len(), |
| 357 | ); |
| 358 | let source = ConstraintSource::Inst(inst); |
| 359 | for &op in operands { |
| 360 | match op.kind() { |
| 361 | OperandKind::Def(value) | OperandKind::EarlyDef(value) => { |
| 362 | self.check_entity(Entity::Value(value))?; |
| 363 | self.check_value_def(value, ValueDef::Inst(block, inst))?; |
| 364 | self.check_constraint(source, operands, op, ValueOrGroup::Value(value))?; |
| 365 | } |
| 366 | OperandKind::Use(value) => { |
| 367 | self.check_entity(Entity::Value(value))?; |
| 368 | self.check_constraint(source, operands, op, ValueOrGroup::Value(value))?; |
| 369 | } |
| 370 | OperandKind::DefGroup(group) | OperandKind::EarlyDefGroup(group) => { |
| 371 | self.check_entity(Entity::ValueGroup(group))?; |
| 372 | for &value in self.func.value_group_members(group) { |
| 373 | self.check_entity(Entity::Value(value))?; |
| 374 | self.check_value_def(value, ValueDef::Inst(block, inst))?; |
| 375 | } |
| 376 | self.check_constraint(source, operands, op, ValueOrGroup::Group(group))?; |
| 377 | } |
| 378 | OperandKind::UseGroup(group) => { |
| 379 | self.check_entity(Entity::ValueGroup(group))?; |
| 380 | for &value in self.func.value_group_members(group) { |
| 381 | self.check_entity(Entity::Value(value))?; |
| 382 | } |
| 383 | self.check_constraint(source, operands, op, ValueOrGroup::Group(group))?; |
| 384 | } |
| 385 | OperandKind::NonAllocatable => match op.constraint() { |
| 386 | OperandConstraint::Fixed(reg) => { |
| 387 | ensure!( |
| 388 | self.reginfo.bank_for_reg(reg).is_none(), |
| 389 | "{inst} {op}: NonAllocatable register must be outside a bank" |
| 390 | ); |
| 391 | } |
| 392 | OperandConstraint::Class(_) | OperandConstraint::Reuse(_) => { |
| 393 | bail!("{inst} {op}: NonAllocatable operand must have a Fixed constraint") |
| 394 | } |
| 395 | }, |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | // Check that clobbers don't overlap with fixed defs or other clobbers. |
| 400 | let mut clobbers = RegUnitSet::new(); |
| 401 | for unit in self.func.inst_clobbers(inst) { |
| 402 | ensure!( |
| 403 | !clobbers.contains(unit), |
no test coverage detected