//===- PredicateInfo.h - Build PredicateInfo ----------------------*-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 // //===----------------------------------------------------------------------===// /// /// \file /// This file implements the PredicateInfo analysis, which creates an Extended /// SSA form for operations used in branch comparisons and llvm.assume /// comparisons. /// /// Copies of these operations are inserted into the true/false edge (and after /// assumes), and information attached to the copies. All uses of the original /// operation in blocks dominated by the true/false edge (and assume), are /// replaced with uses of the copies. This enables passes to easily and sparsely /// propagate condition based info into the operations that may be affected. /// /// Example: /// %cmp = icmp eq i32 %x, 50 /// br i1 %cmp, label %true, label %false /// true: /// ret i32 %x /// false: /// ret i32 1 /// /// will become /// /// %cmp = icmp eq i32, %x, 50 /// br i1 %cmp, label %true, label %false /// true: /// %x.0 = call \@llvm.ssa_copy.i32(i32 %x) /// ret i32 %x.0 /// false: /// ret i32 1 /// /// Using getPredicateInfoFor on x.0 will give you the comparison it is /// dominated by (the icmp), and that you are located in the true edge of that /// comparison, which tells you x.0 is 50. /// /// In order to reduce the number of copies inserted, predicateinfo is only /// inserted where it would actually be live. This means if there are no uses of /// an operation dominated by the branch edges, or by an assume, the associated /// predicate info is never inserted. /// /// //===----------------------------------------------------------------------===// #ifndef LLVM_TRANSFORMS_UTILS_PREDICATEINFO_H #define LLVM_TRANSFORMS_UTILS_PREDICATEINFO_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist_node.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/ValueHandle.h" namespace llvm { class AssumptionCache; class DominatorTree; class Function; class Value; class IntrinsicInst; class raw_ostream; enum PredicateType { … }; /// Constraint for a predicate of the form "cmp Pred Op, OtherOp", where Op /// is the value the constraint applies to (the ssa.copy result). struct PredicateConstraint { … }; // Base class for all predicate information we provide. // All of our predicate information has at least a comparison. class PredicateBase : public ilist_node<PredicateBase> { … }; // Provides predicate information for assumes. Since assumes are always true, // we simply provide the assume instruction, so you can tell your relative // position to it. class PredicateAssume : public PredicateBase { … }; // Mixin class for edge predicates. The FROM block is the block where the // predicate originates, and the TO block is the block where the predicate is // valid. class PredicateWithEdge : public PredicateBase { … }; // Provides predicate information for branches. class PredicateBranch : public PredicateWithEdge { … }; class PredicateSwitch : public PredicateWithEdge { … }; /// Encapsulates PredicateInfo, including all data associated with memory /// accesses. class PredicateInfo { … }; /// Printer pass for \c PredicateInfo. class PredicateInfoPrinterPass : public PassInfoMixin<PredicateInfoPrinterPass> { … }; /// Verifier pass for \c PredicateInfo. struct PredicateInfoVerifierPass : PassInfoMixin<PredicateInfoVerifierPass> { … }; } // end namespace llvm #endif // LLVM_TRANSFORMS_UTILS_PREDICATEINFO_H