source: icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h @ 4959

Last change on this file since 4959 was 4959, checked in by nmedfort, 3 years ago

Initial modifications to Pablo Compiler and Kernel Builder to support circular buffers for Lookahead.

File size: 5.5 KB
Line 
1#ifndef IDISA_BUILDER_H
2#define IDISA_BUILDER_H
3
4/*
5 *  Copyright (c) 2015 International Characters.
6 *  This software is licensed to the public under the Open Software License 3.0.
7 *  icgrep is a trademark of International Characters.
8 */
9#include <llvm/IR/Module.h>
10#include <llvm/IR/Constant.h>
11#include <llvm/IR/Type.h>
12#include <llvm/IR/Value.h>
13#include <llvm/IR/IRBuilder.h>
14
15using namespace llvm;
16
17namespace IDISA {
18
19class IDISA_Builder : public IRBuilder<> {
20public:
21
22    IDISA_Builder(Module * m, Type * bitBlockType) : IRBuilder<>(m->getContext())
23    , mMod(m)
24    , mBitBlockType(bitBlockType)
25    , mBitBlockWidth(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth())
26    , mZeroInitializer(Constant::getNullValue(bitBlockType)) 
27    , mOneInitializer(Constant::getAllOnesValue(bitBlockType))
28    , mPrintRegisterFunction(nullptr) {
29
30    }
31    virtual ~IDISA_Builder() {}
32   
33    Type * getBitBlockType() { return mBitBlockType;}
34    Value * bitCast(Value * a) {return a->getType() == mBitBlockType ? a : CreateBitCast(a, mBitBlockType);}
35    int getBitBlockWidth() { return mBitBlockWidth;}
36    Module * getModule() {return mMod;}
37    void genPrintRegister(std::string regName, Value * bitblockValue);
38   
39   
40    Constant * allZeroes() {return mZeroInitializer;}
41    Constant * allOnes() {return mOneInitializer;}
42    Constant * simd_himask(unsigned fw);
43    Constant * simd_lomask(unsigned fw);
44       
45    LoadInst * CreateBlockAlignedLoad(Value * const ptr);
46    LoadInst * CreateBlockAlignedLoad(Value * const ptr, Value * const index);
47    LoadInst * CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indicies);
48    void CreateBlockAlignedStore(Value * const value, Value * const ptr);
49    void CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index);
50    void CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indicies);
51
52    virtual Value * simd_add(unsigned fw, Value * a, Value * b);
53    virtual Value * simd_sub(unsigned fw, Value * a, Value * b);
54    virtual Value * simd_mult(unsigned fw, Value * a, Value * b);
55    virtual Value * simd_eq(unsigned fw, Value * a, Value * b);
56    virtual Value * simd_gt(unsigned fw, Value * a, Value * b);
57    virtual Value * simd_ugt(unsigned fw, Value * a, Value * b);
58    virtual Value * simd_lt(unsigned fw, Value * a, Value * b);
59    virtual Value * simd_ult(unsigned fw, Value * a, Value * b);
60    virtual Value * simd_max(unsigned fw, Value * a, Value * b);
61    virtual Value * simd_umax(unsigned fw, Value * a, Value * b);
62    virtual Value * simd_min(unsigned fw, Value * a, Value * b);
63    virtual Value * simd_umin(unsigned fw, Value * a, Value * b);
64    virtual Value * simd_if(unsigned fw, Value * cond, Value * a, Value * b);
65   
66    virtual Value * simd_slli(unsigned fw, Value * a, unsigned shift);
67    virtual Value * simd_srli(unsigned fw, Value * a, unsigned shift);
68    virtual Value * simd_srai(unsigned fw, Value * a, unsigned shift);
69   
70    virtual Value * simd_cttz(unsigned fw, Value * a);
71    virtual Value * simd_popcount(unsigned fw, Value * a);
72   
73    virtual Value * esimd_mergeh(unsigned fw, Value * a, Value * b);
74    virtual Value * esimd_mergel(unsigned fw, Value * a, Value * b);
75    virtual Value * esimd_bitspread(unsigned fw, Value * bitmask);
76   
77    virtual Value * hsimd_packh(unsigned fw, Value * a, Value * b);
78    virtual Value * hsimd_packl(unsigned fw, Value * a, Value * b);
79    virtual Value * hsimd_packh_in_lanes(unsigned lanes, unsigned fw, Value * a, Value * b);
80    virtual Value * hsimd_packl_in_lanes(unsigned lanes, unsigned fw, Value * a, Value * b);
81
82    virtual Value * hsimd_signmask(unsigned fw, Value * a);
83
84   
85    virtual Value * mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex);
86    virtual Value * mvmd_insert(unsigned fw, Value * blk, Value * elt, unsigned fieldIndex);
87    virtual Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
88   
89    virtual Value * bitblock_any(Value * a);
90    Value * simd_and(Value * a, Value * b);
91    Value * simd_or(Value * a, Value * b);
92    Value * simd_xor(Value * a, Value * b);
93    Value * simd_not(Value * a);
94    Value * fwCast(unsigned fw, Value * a);
95   
96protected:
97    Module * mMod;
98    Type * mBitBlockType;
99    unsigned mBitBlockWidth;
100    Constant * mZeroInitializer;
101    Constant * mOneInitializer;
102    Constant * mPrintRegisterFunction;
103   
104    VectorType * fwVectorType(unsigned fw);
105};
106
107inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr) {
108    return CreateAlignedLoad(ptr, mBitBlockWidth / 8);
109}
110
111inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, Value * const index) {
112    return CreateBlockAlignedLoad(CreateGEP(ptr, index));
113}
114
115inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indicies) {
116    return CreateBlockAlignedLoad(CreateGEP(ptr, indicies));
117}
118
119inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr) {
120    CreateAlignedStore(value, ptr, mBitBlockWidth / 8);
121}
122
123inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index) {
124    CreateBlockAlignedStore(value, CreateGEP(ptr, index));
125}
126
127inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indicies) {
128    CreateBlockAlignedStore(value, CreateGEP(ptr, indicies));
129}
130
131}
132#endif // IDISA_BUILDER_H
Note: See TracBrowser for help on using the repository browser.