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

Last change on this file since 4903 was 4898, checked in by cameron, 3 years ago

Add IRBuilder functionality to IDISA_Builder; eliminate separate mBuilder

File size: 3.8 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
19    class 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    virtual Value * simd_add(unsigned fw, Value * a, Value * b);
46    virtual Value * simd_sub(unsigned fw, Value * a, Value * b);
47    virtual Value * simd_mult(unsigned fw, Value * a, Value * b);
48    virtual Value * simd_eq(unsigned fw, Value * a, Value * b);
49    virtual Value * simd_gt(unsigned fw, Value * a, Value * b);
50    virtual Value * simd_ugt(unsigned fw, Value * a, Value * b);
51    virtual Value * simd_lt(unsigned fw, Value * a, Value * b);
52    virtual Value * simd_ult(unsigned fw, Value * a, Value * b);
53    virtual Value * simd_max(unsigned fw, Value * a, Value * b);
54    virtual Value * simd_umax(unsigned fw, Value * a, Value * b);
55    virtual Value * simd_min(unsigned fw, Value * a, Value * b);
56    virtual Value * simd_umin(unsigned fw, Value * a, Value * b);
57    virtual Value * simd_if(unsigned fw, Value * cond, Value * a, Value * b);
58   
59    virtual Value * simd_slli(unsigned fw, Value * a, unsigned shift);
60    virtual Value * simd_srli(unsigned fw, Value * a, unsigned shift);
61    virtual Value * simd_srai(unsigned fw, Value * a, unsigned shift);
62   
63    virtual Value * simd_cttz(unsigned fw, Value * a);
64    virtual Value * simd_popcount(unsigned fw, Value * a);
65   
66    virtual Value * esimd_mergeh(unsigned fw, Value * a, Value * b);
67    virtual Value * esimd_mergel(unsigned fw, Value * a, Value * b);
68    virtual Value * esimd_bitspread(unsigned fw, Value * bitmask);
69   
70    virtual Value * hsimd_packh(unsigned fw, Value * a, Value * b);
71    virtual Value * hsimd_packl(unsigned fw, Value * a, Value * b);
72    virtual Value * hsimd_signmask(unsigned fw, Value * a);
73
74   
75    virtual Value * mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex);
76    virtual Value * mvmd_insert(unsigned fw, Value * blk, Value * elt, unsigned fieldIndex);
77    virtual Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
78   
79    virtual Value * bitblock_any(Value * a);
80    Value * simd_and(Value * a, Value * b);
81    Value * simd_or(Value * a, Value * b);
82    Value * simd_xor(Value * a, Value * b);
83    Value * simd_not(Value * a);
84    Value * fwCast(unsigned fw, Value * a);
85   
86protected:
87    Module * mMod;
88    Type * mBitBlockType;
89    unsigned mBitBlockWidth;
90    Constant * mZeroInitializer;
91    Constant * mOneInitializer;
92    Constant * mPrintRegisterFunction;
93   
94    VectorType * fwVectorType(unsigned fw);
95};
96
97}
98#endif // IDISA_BUILDER_H
Note: See TracBrowser for help on using the repository browser.