source: icGREP/icgrep-devel/icgrep/kernels/evenodd.cpp @ 5283

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

Optimized Symbol Generation (and fixed potential bug that could allow duplicate names being constructed); made PabloKernel? extend PabloAST (temporarily removed PabloAST::getName() to avoid diamond problem); added an internal scalar to PabloKernel? struct for each Count to avoid InOut? output scalar variable problem; allowed CodeMotionPass? to move code within the same scope but across a branch statement. Began work on separating Kernels into either Block-Oriented or Segment-Oriented kernels.

File size: 2.7 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "evenodd.h"
7#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
8#include <llvm/IR/Constant.h>      // for Constant
9#include <llvm/IR/Module.h>
10#include <llvm/IR/Function.h>
11#include <llvm/IR/Module.h>
12#include <llvm/ExecutionEngine/ExecutionEngine.h>
13#include "llvm/Linker/Linker.h"
14#include <llvm/Support/CommandLine.h>
15#include <llvm/Support/raw_ostream.h>
16namespace llvm { class BasicBlock; }
17namespace llvm { class Function; }
18namespace llvm { class Value; }
19
20using namespace llvm;
21
22namespace kernel {
23
24   
25void EvenOddKernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
26    Value * even = iBuilder->simd_fill(64, iBuilder->getInt64(0x5555555555555555));
27    Value * odd = iBuilder->bitCast(iBuilder->simd_fill(8, iBuilder->getInt8(0xAA)));
28    Value * evenBitsPtr = getStream(self, "even_odd", blockNo, iBuilder->getInt32(0));
29    iBuilder->CreateBlockAlignedStore(even, evenBitsPtr);
30    Value * oddBitsPtr = getStream(self, "even_odd", blockNo, iBuilder->getInt32(1));
31    iBuilder->CreateBlockAlignedStore(odd, oddBitsPtr);
32}
33
34void EvenOddKernel::generateDoBlockMethod() const {
35    auto savePoint = iBuilder->saveIP();
36
37    Function * doBlockFunction = iBuilder->getModule()->getFunction(mKernelName + doBlock_suffix);
38   
39    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction));
40   
41    Value * self = getParameter(doBlockFunction, "self");
42    Value * blockNo = getScalarField(self, blockNoScalar);
43   
44    generateDoBlockLogic(self, blockNo);
45
46    iBuilder->CreateRetVoid();
47    iBuilder->restoreIP(savePoint);
48}
49
50void EvenOddKernel::generateFinalBlockMethod() const {
51    auto savePoint = iBuilder->saveIP();
52    Module * m = iBuilder->getModule();
53    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
54    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
55   
56    Value * self = getParameter(finalBlockFunction, "self");
57    Value * remainingBytes = getParameter(finalBlockFunction, "remainingBytes");
58    Value * blockNo = getScalarField(self, blockNoScalar);
59    generateDoBlockLogic(self, blockNo);
60   
61    iBuilder->CreateRetVoid();
62    iBuilder->restoreIP(savePoint);
63}
64   
65
66
67EvenOddKernel::EvenOddKernel(IDISA::IDISA_Builder * builder)
68: BlockOrientedKernel(builder, "EvenOdd", {Binding{builder->getStreamSetTy(8, 1), "BasisBits"}}, {Binding{builder->getStreamSetTy(2, 1), "even_odd"}}, {}, {}, {}) {
69    setNoTerminateAttribute(true);
70    setDoBlockUpdatesProducedItemCountsAttribute(false);
71
72}
73
74}
Note: See TracBrowser for help on using the repository browser.