//===- Reassociate.h - Reassociate binary expressions -----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This pass reassociates commutative expressions in an order that is designed // to promote better constant propagation, GCSE, LICM, PRE, etc. // // For example: 4 + (x + 5) -> x + (4 + 5) // // In the implementation of this algorithm, constants are assigned rank = 0, // function arguments are rank = 1, and other values are assigned ranks // corresponding to the reverse post order traversal of current function // (starting at 2), which effectively gives values in deep loops higher rank // than values not in loops. // //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_SCALAR_REASSOCIATE_H #define LLVM_TRANSFORMS_SCALAR_REASSOCIATE_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SetVector.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/ValueHandle.h" #include <deque> namespace llvm { class APInt; class BasicBlock; class BinaryOperator; class Function; class Instruction; class IRBuilderBase; class Value; /// A private "module" namespace for types and utilities used by Reassociate. /// These are implementation details and should not be used by clients. namespace reassociate { struct ValueEntry { … }; inline bool operator<(const ValueEntry &LHS, const ValueEntry &RHS) { … } /// Utility class representing a base and exponent pair which form one /// factor of some product. struct Factor { … }; struct OverflowTracking { … }; class XorOpnd; } // end namespace reassociate /// Reassociate commutative expressions. class ReassociatePass : public PassInfoMixin<ReassociatePass> { … }; } // end namespace llvm #endif // LLVM_TRANSFORMS_SCALAR_REASSOCIATE_H