source: icGREP/icgrep-devel/icgrep/kernels/grep_kernel.h @ 6173

Last change on this file since 6173 was 6147, checked in by xwa163, 13 months ago

Fix bug of multiplexing grep kernel cause by cacheable (Since two multiplexed RE with them same representation “mpx_1” may have different alphabets, while for now GrepKernel? use the string representation of RE AST as cache key)

File size: 4.9 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#ifndef GREP_KERNEL_H
6#define GREP_KERNEL_H
7
8#include <pablo/pablo_kernel.h>  // for PabloKernel
9#include <cc/alphabet.h>
10
11namespace IDISA { class IDISA_Builder; }
12namespace re { class RE; }
13namespace cc { class Alphabet; }
14namespace kernel {
15
16   
17class UnicodeNonFinalKernel : public pablo::PabloKernel {
18public:
19    UnicodeNonFinalKernel(const std::unique_ptr<kernel::KernelBuilder> & kb);
20    bool isCachable() const override { return true; }
21    bool hasSignature() const override { return false; }
22protected:
23    void generatePabloMethod() override;
24};
25
26class UnicodeLineBreakKernel : public pablo::PabloKernel {
27public:
28    UnicodeLineBreakKernel(const std::unique_ptr<kernel::KernelBuilder> & kb);
29    bool isCachable() const override { return true; }
30    bool hasSignature() const override { return false; }
31protected:
32    void generatePabloMethod() override;
33};
34
35class RequiredStreams_UTF8 : public pablo::PabloKernel {
36public:
37    RequiredStreams_UTF8(const std::unique_ptr<kernel::KernelBuilder> & kb);
38    bool isCachable() const override { return true; }
39    bool hasSignature() const override { return false; }
40protected:
41    void generatePabloMethod() override;
42};
43
44class RequiredStreams_UTF16 : public pablo::PabloKernel {
45public:
46    RequiredStreams_UTF16(const std::unique_ptr<kernel::KernelBuilder> & kb);
47    bool isCachable() const override { return true; }
48    bool hasSignature() const override { return false; }
49protected:
50    void generatePabloMethod() override;
51};
52
53
54struct ICGrepSignature {
55    ICGrepSignature(re::RE * re_ast);
56protected:
57    re::RE * const  mRE;
58    std::string     mSignature;
59};
60
61   
62class ICGrepKernel : public ICGrepSignature, public pablo::PabloKernel {
63public:
64    ICGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::RE * const re_ast, std::vector<std::string> externals, std::vector<cc::Alphabet *> alphabets = {}, cc::BitNumbering basisSetNumbering = cc::BitNumbering::LittleEndian);
65    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
66    bool isCachable() const override { return mIsCachable; }
67    void setCachable(bool c){mIsCachable = c;}
68protected:
69    void generatePabloMethod() override;
70    std::vector<std::string> mExternals;
71    std::vector<cc::Alphabet *> mAlphabets;
72    cc::BitNumbering mBasisSetNumbering;
73private:
74    bool mIsCachable;
75};
76
77struct ByteGrepSignature {
78    ByteGrepSignature(re::RE * re);
79protected:
80    re::RE * const  mRE;
81    std::string     mSignature;
82};
83
84
85class ByteGrepKernel : public ByteGrepSignature, public pablo::PabloKernel {
86public:
87    ByteGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::RE * const re, std::vector<std::string> externals = {});
88    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
89    bool isCachable() const override { return true; }
90protected:
91    void generatePabloMethod() override;
92    std::vector<std::string> mExternals;
93};
94   
95struct ByteBitGrepSignature {
96    ByteBitGrepSignature(re::RE * prefix, re::RE * suffix);
97protected:
98    re::RE * const  mPrefixRE;
99    re::RE * const  mSuffixRE;
100    std::string     mSignature;
101};
102
103   
104class ByteBitGrepKernel : public ByteBitGrepSignature, public pablo::PabloKernel {
105public:
106    ByteBitGrepKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, re::RE * const prefix, re::RE * const suffix, std::vector<std::string> externals = {});
107    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
108    bool isCachable() const override { return true; }
109protected:
110    void generatePabloMethod() override;
111    std::vector<std::string> mExternals;
112};
113
114class MatchedLinesKernel : public pablo::PabloKernel {
115public:
116    MatchedLinesKernel(const std::unique_ptr<kernel::KernelBuilder> & builder);
117    bool isCachable() const override { return true; }
118    bool hasSignature() const override { return false; }
119protected:
120    void generatePabloMethod() override;   
121};
122
123class InvertMatchesKernel : public BlockOrientedKernel {
124public:
125    InvertMatchesKernel(const std::unique_ptr<kernel::KernelBuilder> & builder);
126private:
127    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
128};
129
130class PopcountKernel : public pablo::PabloKernel {
131public:
132    PopcountKernel(const std::unique_ptr<kernel::KernelBuilder> & builder);
133    bool isCachable() const override { return true; }
134    bool hasSignature() const override { return false; }
135protected:
136    void generatePabloMethod() override;   
137};
138
139class AbortOnNull final : public MultiBlockKernel {
140public:
141    AbortOnNull(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
142private:
143    void generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & b, llvm::Value * const numOfStrides) final;
144   
145};
146
147}
148#endif
Note: See TracBrowser for help on using the repository browser.