[clang] [llvm] [IR] Add getelementptr nusw and nuw flags (PR #90824)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 17:45:30 PDT 2024
================
@@ -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)
----------------
nikic wrote:
This is a backwards-compatiblity ctor because we're replacing existing `bool IsInBounds` parameters with `GEPNoWrapFlags NW` instead. As the TODO indicates, this ctor will be removed in the future. It avoids having to touch large amounts of code in this PR in sub-optimal ways.
https://github.com/llvm/llvm-project/pull/90824
More information about the llvm-commits
mailing list