Ignore:
Timestamp:
Jan 14, 2017, 3:49:56 PM (3 years ago)
Author:
nmedfort
Message:

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5245 r5260  
    77 *  icgrep is a trademark of International Characters.
    88 */
    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 #include <llvm/Support/Host.h>
    15 #include <llvm/ADT/Triple.h>
    16 #include <IR_Gen/CBuilder.h>
     9#include "CBuilder.h"
     10#include <llvm/IR/DerivedTypes.h>
    1711#include <IR_Gen/types/streamtype.h>
    1812#include <boost/container/flat_map.hpp>
    19 
    20 using namespace llvm;
     13namespace llvm { class Constant; }
     14namespace llvm { class LoadInst; }
     15namespace llvm { class Module; }
     16namespace llvm { class Type; }
     17namespace llvm { class Value; }
    2118
    2219namespace IDISA {
     
    2825public:
    2926
    30     IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, unsigned CacheAlignment=64);
     27    IDISA_Builder(llvm::Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, unsigned CacheAlignment=64);
    3128
    3229    virtual ~IDISA_Builder();
     
    3431    std::string getBitBlockTypeName() const;  // A short string such as v4i64 or i256.
    3532
    36     Value * bitCast(Value * a) {
     33    llvm::Value * bitCast(llvm::Value * a) {
    3734        return (a->getType() == mBitBlockType) ? a : CreateBitCast(a, mBitBlockType);
    3835    }
     
    4643    }
    4744
    48     Constant * allZeroes() const {
     45    llvm::Constant * allZeroes() const {
    4946        return mZeroInitializer;
    5047    }
    5148
    52     Constant * allOnes() const {
     49    llvm::Constant * allOnes() const {
    5350        return mOneInitializer;
    5451    }
    5552   
    5653
    57     LoadInst * CreateBlockAlignedLoad(Value * const ptr);
    58     LoadInst * CreateBlockAlignedLoad(Value * const ptr, Value * const index);
    59     LoadInst * CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indices);
     54    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr);
     55    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index);
     56    llvm::LoadInst * CreateBlockAlignedLoad(llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices);
    6057
    61     void CreateBlockAlignedStore(Value * const value, Value * const ptr);
    62     void CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index);
    63     void CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indices);
     58    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr);
     59    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, llvm::Value * const index);
     60    void CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices);
    6461
    65     VectorType * fwVectorType(unsigned fw);
     62    llvm::VectorType * fwVectorType(unsigned fw);
    6663
    67     Constant * simd_himask(unsigned fw);
    68     Constant * simd_lomask(unsigned fw);
     64    llvm::Constant * simd_himask(unsigned fw);
     65    llvm::Constant * simd_lomask(unsigned fw);
    6966   
    70     virtual Value * simd_fill(unsigned fw, Value * a);
     67    virtual llvm::Value * simd_fill(unsigned fw, llvm::Value * a);
    7168
    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);
     69    virtual llvm::Value * simd_add(unsigned fw, llvm::Value * a, llvm::Value * b);
     70    virtual llvm::Value * simd_sub(unsigned fw, llvm::Value * a, llvm::Value * b);
     71    virtual llvm::Value * simd_mult(unsigned fw, llvm::Value * a, llvm::Value * b);
     72    virtual llvm::Value * simd_eq(unsigned fw, llvm::Value * a, llvm::Value * b);
     73    virtual llvm::Value * simd_gt(unsigned fw, llvm::Value * a, llvm::Value * b);
     74    virtual llvm::Value * simd_ugt(unsigned fw, llvm::Value * a, llvm::Value * b);
     75    virtual llvm::Value * simd_lt(unsigned fw, llvm::Value * a, llvm::Value * b);
     76    virtual llvm::Value * simd_ult(unsigned fw, llvm::Value * a, llvm::Value * b);
     77    virtual llvm::Value * simd_max(unsigned fw, llvm::Value * a, llvm::Value * b);
     78    virtual llvm::Value * simd_umax(unsigned fw, llvm::Value * a, llvm::Value * b);
     79    virtual llvm::Value * simd_min(unsigned fw, llvm::Value * a, llvm::Value * b);
     80    virtual llvm::Value * simd_umin(unsigned fw, llvm::Value * a, llvm::Value * b);
     81    virtual llvm::Value * simd_if(unsigned fw, llvm::Value * cond, llvm::Value * a, llvm::Value * b);
    8582   
    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);
     83    virtual llvm::Value * simd_slli(unsigned fw, llvm::Value * a, unsigned shift);
     84    virtual llvm::Value * simd_srli(unsigned fw, llvm::Value * a, unsigned shift);
     85    virtual llvm::Value * simd_srai(unsigned fw, llvm::Value * a, unsigned shift);
    8986   
    90     virtual Value * simd_cttz(unsigned fw, Value * a);
    91     virtual Value * simd_popcount(unsigned fw, Value * a);
     87    virtual llvm::Value * simd_cttz(unsigned fw, llvm::Value * a);
     88    virtual llvm::Value * simd_popcount(unsigned fw, llvm::Value * a);
    9289   
    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);
     90    virtual llvm::Value * esimd_mergeh(unsigned fw, llvm::Value * a, llvm::Value * b);
     91    virtual llvm::Value * esimd_mergel(unsigned fw, llvm::Value * a, llvm::Value * b);
     92    virtual llvm::Value * esimd_bitspread(unsigned fw, llvm::Value * bitmask);
    9693   
    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);
     94    virtual llvm::Value * hsimd_packh(unsigned fw, llvm::Value * a, llvm::Value * b);
     95    virtual llvm::Value * hsimd_packl(unsigned fw, llvm::Value * a, llvm::Value * b);
     96    virtual llvm::Value * hsimd_packh_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b);
     97    virtual llvm::Value * hsimd_packl_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b);
    10198
    102     virtual Value * hsimd_signmask(unsigned fw, Value * a);
     99    virtual llvm::Value * hsimd_signmask(unsigned fw, llvm::Value * a);
    103100   
    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_slli(unsigned fw, Value * a, unsigned shift);
    107     virtual Value * mvmd_srli(unsigned fw, Value * a, unsigned shift);
    108     virtual Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
     101    virtual llvm::Value * mvmd_extract(unsigned fw, llvm::Value * a, unsigned fieldIndex);
     102    virtual llvm::Value * mvmd_insert(unsigned fw, llvm::Value * blk, llvm::Value * elt, unsigned fieldIndex);
     103    virtual llvm::Value * mvmd_slli(unsigned fw, llvm::Value * a, unsigned shift);
     104    virtual llvm::Value * mvmd_srli(unsigned fw, llvm::Value * a, unsigned shift);
     105    virtual llvm::Value * mvmd_dslli(unsigned fw, llvm::Value * a, llvm::Value * b, unsigned shift);
    109106   
    110107   
    111     virtual Value * bitblock_any(Value * a);
     108    virtual llvm::Value * bitblock_any(llvm::Value * a);
    112109    // full add producing {carryout, sum}
    113     virtual std::pair<Value *, Value *> bitblock_add_with_carry(Value * a, Value * b, Value * carryin);
     110    virtual std::pair<llvm::Value *, llvm::Value *> bitblock_add_with_carry(llvm::Value * a, llvm::Value * b, llvm::Value * carryin);
    114111    // full shift producing {shiftout, shifted}
    115     virtual std::pair<Value *, Value *> bitblock_advance(Value * a, Value * shiftin, unsigned shift);
    116     virtual Value * bitblock_mask_from(Value * pos);
    117     virtual Value * bitblock_set_bit(Value * pos);
     112    virtual std::pair<llvm::Value *, llvm::Value *> bitblock_advance(llvm::Value * a, llvm::Value * shiftin, unsigned shift);
     113    virtual llvm::Value * bitblock_mask_from(llvm::Value * pos);
     114    virtual llvm::Value * bitblock_set_bit(llvm::Value * pos);
    118115   
    119     Value * simd_and(Value * a, Value * b);
    120     Value * simd_or(Value * a, Value * b);
    121     Value * simd_xor(Value * a, Value * b);
    122     Value * simd_not(Value * a);
    123     Value * fwCast(unsigned fw, Value * a);
     116    llvm::Value * simd_and(llvm::Value * a, llvm::Value * b);
     117    llvm::Value * simd_or(llvm::Value * a, llvm::Value * b);
     118    llvm::Value * simd_xor(llvm::Value * a, llvm::Value * b);
     119    llvm::Value * simd_not(llvm::Value * a);
     120    llvm::Value * fwCast(unsigned fw, llvm::Value * a);
    124121   
    125     inline VectorType * getBitBlockType() const {
     122    inline llvm::VectorType * getBitBlockType() const {
    126123        return mBitBlockType;
    127124    }
    128125
    129     inline Type * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
    130         return ArrayType::get(getStreamTy(FieldWidth), NumElements);
     126    inline llvm::ArrayType * getStreamSetTy(const unsigned NumElements = 1, const unsigned FieldWidth = 1) {
     127        return llvm::ArrayType::get(getStreamTy(FieldWidth), NumElements);
    131128    }
    132129   
    133     Type * getStreamTy(const unsigned FieldWidth = 1);
     130    StreamType * getStreamTy(const unsigned FieldWidth = 1);
    134131
    135     void CallPrintRegister(const std::string & regName, Value * const value);
     132    void CallPrintRegister(const std::string & regName, llvm::Value * const value);
    136133   
    137134protected:
    138135    unsigned            mBitBlockWidth;
    139136    unsigned            mStride;
    140     VectorType *        mBitBlockType;
     137    llvm::VectorType *  mBitBlockType;
    141138
    142     Constant *          mZeroInitializer;
    143     Constant *          mOneInitializer;
    144     Constant *          mPrintRegisterFunction;
     139    llvm::Constant *    mZeroInitializer;
     140    llvm::Constant *    mOneInitializer;
     141    llvm::Constant *    mPrintRegisterFunction;
    145142    StreamTypes         mStreamTypes;
    146143};
    147144
    148 inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr) {
     145inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr) {
    149146    return CreateAlignedLoad(ptr, mBitBlockWidth / 8);
    150147}
    151148
    152 inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, Value * const index) {
     149inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index) {
    153150    return CreateBlockAlignedLoad(CreateGEP(ptr, index));
    154151}
    155152
    156 inline LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr, std::initializer_list<Value *> indices) {
     153inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices) {
    157154    return CreateBlockAlignedLoad(CreateGEP(ptr, indices));
    158155}
    159156
    160 inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr) {
     157inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr) {
    161158    CreateAlignedStore(value, ptr, mBitBlockWidth / 8);
    162159}
    163160
    164 inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, Value * const index) {
     161inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, llvm::Value * const index) {
    165162    CreateBlockAlignedStore(value, CreateGEP(ptr, index));
    166163}
    167164
    168 inline void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr, std::initializer_list<Value *> indices) {
     165inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices) {
    169166    CreateBlockAlignedStore(value, CreateGEP(ptr, indices));
    170167}
Note: See TracChangeset for help on using the changeset viewer.