source: icGREP/icgrep-devel/icgrep/kernels/match_count.cpp @ 5440

Last change on this file since 5440 was 5440, checked in by nmedfort, 2 years ago

Large refactoring step. Removed IR generation code from Kernel (formally KernelBuilder?) and moved it into the new KernelBuilder? class.

File size: 1.4 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "match_count.h"
7#include <kernels/kernel_builder.h>
8
9using namespace llvm;
10
11namespace kernel {
12
13MatchCount::MatchCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder)
14    : BlockOrientedKernel("matchCount",
15                        {Binding{iBuilder->getStreamSetTy(1, 1), "matches"}}, {}, {}, {Binding{iBuilder->getSizeTy(), "matchedLineCount"}}, {}) {
16    }
17
18void MatchCount::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
19
20    const unsigned counterSize = iBuilder->getSizeTy()->getBitWidth();
21    Value * to_count = iBuilder->loadInputStreamBlock("matches", iBuilder->getInt32(0));
22    Value * count = iBuilder->getScalarField("matchedLineCount");
23   
24    Value * value = nullptr;
25    Value * const partial = iBuilder->simd_popcount(counterSize, to_count);
26    if (LLVM_UNLIKELY(counterSize <= 1)) {
27        value = partial;
28    } else {
29        value = iBuilder->mvmd_extract(counterSize, partial, 0);
30        const auto fields = (iBuilder->getBitBlockWidth() / counterSize);
31        for (unsigned i = 1; i < fields; ++i) {
32            Value * temp = iBuilder->mvmd_extract(counterSize, partial, i);
33            value = iBuilder->CreateAdd(value, temp);
34        }
35    }
36    value = iBuilder->CreateAdd(value, count);
37    iBuilder->setScalarField("matchedLineCount", value);
38}
39
40
41}
Note: See TracBrowser for help on using the repository browser.