source: icGREP/icgrep-devel/icgrep/kernels/lz4_index_decoder.h @ 5805

Last change on this file since 5805 was 5755, checked in by nmedfort, 16 months ago

Bug fixes and simplified MultiBlockKernel? logic

File size: 4.3 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 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef LZ4_INDEX_DECODER_H
8#define LZ4_INDEX_DECODER_H
9
10#include <map>
11
12#include "kernel.h"
13
14namespace llvm {
15    class Module;
16    class Function;
17    class BasicBlock;
18    class Value;
19}
20namespace IDISA { class IDISA_Builder; }
21
22namespace kernel {
23
24class LZ4IndexDecoderKernel final : public BlockOrientedKernel {
25public:
26    LZ4IndexDecoderKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
27protected:
28    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder)override;
29private:
30
31    enum State : unsigned char {
32        AT_BLOCK_SIZE = 0,
33        AT_TOKEN = 1,
34        EXTENDING_LITERAL_LENGTH = 2,
35        AT_LITERALS = 3,
36        AT_FIRST_OFFSET = 4,
37        AT_SECOND_OFFSET = 5,
38        EXTENDING_MATCH_LENGTH = 6,
39        AT_BLOCK_CHECKSUM = 7,
40        SKIPPING_BYTES = 255,   // not included in the indirectbr table
41    };
42
43    const std::map<enum State, std::string> StateLabels = {
44        {State::AT_BLOCK_SIZE, "at_block_size"},
45        {State::AT_TOKEN, "at_token"},
46        {State::EXTENDING_LITERAL_LENGTH, "extending_literal_length"},
47        {State::AT_LITERALS, "at_literals"},
48        {State::AT_FIRST_OFFSET, "at_first_offset"},
49        {State::AT_SECOND_OFFSET, "at_second_offset"},
50        {State::EXTENDING_MATCH_LENGTH, "extending_match_length"},
51        {State::AT_BLOCK_CHECKSUM, "at_block_checksum"},
52        {State::SKIPPING_BYTES, "skipping_bytes"},
53    };
54
55    const size_t wordWidth;
56
57    // Some variables that are constant (at least in each bit block).
58    llvm::Value * blockStartPos;        // The global position of the start of the block.
59    llvm::Value * extenders;    // Bitcasted extender stream.
60 
61    // Stack variables (will be promoted by mem2reg).
62    llvm::Value * sOffset;      // offset within the current bit block
63    llvm::Value * sTempLength;  // tempLength have different purposes in different states.
64    llvm::Value * sTempCount;   // tempCount is used as a loop counter.
65    llvm::Value * sExtender;    // Current extender word.
66    llvm::Value * sState;
67
68    // Helper methods.
69    llvm::Value * getWordOffset(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
70    llvm::Value * getWordStartOffset(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
71    llvm::Value * loadRawByte(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * offset = nullptr);
72    void setExtenderUntilOffset(const std::unique_ptr<KernelBuilder> & iBuilder);
73    void loadCurrentExtender(const std::unique_ptr<KernelBuilder> & iBuilder);
74
75    void generateProduceOutput(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
76    void generateBoundaryDetection(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, State state, llvm::BasicBlock * exit_block, bool updateExtenderWord = false);
77    // Generate basic blocks for each state.
78    void generateSkippingBytes(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
79    void generateAtBlockSize(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * skippingBytes, llvm::BasicBlock * exit_block);
80    void generateAtToken(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
81    void generateExtendingLiteralLen(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
82    void generateAtLiterals(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb);
83    void generateAtFirstOffset(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
84    void generateAtSecondOffset(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
85    void generateExtendingMatchLen(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
86    void generateAtBlockChecksum(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::BasicBlock * bb, llvm::BasicBlock * skippingBytes);
87};
88
89}
90
91#endif // LZ4_INDEX_DECODER_H
Note: See TracBrowser for help on using the repository browser.