diff options
Diffstat (limited to 'include/llvm/IR/Instruction.h')
-rw-r--r-- | include/llvm/IR/Instruction.h | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/include/llvm/IR/Instruction.h b/include/llvm/IR/Instruction.h index fd7c54d69b63..90c3175122fd 100644 --- a/include/llvm/IR/Instruction.h +++ b/include/llvm/IR/Instruction.h @@ -68,14 +68,20 @@ public: /// Note: this is undefined behavior if the instruction does not have a /// parent, or the parent basic block does not have a parent function. const Module *getModule() const; - Module *getModule(); + Module *getModule() { + return const_cast<Module *>( + static_cast<const Instruction *>(this)->getModule()); + } /// Return the function this instruction belongs to. /// /// Note: it is undefined behavior to call this on an instruction not /// currently inserted into a function. const Function *getFunction() const; - Function *getFunction(); + Function *getFunction() { + return const_cast<Function *>( + static_cast<const Instruction *>(this)->getFunction()); + } /// This method unlinks 'this' from the containing basic block, but does not /// delete it. @@ -252,6 +258,12 @@ public: /// Returns false if no metadata was found. bool extractProfTotalWeight(uint64_t &TotalVal) const; + /// Updates branch_weights metadata by scaling it by \p S / \p T. + void updateProfWeight(uint64_t S, uint64_t T); + + /// Sets the branch_weights metadata to \p W for CallInst. + void setProfWeight(uint64_t W); + /// Set the debug location information for this instruction. void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } @@ -276,6 +288,10 @@ public: /// Determine whether the no signed wrap flag is set. bool hasNoSignedWrap() const; + /// Drops flags that may cause this instruction to evaluate to poison despite + /// having non-poison inputs. + void dropPoisonGeneratingFlags(); + /// Determine whether the exact flag is set. bool isExact() const; @@ -329,6 +345,9 @@ public: /// Determine whether the allow-reciprocal flag is set. bool hasAllowReciprocal() const; + /// Determine whether the allow-contract flag is set. + bool hasAllowContract() const; + /// Convenience function for getting all the fast-math flags, which must be an /// operator which supports these flags. See LangRef.html for the meaning of /// these flags. @@ -372,18 +391,30 @@ public: /// /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. /// - bool isAssociative() const; - static bool isAssociative(unsigned op); + bool isAssociative() const LLVM_READONLY; + static bool isAssociative(unsigned Opcode) { + return Opcode == And || Opcode == Or || Opcode == Xor || + Opcode == Add || Opcode == Mul; + } /// 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 + /// 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: /// @@ -392,7 +423,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: /// @@ -404,7 +437,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; |