LLVM 20.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"
17
18namespace llvm {
19/// An abstraction over a floating-point predicate, and a pack of an integer
20/// predicate with samesign information. Some functions in ICmpInst construct
21/// and return this type in place of a Predicate.
24 bool HasSameSign;
25
26public:
27 /// Default constructor.
28 CmpPredicate() : Pred(CmpInst::BAD_ICMP_PREDICATE), HasSameSign(false) {}
29
30 /// Constructed implictly with a either Predicate and samesign information, or
31 /// just a Predicate, dropping samesign information.
32 CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign = false)
33 : Pred(Pred), HasSameSign(HasSameSign) {
34 assert(!HasSameSign || CmpInst::isIntPredicate(Pred));
35 }
36
37 /// Implictly converts to the underlying Predicate, dropping samesign
38 /// information.
39 operator CmpInst::Predicate() const { return Pred; }
40
41 /// Query samesign information, for optimizations.
42 bool hasSameSign() const { return HasSameSign; }
43
44 /// Compares two CmpPredicates taking samesign into account and returns the
45 /// canonicalized CmpPredicate if they match. An alternative to operator==.
46 ///
47 /// For example,
48 /// samesign ult + samesign ult -> samesign ult
49 /// samesign ult + ult -> ult
50 /// samesign ult + slt -> slt
51 /// ult + ult -> ult
52 /// ult + slt -> std::nullopt
53 static std::optional<CmpPredicate> getMatching(CmpPredicate A,
55
56 /// An operator== on the underlying Predicate.
57 bool operator==(CmpInst::Predicate P) const { return Pred == P; }
58 bool operator!=(CmpInst::Predicate P) const { return Pred != P; }
59
60 /// There is no operator== defined on CmpPredicate. Use getMatching instead to
61 /// get the canonicalized matching CmpPredicate.
62 bool operator==(CmpPredicate) const = delete;
63 bool operator!=(CmpPredicate) const = delete;
64
65 /// Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as
66 /// appropriate.
67 static CmpPredicate get(const CmpInst *Cmp);
68
69 /// Get the swapped predicate of a CmpPredicate.
71
72 /// Get the swapped predicate of a CmpInst.
73 static CmpPredicate getSwapped(const CmpInst *Cmp);
74};
75} // namespace llvm
76
77#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:661
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:673
bool isIntPredicate() const
Definition: InstrTypes.h:781
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Definition: CmpPredicate.h:22
static 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:28
bool operator==(CmpPredicate) const =delete
There is no operator== defined on CmpPredicate.
static CmpPredicate get(const CmpInst *Cmp)
Do a ICmpInst::getCmpPredicate() or CmpInst::getPredicate(), as appropriate.
bool operator==(CmpInst::Predicate P) const
An operator== on the underlying Predicate.
Definition: CmpPredicate.h:57
CmpPredicate(CmpInst::Predicate Pred, bool HasSameSign=false)
Constructed implictly with a either Predicate and samesign information, or just a Predicate,...
Definition: CmpPredicate.h:32
bool operator!=(CmpPredicate) const =delete
bool hasSameSign() const
Query samesign information, for optimizations.
Definition: CmpPredicate.h:42
bool operator!=(CmpInst::Predicate P) const
Definition: CmpPredicate.h:58
static 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