Changeset 5137


Ignore:
Timestamp:
Aug 29, 2016, 3:37:03 PM (3 years ago)
Author:
cameron
Message:

Some clean ups of encoding info for ccc restructuring.

Location:
icGREP/icgrep-devel/icgrep
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r5037 r5137  
    66
    77#include "cc_compiler.h"
    8 #include "utf_encoding.h"
    98
    109//Pablo Expressions
     
    2726namespace cc {
    2827
    29 CC_Compiler::CC_Compiler(PabloFunction & function, const Encoding & encoding, const std::string prefix)
     28CC_Compiler::CC_Compiler(PabloFunction & function, const unsigned encodingBits, const std::string prefix)
    3029: mBuilder(function.getEntryBlock())
    31 , mBasisBit(encoding.getBits())
    32 , mEncoding(encoding) {
    33     for (unsigned i = 0; i != encoding.getBits(); i++) {
     30, mBasisBit(encodingBits)
     31, mEncodingBits(encodingBits) {
     32    for (unsigned i = 0; i != mEncodingBits; i++) {
    3433        Var * var = mBuilder.createVar(prefix + std::to_string(i));
    3534        function.setParameter(i, var);
    3635        mBasisBit[i] = var;
    3736    }
     37    mEncodingMask = (static_cast<unsigned>(1) << encodingBits) - static_cast<unsigned>(1);
    3838}
    3939
     
    5353        return pb.createZeroes();
    5454    }
    55 #ifdef CC_COMPILER_ENFORCES_INFILE
    56     bool includes_codepoint_zero = lo_codepoint(cc->begin()) == 0;
    57 #endif
    5855    if (cc->size() > 2) {
    5956        bool combine = true;
     
    7572                codepoint_t lo = lo_codepoint(cc->front());
    7673                codepoint_t hi = lo_codepoint(cc->back());
    77                 const codepoint_t mask = mEncoding.getMask();
    78                 lo &= (mask - 1);
    79                 hi |= (mask ^ (mask - 1));
     74                lo &= (mEncodingMask - 1);
     75                hi |= (mEncodingMask ^ (mEncodingMask - 1));
    8076                PabloAST * expr = make_range(lo, hi, pb);
    8177                PabloAST * bit0 = getBasisVar(0);
     
    9288        expr = (expr == nullptr) ? temp : pb.createOr(expr, temp);
    9389    }
    94 #ifdef CC_COMPILER_ENFORCES_INFILE
    95     if (includes_codepoint_zero) {
    96         return pb.createInFile(expr);
    97     }
    98     else {
    99         return expr;
    100     }
    101 #else
    10290    return expr;
    103 #endif
    10491   
    10592}
     
    146133template<typename PabloBlockOrBuilder>
    147134inline PabloAST * CC_Compiler::char_test_expr(const codepoint_t ch, PabloBlockOrBuilder &pb) {
    148     return bit_pattern_expr(ch, mEncoding.getMask(), pb);
     135    return bit_pattern_expr(ch, mEncodingMask, pb);
    149136}
    150137
     
    155142    for (codepoint_t diff_bits = n1 ^ n2; diff_bits; diff_count++, diff_bits >>= 1);
    156143
    157     if ((n2 < n1) || (diff_count > mEncoding.getBits()))
     144    if ((n2 < n1) || (diff_count > mEncodingBits))
    158145    {
    159146        throw std::runtime_error("Bad Range: [" + std::to_string(n1) + "," + std::to_string(n2) + "]");
     
    162149    const codepoint_t mask0 = (static_cast<codepoint_t>(1) << diff_count) - 1;
    163150
    164     PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncoding.getMask() ^ mask0, pb);
     151    PabloAST * common = bit_pattern_expr(n1 & ~mask0, mEncodingMask ^ mask0, pb);
    165152
    166153    if (diff_count == 0) return common;
     
    238225
    239226inline Var * CC_Compiler::getBasisVar(const unsigned i) const {
    240     assert (i < mEncoding.getBits());
    241     return mBasisBit[mEncoding.getBits() - i - 1];
     227    assert (i < mEncodingBits);
     228    return mBasisBit[mEncodingBits - i - 1];
    242229}
    243230
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.h

    r5046 r5137  
    1010#include <re/re_cc.h>
    1111#include <pablo/builder.hpp>
    12 #include "utf_encoding.h"
    1312#include <string>
    1413
     
    2726    using Vars = std::vector<pablo::Var *>;
    2827
    29     CC_Compiler(pablo::PabloFunction & function, const Encoding & encoding, const std::string prefix = "basis");
     28    CC_Compiler(pablo::PabloFunction & function, const unsigned encodingBits = 8, const std::string prefix = "basis");
    3029
    3130    pablo::Assign * compileCC(const re::CC *cc);
     
    4645
    4746    bool isUTF_16() {
    48         return mEncoding.getBits() == 16;
     47        return mEncodingBits == 16;
    4948    }
    5049
     
    6867    pablo::PabloBuilder         mBuilder;
    6968    std::vector<pablo::Var *>   mBasisBit;
    70     const Encoding &            mEncoding;
     69    const unsigned              mEncodingBits;
     70    unsigned                    mEncodingMask;
    7171};
    7272
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5136 r5137  
    1414#include <pablo/pablo_toolchain.h>
    1515#include <toolchain.h>
    16 #include <utf_encoding.h>
    1716#include <pablo/pablo_compiler.h>
    1817#include <kernels/pipeline.h>
     
    130129    const unsigned bufferSegments = codegen::BufferSegments;
    131130
    132     Encoding::Type type;
    133     type = UTF_16 ? Encoding::Type::UTF_16 : Encoding::Type::UTF_8;
    134     unsigned bits;
    135     bits = UTF_16 ? 16 : 8;
    136 
    137     Encoding encoding(type, bits);
     131    unsigned encodingBits = UTF_16 ? 16 : 8;
     132
    138133    mIsNameExpression = isNameExpression;
    139134
     
    164159    s2pk.generateKernel({&ByteStream}, {&BasisBits});
    165160
    166     re_ast = re::regular_expression_passes(encoding, re_ast);   
    167     pablo::PabloFunction * function = re::re2pablo_compiler(encoding, re_ast, CountOnly);
     161    re_ast = re::regular_expression_passes(re_ast);   
     162    pablo::PabloFunction * function = re::re2pablo_compiler(encodingBits, re_ast, CountOnly);
    168163    pablo_function_passes(function);
    169164
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5135 r5137  
    77#include <toolchain.h>
    88#include "pipeline.h"
    9 #include "utf_encoding.h"
    109
    1110#include <IDISA/idisa_builder.h>
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5134 r5137  
    4343namespace re {
    4444
    45 void RE_Compiler::initializeRequiredStreams(Encoding encoding) {
    46     if (encoding.getType() == Encoding::Type::UTF_8) {
     45void RE_Compiler::initializeRequiredStreams(const unsigned encodingBits) {
     46    if (encodingBits == 8) {
    4747      RE_Compiler::initializeRequiredStreams_utf8();
    4848    }
    49     else if (encoding.getType() == Encoding::Type::UTF_16) {
     49    else if (encodingBits == 16) {
    5050      RE_Compiler::initializeRequiredStreams_utf16();
    5151    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r5134 r5137  
    5353
    5454    RE_Compiler(pablo::PabloFunction & function, cc::CC_Compiler & ccCompiler, bool CountOnly = false);
    55     void initializeRequiredStreams(Encoding encoding);
     55    void initializeRequiredStreams(const unsigned encodingBits);
    5656    void compileUnicodeNames(RE *& re);
    5757    void finalizeMatchResult(MarkerType match_result, bool InvertMatches = false);
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5134 r5137  
    6363
    6464
    65 RE * regular_expression_passes(const Encoding encoding, RE * re_ast)  {
     65RE * regular_expression_passes(RE * re_ast)  {
    6666    if (PrintOptions.isSet(PrintAllREs) || PrintOptions.isSet(PrintParsedREs)) {
    6767        std::cerr << "Parser:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     
    8686}
    8787   
    88 PabloFunction * re2pablo_compiler(const Encoding encoding, RE * re_ast, bool CountOnly) {
    89     PabloFunction * function = PabloFunction::Create("process_block", encoding.getBits(), CountOnly ? 0 : 2);
    90     cc::CC_Compiler cc_compiler(*function, encoding);
     88PabloFunction * re2pablo_compiler(const unsigned encodingBits, RE * re_ast, bool CountOnly) {
     89    PabloFunction * function = PabloFunction::Create("process_block", encodingBits, CountOnly ? 0 : 2);
     90    cc::CC_Compiler cc_compiler(*function, encodingBits);
    9191    re::RE_Compiler re_compiler(*function, cc_compiler, CountOnly);
    92     re_compiler.initializeRequiredStreams(encoding);
     92    re_compiler.initializeRequiredStreams(encodingBits);
    9393    re_compiler.compileUnicodeNames(re_ast);
    9494    re_compiler.finalizeMatchResult(re_compiler.compile(re_ast), AlgorithmOptions.isSet(InvertMatches));
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.h

    r5134 r5137  
    77#ifndef RE_TOOLCHAIN_H
    88#define RE_TOOLCHAIN_H
    9 
    10 #include "utf_encoding.h"
    119
    1210#include <re/re_re.h>
     
    3129const cl::OptionCategory * re_toolchain_flags();
    3230
    33 RE * regular_expression_passes(const Encoding encoding, RE * re_ast);
     31RE * regular_expression_passes(RE * re_ast);
    3432
    35 pablo::PabloFunction * re2pablo_compiler(const Encoding encoding, RE * re_ast, bool CountOnly = false);
     33pablo::PabloFunction * re2pablo_compiler(const unsigned encodingBits, RE * re_ast, bool CountOnly = false);
    3634   
    3735}
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5133 r5137  
    3636#include <kernels/stdout_kernel.h>
    3737
    38 #include <utf_encoding.h>
    3938
    4039// mmap system
     
    5352namespace pablo {
    5453
    55 PabloFunction * u8u16_pablo(const Encoding encoding) {
     54PabloFunction * u8u16_pablo() {
    5655    //  input: 8 basis bit streams
    5756    //  output: 16 u8-indexed streams, + delmask stream + error stream
    5857    PabloFunction * function = PabloFunction::Create("u8u16", 8, 18);
    59     cc::CC_Compiler ccc(*function, encoding);
     58    cc::CC_Compiler ccc(*function);
    6059   
    6160    PabloBuilder pBuilder(ccc.getBuilder().getPabloBlock(), ccc.getBuilder());
     
    295294    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    296295
    297     Encoding encoding(Encoding::Type::UTF_8, 8);
    298     pablo::PabloFunction * function = pablo::u8u16_pablo(encoding);
     296    pablo::PabloFunction * function = pablo::u8u16_pablo();
    299297   
    300298    llvm::Function * main_IR = u8u16Pipeline(M, idb, function);
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5133 r5137  
    2323#include <llvm/Support/raw_ostream.h>
    2424
    25 #include <utf_encoding.h>
    2625#include <re/re_cc.h>
    2726#include <cc/cc_compiler.h>
     
    3837#include <pablo/pablo_compiler.h>
    3938#include <pablo/pablo_toolchain.h>
    40 
    41 
    42 #include <utf_encoding.h>
    4339
    4440// mmap system
     
    10197//
    10298
    103 pablo::PabloFunction * wc_gen(Encoding encoding) {
     99pablo::PabloFunction * wc_gen() {
    104100    //  input: 8 basis bit streams
    105101    //  output: 3 counters
    106102   
    107103    pablo::PabloFunction * function = pablo::PabloFunction::Create("wc", 8, 0);
    108     cc::CC_Compiler ccc(*function, encoding);
     104    cc::CC_Compiler ccc(*function);
    109105   
    110106    pablo::PabloBuilder pBuilder(ccc.getBuilder().getPabloBlock(), ccc.getBuilder());
     
    209205    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    210206
    211     Encoding encoding(Encoding::Type::UTF_8, 8);
    212     pablo::PabloFunction * function = wc_gen(encoding);
     207    pablo::PabloFunction * function = wc_gen();
    213208    llvm::Function * main_IR = wcPipeline(M, idb, function);
    214209
Note: See TracChangeset for help on using the changeset viewer.