2018-12-28 07:06:22 +08:00
|
|
|
//===- Value.cpp - MLIR Value Classes -------------------------------------===//
|
2018-08-02 01:43:18 +08:00
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-08-02 01:43:18 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-08-02 01:43:18 +08:00
|
|
|
|
2018-12-28 07:06:22 +08:00
|
|
|
#include "mlir/IR/Value.h"
|
2019-04-25 00:24:57 +08:00
|
|
|
#include "mlir/IR/Block.h"
|
2020-12-04 09:22:29 +08:00
|
|
|
#include "mlir/IR/BuiltinTypes.h"
|
2019-03-27 05:45:38 +08:00
|
|
|
#include "mlir/IR/Operation.h"
|
2020-04-20 15:17:45 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2020-04-24 07:23:34 +08:00
|
|
|
|
2018-08-02 01:43:18 +08:00
|
|
|
using namespace mlir;
|
2020-04-24 07:23:34 +08:00
|
|
|
using namespace mlir::detail;
|
2018-08-02 01:43:18 +08:00
|
|
|
|
2019-03-27 08:05:09 +08:00
|
|
|
/// If this value is the result of an Operation, return the operation that
|
|
|
|
/// defines it.
|
2019-12-24 04:36:20 +08:00
|
|
|
Operation *Value::getDefiningOp() const {
|
|
|
|
if (auto result = dyn_cast<OpResult>())
|
2020-01-12 00:54:04 +08:00
|
|
|
return result.getOwner();
|
2018-08-02 01:43:18 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-01-12 00:54:04 +08:00
|
|
|
Location Value::getLoc() const {
|
2019-07-09 02:20:26 +08:00
|
|
|
if (auto *op = getDefiningOp())
|
2019-04-02 01:42:34 +08:00
|
|
|
return op->getLoc();
|
[mlir][DialectConversion] Enable deeper integration of type conversions
This revision adds support for much deeper type conversion integration into the conversion process, and enables auto-generating cast operations when necessary. Type conversions are now largely automatically managed by the conversion infra when using a ConversionPattern with a provided TypeConverter. This removes the need for patterns to do type cast wrapping themselves and moves the burden to the infra. This makes it much easier to perform partial lowerings when type conversions are involved, as any lingering type conversions will be automatically resolved/legalized by the conversion infra.
To support this new integration, a few changes have been made to the type materialization API on TypeConverter. Materialization has been split into three separate categories:
* Argument Materialization: This type of materialization is used when converting the type of block arguments when calling `convertRegionTypes`. This is useful for contextually inserting additional conversion operations when converting a block argument type, such as when converting the types of a function signature.
* Source Materialization: This type of materialization is used to convert a legal type of the converter into a non-legal type, generally a source type. This may be called when uses of a non-legal type persist after the conversion process has finished.
* Target Materialization: This type of materialization is used to convert a non-legal, or source, type into a legal, or target, type. This type of materialization is used when applying a pattern on an operation, but the types of the operands have not yet been converted.
Differential Revision: https://reviews.llvm.org/D82831
2020-07-24 10:38:30 +08:00
|
|
|
|
2021-05-24 05:08:31 +08:00
|
|
|
return cast<BlockArgument>().getLoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Value::setLoc(Location loc) {
|
|
|
|
if (auto *op = getDefiningOp())
|
|
|
|
return op->setLoc(loc);
|
|
|
|
|
|
|
|
return cast<BlockArgument>().setLoc(loc);
|
2019-04-02 01:42:34 +08:00
|
|
|
}
|
|
|
|
|
2019-04-25 00:24:57 +08:00
|
|
|
/// Return the Region in which this Value is defined.
|
2019-08-10 11:07:25 +08:00
|
|
|
Region *Value::getParentRegion() {
|
2019-10-15 07:21:17 +08:00
|
|
|
if (auto *op = getDefiningOp())
|
|
|
|
return op->getParentRegion();
|
2020-01-12 00:54:04 +08:00
|
|
|
return cast<BlockArgument>().getOwner()->getParent();
|
2019-04-25 00:24:57 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 10:54:36 +08:00
|
|
|
/// Return the Block in which this Value is defined.
|
|
|
|
Block *Value::getParentBlock() {
|
|
|
|
if (Operation *op = getDefiningOp())
|
|
|
|
return op->getBlock();
|
|
|
|
return cast<BlockArgument>().getOwner();
|
|
|
|
}
|
|
|
|
|
2019-12-28 12:33:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-12-31 12:49:47 +08:00
|
|
|
// Value::UseLists
|
2019-12-28 12:33:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-20 15:17:45 +08:00
|
|
|
/// Replace all uses of 'this' value with the new value, updating anything in
|
|
|
|
/// the IR that uses 'this' to use the other value instead except if the user is
|
|
|
|
/// listed in 'exceptions' .
|
|
|
|
void Value::replaceAllUsesExcept(
|
|
|
|
Value newValue, const SmallPtrSetImpl<Operation *> &exceptions) const {
|
2021-05-13 05:59:12 +08:00
|
|
|
for (OpOperand &use : llvm::make_early_inc_range(getUses())) {
|
2020-04-20 15:17:45 +08:00
|
|
|
if (exceptions.count(use.getOwner()) == 0)
|
|
|
|
use.set(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-13 05:59:12 +08:00
|
|
|
/// Replace all uses of 'this' value with 'newValue', updating anything in the
|
|
|
|
/// IR that uses 'this' to use the other value instead except if the user is
|
|
|
|
/// 'exceptedUser'.
|
|
|
|
void Value::replaceAllUsesExcept(Value newValue,
|
|
|
|
Operation *exceptedUser) const {
|
|
|
|
for (OpOperand &use : llvm::make_early_inc_range(getUses())) {
|
|
|
|
if (use.getOwner() != exceptedUser)
|
|
|
|
use.set(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 03:25:05 +08:00
|
|
|
/// Replace all uses of 'this' value with 'newValue' if the given callback
|
|
|
|
/// returns true.
|
|
|
|
void Value::replaceUsesWithIf(Value newValue,
|
|
|
|
function_ref<bool(OpOperand &)> shouldReplace) {
|
|
|
|
for (OpOperand &use : llvm::make_early_inc_range(getUses()))
|
|
|
|
if (shouldReplace(use))
|
|
|
|
use.set(newValue);
|
|
|
|
}
|
|
|
|
|
2020-05-05 10:54:36 +08:00
|
|
|
/// Returns true if the value is used outside of the given block.
|
|
|
|
bool Value::isUsedOutsideOfBlock(Block *block) {
|
|
|
|
return llvm::any_of(getUsers(), [block](Operation *user) {
|
|
|
|
return user->getBlock() != block;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-03 06:28:37 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OpResult
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[mlir][IR] Refactor the internal implementation of Value
The current implementation of Value involves a pointer int pair with several different kinds of owners, i.e. BlockArgumentImpl*, Operation *, TrailingOpResult*. This design arose from the desire to save memory overhead for operations that have a very small number of results (generally 0-2). There are, unfortunately, many problematic aspects of the current implementation that make Values difficult to work with or just inefficient.
Operation result types are stored as a separate array on the Operation. This is very inefficient for many reasons: we use TupleType for multiple results, which can lead to huge amounts of memory usage if multi-result operations change types frequently(they do). It also means that simple methods like Value::getType/Value::setType now require complex logic to get to the desired type.
Value only has one pointer bit free, severely limiting the ability to use it in things like PointerUnion/PointerIntPair. Given that we store the kind of a Value along with the "owner" pointer, we only leave one bit free for users of Value. This creates situations where we end up nesting PointerUnions to be able to use Value in one.
As noted above, most of the methods in Value need to branch on at least 3 different cases which is both inefficient, possibly error prone, and verbose. The current storage of results also creates problems for utilities like ValueRange/TypeRange, which want to efficiently store base pointers to ranges (of which Operation* isn't really useful as one).
This revision greatly simplifies the implementation of Value by the introduction of a new ValueImpl class. This class contains all of the state shared between all of the various derived value classes; i.e. the use list, the type, and the kind. This shared implementation class provides several large benefits:
* Most of the methods on value are now branchless, and often one-liners.
* The "kind" of the value is now stored in ValueImpl instead of Value
This frees up all of Value's pointer bits, allowing for users to take full advantage of PointerUnion/PointerIntPair/etc. It also allows for storing more operation results as "inline", 6 now instead of 2, freeing up 1 word per new inline result.
* Operation result types are now stored in the result, instead of a side array
This drops the size of zero-result operations by 1 word. It also removes the memory crushing use of TupleType for operations results (which could lead up to hundreds of megabytes of "dead" TupleTypes in the context). This also allowed restructured ValueRange, making it simpler and one word smaller.
This revision does come with two conceptual downsides:
* Operation::getResultTypes no longer returns an ArrayRef<Type>
This conceptually makes some usages slower, as the iterator increment is slightly more complex.
* OpResult::getOwner is slightly more expensive, as it now requires a little bit of arithmetic
From profiling, neither of the conceptual downsides have resulted in any perceivable hit to performance. Given the advantages of the new design, most compiles are slightly faster.
Differential Revision: https://reviews.llvm.org/D97804
2021-03-04 06:23:14 +08:00
|
|
|
/// Returns the parent operation of this trailing result.
|
|
|
|
Operation *OpResultImpl::getOwner() const {
|
|
|
|
// We need to do some arithmetic to get the operation pointer. Results are
|
|
|
|
// stored in reverse order before the operation, so move the trailing owner up
|
|
|
|
// to the start of the array. A rough diagram of the memory layout is:
|
|
|
|
//
|
|
|
|
// | Out-of-Line results | Inline results | Operation |
|
|
|
|
//
|
|
|
|
// Given that the results are reverse order we use the result number to know
|
|
|
|
// how far to jump to get to the operation. So if we are currently the 0th
|
|
|
|
// result, the layout would be:
|
|
|
|
//
|
|
|
|
// | Inline result 0 | Operation
|
|
|
|
//
|
|
|
|
// ^-- To get the base address of the operation, we add the result count + 1.
|
|
|
|
if (const auto *result = dyn_cast<InlineOpResult>(this)) {
|
|
|
|
result += result->getResultNumber() + 1;
|
|
|
|
return reinterpret_cast<Operation *>(const_cast<InlineOpResult *>(result));
|
|
|
|
}
|
2020-01-03 06:28:37 +08:00
|
|
|
|
[mlir][IR] Refactor the internal implementation of Value
The current implementation of Value involves a pointer int pair with several different kinds of owners, i.e. BlockArgumentImpl*, Operation *, TrailingOpResult*. This design arose from the desire to save memory overhead for operations that have a very small number of results (generally 0-2). There are, unfortunately, many problematic aspects of the current implementation that make Values difficult to work with or just inefficient.
Operation result types are stored as a separate array on the Operation. This is very inefficient for many reasons: we use TupleType for multiple results, which can lead to huge amounts of memory usage if multi-result operations change types frequently(they do). It also means that simple methods like Value::getType/Value::setType now require complex logic to get to the desired type.
Value only has one pointer bit free, severely limiting the ability to use it in things like PointerUnion/PointerIntPair. Given that we store the kind of a Value along with the "owner" pointer, we only leave one bit free for users of Value. This creates situations where we end up nesting PointerUnions to be able to use Value in one.
As noted above, most of the methods in Value need to branch on at least 3 different cases which is both inefficient, possibly error prone, and verbose. The current storage of results also creates problems for utilities like ValueRange/TypeRange, which want to efficiently store base pointers to ranges (of which Operation* isn't really useful as one).
This revision greatly simplifies the implementation of Value by the introduction of a new ValueImpl class. This class contains all of the state shared between all of the various derived value classes; i.e. the use list, the type, and the kind. This shared implementation class provides several large benefits:
* Most of the methods on value are now branchless, and often one-liners.
* The "kind" of the value is now stored in ValueImpl instead of Value
This frees up all of Value's pointer bits, allowing for users to take full advantage of PointerUnion/PointerIntPair/etc. It also allows for storing more operation results as "inline", 6 now instead of 2, freeing up 1 word per new inline result.
* Operation result types are now stored in the result, instead of a side array
This drops the size of zero-result operations by 1 word. It also removes the memory crushing use of TupleType for operations results (which could lead up to hundreds of megabytes of "dead" TupleTypes in the context). This also allowed restructured ValueRange, making it simpler and one word smaller.
This revision does come with two conceptual downsides:
* Operation::getResultTypes no longer returns an ArrayRef<Type>
This conceptually makes some usages slower, as the iterator increment is slightly more complex.
* OpResult::getOwner is slightly more expensive, as it now requires a little bit of arithmetic
From profiling, neither of the conceptual downsides have resulted in any perceivable hit to performance. Given the advantages of the new design, most compiles are slightly faster.
Differential Revision: https://reviews.llvm.org/D97804
2021-03-04 06:23:14 +08:00
|
|
|
// Out-of-line results are stored in an array just before the inline results.
|
|
|
|
const OutOfLineOpResult *outOfLineIt = (const OutOfLineOpResult *)(this);
|
|
|
|
outOfLineIt += (outOfLineIt->outOfLineIndex + 1);
|
|
|
|
|
|
|
|
// Move the owner past the inline results to get to the operation.
|
|
|
|
const auto *inlineIt = reinterpret_cast<const InlineOpResult *>(outOfLineIt);
|
|
|
|
inlineIt += getMaxInlineResults();
|
|
|
|
return reinterpret_cast<Operation *>(const_cast<InlineOpResult *>(inlineIt));
|
|
|
|
}
|
|
|
|
|
|
|
|
OpResultImpl *OpResultImpl::getNextResultAtOffset(intptr_t offset) {
|
|
|
|
if (offset == 0)
|
|
|
|
return this;
|
|
|
|
// We need to do some arithmetic to get the next result given that results are
|
|
|
|
// in reverse order, and that we need to account for the different types of
|
|
|
|
// results. As a reminder, the rough diagram of the memory layout is:
|
|
|
|
//
|
|
|
|
// | Out-of-Line results | Inline results | Operation |
|
|
|
|
//
|
|
|
|
// So an example operation with two results would look something like:
|
|
|
|
//
|
|
|
|
// | Inline result 1 | Inline result 0 | Operation |
|
|
|
|
//
|
|
|
|
|
|
|
|
// Handle the case where this result is an inline result.
|
|
|
|
OpResultImpl *result = this;
|
|
|
|
if (auto *inlineResult = dyn_cast<InlineOpResult>(this)) {
|
|
|
|
// Check to see how many results there are after this one before the start
|
|
|
|
// of the out-of-line results. If the desired offset is less than the number
|
|
|
|
// remaining, we can directly use the offset from the current result
|
|
|
|
// pointer. The following diagrams highlight the two situations.
|
|
|
|
//
|
|
|
|
// | Out-of-Line results | Inline results | Operation |
|
|
|
|
// ^- Say we are here.
|
|
|
|
// ^- If our destination is here, we can use the
|
|
|
|
// offset directly.
|
|
|
|
//
|
|
|
|
intptr_t leftBeforeTrailing =
|
|
|
|
getMaxInlineResults() - inlineResult->getResultNumber() - 1;
|
|
|
|
if (leftBeforeTrailing >= offset)
|
|
|
|
return inlineResult - offset;
|
|
|
|
|
|
|
|
// Otherwise, adjust the current result pointer to the end (start in memory)
|
|
|
|
// of the inline result array.
|
|
|
|
//
|
|
|
|
// | Out-of-Line results | Inline results | Operation |
|
|
|
|
// ^- Say we are here.
|
|
|
|
// ^- If our destination is here, we need to first jump to
|
|
|
|
// the end (start in memory) of the inline result array.
|
|
|
|
//
|
|
|
|
result = inlineResult - leftBeforeTrailing;
|
|
|
|
offset -= leftBeforeTrailing;
|
|
|
|
}
|
2020-01-03 06:28:37 +08:00
|
|
|
|
[mlir][IR] Refactor the internal implementation of Value
The current implementation of Value involves a pointer int pair with several different kinds of owners, i.e. BlockArgumentImpl*, Operation *, TrailingOpResult*. This design arose from the desire to save memory overhead for operations that have a very small number of results (generally 0-2). There are, unfortunately, many problematic aspects of the current implementation that make Values difficult to work with or just inefficient.
Operation result types are stored as a separate array on the Operation. This is very inefficient for many reasons: we use TupleType for multiple results, which can lead to huge amounts of memory usage if multi-result operations change types frequently(they do). It also means that simple methods like Value::getType/Value::setType now require complex logic to get to the desired type.
Value only has one pointer bit free, severely limiting the ability to use it in things like PointerUnion/PointerIntPair. Given that we store the kind of a Value along with the "owner" pointer, we only leave one bit free for users of Value. This creates situations where we end up nesting PointerUnions to be able to use Value in one.
As noted above, most of the methods in Value need to branch on at least 3 different cases which is both inefficient, possibly error prone, and verbose. The current storage of results also creates problems for utilities like ValueRange/TypeRange, which want to efficiently store base pointers to ranges (of which Operation* isn't really useful as one).
This revision greatly simplifies the implementation of Value by the introduction of a new ValueImpl class. This class contains all of the state shared between all of the various derived value classes; i.e. the use list, the type, and the kind. This shared implementation class provides several large benefits:
* Most of the methods on value are now branchless, and often one-liners.
* The "kind" of the value is now stored in ValueImpl instead of Value
This frees up all of Value's pointer bits, allowing for users to take full advantage of PointerUnion/PointerIntPair/etc. It also allows for storing more operation results as "inline", 6 now instead of 2, freeing up 1 word per new inline result.
* Operation result types are now stored in the result, instead of a side array
This drops the size of zero-result operations by 1 word. It also removes the memory crushing use of TupleType for operations results (which could lead up to hundreds of megabytes of "dead" TupleTypes in the context). This also allowed restructured ValueRange, making it simpler and one word smaller.
This revision does come with two conceptual downsides:
* Operation::getResultTypes no longer returns an ArrayRef<Type>
This conceptually makes some usages slower, as the iterator increment is slightly more complex.
* OpResult::getOwner is slightly more expensive, as it now requires a little bit of arithmetic
From profiling, neither of the conceptual downsides have resulted in any perceivable hit to performance. Given the advantages of the new design, most compiles are slightly faster.
Differential Revision: https://reviews.llvm.org/D97804
2021-03-04 06:23:14 +08:00
|
|
|
// If we land here, the current result is an out-of-line result and we can
|
|
|
|
// offset directly.
|
|
|
|
return reinterpret_cast<OutOfLineOpResult *>(result) - offset;
|
2020-04-24 07:23:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a number of operation results, returns the number that need to be
|
|
|
|
/// stored inline.
|
|
|
|
unsigned OpResult::getNumInline(unsigned numResults) {
|
[mlir][IR] Refactor the internal implementation of Value
The current implementation of Value involves a pointer int pair with several different kinds of owners, i.e. BlockArgumentImpl*, Operation *, TrailingOpResult*. This design arose from the desire to save memory overhead for operations that have a very small number of results (generally 0-2). There are, unfortunately, many problematic aspects of the current implementation that make Values difficult to work with or just inefficient.
Operation result types are stored as a separate array on the Operation. This is very inefficient for many reasons: we use TupleType for multiple results, which can lead to huge amounts of memory usage if multi-result operations change types frequently(they do). It also means that simple methods like Value::getType/Value::setType now require complex logic to get to the desired type.
Value only has one pointer bit free, severely limiting the ability to use it in things like PointerUnion/PointerIntPair. Given that we store the kind of a Value along with the "owner" pointer, we only leave one bit free for users of Value. This creates situations where we end up nesting PointerUnions to be able to use Value in one.
As noted above, most of the methods in Value need to branch on at least 3 different cases which is both inefficient, possibly error prone, and verbose. The current storage of results also creates problems for utilities like ValueRange/TypeRange, which want to efficiently store base pointers to ranges (of which Operation* isn't really useful as one).
This revision greatly simplifies the implementation of Value by the introduction of a new ValueImpl class. This class contains all of the state shared between all of the various derived value classes; i.e. the use list, the type, and the kind. This shared implementation class provides several large benefits:
* Most of the methods on value are now branchless, and often one-liners.
* The "kind" of the value is now stored in ValueImpl instead of Value
This frees up all of Value's pointer bits, allowing for users to take full advantage of PointerUnion/PointerIntPair/etc. It also allows for storing more operation results as "inline", 6 now instead of 2, freeing up 1 word per new inline result.
* Operation result types are now stored in the result, instead of a side array
This drops the size of zero-result operations by 1 word. It also removes the memory crushing use of TupleType for operations results (which could lead up to hundreds of megabytes of "dead" TupleTypes in the context). This also allowed restructured ValueRange, making it simpler and one word smaller.
This revision does come with two conceptual downsides:
* Operation::getResultTypes no longer returns an ArrayRef<Type>
This conceptually makes some usages slower, as the iterator increment is slightly more complex.
* OpResult::getOwner is slightly more expensive, as it now requires a little bit of arithmetic
From profiling, neither of the conceptual downsides have resulted in any perceivable hit to performance. Given the advantages of the new design, most compiles are slightly faster.
Differential Revision: https://reviews.llvm.org/D97804
2021-03-04 06:23:14 +08:00
|
|
|
return std::min(numResults, OpResultImpl::getMaxInlineResults());
|
2020-01-03 06:28:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a number of operation results, returns the number that need to be
|
|
|
|
/// stored as trailing.
|
|
|
|
unsigned OpResult::getNumTrailing(unsigned numResults) {
|
|
|
|
// If we can pack all of the results, there is no need for additional storage.
|
[mlir][IR] Refactor the internal implementation of Value
The current implementation of Value involves a pointer int pair with several different kinds of owners, i.e. BlockArgumentImpl*, Operation *, TrailingOpResult*. This design arose from the desire to save memory overhead for operations that have a very small number of results (generally 0-2). There are, unfortunately, many problematic aspects of the current implementation that make Values difficult to work with or just inefficient.
Operation result types are stored as a separate array on the Operation. This is very inefficient for many reasons: we use TupleType for multiple results, which can lead to huge amounts of memory usage if multi-result operations change types frequently(they do). It also means that simple methods like Value::getType/Value::setType now require complex logic to get to the desired type.
Value only has one pointer bit free, severely limiting the ability to use it in things like PointerUnion/PointerIntPair. Given that we store the kind of a Value along with the "owner" pointer, we only leave one bit free for users of Value. This creates situations where we end up nesting PointerUnions to be able to use Value in one.
As noted above, most of the methods in Value need to branch on at least 3 different cases which is both inefficient, possibly error prone, and verbose. The current storage of results also creates problems for utilities like ValueRange/TypeRange, which want to efficiently store base pointers to ranges (of which Operation* isn't really useful as one).
This revision greatly simplifies the implementation of Value by the introduction of a new ValueImpl class. This class contains all of the state shared between all of the various derived value classes; i.e. the use list, the type, and the kind. This shared implementation class provides several large benefits:
* Most of the methods on value are now branchless, and often one-liners.
* The "kind" of the value is now stored in ValueImpl instead of Value
This frees up all of Value's pointer bits, allowing for users to take full advantage of PointerUnion/PointerIntPair/etc. It also allows for storing more operation results as "inline", 6 now instead of 2, freeing up 1 word per new inline result.
* Operation result types are now stored in the result, instead of a side array
This drops the size of zero-result operations by 1 word. It also removes the memory crushing use of TupleType for operations results (which could lead up to hundreds of megabytes of "dead" TupleTypes in the context). This also allowed restructured ValueRange, making it simpler and one word smaller.
This revision does come with two conceptual downsides:
* Operation::getResultTypes no longer returns an ArrayRef<Type>
This conceptually makes some usages slower, as the iterator increment is slightly more complex.
* OpResult::getOwner is slightly more expensive, as it now requires a little bit of arithmetic
From profiling, neither of the conceptual downsides have resulted in any perceivable hit to performance. Given the advantages of the new design, most compiles are slightly faster.
Differential Revision: https://reviews.llvm.org/D97804
2021-03-04 06:23:14 +08:00
|
|
|
unsigned maxInline = OpResultImpl::getMaxInlineResults();
|
2020-04-24 07:23:34 +08:00
|
|
|
return numResults <= maxInline ? 0 : numResults - maxInline;
|
2020-01-03 06:28:37 +08:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:49:47 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// BlockOperand
|
|
|
|
//===----------------------------------------------------------------------===//
|
2019-12-28 12:33:53 +08:00
|
|
|
|
2019-12-31 12:49:47 +08:00
|
|
|
/// Provide the use list that is attached to the given block.
|
|
|
|
IRObjectWithUseList<BlockOperand> *BlockOperand::getUseList(Block *value) {
|
|
|
|
return value;
|
|
|
|
}
|
2019-12-28 12:33:53 +08:00
|
|
|
|
|
|
|
/// Return which operand this is in the operand list.
|
|
|
|
unsigned BlockOperand::getOperandNumber() {
|
|
|
|
return this - &getOwner()->getBlockOperands()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// OpOperand
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Return which operand this is in the operand list.
|
|
|
|
unsigned OpOperand::getOperandNumber() {
|
|
|
|
return this - &getOwner()->getOpOperands()[0];
|
|
|
|
}
|
|
|
|
|