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

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

Added the kernel instance class; removed original mmap file access in favour of the boost mmap system. corrected PrintRegister? routine.

File size: 5.6 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)
23    : IRBuilder<>(m->getContext())
24    , mMod(m)
25    , mBitBlockType(bitBlockType)
26    , mBitBlockWidth(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth())
27    , mZeroInitializer(Constant::getNullValue(bitBlockType)) 
28    , mOneInitializer(Constant::getAllOnesValue(bitBlockType))
29    , mPrintRegisterFunction(nullptr) {
30
31    }
32
33    virtual ~IDISA_Builder() {}
34   
35    Type * getBitBlockType() const {
36        return mBitBlockType;
37    }
38
39    Value * bitCast(Value * a) {
40        return a->getType() == mBitBlockType ? a : CreateBitCast(a, mBitBlockType);
41    }
42
43    unsigned getBitBlockWidth() const {
44        return mBitBlockWidth;
45    }
46
47    Module * getModule() const {
48        return mMod;
49    }
50   
51    Constant * allZeroes() const {
52        return mZeroInitializer;
53    }
54
55    Constant * allOnes() const {
56        return mOneInitializer;
57    }
58
59    LoadInst * CreateBlockAlignedLoad(Value * const ptr);
60    LoadInst * CreateBlockAlignedLoad(Value * const ptr, Value * const index);
61    LoadInst * CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indicies);
62
63    void CreateBlockAlignedStore(Value * const value, Value * const ptr);
64    void CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index);
65    void CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indicies);
66
67    void CallPrintRegister(const std::string & regName, Value * const value);
68
69    Constant * simd_himask(unsigned fw);
70    Constant * simd_lomask(unsigned fw);
71
72    virtual Value * simd_add(unsigned fw, Value * a, Value * b);
73    virtual Value * simd_sub(unsigned fw, Value * a, Value * b);
74    virtual Value * simd_mult(unsigned fw, Value * a, Value * b);
75    virtual Value * simd_eq(unsigned fw, Value * a, Value * b);
76    virtual Value * simd_gt(unsigned fw, Value * a, Value * b);
77    virtual Value * simd_ugt(unsigned fw, Value * a, Value * b);
78    virtual Value * simd_lt(unsigned fw, Value * a, Value * b);
79    virtual Value * simd_ult(unsigned fw, Value * a, Value * b);
80    virtual Value * simd_max(unsigned fw, Value * a, Value * b);
81    virtual Value * simd_umax(unsigned fw, Value * a, Value * b);
82    virtual Value * simd_min(unsigned fw, Value * a, Value * b);
83    virtual Value * simd_umin(unsigned fw, Value * a, Value * b);
84    virtual Value * simd_if(unsigned fw, Value * cond, Value * a, Value * b);
85   
86    virtual Value * simd_slli(unsigned fw, Value * a, unsigned shift);
87    virtual Value * simd_srli(unsigned fw, Value * a, unsigned shift);
88    virtual Value * simd_srai(unsigned fw, Value * a, unsigned shift);
89   
90    virtual Value * simd_cttz(unsigned fw, Value * a);
91    virtual Value * simd_popcount(unsigned fw, Value * a);
92   
93    virtual Value * esimd_mergeh(unsigned fw, Value * a, Value * b);
94    virtual Value * esimd_mergel(unsigned fw, Value * a, Value * b);
95    virtual Value * esimd_bitspread(unsigned fw, Value * bitmask);
96   
97    virtual Value * hsimd_packh(unsigned fw, Value * a, Value * b);
98    virtual Value * hsimd_packl(unsigned fw, Value * a, Value * b);
99    virtual Value * hsimd_packh_in_lanes(unsigned lanes, unsigned fw, Value * a, Value * b);
100    virtual Value * hsimd_packl_in_lanes(unsigned lanes, unsigned fw, Value * a, Value * b);
101
102    virtual Value * hsimd_signmask(unsigned fw, Value * a);
103   
104    virtual Value * mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex);
105    virtual Value * mvmd_insert(unsigned fw, Value * blk, Value * elt, unsigned fieldIndex);
106    virtual Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
107   
108    virtual Value * bitblock_any(Value * a);
109    Value * simd_and(Value * a, Value * b);
110    Value * simd_or(Value * a, Value * b);
111    Value * simd_xor(Value * a, Value * b);
112    Value * simd_not(Value * a);
113    Value * fwCast(unsigned fw, Value * a);
114   
115protected:
116    Module * mMod;
117    Type * mBitBlockType;
118    unsigned mBitBlockWidth;
119    Constant * mZeroInitializer;
120    Constant * mOneInitializer;
121    Constant * mPrintRegisterFunction;
122   
123    VectorType * fwVectorType(unsigned fw);
124};
125
126inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr) {
127    return CreateAlignedLoad(ptr, mBitBlockWidth / 8);
128}
129
130inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, Value * const index) {
131    return CreateBlockAlignedLoad(CreateGEP(ptr, index));
132}
133
134inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indicies) {
135    return CreateBlockAlignedLoad(CreateGEP(ptr, indicies));
136}
137
138inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr) {
139    CreateAlignedStore(value, ptr, mBitBlockWidth / 8);
140}
141
142inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index) {
143    CreateBlockAlignedStore(value, CreateGEP(ptr, index));
144}
145
146inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indicies) {
147    CreateBlockAlignedStore(value, CreateGEP(ptr, indicies));
148}
149
150}
151#endif // IDISA_BUILDER_H
Note: See TracBrowser for help on using the repository browser.