зеркало из https://github.com/microsoft/clang.git
Introduce __builtin_expect() intrinsic support.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134761 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
df41b4c10a
Коммит
558229f267
|
@ -22,6 +22,7 @@
|
|||
#include "clang/Basic/TargetBuiltins.h"
|
||||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
|
||||
using namespace clang;
|
||||
using namespace CodeGen;
|
||||
using namespace llvm;
|
||||
|
@ -311,11 +312,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
return RValue::get(Result);
|
||||
}
|
||||
case Builtin::BI__builtin_expect: {
|
||||
// FIXME: pass expect through to LLVM
|
||||
Value *ArgValue = EmitScalarExpr(E->getArg(0));
|
||||
if (E->getArg(1)->HasSideEffects(getContext()))
|
||||
(void)EmitScalarExpr(E->getArg(1));
|
||||
return RValue::get(ArgValue);
|
||||
const llvm::Type *ArgType = ArgValue->getType();
|
||||
|
||||
Value *FnExpect = CGM.getIntrinsic(Intrinsic::expect, &ArgType, 1);
|
||||
Value *ExpectedValue = EmitScalarExpr(E->getArg(1));
|
||||
|
||||
Value *Result = Builder.CreateCall2(FnExpect, ArgValue, ExpectedValue,
|
||||
"expval");
|
||||
return RValue::get(Result);
|
||||
|
||||
}
|
||||
case Builtin::BI__builtin_bswap32:
|
||||
case Builtin::BI__builtin_bswap64: {
|
||||
|
|
|
@ -19,3 +19,29 @@ int main() {
|
|||
|
||||
// CHECK: call void @isigprocmask()
|
||||
// CHECK: [[C:%.*]] = call i64 (...)* @bar()
|
||||
|
||||
|
||||
// CHECK: @test1
|
||||
int test1(int x) {
|
||||
// CHECK: @llvm.expect
|
||||
if (__builtin_expect (x, 1))
|
||||
return 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
// CHECK: @test2
|
||||
int test2(int x) {
|
||||
// CHECK: @llvm.expect
|
||||
switch(__builtin_expect(x, 5)) {
|
||||
default:
|
||||
return 0;
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return 1;
|
||||
case 5:
|
||||
return 5;
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче