2016-09-26 07:00:19 +00:00
|
|
|
|
2016-10-01 09:47:21 +00:00
|
|
|
#include "r_compiler/llvm_include.h"
|
2016-09-26 07:00:19 +00:00
|
|
|
#include "ssa_for_block.h"
|
|
|
|
#include "ssa_scope.h"
|
|
|
|
|
|
|
|
SSAForBlock::SSAForBlock()
|
|
|
|
: if_basic_block(0), loop_basic_block(0), end_basic_block(0)
|
|
|
|
{
|
|
|
|
if_basic_block = llvm::BasicBlock::Create(SSAScope::context(), "forbegin", SSAScope::builder().GetInsertBlock()->getParent());
|
|
|
|
loop_basic_block = llvm::BasicBlock::Create(SSAScope::context(), "forloop", SSAScope::builder().GetInsertBlock()->getParent());
|
|
|
|
end_basic_block = llvm::BasicBlock::Create(SSAScope::context(), "forend", SSAScope::builder().GetInsertBlock()->getParent());
|
|
|
|
SSAScope::builder().CreateBr(if_basic_block);
|
|
|
|
SSAScope::builder().SetInsertPoint(if_basic_block);
|
|
|
|
}
|
|
|
|
|
2016-10-08 04:50:33 +00:00
|
|
|
void SSAForBlock::loop_block(SSABool true_condition, int unroll_count)
|
2016-09-26 07:00:19 +00:00
|
|
|
{
|
2016-10-08 04:50:33 +00:00
|
|
|
auto branch = SSAScope::builder().CreateCondBr(true_condition.v, loop_basic_block, end_basic_block);
|
2016-10-16 22:19:07 +00:00
|
|
|
#if LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9)
|
2016-10-08 04:50:33 +00:00
|
|
|
if (unroll_count > 0)
|
|
|
|
{
|
|
|
|
using namespace llvm;
|
|
|
|
auto md_unroll_enable = MDNode::get(SSAScope::context(), {
|
|
|
|
MDString::get(SSAScope::context(), "llvm.loop.unroll.enable")
|
|
|
|
});
|
|
|
|
auto md_unroll_count = MDNode::get(SSAScope::context(), {
|
|
|
|
MDString::get(SSAScope::context(), "llvm.loop.unroll.count"),
|
|
|
|
ConstantAsMetadata::get(ConstantInt::get(SSAScope::context(), APInt(32, unroll_count)))
|
|
|
|
});
|
|
|
|
auto md_loop = MDNode::getDistinct(SSAScope::context(), { md_unroll_enable, md_unroll_count });
|
|
|
|
branch->setMetadata(LLVMContext::MD_loop, md_loop);
|
|
|
|
}
|
2016-10-16 22:19:07 +00:00
|
|
|
#endif
|
2016-09-26 07:00:19 +00:00
|
|
|
SSAScope::builder().SetInsertPoint(loop_basic_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSAForBlock::end_block()
|
|
|
|
{
|
|
|
|
SSAScope::builder().CreateBr(if_basic_block);
|
|
|
|
SSAScope::builder().SetInsertPoint(end_basic_block);
|
|
|
|
}
|