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

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

Some fixes for threading and kernel builder.

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    virtual Value * mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex);
85    virtual Value * mvmd_insert(unsigned fw, Value * blk, Value * elt, unsigned fieldIndex);
86    virtual Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
87   
88    virtual Value * bitblock_any(Value * a);
89    Value * simd_and(Value * a, Value * b);
90    Value * simd_or(Value * a, Value * b);
91    Value * simd_xor(Value * a, Value * b);
92    Value * simd_not(Value * a);
93    Value * fwCast(unsigned fw, Value * a);
94   
95protected:
96    Module * mMod;
97    Type * mBitBlockType;
98    unsigned mBitBlockWidth;
99    Constant * mZeroInitializer;
100    Constant * mOneInitializer;
101    Constant * mPrintRegisterFunction;
102   
103    VectorType * fwVectorType(unsigned fw);
104};
105
106inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr) {
107    return CreateAlignedLoad(ptr, mBitBlockWidth / 8);
108}
109
110inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, Value * const index) {
111    return CreateBlockAlignedLoad(CreateGEP(ptr, index));
112}
113
114inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indicies) {
115    return CreateBlockAlignedLoad(CreateGEP(ptr, indicies));
116}
117
118inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr) {
119    CreateAlignedStore(value, ptr, mBitBlockWidth / 8);
120}
121
122inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index) {
123    CreateBlockAlignedStore(value, CreateGEP(ptr, index));
124}
125
126inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indicies) {
127    CreateBlockAlignedStore(value, CreateGEP(ptr, indicies));
128}
129
130}
131#endif // IDISA_BUILDER_H
Note: See TracBrowser for help on using the repository browser.