Changeset 4240


Ignore:
Timestamp:
Oct 15, 2014, 10:07:10 AM (5 years ago)
Author:
nmedfort
Message:

Intergrated Meng's uadd with overflow patch; untested for now. Minor misc changes to Pablo Compiler.

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4237 r4240  
    1515#include <pablo/printer_pablos.h>
    1616#include <stdexcept>
     17#include <include/simd-lib/bitblock.hpp>
    1718
    1819// #define DUMP_GENERATED_IR
     
    7879, mBasicBlock(nullptr)
    7980, mExecutionEngine(nullptr)
    80 , mXi64Vect(nullptr)
    81 , mXi128Vect(nullptr)
     81, mXi64Vect(VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64))
     82, mXi128Vect(VectorType::get(IntegerType::get(mMod->getContext(), 128), BLOCK_SIZE / 128))
    8283, mBasisBitsInputPtr(nullptr)
    8384, mOutputPtr(nullptr)
     
    8586, mptr_carry_q(nullptr)
    8687, mCarryQueueSize(0)
    87 , mConst_int64_neg1(nullptr)
    88 , mZeroInitializer(nullptr)
    89 , mAllOneInitializer(nullptr)
     88, mZeroInitializer(ConstantAggregateZero::get(mXi64Vect))
     89, mAllOneInitializer(ConstantVector::getAllOnesValue(mXi64Vect))
    9090, mFuncTy_0(nullptr)
    9191, mFunc_process_block(nullptr)
     
    238238void PabloCompiler::DefineTypes()
    239239{
    240     //The BitBlock vector.
    241     mXi64Vect = VectorType::get(IntegerType::get(mMod->getContext(), 64), BLOCK_SIZE / 64);
    242     mXi128Vect = VectorType::get(IntegerType::get(mMod->getContext(), 128), BLOCK_SIZE / 128);
    243 
    244     //Constant definitions.
    245     mConst_int64_neg1 = ConstantInt::get(mMod->getContext(), APInt(64, -1));
    246     mZeroInitializer = ConstantAggregateZero::get(mXi64Vect);
    247 
    248     std::vector<Constant*> const_packed_27_elems;
    249     for (int i = 0; i < BLOCK_SIZE / 64; ++i) {
    250         const_packed_27_elems.push_back(mConst_int64_neg1);
    251     }
    252     mAllOneInitializer = ConstantVector::get(const_packed_27_elems);
    253 
    254 
    255240    StructType * StructTy_struct_Basis_bits = mMod->getTypeByName("struct.Basis_bits");
    256241    if (StructTy_struct_Basis_bits == nullptr) {
     
    262247        StructTy_struct_Basis_bits_fields.push_back(mXi64Vect);
    263248    }
    264 
    265 
    266 
    267 
    268249    if (StructTy_struct_Basis_bits->isOpaque()) {
    269250        StructTy_struct_Basis_bits->setBody(StructTy_struct_Basis_bits_fields, /*isPacked=*/false);
     
    308289
    309290#ifdef USE_UADD_OVERFLOW
    310     // Type Definitions for llvm.uadd.with.overflow.i128 or .i256
     291    // Type Definitions for llvm.uadd.with.overflow.carryin.i128 or .i256
    311292    std::vector<Type*>StructTy_0_fields;
    312293    StructTy_0_fields.push_back(IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     
    317298    FuncTy_1_args.push_back(IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    318299    FuncTy_1_args.push_back(IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     300    FuncTy_1_args.push_back(IntegerType::get(mMod->getContext(), 1));
    319301    FunctionType* FuncTy_1 = FunctionType::get(
    320302                                              /*Result=*/StructTy_0,
     
    322304                                              /*isVarArg=*/false);
    323305
    324     mFunc_llvm_uadd_with_overflow = mMod->getFunction("llvm.uadd.with.overflow.i" + std::to_string(BLOCK_SIZE));
     306    mFunc_llvm_uadd_with_overflow = mMod->getFunction("llvm.uadd.with.overflow.carryin.i##BLOCK_SIZE");
    325307    if (!mFunc_llvm_uadd_with_overflow) {
    326308        mFunc_llvm_uadd_with_overflow = Function::Create(
    327           /*Type=*/FuncTy_1,
    328           /*Linkage=*/GlobalValue::ExternalLinkage,
    329           /*Name=*/"llvm.uadd.with.overflow.i" + std::to_string(BLOCK_SIZE), mMod); // (external, no body)
     309          /*Type=*/ FuncTy_1,
     310          /*Linkage=*/ GlobalValue::ExternalLinkage,
     311          /*Name=*/ "llvm.uadd.with.overflow.carryin.i##BLOCK_SIZE", mMod); // (external, no body)
    330312        mFunc_llvm_uadd_with_overflow->setCallingConv(CallingConv::C);
    331313    }
     
    526508}
    527509
    528 Value * PabloCompiler::compileStatement(PabloE * stmt)
     510Value * PabloCompiler::compileStatement(const PabloE * stmt)
    529511{
    530512    Value * retVal = nullptr;
     
    643625}
    644626
    645 Value * PabloCompiler::compileExpression(PabloE * expr)
     627Value * PabloCompiler::compileExpression(const PabloE * expr)
    646628{
    647629    Value * retVal = nullptr;
     
    720702
    721703#ifdef USE_UADD_OVERFLOW
    722 SumWithOverflowPack LLVM_Generator::callUaddOverflow(Value* int128_e1, Value* int128_e2) {
     704SumWithOverflowPack PabloCompiler::callUaddOverflow(Value* int128_e1, Value* int128_e2, Value* int1_cin) {
    723705    std::vector<Value*> struct_res_params;
    724706    struct_res_params.push_back(int128_e1);
    725707    struct_res_params.push_back(int128_e2);
     708    struct_res_params.push_back(int1_cin);
    726709    CallInst* struct_res = CallInst::Create(mFunc_llvm_uadd_with_overflow, struct_res_params, "uadd_overflow_res", mBasicBlock);
    727710    struct_res->setCallingConv(CallingConv::C);
     
    748731
    749732    //CarryQ - carry in.
    750     int this_carry_idx = mCarryQueueIdx;
    751     mCarryQueueIdx++;
    752 
     733    int this_carry_idx = mCarryQueueIdx++;
    753734    Value* carryq_value = genCarryInLoad(mptr_carry_q, this_carry_idx);
    754735
    755736#ifdef USE_UADD_OVERFLOW
    756737    //use llvm.uadd.with.overflow.i128 or i256
    757 
     738    ConstantInt* const_int32_6 = ConstantInt::get(mMod->getContext(), APInt(32, StringRef("0"), 10));
    758739    CastInst* int128_e1 = new BitCastInst(e1, IntegerType::get(mMod->getContext(), BLOCK_SIZE), "e1_128", mBasicBlock);
    759740    CastInst* int128_e2 = new BitCastInst(e2, IntegerType::get(mMod->getContext(), BLOCK_SIZE), "e2_128", mBasicBlock);
    760     CastInst* int128_carryq_value = new BitCastInst(carryq_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE), "carryq_128", mBasicBlock);
    761 
    762     SumWithOverflowPack sumpack0, sumpack1;
    763 
    764     sumpack0 = callUaddOverflow(int128_e1, int128_e2);
    765     sumpack1 = callUaddOverflow(sumpack0.sum, int128_carryq_value);
    766 
    767     Value* obit = b.CreateOr(sumpack0.obit, sumpack1.obit, "carry_bit");
    768     Value* ret_sum = b.CreateBitCast(sumpack1.sum, mXi64Vect, "ret_sum");
    769 
     741    ExtractElementInst * int64_carryq_value = ExtractElementInst::Create(carryq_value, const_int32_6, "carryq_64", mBasicBlock);
     742    CastInst* int1_carryq_value = new TruncInst(int64_carryq_value, IntegerType::get(mMod->getContext(), 1), "carryq_1", mBasicBlock);
     743    SumWithOverflowPack sumpack0;
     744    sumpack0 = callUaddOverflow(int128_e1, int128_e2, int1_carryq_value);
     745    Value* obit = sumpack0.obit;
     746    Value* sum = b.CreateBitCast(sumpack0.sum, mXi64Vect, "sum");
    770747    /*obit is the i1 carryout, zero extend and insert it into a v2i64 or v4i64 vector.*/
    771748    ConstantAggregateZero* const_packed_5 = ConstantAggregateZero::get(mXi64Vect);
    772     ConstantInt* const_int32_6 = ConstantInt::get(mMod->getContext(), APInt(32, StringRef("0"), 10));
    773749    CastInst* int64_o0 = new ZExtInst(obit, IntegerType::get(mMod->getContext(), 64), "o0", mBasicBlock);
    774750    InsertElementInst* carry_out = InsertElementInst::Create(const_packed_5, int64_o0, const_int32_6, "carry_out", mBasicBlock);
    775 
    776     Value* void_1 = genCarryOutStore(carry_out, mptr_carry_q, this_carry_idx);
    777     return ret_sum;
    778751#else
    779752    //calculate carry through logical ops
     
    787760    Value* sum = b.CreateAdd(partial, mid_carry_in, "sum");
    788761    Value* carry_out = genShiftHighbitToLow(b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))), "carry_out");
    789     Value* void_1 = genCarryOutStore(carry_out, mptr_carry_q, this_carry_idx);
    790 
     762#endif
     763    genCarryOutStore(carry_out, mptr_carry_q, this_carry_idx);
    791764    return sum;
    792 #endif
    793765}
    794766
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4237 r4240  
    88#define PABLO_COMPILER_H
    99
    10 //define this indicates that we use llvm.uadd.with.overflow for genAddWithCarry
     10//indicates that we use llvm.uadd.with.overflow.carryin for genAddWithCarry
    1111//#define USE_UADD_OVERFLOW
    1212
     
    1515#include <pablo/pe_pabloe.h>
    1616#include "unicode_categories.h"
    17 //#include "unicode_categories-flat.h"
    18 //#include "unicode_categories-simple.h"
    1917#include <iostream>
    2018#include <string>
     
    6765#include <llvm/IR/IRBuilder.h>
    6866
    69 #include "include/simd-lib/bitblock.hpp"
    70 
    7167using namespace llvm;
    7268
     
    7975};
    8076
    81 struct SumWithOverflowPack {
    82   Value *sum;
    83   Value *obit;
    84 };
    85 
    8677class PabloCompiler {
     78    #ifdef USE_UADD_OVERFLOW
     79    struct SumWithOverflowPack {
     80        Value * sum;
     81        Value * obit;
     82    };
     83    #endif
    8784public:
    8885    PabloCompiler(std::map<std::string, std::string> name_map, std::string basis_pattern, int bits);
    8986    ~PabloCompiler();
    90 
    91 
    9287    LLVM_Gen_RetVal compile(const PabloBlock & cg_state);
    9388private:
     
    10095    void SetReturnMarker(Value * marker, const unsigned output_idx);
    10196
    102     Value * GetMarker(const std::string & name);
     97    Value* GetMarker(const std::string & name);
    10398
    104     Value * compileStatements(const ExpressionList & stmts);
    105     Value * compileStatement(PabloE *stmt);
     99    Value* compileStatements(const ExpressionList & stmts);
     100    Value* compileStatement(const PabloE * stmt);
    106101
    107     Value* compileExpression(PabloE * expr);
     102    Value* compileExpression(const PabloE * expr);
    108103    Value* genCarryInLoad(Value* ptr_carry_q, int carryq_idx);
    109104    Value* genCarryOutStore(Value* carryout, Value* ptr_carry_q, int carryq_idx);
     
    115110    Value* genNot(Value* e, const Twine &namehint = "");
    116111
    117     SumWithOverflowPack callUaddOverflow(Value *e1, Value *e2);
     112    #ifdef USE_UADD_OVERFLOW
     113    SumWithOverflowPack callUaddOverflow(Value *e1, Value *e2, Value *cin);
     114    #endif
    118115
    119116    std::map<std::string, Value*>       mCalleeMap;
     
    125122    std::string                         mBasisBitPattern;
    126123
    127 
    128 
    129     Module*                             mMod;
     124    Module* const                       mMod;
    130125    BasicBlock*                         mBasicBlock;
    131126    ExecutionEngine*                    mExecutionEngine;
    132127
    133     VectorType*                         mXi64Vect;
    134 
    135     VectorType*                         mXi128Vect;
    136 
     128    VectorType* const                   mXi64Vect;
     129    VectorType* const                   mXi128Vect;
    137130    PointerType*                        mBasisBitsInputPtr;
    138131    PointerType*                        mOutputPtr;
     
    143136    int                                 mCarryQueueSize;
    144137
    145     ConstantInt*                        mConst_int64_neg1;
    146     ConstantAggregateZero*              mZeroInitializer;
    147     Constant*                           mAllOneInitializer;
     138    ConstantAggregateZero* const        mZeroInitializer;
     139    Constant* const                     mAllOneInitializer;
    148140
    149141    FunctionType*                       mFuncTy_0;
Note: See TracChangeset for help on using the changeset viewer.