Commit e8cf7b80a7cb26ed6aa3959d2d07ae28ee6cd0de
1 parent
58e3dd0e
llvm bug fixes
Showing
1 changed file
with
22 additions
and
15 deletions
sdk/plugins/llvm.cpp
| ... | ... | @@ -129,14 +129,14 @@ struct MatrixBuilder : public Matrix |
| 129 | 129 | setHash(other.getHash()); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - void allocate() const { | |
| 132 | + void allocateCode() const { | |
| 133 | 133 | Function *malloc = TheModule->getFunction("malloc"); |
| 134 | 134 | if (!malloc) { |
| 135 | 135 | PointerType *mallocReturn = Type::getInt8PtrTy(getGlobalContext()); |
| 136 | 136 | std::vector<Type*> mallocParams; |
| 137 | 137 | mallocParams.push_back(Type::getInt32Ty(getGlobalContext())); |
| 138 | 138 | FunctionType* mallocType = FunctionType::get(mallocReturn, mallocParams, false); |
| 139 | - malloc = Function::Create(mallocType, GlobalValue::ExternalLinkage, "malloc"); | |
| 139 | + malloc = Function::Create(mallocType, GlobalValue::ExternalLinkage, "malloc", TheModule); | |
| 140 | 140 | malloc->setCallingConv(CallingConv::C); |
| 141 | 141 | } |
| 142 | 142 | |
| ... | ... | @@ -392,7 +392,7 @@ private: |
| 392 | 392 | |
| 393 | 393 | BasicBlock *getKernel = BasicBlock::Create(getGlobalContext(), "get_kernel", function); |
| 394 | 394 | BasicBlock *preallocate = BasicBlock::Create(getGlobalContext(), "preallocate", function); |
| 395 | - Value *hashTest = builder.CreateICmpNE(mb.getHash(), kernelHash, "hash_fail_test"); | |
| 395 | + Value *hashTest = builder.CreateICmpNE(mb.getHash(), builder.CreateLoad(kernelHash), "hash_fail_test"); | |
| 396 | 396 | builder.CreateCondBr(hashTest, getKernel, preallocate); |
| 397 | 397 | |
| 398 | 398 | builder.SetInsertPoint(getKernel); |
| ... | ... | @@ -401,12 +401,19 @@ private: |
| 401 | 401 | builder.CreateBr(preallocate); |
| 402 | 402 | builder.SetInsertPoint(preallocate); |
| 403 | 403 | Value *kernelSize = buildPreallocate(mb, nb); |
| 404 | - nb.allocate(); | |
| 405 | 404 | |
| 405 | + BasicBlock *allocate = BasicBlock::Create(getGlobalContext(), "allocate", function); | |
| 406 | + builder.CreateBr(allocate); | |
| 407 | + builder.SetInsertPoint(allocate); | |
| 408 | + nb.allocateCode(); | |
| 409 | + | |
| 410 | + BasicBlock *callKernel = BasicBlock::Create(getGlobalContext(), "call_kernel", function); | |
| 411 | + builder.CreateBr(callKernel); | |
| 412 | + builder.SetInsertPoint(callKernel); | |
| 406 | 413 | builder.CreateCall3(builder.CreateLoad(kernelFunction), src, dst, kernelSize); |
| 407 | 414 | builder.CreateRetVoid(); |
| 408 | 415 | |
| 409 | - // optimize(function); | |
| 416 | + optimize(function); | |
| 410 | 417 | return kernel; |
| 411 | 418 | } |
| 412 | 419 | |
| ... | ... | @@ -991,7 +998,7 @@ class LLVMInitializer : public Initializer |
| 991 | 998 | TheFunctionPassManager->add(createDeadInstEliminationPass()); |
| 992 | 999 | |
| 993 | 1000 | TheExtraFunctionPassManager = new FunctionPassManager(TheModule); |
| 994 | -// TheExtraFunctionPassManager->add(createPrintFunctionPass("--------------------------------------------------------------------------------", &errs())); | |
| 1001 | + TheExtraFunctionPassManager->add(createPrintFunctionPass("--------------------------------------------------------------------------------", &errs())); | |
| 995 | 1002 | // TheExtraFunctionPassManager->add(createLoopUnrollPass(INT_MAX,8)); |
| 996 | 1003 | |
| 997 | 1004 | TheMatrixStruct = StructType::create("Matrix", |
| ... | ... | @@ -1010,17 +1017,17 @@ class LLVMInitializer : public Initializer |
| 1010 | 1017 | kernel->project(src, dst); |
| 1011 | 1018 | qDebug() << dst.m(); |
| 1012 | 1019 | |
| 1013 | - src.m() = (Mat_<qint32>(2,2) << -1, -3, 9, 27); | |
| 1014 | - kernel->project(src, dst); | |
| 1015 | - qDebug() << dst.m(); | |
| 1020 | +// src.m() = (Mat_<qint32>(2,2) << -1, -3, 9, 27); | |
| 1021 | +// kernel->project(src, dst); | |
| 1022 | +// qDebug() << dst.m(); | |
| 1016 | 1023 | |
| 1017 | - src.m() = (Mat_<float>(2,2) << -1.5, -2.5, 3.5, 4.5); | |
| 1018 | - kernel->project(src, dst); | |
| 1019 | - qDebug() << dst.m(); | |
| 1024 | +// src.m() = (Mat_<float>(2,2) << -1.5, -2.5, 3.5, 4.5); | |
| 1025 | +// kernel->project(src, dst); | |
| 1026 | +// qDebug() << dst.m(); | |
| 1020 | 1027 | |
| 1021 | - src.m() = (Mat_<double>(2,2) << 1.75, 2.75, -3.75, -4.75); | |
| 1022 | - kernel->project(src, dst); | |
| 1023 | - qDebug() << dst.m(); | |
| 1028 | +// src.m() = (Mat_<double>(2,2) << 1.75, 2.75, -3.75, -4.75); | |
| 1029 | +// kernel->project(src, dst); | |
| 1030 | +// qDebug() << dst.m(); | |
| 1024 | 1031 | } |
| 1025 | 1032 | |
| 1026 | 1033 | void finalize() const | ... | ... |