-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IR] Add getelementptr nusw and nuw flags #90824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff4658c
29787e1
dd242f6
c85d5f5
926a4e2
c7b061f
59d356c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ enum Kind { | |
kw_fast, | ||
kw_nuw, | ||
kw_nsw, | ||
kw_nusw, | ||
kw_exact, | ||
kw_disjoint, | ||
kw_inbounds, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//===-- llvm/GEPNoWrapFlags.h - NoWrap flags for GEPs -----------*- 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 file defines the nowrap flags for getelementptr operators. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_IR_GEPNOWRAPFLAGS_H | ||
#define LLVM_IR_GEPNOWRAPFLAGS_H | ||
|
||
namespace llvm { | ||
|
||
/// Represents flags for the getelementptr instruction/expression. | ||
/// The following flags are supported: | ||
/// * inbounds (implies nusw) | ||
/// * nusw (no unsigned signed wrap) | ||
/// * nuw (no unsigned wrap) | ||
/// See LangRef for a description of their semantics. | ||
class GEPNoWrapFlags { | ||
enum : unsigned { | ||
InBoundsFlag = (1 << 0), | ||
NUSWFlag = (1 << 1), | ||
NUWFlag = (1 << 2), | ||
}; | ||
|
||
unsigned Flags; | ||
GEPNoWrapFlags(unsigned Flags) : Flags(Flags) { | ||
assert((!isInBounds() || hasNoUnsignedSignedWrap()) && | ||
"inbounds implies nusw"); | ||
} | ||
|
||
public: | ||
GEPNoWrapFlags() : Flags(0) {} | ||
// For historical reasons, interpret plain boolean as InBounds. | ||
// TODO: Migrate users to pass explicit GEPNoWrapFlags and remove this ctor. | ||
GEPNoWrapFlags(bool IsInBounds) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this CTOR? Seems to be entirely encapsulated with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a backwards-compatiblity ctor because we're replacing existing |
||
: Flags(IsInBounds ? (InBoundsFlag | NUSWFlag) : 0) {} | ||
|
||
static GEPNoWrapFlags none() { return GEPNoWrapFlags(); } | ||
static GEPNoWrapFlags inBounds() { | ||
return GEPNoWrapFlags(InBoundsFlag | NUSWFlag); | ||
} | ||
static GEPNoWrapFlags noUnsignedSignedWrap() { | ||
return GEPNoWrapFlags(NUSWFlag); | ||
} | ||
static GEPNoWrapFlags noUnsignedWrap() { return GEPNoWrapFlags(NUWFlag); } | ||
|
||
static GEPNoWrapFlags fromRaw(unsigned Flags) { | ||
return GEPNoWrapFlags(Flags); | ||
} | ||
unsigned getRaw() const { return Flags; } | ||
|
||
bool isInBounds() const { return Flags & InBoundsFlag; } | ||
bool hasNoUnsignedSignedWrap() const { return Flags & NUSWFlag; } | ||
bool hasNoUnsignedWrap() const { return Flags & NUWFlag; } | ||
|
||
GEPNoWrapFlags withoutInBounds() const { | ||
return GEPNoWrapFlags(Flags & ~InBoundsFlag); | ||
} | ||
GEPNoWrapFlags withoutNoUnsignedSignedWrap() const { | ||
return GEPNoWrapFlags(Flags & ~(InBoundsFlag | NUSWFlag)); | ||
} | ||
GEPNoWrapFlags withoutNoUnsignedWrap() const { | ||
return GEPNoWrapFlags(Flags & ~NUWFlag); | ||
} | ||
|
||
bool operator==(GEPNoWrapFlags Other) const { return Flags == Other.Flags; } | ||
bool operator!=(GEPNoWrapFlags Other) const { return !(*this == Other); } | ||
|
||
GEPNoWrapFlags operator&(GEPNoWrapFlags Other) const { | ||
return GEPNoWrapFlags(Flags & Other.Flags); | ||
} | ||
GEPNoWrapFlags operator|(GEPNoWrapFlags Other) const { | ||
return GEPNoWrapFlags(Flags | Other.Flags); | ||
} | ||
GEPNoWrapFlags &operator&=(GEPNoWrapFlags Other) { | ||
Flags &= Other.Flags; | ||
return *this; | ||
} | ||
GEPNoWrapFlags &operator|=(GEPNoWrapFlags Other) { | ||
Flags |= Other.Flags; | ||
return *this; | ||
} | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_IR_GEPNOWRAPFLAGS_H |
Uh oh!
There was an error while loading. Please reload this page.