diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-27 15:32:46 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-27 15:32:46 +0000 |
| commit | 5e2281ede8364dd7d2af7c9a0e4dd15ad6653fdd (patch) | |
| tree | bd1dd8e9ca76d3edcc5037b0dfcc2e78070de170 /clang/lib/CodeGen | |
| parent | 824f8c12fdfd3bb729743e12a2c0fe4cce143057 (diff) | |
| download | bcm5719-llvm-5e2281ede8364dd7d2af7c9a0e4dd15ad6653fdd.tar.gz bcm5719-llvm-5e2281ede8364dd7d2af7c9a0e4dd15ad6653fdd.zip | |
Implementation of __builtin_ctlz.
llvm-svn: 51595
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a43649dc4bd..232f6d6d4af 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -192,6 +192,20 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { Result = Builder.CreateIntCast(Result, ResultType, "cast"); return RValue::get(Result); } + case Builtin::BI__builtin_clz: + case Builtin::BI__builtin_clzl: + case Builtin::BI__builtin_clzll: { + Value *ArgValue = EmitScalarExpr(E->getArg(0)); + + const llvm::Type *ArgType = ArgValue->getType(); + Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1); + + const llvm::Type *ResultType = ConvertType(E->getType()); + Value *Result = Builder.CreateCall(F, ArgValue, "tmp"); + if (Result->getType() != ResultType) + Result = Builder.CreateIntCast(Result, ResultType, "cast"); + return RValue::get(Result); + } case Builtin::BI__builtin_expect: return RValue::get(EmitScalarExpr(E->getArg(0))); case Builtin::BI__builtin_bswap32: |

