[llvm] Add the 'initializes' attribute langref and support (PR #84803)

Haopeng Liu via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 10:58:56 PDT 2024


================
@@ -0,0 +1,108 @@
+//===- ConstantRangeList.h - A list of constant range -----------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Represent a list of signed ConstantRange and do NOT support wrap around the
+// end of the numeric range. Ranges in the list should have the same bitwidth.
+// Each range's lower should be less than its upper. Special lists (take 8-bit
+// as an example):
+//
+// {[0, 0)}     = Empty set
+// {[255, 255)} = Full Set
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_CONSTANTRANGELIST_H
+#define LLVM_IR_CONSTANTRANGELIST_H
+
+#include "llvm/ADT/APInt.h"
+#include "llvm/IR/ConstantRange.h"
+#include <cstddef>
+#include <cstdint>
+
+namespace llvm {
+
+class raw_ostream;
+
+/// This class represents a list of constant ranges.
+class [[nodiscard]] ConstantRangeList {
+  SmallVector<ConstantRange, 2> Ranges;
+  // Whether the range list is sorted: [i].lower() < [i+1].lower()
+  bool Sorted = true;
+
+public:
+  /// Initialize a full or empty set for the specified bit width.
+  explicit ConstantRangeList(uint32_t BitWidth, bool isFullSet);
+
+  ConstantRangeList(int64_t Lower, int64_t Upper);
+
+  SmallVectorImpl<ConstantRange>::iterator begin() { return Ranges.begin(); }
----------------
haopliu wrote:

Good point! Add assert to disallow this kind of accessing.

https://github.com/llvm/llvm-project/pull/84803


More information about the llvm-commits mailing list