[llvm] Add the 'initializes' attribute langref and support (PR #84803)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 18:57:05 PDT 2024
================
@@ -0,0 +1,86 @@
+//===- 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 are ordered and no overlapping.
+// Ranges should have the same bitwidth. Each range's lower should be less than
+// its upper.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_CONSTANTRANGELIST_H
+#define LLVM_IR_CONSTANTRANGELIST_H
+
+#include "llvm/ADT/APInt.h"
+#include "llvm/IR/ConstantRange.h"
+#include "llvm/Support/Debug.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;
+
+public:
+ ConstantRangeList() = default;
+ ConstantRangeList(ArrayRef<ConstantRange> RangesRef) {
+ for (const ConstantRange &R : RangesRef) {
+ assert(R.getBitWidth() == getBitWidth());
+ Ranges.push_back(R);
+ }
+ }
+ ArrayRef<ConstantRange> rangesRef() const { return Ranges; }
+ 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());
----------------
nikic wrote:
`operator[]` already has this assert.
https://github.com/llvm/llvm-project/pull/84803
More information about the llvm-commits
mailing list