summaryrefslogtreecommitdiff
path: root/src/compiler_llvm/ir_builder.cc
diff options
context:
space:
mode:
author TDYa127 <tdy@google.com> 2012-05-11 13:17:49 -0700
committer Shih-wei Liao <sliao@google.com> 2012-05-12 00:57:37 -0700
commitac7b5bb79899865b2375d14bc3af2079ec2eb28d (patch)
treea835cbd1158a04bb01ea3505a6a5e561e0f9d527 /src/compiler_llvm/ir_builder.cc
parent6819a91aa4e9c59a555a8fd14f4be263ae5d8dbb (diff)
Add support for llvm static branch prediction.
Change-Id: I8025db404d59a7ef17e4f8b878d0ab5c8cf7dab4
Diffstat (limited to 'src/compiler_llvm/ir_builder.cc')
-rw-r--r--src/compiler_llvm/ir_builder.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler_llvm/ir_builder.cc b/src/compiler_llvm/ir_builder.cc
index 8b2f0f7d96..d93b5885d0 100644
--- a/src/compiler_llvm/ir_builder.cc
+++ b/src/compiler_llvm/ir_builder.cc
@@ -19,6 +19,8 @@
#include <llvm/Module.h>
+#include <algorithm>
+
namespace art {
namespace compiler_llvm {
@@ -44,6 +46,22 @@ IRBuilder::IRBuilder(llvm::LLVMContext& context, llvm::Module& module)
CHECK(art_frame_type_ != NULL);
runtime_support_ = NULL;
+
+
+ // Pre-generate the MDNode for static branch prediction
+ llvm::Type* int32ty = llvm::Type::getInt32Ty(context);
+ llvm::MDString* branch_weights = llvm::MDString::get(context, "branch_weights");
+ llvm::Constant* likely = llvm::ConstantInt::get(int32ty, 64);
+ llvm::Constant* unlikely = llvm::ConstantInt::get(int32ty, 4);
+ llvm::Value *opts[] = {
+ branch_weights,
+ likely,
+ unlikely
+ };
+
+ expect_cond_[kLikely] = llvm::MDNode::get(context, opts);
+ std::swap(opts[1], opts[2]);
+ expect_cond_[kUnlikely] = llvm::MDNode::get(context, opts);
}