LLVM 22.0.0git
CmpPredicate.h
Go to the documentation of this file.
1//===- CmpPredicate.h - CmpInst Predicate with samesign information -------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// A CmpInst::Predicate with any samesign information (applicable to ICmpInst).
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_CMPPREDICATE_H
14#define LLVM_IR_CMPPREDICATE_H
15
16#include "llvm/IR/InstrTypes.h"
18
19namespace llvm {
20/// An abstraction over a floating-point predicate, and a pack of an integer
21/// predicate with samesign information. Some functions in ICmpInst construct
22/// and return this type in place of a Predicate.
25 bool HasSameSign;
26
27public:
28 /// Default constructor.
29 CmpPredicate() : Pred(CmpInst::BAD_ICMP_PREDICATE), HasSameSign(false) {}
30
31 /// Constructed implictly with a either Predicate and samesign information, or
32 /// just a Predicate, dropping samesign information.
33 CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign = false)
34 : Pred(Pred), HasSameSign(HasSameSign) {
35 assert(!HasSameSign || CmpInst::isIntPredicate(Pred));
36 }
37
38 /// Implictly converts to the underlying Predicate, dropping samesign
39 /// information.
40 operator CmpInst::Predicate() const { return Pred; }
41
42 /// Query samesign information, for optimizations.
43 bool hasSameSign() const { return HasSameSign; }
44
45 /// Drops samesign information. This is used when the samesign information
46 /// should be dropped explicitly.
47 CmpInst::Predicate dropSameSign() const { return Pred; }
48
49 /// Compares two CmpPredicates taking samesign into account and returns the
50 /// canonicalized CmpPredicate if they match. An alternative to operator==.
51 ///
52 /// For example,
53 /// samesign ult + samesign ult -> samesign ult
54 /// samesign ult + ult -> ult
55 /// samesign ult + slt -> slt
56 /// ult + ult -> ult
57 /// ult + slt -> std::nullopt
58 LLVM_ABI static std::optional<CmpPredicate> getMatching(CmpPredicate A,
60
61 /// Attempts to return a signed CmpInst::Predicate from the CmpPredicate. If
62 /// the CmpPredicate has samesign, return ICmpInst::getSignedPredicate,
63 /// dropping samesign information. Otherwise, return the predicate, dropping
64 /// samesign information.
66
67 /// An operator== on the underlying Predicate.
68 bool operator==(CmpInst::Predicate P) const { return Pred == P; }
69 bool operator!=(CmpInst::Predicate P) const { return Pred != P; }
70
71 /// There is no operator== defined on CmpPredicate. Use getMatching instead to
72 /// get the canonicalized matching CmpPredicate.
73 bool operator==(CmpPredicate) const = delete;
74 bool operator!=(CmpPredicate) const = delete;
75
76 /// Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as
77 /// appropriate.
78 LLVM_ABI static CmpPredicate get(const CmpInst *Cmp);
79
80 /// Get the swapped predicate of a CmpPredicate.
82
83 /// Get the swapped predicate of a CmpInst.
84 LLVM_ABI static CmpPredicate getSwapped(const CmpInst *Cmp);
85};
86} // namespace llvm
87
88#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition: Compiler.h:213
#define P(N)
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:666
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:678
bool isIntPredicate() const
Definition: InstrTypes.h:785
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:23
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
CmpPredicate()
Default constructor.
Definition: CmpPredicate.h:29
bool operator==(CmpPredicate) const =delete
There is no operator== defined on CmpPredicate.
static LLVM_ABI CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
LLVM_ABI CmpInst::Predicate getPreferredSignedPredicate() const
Attempts to return a signed CmpInst::Predicate from the CmpPredicate.
bool operator==(CmpInst::Predicate P) const
An operator== on the underlying Predicate.
Definition: CmpPredicate.h:68
CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign=false)
Constructed implictly with a either Predicate and samesign information, or just a Predicate,...
Definition: CmpPredicate.h:33
CmpInst::Predicate dropSameSign() const
Drops samesign information.
Definition: CmpPredicate.h:47
bool operator!=(CmpPredicate) const =delete
bool hasSameSign() const
Query samesign information, for optimizations.
Definition: CmpPredicate.h:43
bool operator!=(CmpInst::Predicate P) const
Definition: CmpPredicate.h:69
static LLVM_ABI CmpPredicate getSwapped(CmpPredicate P)
Get the swapped predicate of a CmpPredicate.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18