Commit 7a6cef730b57ee0081d61d7261997a93d1d481ed
1 parent
8fa78f7e
some llvm refactoring
Showing
2 changed files
with
88 additions
and
86 deletions
sdk/jitcv/jitcv.h
| ... | ... | @@ -85,13 +85,13 @@ struct Matrix |
| 85 | 85 | |
| 86 | 86 | typedef void (*UnaryFunction)(const Matrix *src, Matrix *dst); |
| 87 | 87 | typedef void (*BinaryFunction)(const Matrix *srcA, const Matrix *srcB, Matrix *dst); |
| 88 | -UnaryFunction jit_make_unary_function(const char *description); | |
| 89 | -BinaryFunction jit_make_binary_function(const char *description); | |
| 88 | +UnaryFunction makeUnaryFunction(const char *description); | |
| 89 | +BinaryFunction makeBinaryFunction(const char *description); | |
| 90 | 90 | |
| 91 | 91 | typedef void (*UnaryKernel)(const Matrix *src, Matrix *dst, uint32_t size); |
| 92 | 92 | typedef void (*BinaryKernel)(const Matrix *srcA, const Matrix *srcB, Matrix *dst, uint32_t size); |
| 93 | -UnaryKernel jit_make_unary_kernel(const char *description, const Matrix *src); | |
| 94 | -BinaryKernel jit_make_binary_kernel(const char *description, const Matrix *srcA, const Matrix *srcB); | |
| 93 | +UnaryKernel makeUnaryKernel(const char *description, const Matrix *src); | |
| 94 | +BinaryKernel makeBinaryKernel(const char *description, const Matrix *srcA, const Matrix *srcB); | |
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | ... | ... |
sdk/plugins/llvm.cpp
| ... | ... | @@ -87,37 +87,39 @@ QDebug operator<<(QDebug dbg, const Matrix &m) |
| 87 | 87 | return dbg; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | -struct MatrixBuilder : public Matrix | |
| 90 | +struct MatrixBuilder | |
| 91 | 91 | { |
| 92 | - Value *m; | |
| 92 | + const Matrix *m; | |
| 93 | + Value *v; | |
| 93 | 94 | IRBuilder<> *b; |
| 94 | 95 | Function *f; |
| 95 | 96 | Twine name; |
| 96 | 97 | |
| 97 | - MatrixBuilder(const Matrix &matrix, Value *value, IRBuilder<> *builder, Function *function, const Twine &name_) | |
| 98 | - : Matrix(matrix), m(value), b(builder), f(function), name(name_) {} | |
| 98 | + MatrixBuilder(const Matrix *matrix, Value *value, IRBuilder<> *builder, Function *function, const Twine &name_) | |
| 99 | + : m(matrix), v(value), b(builder), f(function), name(name_) {} | |
| 99 | 100 | |
| 100 | - static Constant *zero() { return constant(0); } | |
| 101 | - static Constant *one() { return constant(1); } | |
| 102 | 101 | static Constant *constant(int value, int bits = 32) { return Constant::getIntegerValue(Type::getInt32Ty(getGlobalContext()), APInt(bits, value)); } |
| 103 | 102 | static Constant *constant(float value) { return ConstantFP::get(Type::getFloatTy(getGlobalContext()), value == 0 ? -0.0f : value); } |
| 104 | 103 | static Constant *constant(double value) { return ConstantFP::get(Type::getDoubleTy(getGlobalContext()), value == 0 ? -0.0 : value); } |
| 105 | - Constant *autoConstant(double value) const { return isFloating() ? ((bits() == 64) ? constant(value) : constant(float(value))) : constant(int(value), bits()); } | |
| 104 | + static Constant *zero() { return constant(0); } | |
| 105 | + static Constant *one() { return constant(1); } | |
| 106 | + | |
| 107 | + Constant *autoConstant(double value) const { return m->isFloating() ? ((m->bits() == 64) ? constant(value) : constant(float(value))) : constant(int(value), m->bits()); } | |
| 106 | 108 | AllocaInst *autoAlloca(double value, const Twine &name = "") const { AllocaInst *alloca = b->CreateAlloca(ty(), 0, name); b->CreateStore(autoConstant(value), alloca); return alloca; } |
| 107 | 109 | |
| 108 | - Value *getData(bool cast = true) const { LoadInst *data = b->CreateLoad(b->CreateStructGEP(m, 0), name+"_data"); return cast ? b->CreatePointerCast(data, ptrTy()) : data; } | |
| 109 | - Value *getChannels() const { return singleChannel() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(m, 1), name+"_channels")); } | |
| 110 | - Value *getColumns() const { return singleColumn() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(m, 2), name+"_columns")); } | |
| 111 | - Value *getRows() const { return singleRow() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(m, 3), name+"_rows")); } | |
| 112 | - Value *getFrames() const { return singleFrame() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(m, 4), name+"_frames")); } | |
| 113 | - Value *getHash() const { return b->CreateLoad(b->CreateStructGEP(m, 5), name+"_hash"); } | |
| 110 | + Value *getData(bool cast = true) const { LoadInst *data = b->CreateLoad(b->CreateStructGEP(v, 0), name+"_data"); return cast ? b->CreatePointerCast(data, ptrTy()) : data; } | |
| 111 | + Value *getChannels() const { return m->singleChannel() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(v, 1), name+"_channels")); } | |
| 112 | + Value *getColumns() const { return m->singleColumn() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(v, 2), name+"_columns")); } | |
| 113 | + Value *getRows() const { return m->singleRow() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(v, 3), name+"_rows")); } | |
| 114 | + Value *getFrames() const { return m->singleFrame() ? static_cast<Value*>(one()) : static_cast<Value*>(b->CreateLoad(b->CreateStructGEP(v, 4), name+"_frames")); } | |
| 115 | + Value *getHash() const { return b->CreateLoad(b->CreateStructGEP(v, 5), name+"_hash"); } | |
| 114 | 116 | |
| 115 | - void setData(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 0)); } | |
| 116 | - void setChannels(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 1)); } | |
| 117 | - void setColumns(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 2)); } | |
| 118 | - void setRows(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 3)); } | |
| 119 | - void setFrames(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 4)); } | |
| 120 | - void setHash(Value *value) const { b->CreateStore(value, b->CreateStructGEP(m, 5)); } | |
| 117 | + void setData(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 0)); } | |
| 118 | + void setChannels(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 1)); } | |
| 119 | + void setColumns(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 2)); } | |
| 120 | + void setRows(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 3)); } | |
| 121 | + void setFrames(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 4)); } | |
| 122 | + void setHash(Value *value) const { b->CreateStore(value, b->CreateStructGEP(v, 5)); } | |
| 121 | 123 | |
| 122 | 124 | void copyHeaderCode(const MatrixBuilder &other) const { |
| 123 | 125 | setChannels(other.getChannels()); |
| ... | ... | @@ -147,44 +149,44 @@ struct MatrixBuilder : public Matrix |
| 147 | 149 | void set(int value, int mask) const { setHash(b->CreateOr(b->CreateAnd(getHash(), constant(~mask, 16)), b->CreateAnd(constant(value, 16), constant(mask, 16)))); } |
| 148 | 150 | void setBit(bool on, int mask) const { on ? setHash(b->CreateOr(getHash(), constant(mask, 16))) : setHash(b->CreateAnd(getHash(), constant(~mask, 16))); } |
| 149 | 151 | |
| 150 | - Value *bitsCode() const { return get(Bits); } | |
| 151 | - void setBitsCode(int bits) const { set(bits, Bits); } | |
| 152 | - Value *isFloatingCode() const { return get(Floating); } | |
| 153 | - void setFloatingCode(bool isFloating) const { if (isFloating) setSignedCode(true); setBit(isFloating, Floating); } | |
| 154 | - Value *isSignedCode() const { return get(Signed); } | |
| 155 | - void setSignedCode(bool isSigned) const { setBit(isSigned, Signed); } | |
| 156 | - Value *typeCode() const { return get(Bits + Floating + Signed); } | |
| 157 | - void setTypeCode(int type) const { set(type, Bits + Floating + Signed); } | |
| 158 | - Value *singleChannelCode() const { return get(SingleChannel); } | |
| 159 | - void setSingleChannelCode(bool singleChannel) const { setBit(singleChannel, SingleChannel); } | |
| 160 | - Value *singleColumnCode() const { return get(SingleColumn); } | |
| 161 | - void setSingleColumnCode(bool singleColumn) { setBit(singleColumn, SingleColumn); } | |
| 162 | - Value *singleRowCode() const { return get(SingleRow); } | |
| 163 | - void setSingleRowCode(bool singleRow) const { setBit(singleRow, SingleRow); } | |
| 164 | - Value *singleFrameCode() const { return get(SingleFrame); } | |
| 165 | - void setSingleFrameCode(bool singleFrame) const { setBit(singleFrame, SingleFrame); } | |
| 152 | + Value *bitsCode() const { return get(Matrix::Bits); } | |
| 153 | + void setBitsCode(int bits) const { set(bits, Matrix::Bits); } | |
| 154 | + Value *isFloatingCode() const { return get(Matrix::Floating); } | |
| 155 | + void setFloatingCode(bool isFloating) const { if (isFloating) setSignedCode(true); setBit(isFloating, Matrix::Floating); } | |
| 156 | + Value *isSignedCode() const { return get(Matrix::Signed); } | |
| 157 | + void setSignedCode(bool isSigned) const { setBit(isSigned, Matrix::Signed); } | |
| 158 | + Value *typeCode() const { return get(Matrix::Bits + Matrix::Floating + Matrix::Signed); } | |
| 159 | + void setTypeCode(int type) const { set(type, Matrix::Bits + Matrix::Floating + Matrix::Signed); } | |
| 160 | + Value *singleChannelCode() const { return get(Matrix::SingleChannel); } | |
| 161 | + void setSingleChannelCode(bool singleChannel) const { setBit(singleChannel, Matrix::SingleChannel); } | |
| 162 | + Value *singleColumnCode() const { return get(Matrix::SingleColumn); } | |
| 163 | + void setSingleColumnCode(bool singleColumn) { setBit(singleColumn, Matrix::SingleColumn); } | |
| 164 | + Value *singleRowCode() const { return get(Matrix::SingleRow); } | |
| 165 | + void setSingleRowCode(bool singleRow) const { setBit(singleRow, Matrix::SingleRow); } | |
| 166 | + Value *singleFrameCode() const { return get(Matrix::SingleFrame); } | |
| 167 | + void setSingleFrameCode(bool singleFrame) const { setBit(singleFrame, Matrix::SingleFrame); } | |
| 166 | 168 | Value *elementsCode() const { return b->CreateMul(b->CreateMul(b->CreateMul(getChannels(), getColumns()), getRows()), getFrames()); } |
| 167 | 169 | Value *bytesCode() const { return b->CreateMul(b->CreateUDiv(b->CreateCast(Instruction::ZExt, bitsCode(), Type::getInt32Ty(getGlobalContext())), constant(8, 32)), elementsCode()); } |
| 168 | 170 | |
| 169 | 171 | Value *columnStep() const { Value *columnStep = getChannels(); columnStep->setName(name+"_cStep"); return columnStep; } |
| 170 | 172 | Value *rowStep() const { return b->CreateMul(getColumns(), columnStep(), name+"_rStep"); } |
| 171 | 173 | Value *frameStep() const { return b->CreateMul(getRows(), rowStep(), name+"_tStep"); } |
| 172 | - Value *aliasColumnStep(const MatrixBuilder &other) const { return (channels == other.channels) ? other.columnStep() : columnStep(); } | |
| 173 | - Value *aliasRowStep(const MatrixBuilder &other) const { return (columns == other.columns) ? other.rowStep() : rowStep(); } | |
| 174 | - Value *aliasFrameStep(const MatrixBuilder &other) const { return (rows == other.rows) ? other.frameStep() : frameStep(); } | |
| 175 | - | |
| 176 | - Value *index(Value *c) const { return singleChannel() ? constant(0) : c; } | |
| 177 | - Value *index(Value *c, Value *x) const { return singleColumn() ? index(c) : b->CreateAdd(b->CreateMul(x, columnStep()), index(c)); } | |
| 178 | - Value *index(Value *c, Value *x, Value *y) const { return singleRow() ? index(c, x) : b->CreateAdd(b->CreateMul(y, rowStep()), index(c, x)); } | |
| 179 | - Value *index(Value *c, Value *x, Value *y, Value *f) const { return singleFrame() ? index(c, x, y) : b->CreateAdd(b->CreateMul(f, frameStep()), index(c, x, y)); } | |
| 180 | - Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x) const { return singleColumn() ? index(c) : b->CreateAdd(b->CreateMul(x, aliasColumnStep(other)), index(c)); } | |
| 181 | - Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x, Value *y) const { return singleRow() ? aliasIndex(other, c, x) : b->CreateAdd(b->CreateMul(y, aliasRowStep(other)), aliasIndex(other, c, x)); } | |
| 182 | - Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x, Value *y, Value *f) const { return singleFrame() ? aliasIndex(other, c, x, y) : b->CreateAdd(b->CreateMul(f, aliasFrameStep(other)), aliasIndex(other, c, x, y)); } | |
| 183 | - | |
| 184 | - void deindex(Value *i, Value **c) const { *c = singleChannel() ? constant(0) : i; } | |
| 174 | + Value *aliasColumnStep(const MatrixBuilder &other) const { return (m->channels == other.m->channels) ? other.columnStep() : columnStep(); } | |
| 175 | + Value *aliasRowStep(const MatrixBuilder &other) const { return (m->columns == other.m->columns) ? other.rowStep() : rowStep(); } | |
| 176 | + Value *aliasFrameStep(const MatrixBuilder &other) const { return (m->rows == other.m->rows) ? other.frameStep() : frameStep(); } | |
| 177 | + | |
| 178 | + Value *index(Value *c) const { return m->singleChannel() ? constant(0) : c; } | |
| 179 | + Value *index(Value *c, Value *x) const { return m->singleColumn() ? index(c) : b->CreateAdd(b->CreateMul(x, columnStep()), index(c)); } | |
| 180 | + Value *index(Value *c, Value *x, Value *y) const { return m->singleRow() ? index(c, x) : b->CreateAdd(b->CreateMul(y, rowStep()), index(c, x)); } | |
| 181 | + Value *index(Value *c, Value *x, Value *y, Value *f) const { return m->singleFrame() ? index(c, x, y) : b->CreateAdd(b->CreateMul(f, frameStep()), index(c, x, y)); } | |
| 182 | + Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x) const { return m->singleColumn() ? index(c) : b->CreateAdd(b->CreateMul(x, aliasColumnStep(other)), index(c)); } | |
| 183 | + Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x, Value *y) const { return m->singleRow() ? aliasIndex(other, c, x) : b->CreateAdd(b->CreateMul(y, aliasRowStep(other)), aliasIndex(other, c, x)); } | |
| 184 | + Value *aliasIndex(const MatrixBuilder &other, Value *c, Value *x, Value *y, Value *f) const { return m->singleFrame() ? aliasIndex(other, c, x, y) : b->CreateAdd(b->CreateMul(f, aliasFrameStep(other)), aliasIndex(other, c, x, y)); } | |
| 185 | + | |
| 186 | + void deindex(Value *i, Value **c) const { *c = m->singleChannel() ? constant(0) : i; } | |
| 185 | 187 | void deindex(Value *i, Value **c, Value **x) const { |
| 186 | 188 | Value *rem; |
| 187 | - if (singleColumn()) { | |
| 189 | + if (m->singleColumn()) { | |
| 188 | 190 | rem = i; |
| 189 | 191 | *x = constant(0); |
| 190 | 192 | } else { |
| ... | ... | @@ -196,7 +198,7 @@ struct MatrixBuilder : public Matrix |
| 196 | 198 | } |
| 197 | 199 | void deindex(Value *i, Value **c, Value **x, Value **y) const { |
| 198 | 200 | Value *rem; |
| 199 | - if (singleRow()) { | |
| 201 | + if (m->singleRow()) { | |
| 200 | 202 | rem = i; |
| 201 | 203 | *y = constant(0); |
| 202 | 204 | } else { |
| ... | ... | @@ -208,7 +210,7 @@ struct MatrixBuilder : public Matrix |
| 208 | 210 | } |
| 209 | 211 | void deindex(Value *i, Value **c, Value **x, Value **y, Value **t) const { |
| 210 | 212 | Value *rem; |
| 211 | - if (singleFrame()) { | |
| 213 | + if (m->singleFrame()) { | |
| 212 | 214 | rem = i; |
| 213 | 215 | *t = constant(0); |
| 214 | 216 | } else { |
| ... | ... | @@ -221,12 +223,12 @@ struct MatrixBuilder : public Matrix |
| 221 | 223 | |
| 222 | 224 | LoadInst *load(Value *i) const { return b->CreateLoad(b->CreateGEP(getData(), i)); } |
| 223 | 225 | StoreInst *store(Value *i, Value *value) const { return b->CreateStore(value, b->CreateGEP(getData(), i)); } |
| 224 | - Value *cast(Value *i, const MatrixBuilder &dst) const { return (type() == dst.type()) ? i : b->CreateCast(CastInst::getCastOpcode(i, isSigned(), dst.ty(), dst.isSigned()), i, dst.ty()); } | |
| 225 | - Value *add(Value *i, Value *j, const Twine &name = "") const { return isFloating() ? b->CreateFAdd(i, j, name) : b->CreateAdd(i, j, name); } | |
| 226 | - Value *multiply(Value *i, Value *j, const Twine &name = "") const { return isFloating() ? b->CreateFMul(i, j, name) : b->CreateMul(i, j, name); } | |
| 226 | + Value *cast(Value *i, const MatrixBuilder &dst) const { return (m->type() == dst.m->type()) ? i : b->CreateCast(CastInst::getCastOpcode(i, m->isSigned(), dst.ty(), dst.m->isSigned()), i, dst.ty()); } | |
| 227 | + Value *add(Value *i, Value *j, const Twine &name = "") const { return m->isFloating() ? b->CreateFAdd(i, j, name) : b->CreateAdd(i, j, name); } | |
| 228 | + Value *multiply(Value *i, Value *j, const Twine &name = "") const { return m->isFloating() ? b->CreateFMul(i, j, name) : b->CreateMul(i, j, name); } | |
| 227 | 229 | |
| 228 | - Value *compareLT(Value *i, Value *j) const { return isFloating() ? b->CreateFCmpOLT(i, j) : (isSigned() ? b->CreateICmpSLT(i, j) : b->CreateICmpULT(i, j)); } | |
| 229 | - Value *compareGT(Value *i, Value *j) const { return isFloating() ? b->CreateFCmpOGT(i, j) : (isSigned() ? b->CreateICmpSGT(i, j) : b->CreateICmpUGT(i, j)); } | |
| 230 | + Value *compareLT(Value *i, Value *j) const { return m->isFloating() ? b->CreateFCmpOLT(i, j) : (m->isSigned() ? b->CreateICmpSLT(i, j) : b->CreateICmpULT(i, j)); } | |
| 231 | + Value *compareGT(Value *i, Value *j) const { return m->isFloating() ? b->CreateFCmpOGT(i, j) : (m->isSigned() ? b->CreateICmpSGT(i, j) : b->CreateICmpUGT(i, j)); } | |
| 230 | 232 | |
| 231 | 233 | static PHINode *beginLoop(IRBuilder<> &builder, Function *function, BasicBlock *entry, BasicBlock *&loop, BasicBlock *&exit, Value *stop, const Twine &name = "") { |
| 232 | 234 | loop = BasicBlock::Create(getGlobalContext(), "loop_"+name, function); |
| ... | ... | @@ -272,7 +274,7 @@ struct MatrixBuilder : public Matrix |
| 272 | 274 | qFatal("Invalid matrix type."); |
| 273 | 275 | return NULL; |
| 274 | 276 | } |
| 275 | - inline Type *ty() const { return ty(*this); } | |
| 277 | + inline Type *ty() const { return ty(*m); } | |
| 276 | 278 | inline std::vector<Type*> tys() const { return toVector<Type*>(ty()); } |
| 277 | 279 | |
| 278 | 280 | static Type *ptrTy(const Matrix &m) |
| ... | ... | @@ -292,7 +294,7 @@ struct MatrixBuilder : public Matrix |
| 292 | 294 | qFatal("Invalid matrix type."); |
| 293 | 295 | return NULL; |
| 294 | 296 | } |
| 295 | - inline Type *ptrTy() const { return ptrTy(*this); } | |
| 297 | + inline Type *ptrTy() const { return ptrTy(*m); } | |
| 296 | 298 | }; |
| 297 | 299 | |
| 298 | 300 | namespace br |
| ... | ... | @@ -374,8 +376,8 @@ private: |
| 374 | 376 | |
| 375 | 377 | BasicBlock *entry = BasicBlock::Create(getGlobalContext(), "entry", function); |
| 376 | 378 | IRBuilder<> builder(entry); |
| 377 | - MatrixBuilder mb(m, src, &builder, function, "src"); | |
| 378 | - MatrixBuilder nb(m, dst, &builder, function, "dst"); | |
| 379 | + MatrixBuilder mb(&m, src, &builder, function, "src"); | |
| 380 | + MatrixBuilder nb(&m, dst, &builder, function, "dst"); | |
| 379 | 381 | |
| 380 | 382 | std::vector<Type*> kernelArgs; |
| 381 | 383 | kernelArgs.push_back(PointerType::getUnqual(TheMatrixStruct)); |
| ... | ... | @@ -447,7 +449,7 @@ private: |
| 447 | 449 | |
| 448 | 450 | Matrix n; |
| 449 | 451 | preallocate(m, n); |
| 450 | - build(MatrixBuilder(m, src, &builder, function, "src"), MatrixBuilder(n, dst, &builder, function, "dst"), i); | |
| 452 | + build(MatrixBuilder(&m, src, &builder, function, "src"), MatrixBuilder(&n, dst, &builder, function, "dst"), i); | |
| 451 | 453 | |
| 452 | 454 | MatrixBuilder::endLoop(builder, loop, exit); |
| 453 | 455 | |
| ... | ... | @@ -525,7 +527,7 @@ private: |
| 525 | 527 | |
| 526 | 528 | Matrix o; |
| 527 | 529 | preallocate(m, n, o); |
| 528 | - build(MatrixBuilder(m, srcA, &builder, function, "srcA"), MatrixBuilder(n, srcB, &builder, function, "srcB"), MatrixBuilder(o, dst, &builder, function, "dst"), i); | |
| 530 | + build(MatrixBuilder(&m, srcA, &builder, function, "srcA"), MatrixBuilder(&n, srcB, &builder, function, "srcB"), MatrixBuilder(&o, dst, &builder, function, "dst"), i); | |
| 529 | 531 | |
| 530 | 532 | MatrixBuilder::endLoop(builder, loop, exit); |
| 531 | 533 | |
| ... | ... | @@ -626,10 +628,10 @@ class stitchTransform : public UnaryTransform |
| 626 | 628 | MatrixBuilder dst(dst_); |
| 627 | 629 | Value *val = src.load(i); |
| 628 | 630 | foreach (Transform *transform, kernels) { |
| 629 | - static_cast<UnaryTransform*>(transform)->preallocate(src, dst); | |
| 631 | + static_cast<UnaryTransform*>(transform)->preallocate(*src.m, *const_cast<Matrix*>(dst.m)); | |
| 630 | 632 | val = static_cast<StitchableTransform*>(transform)->stitch(src, dst, val); |
| 631 | - src.copyHeader(dst); | |
| 632 | - src.m = dst.m; | |
| 633 | + //src.m->copyHeader(*dst.m); | |
| 634 | + //src.v = dst.v; | |
| 633 | 635 | } |
| 634 | 636 | dst.store(i, val); |
| 635 | 637 | } |
| ... | ... | @@ -735,7 +737,7 @@ class sumTransform : public UnaryTransform |
| 735 | 737 | loops.push_back(i->getParent()); |
| 736 | 738 | Value *src_c, *src_x, *src_y, *src_t; |
| 737 | 739 | |
| 738 | - if (frames && !src.singleFrame()) { | |
| 740 | + if (frames && !src.m->singleFrame()) { | |
| 739 | 741 | BasicBlock *loop, *exit; |
| 740 | 742 | src_t = dst.beginLoop(loops.last(), loop, exit, src.getFrames(), "src_t"); |
| 741 | 743 | loops.append(loop); |
| ... | ... | @@ -744,7 +746,7 @@ class sumTransform : public UnaryTransform |
| 744 | 746 | src_t = t; |
| 745 | 747 | } |
| 746 | 748 | |
| 747 | - if (rows && !src.singleRow()) { | |
| 749 | + if (rows && !src.m->singleRow()) { | |
| 748 | 750 | BasicBlock *loop, *exit; |
| 749 | 751 | src_y = dst.beginLoop(loops.last(), loop, exit, src.getRows(), "src_y"); |
| 750 | 752 | loops.append(loop); |
| ... | ... | @@ -753,7 +755,7 @@ class sumTransform : public UnaryTransform |
| 753 | 755 | src_y = y; |
| 754 | 756 | } |
| 755 | 757 | |
| 756 | - if (columns && !src.singleColumn()) { | |
| 758 | + if (columns && !src.m->singleColumn()) { | |
| 757 | 759 | BasicBlock *loop, *exit; |
| 758 | 760 | src_x = dst.beginLoop(loops.last(), loop, exit, src.getColumns(), "src_x"); |
| 759 | 761 | loops.append(loop); |
| ... | ... | @@ -762,7 +764,7 @@ class sumTransform : public UnaryTransform |
| 762 | 764 | src_x = x; |
| 763 | 765 | } |
| 764 | 766 | |
| 765 | - if (channels && !src.singleChannel()) { | |
| 767 | + if (channels && !src.m->singleChannel()) { | |
| 766 | 768 | BasicBlock *loop, *exit; |
| 767 | 769 | src_c = dst.beginLoop(loops.last(), loop, exit, src.getChannels(), "src_c"); |
| 768 | 770 | loops.append(loop); |
| ... | ... | @@ -773,10 +775,10 @@ class sumTransform : public UnaryTransform |
| 773 | 775 | |
| 774 | 776 | dst.b->CreateStore(dst.add(dst.b->CreateLoad(sum), src.cast(src.load(src.aliasIndex(dst, src_c, src_x, src_y, src_t)), dst), "accumulate"), sum); |
| 775 | 777 | |
| 776 | - if (channels && !src.singleChannel()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 777 | - if (columns && !src.singleColumn()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 778 | - if (rows && !src.singleRow()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 779 | - if (frames && !src.singleFrame()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 778 | + if (channels && !src.m->singleChannel()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 779 | + if (columns && !src.m->singleColumn()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 780 | + if (rows && !src.m->singleRow()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 781 | + if (frames && !src.m->singleFrame()) dst.endLoop(loops.takeLast(), exits.takeLast()); | |
| 780 | 782 | |
| 781 | 783 | dst.store(i, dst.b->CreateLoad(sum)); |
| 782 | 784 | } |
| ... | ... | @@ -860,11 +862,11 @@ class absTransform : public StitchableTransform |
| 860 | 862 | Value *stitch(const MatrixBuilder &src, const MatrixBuilder &dst, Value *val) const |
| 861 | 863 | { |
| 862 | 864 | (void) dst; |
| 863 | - if (!src.isSigned()) return val; | |
| 864 | - if (src.isFloating()) return src.b->CreateCall(Intrinsic::getDeclaration(TheModule, Intrinsic::fabs, src.tys()), val); | |
| 865 | - else return src.b->CreateSelect(src.b->CreateICmpSLT(val, src.autoConstant(0)), | |
| 866 | - src.b->CreateSub(src.autoConstant(0), val), | |
| 867 | - val); | |
| 865 | + if (!src.m->isSigned()) return val; | |
| 866 | + if (src.m->isFloating()) return src.b->CreateCall(Intrinsic::getDeclaration(TheModule, Intrinsic::fabs, src.tys()), val); | |
| 867 | + else return src.b->CreateSelect(src.b->CreateICmpSLT(val, src.autoConstant(0)), | |
| 868 | + src.b->CreateSub(src.autoConstant(0), val), | |
| 869 | + val); | |
| 868 | 870 | } |
| 869 | 871 | }; |
| 870 | 872 | |
| ... | ... | @@ -1059,25 +1061,25 @@ class LLVMInitializer : public Initializer |
| 1059 | 1061 | |
| 1060 | 1062 | BR_REGISTER(Initializer, LLVMInitializer) |
| 1061 | 1063 | |
| 1062 | -UnaryFunction jit_make_unary_function(const char *description) | |
| 1064 | +UnaryFunction makeUnaryFunction(const char *description) | |
| 1063 | 1065 | { |
| 1064 | 1066 | QScopedPointer<UnaryTransform> unaryTransform(Factory<UnaryTransform>::make(description)); |
| 1065 | 1067 | return unaryTransform->getFunction(NULL); |
| 1066 | 1068 | } |
| 1067 | 1069 | |
| 1068 | -BinaryFunction jit_make_binary_function(const char *description) | |
| 1070 | +BinaryFunction makeBinaryFunction(const char *description) | |
| 1069 | 1071 | { |
| 1070 | 1072 | (void) description; |
| 1071 | 1073 | return NULL; |
| 1072 | 1074 | } |
| 1073 | 1075 | |
| 1074 | -UnaryKernel jit_make_unary_kernel(const char *description, const Matrix *src) | |
| 1076 | +UnaryKernel makeUnaryKernel(const char *description, const Matrix *src) | |
| 1075 | 1077 | { |
| 1076 | 1078 | QScopedPointer<UnaryTransform> unaryTransform(Factory<UnaryTransform>::make(description)); |
| 1077 | 1079 | return unaryTransform->getKernel(src); |
| 1078 | 1080 | } |
| 1079 | 1081 | |
| 1080 | -BinaryKernel jit_make_binary_kernel(const char *description, const Matrix *srcA, const Matrix *srcB) | |
| 1082 | +BinaryKernel makeBinaryKernel(const char *description, const Matrix *srcA, const Matrix *srcB) | |
| 1081 | 1083 | { |
| 1082 | 1084 | (void) description; |
| 1083 | 1085 | (void) srcA; | ... | ... |