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

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

Changes towards separate compilation

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