Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
e4dccf46
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4dccf46
编写于
6月 28, 2016
作者:
S
Shreedhar Hardikar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement InlineFunction to force inline at call site
上级
71170942
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
2 deletion
+73
-2
src/backend/codegen/include/codegen/utils/codegen_utils.h
src/backend/codegen/include/codegen/utils/codegen_utils.h
+20
-0
src/backend/codegen/tests/codegen_utils_unittest.cc
src/backend/codegen/tests/codegen_utils_unittest.cc
+53
-2
未找到文件。
src/backend/codegen/include/codegen/utils/codegen_utils.h
浏览文件 @
e4dccf46
...
...
@@ -30,6 +30,7 @@
#include "codegen/utils/macros.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
...
...
@@ -43,6 +44,7 @@
#include "llvm/IR/Type.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Value.h"
#include "llvm/Transforms/Utils/Cloning.h"
namespace
gpcodegen
{
...
...
@@ -479,6 +481,24 @@ class CodegenUtils {
void
CreateFallback
(
llvm
::
Function
*
regular_function
,
llvm
::
Function
*
generated_function
);
/*
* @brief Force inline an LLVM function at the call site. Note that this only
* does one level of inlining.
*
* @param LLVM call Instruction where the called function should be inlined
* @return false if it is not possible to inline. true otherwise.
*/
bool
InlineFunction
(
llvm
::
CallInst
*
call_inst
)
{
// Check that the call instruction belongs to a BasicBlock which is part of
// a valid function
if
(
!
(
call_inst
&&
call_inst
->
getParent
()
&&
call_inst
->
getParent
()
->
getParent
())){
return
false
;
}
llvm
::
InlineFunctionInfo
info
;
return
llvm
::
InlineFunction
(
llvm
::
CallSite
(
call_inst
),
info
);
}
private:
// Give ClangCompiler access to 'context_' add allow it to add compiled C++
// sources to 'auxiliary_modules_'.
...
...
src/backend/codegen/tests/codegen_utils_unittest.cc
浏览文件 @
e4dccf46
...
...
@@ -41,6 +41,7 @@
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
...
...
@@ -2736,9 +2737,9 @@ TEST_F(CodegenUtilsTest, CppClassObjectTest) {
EXPECT_EQ
(
-
12.75
,
(
*
accumulate_test_fn_compiled
)(
-
22.75
));
}
// Test GetOr
GetOr
RegisterExternalFunction to return the right llvm::Function if
// Test GetOrRegisterExternalFunction to return the right llvm::Function if
// previously registered or else register it anew
TEST_F
(
CodegenUtilsTest
,
GetOr
GetOr
RegisterExternalFunctionTest
)
{
TEST_F
(
CodegenUtilsTest
,
GetOrRegisterExternalFunctionTest
)
{
// Test previous unregistered function
EXPECT_EQ
(
nullptr
,
codegen_utils_
->
module
()
->
getFunction
(
"floor"
));
llvm
::
Function
*
floor_func
=
codegen_utils_
->
GetOrRegisterExternalFunction
(
...
...
@@ -2762,6 +2763,56 @@ TEST_F(CodegenUtilsTest, GetOrGetOrRegisterExternalFunctionTest) {
EXPECT_EQ
(
expected_fprintf_func
,
fprintf_func
);
}
// Utility method to compute the number of calls in an llvm::Function*
int
GetLLVMFunctionCallCount
(
llvm
::
Function
*
F
)
{
return
std
::
count_if
(
llvm
::
inst_begin
(
F
),
llvm
::
inst_end
(
F
),
[]
(
llvm
::
Instruction
&
i
)
->
bool
{
return
(
llvm
::
dyn_cast
<
llvm
::
CallInst
>
(
&
i
));
});
}
// Test InlineFunction
TEST_F
(
CodegenUtilsTest
,
InlineFunctionTest
)
{
auto
irb
=
codegen_utils_
->
ir_builder
();
typedef
int
(
*
AddConstToIntFn
)
(
int
);
// Create a simple adds 1 to a number and returns the new value
llvm
::
Function
*
add_one_fn
=
codegen_utils_
->
CreateFunction
<
AddConstToIntFn
>
(
"add_one"
);
irb
->
SetInsertPoint
(
codegen_utils_
->
CreateBasicBlock
(
"main"
,
add_one_fn
));
irb
->
CreateRet
(
irb
->
CreateAdd
(
ArgumentByPosition
(
add_one_fn
,
0
),
codegen_utils_
->
GetConstant
(
1
)));
// Create another simple function add_two which calls add_one twice
llvm
::
Function
*
add_two_fn
=
codegen_utils_
->
CreateFunction
<
AddConstToIntFn
>
(
"add_two"
);
irb
->
SetInsertPoint
(
codegen_utils_
->
CreateBasicBlock
(
"main"
,
add_two_fn
));
llvm
::
CallInst
*
first_call
=
irb
->
CreateCall
(
add_one_fn
,
{
ArgumentByPosition
(
add_two_fn
,
0
)});
llvm
::
CallInst
*
second_call
=
irb
->
CreateCall
(
add_one_fn
,
{
first_call
});
irb
->
CreateRet
(
second_call
);
EXPECT_EQ
(
GetLLVMFunctionCallCount
(
add_two_fn
),
2
);
EXPECT_TRUE
(
codegen_utils_
->
InlineFunction
(
first_call
));
EXPECT_EQ
(
GetLLVMFunctionCallCount
(
add_two_fn
),
1
);
EXPECT_FALSE
(
codegen_utils_
->
InlineFunction
(
first_call
));
EXPECT_TRUE
(
codegen_utils_
->
InlineFunction
(
second_call
));
EXPECT_EQ
(
GetLLVMFunctionCallCount
(
add_two_fn
),
0
);
// Compiled module
EXPECT_TRUE
(
codegen_utils_
->
PrepareForExecution
(
CodegenUtils
::
OptimizationLevel
::
kNone
,
false
));
AddConstToIntFn
compiled_add_two_fn
=
codegen_utils_
->
GetFunctionPointer
<
AddConstToIntFn
>
(
"add_two"
);
// Test normal functionality, even after inlining
EXPECT_TRUE
(
nullptr
!=
compiled_add_two_fn
);
EXPECT_EQ
(
compiled_add_two_fn
(
5
),
7
);
EXPECT_EQ
(
compiled_add_two_fn
(
-
5
),
-
3
);
}
#ifdef GPCODEGEN_DEBUG
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录