[llvm] Add the 'initializes' attribute langref and support (PR #84803)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 14:23:12 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(); }
+ SmallVectorImpl<ConstantRange>::iterator end() { return Ranges.end(); }
+ SmallVectorImpl<ConstantRange>::const_iterator begin() const {
+ return Ranges.begin();
+ }
+ SmallVectorImpl<ConstantRange>::const_iterator end() const {
+ return Ranges.end();
+ }
+ ConstantRange getRange(unsigned i) const {
+ assert(i < Ranges.size());
+ return Ranges[i];
+ }
+
+ /// Return true if this set contains no members.
+ bool isEmptySet() const {
+ return Ranges.size() == 1 && Ranges[0].isEmptySet();
+ }
+
+ /// Return true if this set contains all of the elements possible
+ /// for this data-type.
+ bool isFullSet() const { return Ranges.size() == 1 && Ranges[0].isFullSet(); }
+
+ /// Get the bit width of this ConstantRangeList.
+ uint32_t getBitWidth() const { return Ranges[0].getBitWidth(); }
+
+ size_t size() const { return Ranges.size(); }
----------------
aeubanks wrote:
the current comment is kinda redundant with the name, I'd be more specific and say "the number of ranges in this ConstantRangeList"
https://github.com/llvm/llvm-project/pull/84803
More information about the llvm-commits
mailing list