[llvm] [VPlan] Add VPInst::getNumOperandsForOpcode, use to verify in ctor (NFC) (PR #142284)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 03:00:21 PDT 2025
================
@@ -413,8 +413,62 @@ VPInstruction::VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
Opcode(Opcode), Name(Name.str()) {
assert(flagsValidForOpcode(getOpcode()) &&
"Set flags not supported for the provided opcode");
+ assert((getNumOperandsForOpcode() == -1u ||
+ getNumOperandsForOpcode() == getNumOperands()) &&
+ "number of operands does not match opcode");
}
+#ifndef NDEBUG
+unsigned VPInstruction::getNumOperandsForOpcode() const {
+ if (Instruction::isUnaryOp(getOpcode()) || Instruction::isCast(getOpcode()))
+ return 1;
+
+ if (Instruction::isBinaryOp(getOpcode()))
+ return 2;
+
+ switch (getOpcode()) {
+ case VPInstruction::StepVector:
+ return 0;
+ case Instruction::Alloca:
+ case Instruction::ExtractValue:
+ case Instruction::Freeze:
+ case Instruction::Load:
+ case VPInstruction::AnyOf:
+ case VPInstruction::BranchOnCond:
+ case VPInstruction::CalculateTripCountMinusVF:
+ case VPInstruction::CanonicalIVIncrementForPart:
+ case VPInstruction::ExplicitVectorLength:
+ case VPInstruction::ExtractLastElement:
+ case VPInstruction::ExtractPenultimateElement:
+ case VPInstruction::FirstActiveLane:
+ case VPInstruction::Not:
+ return 1;
+
+ case Instruction::ICmp:
+ case Instruction::FCmp:
+ case Instruction::Store:
+ case VPInstruction::ActiveLaneMask:
+ case VPInstruction::BranchOnCount:
+ case VPInstruction::ComputeReductionResult:
+ case VPInstruction::FirstOrderRecurrenceSplice:
+ case VPInstruction::LogicalAnd:
+ case VPInstruction::WideIVStep:
+ case VPInstruction::PtrAdd:
----------------
fhahn wrote:
Flipped, thanks
https://github.com/llvm/llvm-project/pull/142284
More information about the llvm-commits
mailing list