[llvm-commits] [dragonegg] r145130 - /dragonegg/trunk/src/Convert.cpp

Duncan Sands baldrick at free.fr
Fri Nov 25 05:05:04 PST 2011


Author: baldrick
Date: Fri Nov 25 07:05:04 2011
New Revision: 145130

URL: http://llvm.org/viewvc/llvm-project?rev=145130&view=rev
Log:
Turn __builtin_expect into a call to LLVM's expect intrinsic.

Modified:
    dragonegg/trunk/src/Convert.cpp

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=145130&r1=145129&r2=145130&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Fri Nov 25 07:05:04 2011
@@ -5023,11 +5023,18 @@
 }
 
 bool TreeToLLVM::EmitBuiltinExpect(gimple stmt, Value *&Result) {
-  // Ignore the hint for now, just expand the expr.  This is safe, but not
-  // optimal.
-  Result = gimple_call_num_args(stmt) < 2 ?
-    Constant::getNullValue(ConvertType(gimple_call_return_type(stmt))) :
-    EmitMemory(gimple_call_arg(stmt, 0));
+  tree type = gimple_call_return_type(stmt);
+  if (gimple_call_num_args(stmt) < 2) {
+    Result = Constant::getNullValue(ConvertType(type));
+    return true;
+  }
+  Type *ArgTy = getRegType(type);
+  Value *ExpectIntr = Intrinsic::getDeclaration(TheModule, Intrinsic::expect,
+                                                ArgTy);
+  Value *ArgValue = EmitRegister(gimple_call_arg(stmt, 0));
+  Value *ExpectedValue = EmitRegister(gimple_call_arg(stmt, 1));
+  Result = Builder.CreateCall2(ExpectIntr, ArgValue, ExpectedValue);
+  Result = Reg2Mem(Result, type, Builder);
   return true;
 }
 





More information about the llvm-commits mailing list