mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 17:29:19 +00:00
Fix a performance problem in memcpyopt by removing a linear scan over ranges when inserting a new range. No functionality change intended. Patch by Anthony Pesch!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242843 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0a6b8b7be0
commit
f17fb8d947
@ -30,7 +30,7 @@
|
|||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include <list>
|
#include <algorithm>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#define DEBUG_TYPE "memcpyopt"
|
#define DEBUG_TYPE "memcpyopt"
|
||||||
@ -200,15 +200,14 @@ bool MemsetRange::isProfitableToUseMemset(const DataLayout &DL) const {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class MemsetRanges {
|
class MemsetRanges {
|
||||||
/// Ranges - A sorted list of the memset ranges. We use std::list here
|
/// Ranges - A sorted list of the memset ranges.
|
||||||
/// because each element is relatively large and expensive to copy.
|
SmallVector<MemsetRange, 8> Ranges;
|
||||||
std::list<MemsetRange> Ranges;
|
typedef SmallVectorImpl<MemsetRange>::iterator range_iterator;
|
||||||
typedef std::list<MemsetRange>::iterator range_iterator;
|
|
||||||
const DataLayout &DL;
|
const DataLayout &DL;
|
||||||
public:
|
public:
|
||||||
MemsetRanges(const DataLayout &DL) : DL(DL) {}
|
MemsetRanges(const DataLayout &DL) : DL(DL) {}
|
||||||
|
|
||||||
typedef std::list<MemsetRange>::const_iterator const_iterator;
|
typedef SmallVectorImpl<MemsetRange>::const_iterator const_iterator;
|
||||||
const_iterator begin() const { return Ranges.begin(); }
|
const_iterator begin() const { return Ranges.begin(); }
|
||||||
const_iterator end() const { return Ranges.end(); }
|
const_iterator end() const { return Ranges.end(); }
|
||||||
bool empty() const { return Ranges.empty(); }
|
bool empty() const { return Ranges.empty(); }
|
||||||
@ -243,23 +242,17 @@ public:
|
|||||||
/// addRange - Add a new store to the MemsetRanges data structure. This adds a
|
/// addRange - Add a new store to the MemsetRanges data structure. This adds a
|
||||||
/// new range for the specified store at the specified offset, merging into
|
/// new range for the specified store at the specified offset, merging into
|
||||||
/// existing ranges as appropriate.
|
/// existing ranges as appropriate.
|
||||||
///
|
|
||||||
/// Do a linear search of the ranges to see if this can be joined and/or to
|
|
||||||
/// find the insertion point in the list. We keep the ranges sorted for
|
|
||||||
/// simplicity here. This is a linear search of a linked list, which is ugly,
|
|
||||||
/// however the number of ranges is limited, so this won't get crazy slow.
|
|
||||||
void MemsetRanges::addRange(int64_t Start, int64_t Size, Value *Ptr,
|
void MemsetRanges::addRange(int64_t Start, int64_t Size, Value *Ptr,
|
||||||
unsigned Alignment, Instruction *Inst) {
|
unsigned Alignment, Instruction *Inst) {
|
||||||
int64_t End = Start+Size;
|
int64_t End = Start+Size;
|
||||||
range_iterator I = Ranges.begin(), E = Ranges.end();
|
|
||||||
|
|
||||||
while (I != E && Start > I->End)
|
range_iterator I = std::lower_bound(Ranges.begin(), Ranges.end(), Start,
|
||||||
++I;
|
[](const MemsetRange &LHS, int64_t RHS) { return LHS.End < RHS; });
|
||||||
|
|
||||||
// We now know that I == E, in which case we didn't find anything to merge
|
// We now know that I == E, in which case we didn't find anything to merge
|
||||||
// with, or that Start <= I->End. If End < I->Start or I == E, then we need
|
// with, or that Start <= I->End. If End < I->Start or I == E, then we need
|
||||||
// to insert a new range. Handle this now.
|
// to insert a new range. Handle this now.
|
||||||
if (I == E || End < I->Start) {
|
if (I == Ranges.end() || End < I->Start) {
|
||||||
MemsetRange &R = *Ranges.insert(I, MemsetRange());
|
MemsetRange &R = *Ranges.insert(I, MemsetRange());
|
||||||
R.Start = Start;
|
R.Start = Start;
|
||||||
R.End = End;
|
R.End = End;
|
||||||
@ -295,7 +288,7 @@ void MemsetRanges::addRange(int64_t Start, int64_t Size, Value *Ptr,
|
|||||||
if (End > I->End) {
|
if (End > I->End) {
|
||||||
I->End = End;
|
I->End = End;
|
||||||
range_iterator NextI = I;
|
range_iterator NextI = I;
|
||||||
while (++NextI != E && End >= NextI->Start) {
|
while (++NextI != Ranges.end() && End >= NextI->Start) {
|
||||||
// Merge the range in.
|
// Merge the range in.
|
||||||
I->TheStores.append(NextI->TheStores.begin(), NextI->TheStores.end());
|
I->TheStores.append(NextI->TheStores.begin(), NextI->TheStores.end());
|
||||||
if (NextI->End > I->End)
|
if (NextI->End > I->End)
|
||||||
|
Loading…
Reference in New Issue
Block a user