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

Jan Voung via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 17 11:46:04 PDT 2024


================
@@ -0,0 +1,70 @@
+//===- ConstantRangeList.cpp - ConstantRangeList implementation -----------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/ConstantRangeList.h"
+#include <cstddef>
+
+using namespace llvm;
+
+void ConstantRangeList::insert(const ConstantRange &NewRange) {
+  if (NewRange.isEmptySet())
+    return;
+  assert(!NewRange.isFullSet() && "Do not support full set");
+  assert(NewRange.getLower().slt(NewRange.getUpper()));
+  assert(getBitWidth() == NewRange.getBitWidth());
+  // Handle common cases.
+  if (empty() || Ranges.back().getUpper().slt(NewRange.getLower())) {
+    Ranges.push_back(NewRange);
+    return;
+  }
+  if (NewRange.getUpper().slt(Ranges.front().getLower())) {
+    Ranges.insert(Ranges.begin(), NewRange);
+    return;
+  }
+
+  // Slow insert.
+  SmallVector<ConstantRange, 2> ExistingRanges(Ranges.begin(), Ranges.end());
----------------
jvoung wrote:

It seems like the ExistingRanges isn't using the part before LowerBound (below loop Iter = LowerBound and up). So is it possible to do something like this instead?
LowerBound = std::lower_bound(Ranges.begin(), ...)
ExistingTail(LowerBound, Ranges.end());
Ranges.erase(LowerBound, Ranges.end());
...
for (auto Iter = ExistingTail.begin(); ...) { ... }

something like that?

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


More information about the llvm-commits mailing list