Changeset 4274 for icGREP


Ignore:
Timestamp:
Oct 28, 2014, 4:16:05 PM (5 years ago)
Author:
nmedfort
Message:

Potential fix for AVX2 support in LLVM 3.5

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

Legend:

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

    r4273 r4274  
    1818#include <stdexcept>
    1919#include <include/simd-lib/bitblock.hpp>
     20
     21#ifdef USE_LLVM_3_4
     22#include <llvm/Analysis/Verifier.h>
     23#include <llvm/Assembly/PrintModulePass.h>
     24#include <llvm/Linker.h>
     25#endif
     26#ifdef USE_LLVM_3_5
     27#include <llvm/IR/Verifier.h>
     28#endif
     29
     30#include <llvm/Pass.h>
     31#include <llvm/PassManager.h>
     32#include <llvm/ADT/SmallVector.h>
     33#include <llvm/Analysis/Passes.h>
     34#include <llvm/IR/BasicBlock.h>
     35#include <llvm/IR/CallingConv.h>
     36#include <llvm/IR/Constants.h>
     37#include <llvm/IR/DataLayout.h>
     38#include <llvm/IR/DerivedTypes.h>
     39#include <llvm/IR/Function.h>
     40#include <llvm/IR/GlobalVariable.h>
     41#include <llvm/IR/InlineAsm.h>
     42#include <llvm/IR/Instructions.h>
     43#include <llvm/IR/LLVMContext.h>
     44#include <llvm/IR/Module.h>
     45#include <llvm/Support/FormattedStream.h>
     46#include <llvm/Support/MathExtras.h>
     47#include <llvm/Support/Casting.h>
     48#include <llvm/Support/Debug.h>
     49#include <llvm/Support/TargetSelect.h>
     50#include <llvm/Support/Host.h>
     51#include <llvm/Transforms/Scalar.h>
     52#include <llvm/ExecutionEngine/ExecutionEngine.h>
     53#include <llvm/ExecutionEngine/MCJIT.h>
     54#include <llvm/IRReader/IRReader.h>
     55#include <llvm/Bitcode/ReaderWriter.h>
     56#include <llvm/Support/MemoryBuffer.h>
     57
     58#include <llvm/IR/IRBuilder.h>
    2059
    2160//#define DUMP_GENERATED_IR
     
    88127, mOneInitializer(ConstantVector::getAllOnesValue(mBitBlockType))
    89128, mFunctionType(nullptr)
    90 , mFunc_process_block(nullptr)
     129, mFunction(nullptr)
    91130, mBasisBitsAddr(nullptr)
    92131, mOutputAddrPtr(nullptr)
     
    95134    //Create the jit execution engine.up
    96135    InitializeNativeTarget();
    97 
    98136    InitializeNativeTargetAsmPrinter();
    99137    InitializeNativeTargetAsmParser();
    100 
    101138    DefineTypes();
    102139    DeclareFunctions();
     
    145182    mCarryQueueVector.resize(mCarryQueueSize);
    146183
    147     Function::arg_iterator args = mFunc_process_block->arg_begin();
     184    Function::arg_iterator args = mFunction->arg_begin();
    148185    mBasisBitsAddr = args++;
    149186    mBasisBitsAddr->setName("basis_bits");
     
    156193    mCarryQueueIdx = 0;
    157194    mNestingDepth = 0;
    158     mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunc_process_block,0);
     195    mBasicBlock = BasicBlock::Create(mMod->getContext(), "parabix_entry", mFunction,0);
    159196
    160197    //The basis bits structure
     
    191228    //Use the pass manager to run optimizations on the function.
    192229    FunctionPassManager fpm(mMod);
    193     std::string ErrStr;
    194 
    195     if (mMaxPabloWhileDepth == 0) {
    196       mExecutionEngine = EngineBuilder(mMod).setUseMCJIT(true).setErrorStr(&ErrStr).setOptLevel(CodeGenOpt::Level::None).create();
    197     }
    198     else {
    199       mExecutionEngine = EngineBuilder(mMod).setUseMCJIT(true).setErrorStr(&ErrStr).setOptLevel(CodeGenOpt::Level::Less).create();
    200     }
    201     if (mExecutionEngine == nullptr) {
    202         throw std::runtime_error("Could not create ExecutionEngine: " + ErrStr);
    203     }
    204 
    205 
     230    if (true) {
     231        std::string errMessage;
     232        EngineBuilder builder(mMod);
     233        builder.setErrorStr(&errMessage);
     234        builder.setMCPU(sys::getHostCPUName());
     235        builder.setUseMCJIT(true);
     236        builder.setOptLevel(mMaxPabloWhileDepth == 0 ? CodeGenOpt::Level::None : CodeGenOpt::Level::Less);
     237        mExecutionEngine = builder.create();
     238        if (mExecutionEngine == nullptr) {
     239            throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
     240        }
     241    }
    206242#ifdef USE_LLVM_3_5
    207243    mMod->setDataLayout(mExecutionEngine->getDataLayout());
     
    217253    //fpm.add(createBasicAliasAnalysisPass());      //Provide basic AliasAnalysis support for GVN. (Global Value Numbering)
    218254    //fpm.add(createCFGSimplificationPass());       //Simplify the control flow graph.
     255
     256    fpm.add(createCorrelatedValuePropagationPass());
     257    fpm.add(createEarlyCSEPass());
    219258    fpm.add(createInstructionCombiningPass());    //Simple peephole optimizations and bit-twiddling.
    220259    fpm.add(createReassociatePass());             //Reassociate expressions.
    221     fpm.add(createGVNPass());                     //Eliminate common subexpressions.
    222 
     260    fpm.add(createGVNPass());                     //Eliminate common subexpressions.   
     261
     262
     263    // -O1 is based on -O0
     264
     265    // adds: -adce -always-inline -basicaa -basiccg -correlated-propagation -deadargelim -dse -early-cse -functionattrs -globalopt -indvars
     266    // -inline-cost -instcombine -ipsccp -jump-threading -lazy-value-info -lcssa -licm -loop-deletion -loop-idiom -loop-rotate -loop-simplify
     267    // -loop-unroll -loop-unswitch -loops -lower-expect -memcpyopt -memdep -no-aa -notti -prune-eh -reassociate -scalar-evolution -sccp
     268    // -simplifycfg -sroa -strip-dead-prototypes -tailcallelim -tbaa
     269
     270/// no noticable impact on performance
     271
     272//    fpm.add(createConstantPropagationPass());
     273//    fpm.add(createDeadCodeEliminationPass());
     274//    fpm.add(createJumpThreadingPass());
     275//    fpm.add(createLoopIdiomPass());
     276//    fpm.add(createLoopRotatePass());
     277//    fpm.add(createLCSSAPass());
     278//    fpm.add(createLazyValueInfoPass());
     279//    fpm.add(createLowerExpectIntrinsicPass());
     280//    fpm.add(createLoopStrengthReducePass());
     281//    fpm.add(createLoopUnswitchPass());
     282//    fpm.add(createSCCPPass());
     283//    fpm.add(createLICMPass());
     284
     285/// hurt performance significantly
     286
     287//    fpm.add(createLoopUnrollPass());
     288//    fpm.add(createIndVarSimplifyPass());
    223289    fpm.doInitialization();
    224290
    225     fpm.run(*mFunc_process_block);
     291    fpm.run(*mFunction);
    226292
    227293#ifdef DUMP_OPTIMIZED_IR
     
    233299    //Return the required size of the carry queue and a pointer to the process_block function.
    234300    retVal.carry_q_size = mCarryQueueSize;
    235     retVal.process_block_fptr = mExecutionEngine->getPointerToFunction(mFunc_process_block);
     301    retVal.process_block_fptr = mExecutionEngine->getPointerToFunction(mFunction);
    236302
    237303    return retVal;
     
    362428
    363429    //Create the function that will be generated.
    364     mFunc_process_block = mMod->getFunction("process_block");
    365     if (!mFunc_process_block) {
    366         mFunc_process_block = Function::Create(
     430    mFunction = mMod->getFunction("process_block");
     431    if (!mFunction) {
     432        mFunction = Function::Create(
    367433            /*Type=*/mFunctionType,
    368434            /*Linkage=*/GlobalValue::ExternalLinkage,
    369435            /*Name=*/"process_block", mMod);
    370         mFunc_process_block->setCallingConv(CallingConv::C);
    371     }
    372     mFunc_process_block->setAttributes(AttrSet);
     436        mFunction->setCallingConv(CallingConv::C);
     437    }
     438    mFunction->setAttributes(AttrSet);
    373439}
    374440
     
    516582    {
    517583        BasicBlock * ifEntryBlock = mBasicBlock;
    518         BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunc_process_block, 0);
    519         BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunc_process_block, 0);
     584        BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
     585        BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
    520586
    521587        int if_start_idx = mCarryQueueIdx;
     
    594660        mCarryQueueIdx = baseCarryQueueIdx;
    595661
    596         BasicBlock* whileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunc_process_block, 0);
    597         BasicBlock* whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunc_process_block, 0);
    598         BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
     662        BasicBlock* whileCondBlock = BasicBlock::Create(mMod->getContext(), "while.cond", mFunction, 0);
     663        BasicBlock* whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
     664        BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
    599665
    600666        // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. It
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4273 r4274  
    1515#include <pablo/pabloAST.h>
    1616#include "unicode_categories.h"
    17 #include <iostream>
    1817#include <string>
    1918#include <list>
    2019#include <map>
    2120#include <algorithm>
     21#include <llvm/ADT/Twine.h>
    2222
    23 #include <llvm/Support/raw_ostream.h>
    24 
    25 #ifdef USE_LLVM_3_4
    26 #include <llvm/Analysis/Verifier.h>
    27 #include <llvm/Assembly/PrintModulePass.h>
    28 #include <llvm/Linker.h>
    29 #endif
    30 
    31 #ifdef USE_LLVM_3_5
    32 #include <llvm/IR/Verifier.h>
    33 #endif
    34 
    35 #include <llvm/Pass.h>
    36 #include <llvm/PassManager.h>
    37 #include <llvm/ADT/SmallVector.h>
    38 #include <llvm/Analysis/Passes.h>
    39 #include <llvm/IR/BasicBlock.h>
    40 #include <llvm/IR/CallingConv.h>
    41 #include <llvm/IR/Constants.h>
    42 #include <llvm/IR/DataLayout.h>
    43 #include <llvm/IR/DerivedTypes.h>
    44 #include <llvm/IR/Function.h>
    45 #include <llvm/IR/GlobalVariable.h>
    46 #include <llvm/IR/InlineAsm.h>
    47 #include <llvm/IR/Instructions.h>
    48 #include <llvm/IR/LLVMContext.h>
    49 #include <llvm/IR/Module.h>
    50 #include <llvm/Support/FormattedStream.h>
    51 #include <llvm/Support/MathExtras.h>
    52 #include <llvm/Support/Casting.h>
    53 #include <llvm/Support/Debug.h>
    54 
    55 #include <llvm/Support/TargetSelect.h>
    56 #include <llvm/Transforms/Scalar.h>
    57 
    58 #include <llvm/ExecutionEngine/ExecutionEngine.h>
    59 #include <llvm/ExecutionEngine/MCJIT.h>
    60 
    61 #include <llvm/IRReader/IRReader.h>
    62 #include <llvm/Bitcode/ReaderWriter.h>
    63 #include <llvm/Support/MemoryBuffer.h>
    64 
    65 #include <llvm/IR/IRBuilder.h>
     23namespace llvm {
     24    class Value;
     25    class Module;
     26    class ExecutionEngine;
     27    class VectorType;
     28    class PointerType;
     29    class ConstantAggregateZero;
     30    class Constant;
     31    class FunctionType;
     32    class Function;
     33}
    6634
    6735using namespace llvm;
     
    134102
    135103    FunctionType*                       mFunctionType;
    136     Function*                           mFunc_process_block;
     104    Function*                           mFunction;
    137105
    138106
Note: See TracChangeset for help on using the changeset viewer.