LLVM 19.0.0git
GEPNoWrapFlags.h
Go to the documentation of this file.
1//===-- llvm/GEPNoWrapFlags.h - NoWrap flags for GEPs -----------*- C++ -*-===//
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// This file defines the nowrap flags for getelementptr operators.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_GEPNOWRAPFLAGS_H
14#define LLVM_IR_GEPNOWRAPFLAGS_H
15
16#include <assert.h>
17
18namespace llvm {
19
20/// Represents flags for the getelementptr instruction/expression.
21/// The following flags are supported:
22/// * inbounds (implies nusw)
23/// * nusw (no unsigned signed wrap)
24/// * nuw (no unsigned wrap)
25/// See LangRef for a description of their semantics.
27 enum : unsigned {
28 InBoundsFlag = (1 << 0),
29 NUSWFlag = (1 << 1),
30 NUWFlag = (1 << 2),
31 };
32
33 unsigned Flags;
34 GEPNoWrapFlags(unsigned Flags) : Flags(Flags) {
36 "inbounds implies nusw");
37 }
38
39public:
40 GEPNoWrapFlags() : Flags(0) {}
41 // For historical reasons, interpret plain boolean as InBounds.
42 // TODO: Migrate users to pass explicit GEPNoWrapFlags and remove this ctor.
43 GEPNoWrapFlags(bool IsInBounds)
44 : Flags(IsInBounds ? (InBoundsFlag | NUSWFlag) : 0) {}
45
46 static GEPNoWrapFlags none() { return GEPNoWrapFlags(); }
48 return GEPNoWrapFlags(InBoundsFlag | NUSWFlag);
49 }
51 return GEPNoWrapFlags(NUSWFlag);
52 }
53 static GEPNoWrapFlags noUnsignedWrap() { return GEPNoWrapFlags(NUWFlag); }
54
55 static GEPNoWrapFlags fromRaw(unsigned Flags) {
56 return GEPNoWrapFlags(Flags);
57 }
58 unsigned getRaw() const { return Flags; }
59
60 bool isInBounds() const { return Flags & InBoundsFlag; }
61 bool hasNoUnsignedSignedWrap() const { return Flags & NUSWFlag; }
62 bool hasNoUnsignedWrap() const { return Flags & NUWFlag; }
63
65 return GEPNoWrapFlags(Flags & ~InBoundsFlag);
66 }
68 return GEPNoWrapFlags(Flags & ~(InBoundsFlag | NUSWFlag));
69 }
71 return GEPNoWrapFlags(Flags & ~NUWFlag);
72 }
73
74 bool operator==(GEPNoWrapFlags Other) const { return Flags == Other.Flags; }
75 bool operator!=(GEPNoWrapFlags Other) const { return !(*this == Other); }
76
78 return GEPNoWrapFlags(Flags & Other.Flags);
79 }
81 return GEPNoWrapFlags(Flags | Other.Flags);
82 }
84 Flags &= Other.Flags;
85 return *this;
86 }
88 Flags |= Other.Flags;
89 return *this;
90 }
91};
92
93} // end namespace llvm
94
95#endif // LLVM_IR_GEPNOWRAPFLAGS_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents flags for the getelementptr instruction/expression.
GEPNoWrapFlags & operator|=(GEPNoWrapFlags Other)
static GEPNoWrapFlags inBounds()
GEPNoWrapFlags withoutNoUnsignedSignedWrap() const
bool operator==(GEPNoWrapFlags Other) const
GEPNoWrapFlags & operator&=(GEPNoWrapFlags Other)
GEPNoWrapFlags withoutInBounds() const
static GEPNoWrapFlags fromRaw(unsigned Flags)
static GEPNoWrapFlags noUnsignedWrap()
static GEPNoWrapFlags noUnsignedSignedWrap()
GEPNoWrapFlags(bool IsInBounds)
bool hasNoUnsignedSignedWrap() const
bool operator!=(GEPNoWrapFlags Other) const
bool hasNoUnsignedWrap() const
bool isInBounds() const
GEPNoWrapFlags operator&(GEPNoWrapFlags Other) const
GEPNoWrapFlags operator|(GEPNoWrapFlags Other) const
GEPNoWrapFlags withoutNoUnsignedWrap() const
static GEPNoWrapFlags none()
unsigned getRaw() const
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Other
Any other memory.