SPIRV-Tools/source/util/bit_vector.cpp
Steven Perron d42f65e7c1 Use a bit vector in ADCE
The unordered_set in ADCE that holds all of the live instructions takes
a very long time to be destroyed.  In some shaders, it takes over 40% of
the time.

If we look at the unique ids of the live instructions, I believe they
are dense enough make a simple bit vector a good choice for to hold that
data.  When I check the density of the bit vector for larger shaders, we
are usually using less than 4 bytes per element in the vector, and
almost always less than 16.

So, in this commit, I introduce a simple bit vector class, and
use it in ADCE.

This help improve the compile time for some shaders on windows by the
40% mentioned above.

Contributes to https://github.com/KhronosGroup/SPIRV-Tools/issues/1328.
2018-04-13 16:38:02 -04:00

41 lines
1.1 KiB
C++

// Copyright (c) 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "bit_vector.h"
#include <iostream>
namespace spvtools {
namespace utils {
void BitVector::ReportDensity(std::ostream& out) {
uint32_t count = 0;
for (BitContainer e : bits_) {
while (e != 0) {
if ((e & 1) != 0) {
++count;
}
e = e >> 1;
}
}
out << "count=" << count
<< ", total size (bytes)=" << bits_.size() * sizeof(BitContainer)
<< ", bytes per element="
<< (double)(bits_.size() * sizeof(BitContainer)) / (double)(count);
}
} // namespace utils
} // namespace spvtools