source: icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h @ 5436

Last change on this file since 5436 was 5436, checked in by nmedfort, 2 years ago

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

File size: 7.0 KB
RevLine 
[4651]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 */
[5260]9#include "CBuilder.h"
10#include <llvm/IR/DerivedTypes.h>
11namespace llvm { class Constant; }
12namespace llvm { class LoadInst; }
13namespace llvm { class Module; }
14namespace llvm { class Value; }
[4651]15
16namespace IDISA {
17
[5239]18class IDISA_Builder : public CBuilder {
[5230]19
[4651]20public:
[4665]21
[5436]22    IDISA_Builder(llvm::LLVMContext & C, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride);
[4665]23
[5240]24    virtual ~IDISA_Builder();
[4821]25   
[5374]26    virtual std::string getBuilderUniqueName() = 0;  // A name uniquely identifying builder/bitBlockWidth/stride.
27   
[5260]28    llvm::Value * bitCast(llvm::Value * a) {
[5377]29        return CreateBitCast(a, mBitBlockType);
[4974]30    }
31
32    unsigned getBitBlockWidth() const {
33        return mBitBlockWidth;
34    }
35
[5126]36    unsigned getStride() const {
37        return mStride;
38    }
39
[5260]40    llvm::Constant * allZeroes() const {
[4974]41        return mZeroInitializer;
42    }
43
[5260]44    llvm::Constant * allOnes() const {
[4974]45        return mOneInitializer;
46    }
[5106]47   
[5260]48    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr);
49    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index);
50    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices);
[4974]51
[5260]52    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr);
53    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, llvm::Value * const index);
54    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices);
[4959]55
[5377]56    llvm::VectorType * fwVectorType(const unsigned fw);
[5220]57
[5260]58    llvm::Constant * simd_himask(unsigned fw);
59    llvm::Constant * simd_lomask(unsigned fw);
[5140]60   
[5260]61    virtual llvm::Value * simd_fill(unsigned fw, llvm::Value * a);
[4974]62
[5260]63    virtual llvm::Value * simd_add(unsigned fw, llvm::Value * a, llvm::Value * b);
64    virtual llvm::Value * simd_sub(unsigned fw, llvm::Value * a, llvm::Value * b);
65    virtual llvm::Value * simd_mult(unsigned fw, llvm::Value * a, llvm::Value * b);
66    virtual llvm::Value * simd_eq(unsigned fw, llvm::Value * a, llvm::Value * b);
67    virtual llvm::Value * simd_gt(unsigned fw, llvm::Value * a, llvm::Value * b);
68    virtual llvm::Value * simd_ugt(unsigned fw, llvm::Value * a, llvm::Value * b);
69    virtual llvm::Value * simd_lt(unsigned fw, llvm::Value * a, llvm::Value * b);
70    virtual llvm::Value * simd_ult(unsigned fw, llvm::Value * a, llvm::Value * b);
71    virtual llvm::Value * simd_max(unsigned fw, llvm::Value * a, llvm::Value * b);
72    virtual llvm::Value * simd_umax(unsigned fw, llvm::Value * a, llvm::Value * b);
73    virtual llvm::Value * simd_min(unsigned fw, llvm::Value * a, llvm::Value * b);
74    virtual llvm::Value * simd_umin(unsigned fw, llvm::Value * a, llvm::Value * b);
75    virtual llvm::Value * simd_if(unsigned fw, llvm::Value * cond, llvm::Value * a, llvm::Value * b);
[4651]76   
[5260]77    virtual llvm::Value * simd_slli(unsigned fw, llvm::Value * a, unsigned shift);
78    virtual llvm::Value * simd_srli(unsigned fw, llvm::Value * a, unsigned shift);
79    virtual llvm::Value * simd_srai(unsigned fw, llvm::Value * a, unsigned shift);
[4651]80   
[5260]81    virtual llvm::Value * simd_cttz(unsigned fw, llvm::Value * a);
82    virtual llvm::Value * simd_popcount(unsigned fw, llvm::Value * a);
[4651]83   
[5260]84    virtual llvm::Value * esimd_mergeh(unsigned fw, llvm::Value * a, llvm::Value * b);
85    virtual llvm::Value * esimd_mergel(unsigned fw, llvm::Value * a, llvm::Value * b);
86    virtual llvm::Value * esimd_bitspread(unsigned fw, llvm::Value * bitmask);
[4653]87   
[5260]88    virtual llvm::Value * hsimd_packh(unsigned fw, llvm::Value * a, llvm::Value * b);
89    virtual llvm::Value * hsimd_packl(unsigned fw, llvm::Value * a, llvm::Value * b);
90    virtual llvm::Value * hsimd_packh_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b);
91    virtual llvm::Value * hsimd_packl_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b);
[4957]92
[5260]93    virtual llvm::Value * hsimd_signmask(unsigned fw, llvm::Value * a);
[4697]94   
[5260]95    virtual llvm::Value * mvmd_extract(unsigned fw, llvm::Value * a, unsigned fieldIndex);
96    virtual llvm::Value * mvmd_insert(unsigned fw, llvm::Value * blk, llvm::Value * elt, unsigned fieldIndex);
97    virtual llvm::Value * mvmd_slli(unsigned fw, llvm::Value * a, unsigned shift);
98    virtual llvm::Value * mvmd_srli(unsigned fw, llvm::Value * a, unsigned shift);
99    virtual llvm::Value * mvmd_dslli(unsigned fw, llvm::Value * a, llvm::Value * b, unsigned shift);
[4662]100   
[5114]101   
[5260]102    virtual llvm::Value * bitblock_any(llvm::Value * a);
[5114]103    // full add producing {carryout, sum}
[5260]104    virtual std::pair<llvm::Value *, llvm::Value *> bitblock_add_with_carry(llvm::Value * a, llvm::Value * b, llvm::Value * carryin);
[5114]105    // full shift producing {shiftout, shifted}
[5260]106    virtual std::pair<llvm::Value *, llvm::Value *> bitblock_advance(llvm::Value * a, llvm::Value * shiftin, unsigned shift);
107    virtual llvm::Value * bitblock_mask_from(llvm::Value * pos);
108    virtual llvm::Value * bitblock_set_bit(llvm::Value * pos);
[5114]109   
[5260]110    llvm::Value * simd_and(llvm::Value * a, llvm::Value * b);
111    llvm::Value * simd_or(llvm::Value * a, llvm::Value * b);
112    llvm::Value * simd_xor(llvm::Value * a, llvm::Value * b);
113    llvm::Value * simd_not(llvm::Value * a);
114    llvm::Value * fwCast(unsigned fw, llvm::Value * a);
[4837]115   
[5260]116    inline llvm::VectorType * getBitBlockType() const {
[5217]117        return mBitBlockType;
[5204]118    }
[5217]119
[5298]120    llvm::VectorType * getStreamTy(const unsigned FieldWidth = 1) {
121        return llvm::VectorType::get(llvm::IntegerType::getIntNTy(getContext(), FieldWidth), 0);
122    }
[5230]123
[5307]124    inline llvm::ArrayType * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
125        return llvm::ArrayType::get(getStreamTy(FieldWidth), NumElements);
126    }
127
[5260]128    void CallPrintRegister(const std::string & regName, llvm::Value * const value);
[5435]129
130protected:
[5436]131    const unsigned              mBitBlockWidth;
132    const unsigned              mStride;
133    llvm::VectorType * const    mBitBlockType;
134    llvm::Constant * const      mZeroInitializer;
135    llvm::Constant * const      mOneInitializer;
[5398]136
[5436]137    llvm::Constant *            mPrintRegisterFunction;
[4651]138};
139
[5260]140inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index) {
[4959]141    return CreateBlockAlignedLoad(CreateGEP(ptr, index));
142}
143
[5260]144inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices) {
[5239]145    return CreateBlockAlignedLoad(CreateGEP(ptr, indices));
[4959]146}
147
[5260]148inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, llvm::Value * const index) {
[4959]149    CreateBlockAlignedStore(value, CreateGEP(ptr, index));
150}
151
[5260]152inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices) {
[5239]153    CreateBlockAlignedStore(value, CreateGEP(ptr, indices));
[4959]154}
[5435]155
[4959]156}
[4651]157#endif // IDISA_BUILDER_H
Note: See TracBrowser for help on using the repository browser.