source: icGREP/icgrep-devel/icgrep/kernels/charclasses.cpp @ 5564

Last change on this file since 5564 was 5564, checked in by xuedongx, 21 months ago

add some of the kernels multiplex CCs need

File size: 2.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 "charclasses.h"
7#include <boost/uuid/sha1.hpp>
8#include <re/re_toolchain.h>
9#include <pablo/pablo_toolchain.h>
10#include <kernels/kernel_builder.h>
11#include <pablo/builder.hpp>
12#include <pablo/pe_count.h>
13#include <UCD/resolve_properties.h>
14#include <UCD/ucd_compiler.hpp>
15#include <re/re_cc.h>
16#include <cc/cc_compiler.h>
17#include <re/re_name.h>
18#include <llvm/Support/raw_ostream.h>
19
20using NameMap = UCD::UCDCompiler::NameMap;
21
22using namespace cc;
23using namespace kernel;
24using namespace pablo;
25using namespace re;
26using namespace llvm;
27using namespace UCD;
28
29CharClassesKernel::CharClassesKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<UCD::UnicodeSet> multiplexedCCs)
30: PabloKernel(iBuilder,
31              "cc",
32              {Binding{iBuilder->getStreamSetTy(8), "basis"}},
33              {Binding{iBuilder->getStreamSetTy(multiplexedCCs.size(), 1), "charclasses"}}) 
34, mMultiplexedCCs(multiplexedCCs) {
35
36}
37
38void CharClassesKernel::generatePabloMethod() {
39    CC_Compiler ccc(this, getInput(0));
40    auto & pb = ccc.getBuilder();
41    unsigned n = mMultiplexedCCs.size();
42
43    NameMap nameMap;
44    std::vector<Name *> names;
45    for (unsigned i = 0; i < n; i++) {
46        Name * name = re::makeName("cc" + std::to_string(i), makeCC(std::move(mMultiplexedCCs[i])));
47        nameMap.emplace(name, nullptr);
48        names.push_back(name);
49    }
50
51    UCD::UCDCompiler ucdCompiler(ccc);
52    if (LLVM_UNLIKELY(AlgorithmOptionIsSet(DisableIfHierarchy))) {
53        ucdCompiler.generateWithoutIfHierarchy(nameMap, pb);
54    } else {
55        ucdCompiler.generateWithDefaultIfHierarchy(nameMap, pb);
56    }
57
58    // The first UnicodeSet in the vector multiplexedCCs represents the last bit of the character class basis bit streams.
59    std::reverse(names.begin(), names.end());
60    for (unsigned i = 0; i < names.size(); i++) {
61        auto t = nameMap.find(names[i]); 
62        if (t != nameMap.end()) {
63            PabloAST * const r = pb.createExtract(getOutput(0), pb.getInteger(i));
64            if (t->first->getType() == Name::Type::Byte) {
65                pb.createAssign(r, ccc.compileCC(dyn_cast<CC>(t->first->getDefinition())));
66            } else {
67                pb.createAssign(r, t->second);
68            }
69        } else {
70          throw std::runtime_error("Can't compile character classes.");
71        }
72    }
73}
74
75
Note: See TracBrowser for help on using the repository browser.