[llvm] [SLP] Make getSameOpcode support interchangeable instructions. (PR #127450)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 20 11:37:54 PST 2025
================
@@ -810,6 +810,267 @@ static std::optional<unsigned> getExtractIndex(Instruction *E) {
namespace {
+/// Base class for representing instructions that can be interchanged with other
+/// equivalent forms. For example, multiplication by a power of 2 can be
+/// interchanged with a left shift.
+///
+/// Derived classes implement specific interchange patterns by overriding the
+/// virtual methods to define their interchange logic.
+///
+/// The class maintains a reference to the main instruction (MainOp) and
+/// provides methods to:
+/// - Check if another instruction is interchangeable (isSame)
+/// - Get the opcode for the interchangeable form (getOpcode)
+/// - Get the operands for the interchangeable form (getOperand)
+class InterchangeableInstruction {
+protected:
+ Instruction *const MainOp;
+
+public:
+ InterchangeableInstruction(Instruction *MainOp) : MainOp(MainOp) {}
+ virtual bool isSame(Instruction *I) {
+ return MainOp->getOpcode() == I->getOpcode();
+ }
+ virtual unsigned getOpcode() { return MainOp->getOpcode(); }
+ virtual SmallVector<Value *> getOperand(Instruction *I) {
+ assert(MainOp->getOpcode() == I->getOpcode());
----------------
alexey-bataev wrote:
Add a message
https://github.com/llvm/llvm-project/pull/127450
More information about the llvm-commits
mailing list