2011-01-16 09:10:57 +01:00
|
|
|
//===-- User.cpp - Implement the User class -------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2011-01-16 09:10:57 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/User.h"
|
|
|
|
#include "llvm/IR/Constant.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
2020-03-12 00:39:05 +01:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2011-01-16 09:10:57 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2015-06-11 00:38:30 +02:00
|
|
|
class BasicBlock;
|
2011-01-16 09:10:57 +01:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// User Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void User::replaceUsesOfWith(Value *From, Value *To) {
|
|
|
|
if (From == To) return; // Duh what?
|
|
|
|
|
|
|
|
assert((!isa<Constant>(this) || isa<GlobalValue>(this)) &&
|
|
|
|
"Cannot call User::replaceUsesOfWith on a constant!");
|
|
|
|
|
|
|
|
for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
|
|
|
|
if (getOperand(i) == From) { // Is This operand is pointing to oldval?
|
|
|
|
// The side effects of this setOperand call include linking to
|
|
|
|
// "To", adding "this" to the uses list of To, and
|
|
|
|
// most importantly, removing "this" from the use list of "From".
|
2020-07-29 04:02:04 +02:00
|
|
|
setOperand(i, To);
|
2011-01-16 09:10:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// User allocHungoffUses Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-06-11 00:38:46 +02:00
|
|
|
void User::allocHungoffUses(unsigned N, bool IsPhi) {
|
2015-06-12 19:48:14 +02:00
|
|
|
assert(HasHungOffUses && "alloc must have hung off uses");
|
2015-06-17 03:21:20 +02:00
|
|
|
|
[NFC] Remove waymarking because it improves performances
Summary:
This patch remove waymarking and replaces it with storing a pointer to the User in the Use.
here are the results on the measurements for the CTMark tests of the test suite.
```
Metric: instructions_count
Program baseline patched diff
test-suite :: CTMark/ClamAV/clamscan.test 72557942065 71733653521 -1.1%
test-suite :: CTMark/sqlite3/sqlite3.test 76281422939 75484840636 -1.0%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 51364676366 50862185614 -1.0%
test-suite :: CTMark/SPASS/SPASS.test 60476106505 59908437767 -0.9%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 112578442329 111725050856 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 50846133013 50473644539 -0.7%
test-suite :: CTMark/kimwitu++/kc.test 54692641250 54349070299 -0.6%
test-suite :: CTMark/7zip/7zip-benchmark.test 182216614747 181216091230 -0.5%
test-suite :: CTMark/Bullet/bullet.test 123459210616 122905866767 -0.4%
Geomean difference -0.8%
Metric: peak_memory_use
Program baseline patched diff
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 326864 338524 3.6%
test-suite :: CTMark/sqlite3/sqlite3.test 216412 221240 2.2%
test-suite :: CTMark/7zip/7zip-benchmark.test 11808284 12022604 1.8%
test-suite :: CTMark/Bullet/bullet.test 6831752 6945988 1.7%
test-suite :: CTMark/SPASS/SPASS.test 2682552 2721820 1.5%
test-suite :: CTMark/ClamAV/clamscan.test 5037256 5107936 1.4%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 2752728 2790768 1.4%
test-suite :: CTMark/mafft/pairlocalalign.test 1517676 1537244 1.3%
test-suite :: CTMark/kimwitu++/kc.test 1090748 1103448 1.2%
Geomean difference 1.8%
Metric: compile_time
Program baseline patched diff
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 14.71 14.38 -2.2%
test-suite :: CTMark/sqlite3/sqlite3.test 23.18 22.73 -2.0%
test-suite :: CTMark/7zip/7zip-benchmark.test 57.96 56.99 -1.7%
test-suite :: CTMark/ClamAV/clamscan.test 20.75 20.49 -1.2%
test-suite :: CTMark/kimwitu++/kc.test 18.35 18.15 -1.1%
test-suite :: CTMark/SPASS/SPASS.test 18.72 18.57 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 14.09 14.00 -0.6%
test-suite :: CTMark/Bullet/bullet.test 37.38 37.19 -0.5%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 33.81 33.76 -0.2%
Geomean difference -1.1%
```
i believe that it is worth trading +1.8% peak memory use for -1.1% compile time.
also this patch removes waymarking which simplifies the Use and User classes.
Reviewers: nikic, lattner
Reviewed By: lattner
Subscribers: russell.gallop, foad, ggreif, rriddle, ekatz, fhahn, lebedev.ri, mgorny, hiraditya, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77144
2020-04-17 10:53:01 +02:00
|
|
|
static_assert(alignof(Use) >= alignof(BasicBlock *),
|
2015-06-17 15:53:12 +02:00
|
|
|
"Alignment is insufficient for 'hung-off-uses' pieces");
|
2015-06-17 03:21:20 +02:00
|
|
|
|
[NFC] Remove waymarking because it improves performances
Summary:
This patch remove waymarking and replaces it with storing a pointer to the User in the Use.
here are the results on the measurements for the CTMark tests of the test suite.
```
Metric: instructions_count
Program baseline patched diff
test-suite :: CTMark/ClamAV/clamscan.test 72557942065 71733653521 -1.1%
test-suite :: CTMark/sqlite3/sqlite3.test 76281422939 75484840636 -1.0%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 51364676366 50862185614 -1.0%
test-suite :: CTMark/SPASS/SPASS.test 60476106505 59908437767 -0.9%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 112578442329 111725050856 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 50846133013 50473644539 -0.7%
test-suite :: CTMark/kimwitu++/kc.test 54692641250 54349070299 -0.6%
test-suite :: CTMark/7zip/7zip-benchmark.test 182216614747 181216091230 -0.5%
test-suite :: CTMark/Bullet/bullet.test 123459210616 122905866767 -0.4%
Geomean difference -0.8%
Metric: peak_memory_use
Program baseline patched diff
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 326864 338524 3.6%
test-suite :: CTMark/sqlite3/sqlite3.test 216412 221240 2.2%
test-suite :: CTMark/7zip/7zip-benchmark.test 11808284 12022604 1.8%
test-suite :: CTMark/Bullet/bullet.test 6831752 6945988 1.7%
test-suite :: CTMark/SPASS/SPASS.test 2682552 2721820 1.5%
test-suite :: CTMark/ClamAV/clamscan.test 5037256 5107936 1.4%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 2752728 2790768 1.4%
test-suite :: CTMark/mafft/pairlocalalign.test 1517676 1537244 1.3%
test-suite :: CTMark/kimwitu++/kc.test 1090748 1103448 1.2%
Geomean difference 1.8%
Metric: compile_time
Program baseline patched diff
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 14.71 14.38 -2.2%
test-suite :: CTMark/sqlite3/sqlite3.test 23.18 22.73 -2.0%
test-suite :: CTMark/7zip/7zip-benchmark.test 57.96 56.99 -1.7%
test-suite :: CTMark/ClamAV/clamscan.test 20.75 20.49 -1.2%
test-suite :: CTMark/kimwitu++/kc.test 18.35 18.15 -1.1%
test-suite :: CTMark/SPASS/SPASS.test 18.72 18.57 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 14.09 14.00 -0.6%
test-suite :: CTMark/Bullet/bullet.test 37.38 37.19 -0.5%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 33.81 33.76 -0.2%
Geomean difference -1.1%
```
i believe that it is worth trading +1.8% peak memory use for -1.1% compile time.
also this patch removes waymarking which simplifies the Use and User classes.
Reviewers: nikic, lattner
Reviewed By: lattner
Subscribers: russell.gallop, foad, ggreif, rriddle, ekatz, fhahn, lebedev.ri, mgorny, hiraditya, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77144
2020-04-17 10:53:01 +02:00
|
|
|
// Allocate the array of Uses
|
|
|
|
size_t size = N * sizeof(Use);
|
2015-06-11 00:38:30 +02:00
|
|
|
if (IsPhi)
|
|
|
|
size += N * sizeof(BasicBlock *);
|
2011-06-23 11:09:15 +02:00
|
|
|
Use *Begin = static_cast<Use*>(::operator new(size));
|
2011-01-16 09:10:57 +01:00
|
|
|
Use *End = Begin + N;
|
[NFC] Remove waymarking because it improves performances
Summary:
This patch remove waymarking and replaces it with storing a pointer to the User in the Use.
here are the results on the measurements for the CTMark tests of the test suite.
```
Metric: instructions_count
Program baseline patched diff
test-suite :: CTMark/ClamAV/clamscan.test 72557942065 71733653521 -1.1%
test-suite :: CTMark/sqlite3/sqlite3.test 76281422939 75484840636 -1.0%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 51364676366 50862185614 -1.0%
test-suite :: CTMark/SPASS/SPASS.test 60476106505 59908437767 -0.9%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 112578442329 111725050856 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 50846133013 50473644539 -0.7%
test-suite :: CTMark/kimwitu++/kc.test 54692641250 54349070299 -0.6%
test-suite :: CTMark/7zip/7zip-benchmark.test 182216614747 181216091230 -0.5%
test-suite :: CTMark/Bullet/bullet.test 123459210616 122905866767 -0.4%
Geomean difference -0.8%
Metric: peak_memory_use
Program baseline patched diff
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 326864 338524 3.6%
test-suite :: CTMark/sqlite3/sqlite3.test 216412 221240 2.2%
test-suite :: CTMark/7zip/7zip-benchmark.test 11808284 12022604 1.8%
test-suite :: CTMark/Bullet/bullet.test 6831752 6945988 1.7%
test-suite :: CTMark/SPASS/SPASS.test 2682552 2721820 1.5%
test-suite :: CTMark/ClamAV/clamscan.test 5037256 5107936 1.4%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 2752728 2790768 1.4%
test-suite :: CTMark/mafft/pairlocalalign.test 1517676 1537244 1.3%
test-suite :: CTMark/kimwitu++/kc.test 1090748 1103448 1.2%
Geomean difference 1.8%
Metric: compile_time
Program baseline patched diff
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 14.71 14.38 -2.2%
test-suite :: CTMark/sqlite3/sqlite3.test 23.18 22.73 -2.0%
test-suite :: CTMark/7zip/7zip-benchmark.test 57.96 56.99 -1.7%
test-suite :: CTMark/ClamAV/clamscan.test 20.75 20.49 -1.2%
test-suite :: CTMark/kimwitu++/kc.test 18.35 18.15 -1.1%
test-suite :: CTMark/SPASS/SPASS.test 18.72 18.57 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 14.09 14.00 -0.6%
test-suite :: CTMark/Bullet/bullet.test 37.38 37.19 -0.5%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 33.81 33.76 -0.2%
Geomean difference -1.1%
```
i believe that it is worth trading +1.8% peak memory use for -1.1% compile time.
also this patch removes waymarking which simplifies the Use and User classes.
Reviewers: nikic, lattner
Reviewed By: lattner
Subscribers: russell.gallop, foad, ggreif, rriddle, ekatz, fhahn, lebedev.ri, mgorny, hiraditya, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77144
2020-04-17 10:53:01 +02:00
|
|
|
setOperandList(Begin);
|
|
|
|
for (; Begin != End; Begin++)
|
|
|
|
new (Begin) Use(this);
|
2011-01-16 09:10:57 +01:00
|
|
|
}
|
|
|
|
|
2015-06-11 00:38:41 +02:00
|
|
|
void User::growHungoffUses(unsigned NewNumUses, bool IsPhi) {
|
|
|
|
assert(HasHungOffUses && "realloc must have hung off uses");
|
|
|
|
|
|
|
|
unsigned OldNumUses = getNumOperands();
|
|
|
|
|
|
|
|
// We don't support shrinking the number of uses. We wouldn't have enough
|
|
|
|
// space to copy the old uses in to the new space.
|
|
|
|
assert(NewNumUses > OldNumUses && "realloc must grow num uses");
|
|
|
|
|
2015-06-12 19:48:05 +02:00
|
|
|
Use *OldOps = getOperandList();
|
2015-06-11 00:38:41 +02:00
|
|
|
allocHungoffUses(NewNumUses, IsPhi);
|
2015-06-12 19:48:05 +02:00
|
|
|
Use *NewOps = getOperandList();
|
2015-06-11 00:38:41 +02:00
|
|
|
|
|
|
|
// Now copy from the old operands list to the new one.
|
|
|
|
std::copy(OldOps, OldOps + OldNumUses, NewOps);
|
|
|
|
|
|
|
|
// If this is a Phi, then we need to copy the BB pointers too.
|
|
|
|
if (IsPhi) {
|
[NFC] Remove waymarking because it improves performances
Summary:
This patch remove waymarking and replaces it with storing a pointer to the User in the Use.
here are the results on the measurements for the CTMark tests of the test suite.
```
Metric: instructions_count
Program baseline patched diff
test-suite :: CTMark/ClamAV/clamscan.test 72557942065 71733653521 -1.1%
test-suite :: CTMark/sqlite3/sqlite3.test 76281422939 75484840636 -1.0%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 51364676366 50862185614 -1.0%
test-suite :: CTMark/SPASS/SPASS.test 60476106505 59908437767 -0.9%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 112578442329 111725050856 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 50846133013 50473644539 -0.7%
test-suite :: CTMark/kimwitu++/kc.test 54692641250 54349070299 -0.6%
test-suite :: CTMark/7zip/7zip-benchmark.test 182216614747 181216091230 -0.5%
test-suite :: CTMark/Bullet/bullet.test 123459210616 122905866767 -0.4%
Geomean difference -0.8%
Metric: peak_memory_use
Program baseline patched diff
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 326864 338524 3.6%
test-suite :: CTMark/sqlite3/sqlite3.test 216412 221240 2.2%
test-suite :: CTMark/7zip/7zip-benchmark.test 11808284 12022604 1.8%
test-suite :: CTMark/Bullet/bullet.test 6831752 6945988 1.7%
test-suite :: CTMark/SPASS/SPASS.test 2682552 2721820 1.5%
test-suite :: CTMark/ClamAV/clamscan.test 5037256 5107936 1.4%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 2752728 2790768 1.4%
test-suite :: CTMark/mafft/pairlocalalign.test 1517676 1537244 1.3%
test-suite :: CTMark/kimwitu++/kc.test 1090748 1103448 1.2%
Geomean difference 1.8%
Metric: compile_time
Program baseline patched diff
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 14.71 14.38 -2.2%
test-suite :: CTMark/sqlite3/sqlite3.test 23.18 22.73 -2.0%
test-suite :: CTMark/7zip/7zip-benchmark.test 57.96 56.99 -1.7%
test-suite :: CTMark/ClamAV/clamscan.test 20.75 20.49 -1.2%
test-suite :: CTMark/kimwitu++/kc.test 18.35 18.15 -1.1%
test-suite :: CTMark/SPASS/SPASS.test 18.72 18.57 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 14.09 14.00 -0.6%
test-suite :: CTMark/Bullet/bullet.test 37.38 37.19 -0.5%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 33.81 33.76 -0.2%
Geomean difference -1.1%
```
i believe that it is worth trading +1.8% peak memory use for -1.1% compile time.
also this patch removes waymarking which simplifies the Use and User classes.
Reviewers: nikic, lattner
Reviewed By: lattner
Subscribers: russell.gallop, foad, ggreif, rriddle, ekatz, fhahn, lebedev.ri, mgorny, hiraditya, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77144
2020-04-17 10:53:01 +02:00
|
|
|
auto *OldPtr = reinterpret_cast<char *>(OldOps + OldNumUses);
|
|
|
|
auto *NewPtr = reinterpret_cast<char *>(NewOps + NewNumUses);
|
2015-06-11 00:38:41 +02:00
|
|
|
std::copy(OldPtr, OldPtr + (OldNumUses * sizeof(BasicBlock *)), NewPtr);
|
|
|
|
}
|
|
|
|
Use::zap(OldOps, OldOps + OldNumUses, true);
|
|
|
|
}
|
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
|
|
|
|
// This is a private struct used by `User` to track the co-allocated descriptor
|
|
|
|
// section.
|
|
|
|
struct DescriptorInfo {
|
|
|
|
intptr_t SizeInBytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
ArrayRef<const uint8_t> User::getDescriptor() const {
|
|
|
|
auto MutableARef = const_cast<User *>(this)->getDescriptor();
|
|
|
|
return {MutableARef.begin(), MutableARef.end()};
|
|
|
|
}
|
|
|
|
|
|
|
|
MutableArrayRef<uint8_t> User::getDescriptor() {
|
|
|
|
assert(HasDescriptor && "Don't call otherwise!");
|
|
|
|
assert(!HasHungOffUses && "Invariant!");
|
|
|
|
|
|
|
|
auto *DI = reinterpret_cast<DescriptorInfo *>(getIntrusiveOperands()) - 1;
|
|
|
|
assert(DI->SizeInBytes != 0 && "Should not have had a descriptor otherwise!");
|
|
|
|
|
|
|
|
return MutableArrayRef<uint8_t>(
|
|
|
|
reinterpret_cast<uint8_t *>(DI) - DI->SizeInBytes, DI->SizeInBytes);
|
|
|
|
}
|
|
|
|
|
2020-03-12 00:39:05 +01:00
|
|
|
bool User::isDroppable() const {
|
|
|
|
if (const auto *Intr = dyn_cast<IntrinsicInst>(this))
|
|
|
|
return Intr->getIntrinsicID() == Intrinsic::assume;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-16 09:10:57 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// User operator new Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
void *User::allocateFixedOperandUser(size_t Size, unsigned Us,
|
|
|
|
unsigned DescBytes) {
|
2015-06-12 19:48:10 +02:00
|
|
|
assert(Us < (1u << NumUserOperandsBits) && "Too many operands");
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
|
|
|
|
static_assert(sizeof(DescriptorInfo) % sizeof(void *) == 0, "Required below");
|
|
|
|
|
|
|
|
unsigned DescBytesToAllocate =
|
|
|
|
DescBytes == 0 ? 0 : (DescBytes + sizeof(DescriptorInfo));
|
|
|
|
assert(DescBytesToAllocate % sizeof(void *) == 0 &&
|
|
|
|
"We need this to satisfy alignment constraints for Uses");
|
|
|
|
|
|
|
|
uint8_t *Storage = static_cast<uint8_t *>(
|
|
|
|
::operator new(Size + sizeof(Use) * Us + DescBytesToAllocate));
|
|
|
|
Use *Start = reinterpret_cast<Use *>(Storage + DescBytesToAllocate);
|
2011-01-16 09:10:57 +01:00
|
|
|
Use *End = Start + Us;
|
|
|
|
User *Obj = reinterpret_cast<User*>(End);
|
2015-06-12 19:48:10 +02:00
|
|
|
Obj->NumUserOperands = Us;
|
2015-06-12 19:48:18 +02:00
|
|
|
Obj->HasHungOffUses = false;
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
Obj->HasDescriptor = DescBytes != 0;
|
[NFC] Remove waymarking because it improves performances
Summary:
This patch remove waymarking and replaces it with storing a pointer to the User in the Use.
here are the results on the measurements for the CTMark tests of the test suite.
```
Metric: instructions_count
Program baseline patched diff
test-suite :: CTMark/ClamAV/clamscan.test 72557942065 71733653521 -1.1%
test-suite :: CTMark/sqlite3/sqlite3.test 76281422939 75484840636 -1.0%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 51364676366 50862185614 -1.0%
test-suite :: CTMark/SPASS/SPASS.test 60476106505 59908437767 -0.9%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 112578442329 111725050856 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 50846133013 50473644539 -0.7%
test-suite :: CTMark/kimwitu++/kc.test 54692641250 54349070299 -0.6%
test-suite :: CTMark/7zip/7zip-benchmark.test 182216614747 181216091230 -0.5%
test-suite :: CTMark/Bullet/bullet.test 123459210616 122905866767 -0.4%
Geomean difference -0.8%
Metric: peak_memory_use
Program baseline patched diff
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 326864 338524 3.6%
test-suite :: CTMark/sqlite3/sqlite3.test 216412 221240 2.2%
test-suite :: CTMark/7zip/7zip-benchmark.test 11808284 12022604 1.8%
test-suite :: CTMark/Bullet/bullet.test 6831752 6945988 1.7%
test-suite :: CTMark/SPASS/SPASS.test 2682552 2721820 1.5%
test-suite :: CTMark/ClamAV/clamscan.test 5037256 5107936 1.4%
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 2752728 2790768 1.4%
test-suite :: CTMark/mafft/pairlocalalign.test 1517676 1537244 1.3%
test-suite :: CTMark/kimwitu++/kc.test 1090748 1103448 1.2%
Geomean difference 1.8%
Metric: compile_time
Program baseline patched diff
test-suite :: CTMark/consumer-typeset/consumer-typeset.test 14.71 14.38 -2.2%
test-suite :: CTMark/sqlite3/sqlite3.test 23.18 22.73 -2.0%
test-suite :: CTMark/7zip/7zip-benchmark.test 57.96 56.99 -1.7%
test-suite :: CTMark/ClamAV/clamscan.test 20.75 20.49 -1.2%
test-suite :: CTMark/kimwitu++/kc.test 18.35 18.15 -1.1%
test-suite :: CTMark/SPASS/SPASS.test 18.72 18.57 -0.8%
test-suite :: CTMark/mafft/pairlocalalign.test 14.09 14.00 -0.6%
test-suite :: CTMark/Bullet/bullet.test 37.38 37.19 -0.5%
test-suite :: CTMark/tramp3d-v4/tramp3d-v4.test 33.81 33.76 -0.2%
Geomean difference -1.1%
```
i believe that it is worth trading +1.8% peak memory use for -1.1% compile time.
also this patch removes waymarking which simplifies the Use and User classes.
Reviewers: nikic, lattner
Reviewed By: lattner
Subscribers: russell.gallop, foad, ggreif, rriddle, ekatz, fhahn, lebedev.ri, mgorny, hiraditya, george.burgess.iv, asbirlea, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77144
2020-04-17 10:53:01 +02:00
|
|
|
for (; Start != End; Start++)
|
|
|
|
new (Start) Use(Obj);
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
|
|
|
|
if (DescBytes != 0) {
|
|
|
|
auto *DescInfo = reinterpret_cast<DescriptorInfo *>(Storage + DescBytes);
|
|
|
|
DescInfo->SizeInBytes = DescBytes;
|
|
|
|
}
|
|
|
|
|
2011-01-16 09:10:57 +01:00
|
|
|
return Obj;
|
|
|
|
}
|
|
|
|
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
void *User::operator new(size_t Size, unsigned Us) {
|
|
|
|
return allocateFixedOperandUser(Size, Us, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *User::operator new(size_t Size, unsigned Us, unsigned DescBytes) {
|
|
|
|
return allocateFixedOperandUser(Size, Us, DescBytes);
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:48:14 +02:00
|
|
|
void *User::operator new(size_t Size) {
|
2015-06-12 19:48:18 +02:00
|
|
|
// Allocate space for a single Use*
|
|
|
|
void *Storage = ::operator new(Size + sizeof(Use *));
|
|
|
|
Use **HungOffOperandList = static_cast<Use **>(Storage);
|
|
|
|
User *Obj = reinterpret_cast<User *>(HungOffOperandList + 1);
|
2015-06-12 19:48:14 +02:00
|
|
|
Obj->NumUserOperands = 0;
|
2015-06-12 19:48:18 +02:00
|
|
|
Obj->HasHungOffUses = true;
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
Obj->HasDescriptor = false;
|
2015-06-12 19:48:18 +02:00
|
|
|
*HungOffOperandList = nullptr;
|
2015-06-12 19:48:14 +02:00
|
|
|
return Obj;
|
|
|
|
}
|
|
|
|
|
2011-01-16 09:10:57 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// User operator delete Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-11-22 19:58:26 +01:00
|
|
|
// Repress memory sanitization, due to use-after-destroy by operator
|
|
|
|
// delete. Bug report 24578 identifies this issue.
|
|
|
|
LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE void User::operator delete(void *Usr) {
|
2015-06-12 19:48:18 +02:00
|
|
|
// Hung off uses use a single Use* before the User, while other subclasses
|
|
|
|
// use a Use[] allocated prior to the user.
|
|
|
|
User *Obj = static_cast<User *>(Usr);
|
|
|
|
if (Obj->HasHungOffUses) {
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
assert(!Obj->HasDescriptor && "not supported!");
|
|
|
|
|
2015-06-12 19:48:18 +02:00
|
|
|
Use **HungOffOperandList = static_cast<Use **>(Usr) - 1;
|
|
|
|
// drop the hung off uses.
|
|
|
|
Use::zap(*HungOffOperandList, *HungOffOperandList + Obj->NumUserOperands,
|
|
|
|
/* Delete */ true);
|
|
|
|
::operator delete(HungOffOperandList);
|
[IR] Teach `llvm::User` to co-allocate a descriptor.
Summary:
With this change, subclasses of `llvm::User` will be able to co-allocate
a variable number of bytes (called a "descriptor") with the `llvm::User`
instance. The co-allocated descriptor can later be accessed using
`llvm::User::getDescriptor`. This will be used in later changes to
implement operand bundles.
This change steals one bit from `NumUserOperands`, but given that it is
still 28 bits wide I don't think this will be a practical issue.
This change does not allow allocating hung off uses with descriptors.
This only for simplicity, not for any fundamental reason; and we can
easily add this functionality later if needed.
Reviewers: reames, chandlerc, dexonsmith, kmod, majnemer, pete, JosephTremoulet
Subscribers: pete, sanjoy, llvm-commits
Differential Revision: http://reviews.llvm.org/D12455
llvm-svn: 248453
2015-09-24 03:00:49 +02:00
|
|
|
} else if (Obj->HasDescriptor) {
|
|
|
|
Use *UseBegin = static_cast<Use *>(Usr) - Obj->NumUserOperands;
|
|
|
|
Use::zap(UseBegin, UseBegin + Obj->NumUserOperands, /* Delete */ false);
|
|
|
|
|
|
|
|
auto *DI = reinterpret_cast<DescriptorInfo *>(UseBegin) - 1;
|
|
|
|
uint8_t *Storage = reinterpret_cast<uint8_t *>(DI) - DI->SizeInBytes;
|
|
|
|
::operator delete(Storage);
|
2015-06-12 19:48:18 +02:00
|
|
|
} else {
|
|
|
|
Use *Storage = static_cast<Use *>(Usr) - Obj->NumUserOperands;
|
|
|
|
Use::zap(Storage, Storage + Obj->NumUserOperands,
|
|
|
|
/* Delete */ false);
|
|
|
|
::operator delete(Storage);
|
|
|
|
}
|
2011-01-16 09:10:57 +01:00
|
|
|
}
|
|
|
|
|
2020-06-25 18:48:29 +02:00
|
|
|
} // namespace llvm
|