From f4fa291d836de1d5eaf9433106fd2aba08976cf4 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 20 Mar 2017 06:40:39 +0000 Subject: [PATCH] [IR] Move a few static functions in Instruction class inline. They just check for certain opcodes and opcode enums are available in Instruction.h. llvm-svn: 298237 --- llvm/include/llvm/IR/Instruction.h | 21 ++++++++++++++---- llvm/lib/IR/Instruction.cpp | 45 -------------------------------------- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h index 9978730..87457b2 100644 --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -383,11 +383,20 @@ public: /// /// Commutative operators satisfy: (x op y) === (y op x) /// - /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when + /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when /// applied to any type. /// bool isCommutative() const { return isCommutative(getOpcode()); } - static bool isCommutative(unsigned op); + static bool isCommutative(unsigned Opcode) { + switch (Opcode) { + case Add: case FAdd: + case Mul: case FMul: + case And: case Or: case Xor: + return true; + default: + return false; + } + } /// Return true if the instruction is idempotent: /// @@ -396,7 +405,9 @@ public: /// In LLVM, the And and Or operators are idempotent. /// bool isIdempotent() const { return isIdempotent(getOpcode()); } - static bool isIdempotent(unsigned op); + static bool isIdempotent(unsigned Opcode) { + return Opcode == And || Opcode == Or; + } /// Return true if the instruction is nilpotent: /// @@ -408,7 +419,9 @@ public: /// In LLVM, the Xor operator is nilpotent. /// bool isNilpotent() const { return isNilpotent(getOpcode()); } - static bool isNilpotent(unsigned op); + static bool isNilpotent(unsigned Opcode) { + return Opcode == Xor; + } /// Return true if this instruction may modify memory. bool mayWriteToMemory() const; diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 516cdbe..2ca496e 100644 --- a/llvm/lib/IR/Instruction.cpp +++ b/llvm/lib/IR/Instruction.cpp @@ -569,51 +569,6 @@ bool Instruction::isAssociative() const { } } -/// Return true if the instruction is commutative: -/// -/// Commutative operators satisfy: (x op y) === (y op x) -/// -/// In LLVM, these are the associative operators, plus SetEQ and SetNE, when -/// applied to any type. -/// -bool Instruction::isCommutative(unsigned op) { - switch (op) { - case Add: - case FAdd: - case Mul: - case FMul: - case And: - case Or: - case Xor: - return true; - default: - return false; - } -} - -/// Return true if the instruction is idempotent: -/// -/// Idempotent operators satisfy: x op x === x -/// -/// In LLVM, the And and Or operators are idempotent. -/// -bool Instruction::isIdempotent(unsigned Opcode) { - return Opcode == And || Opcode == Or; -} - -/// Return true if the instruction is nilpotent: -/// -/// Nilpotent operators satisfy: x op x === Id, -/// -/// where Id is the identity for the operator, i.e. a constant such that -/// x op Id === x and Id op x === x for all x. -/// -/// In LLVM, the Xor operator is nilpotent. -/// -bool Instruction::isNilpotent(unsigned Opcode) { - return Opcode == Xor; -} - Instruction *Instruction::cloneImpl() const { llvm_unreachable("Subclass of Instruction failed to implement cloneImpl"); } -- 2.7.4