aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2007-12-02 21:58:10 +0000
committerAnders Carlsson <andersca@mac.com>2007-12-02 21:58:10 +0000
commitdf4852ac816e6050d53b808b86d7c1c9738eb99e (patch)
tree4e574f0b34bef40f0db75221fc5b8f5b3c7a8c46
parent12f65f6513afe10181aa68eb387ccac23e9e2b6e (diff)
Implement __builtin_bswap32 and __builtin_bswap64.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44521 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CodeGen/CGBuiltin.cpp12
-rw-r--r--include/clang/AST/Builtins.def2
2 files changed, 14 insertions, 0 deletions
diff --git a/CodeGen/CGBuiltin.cpp b/CodeGen/CGBuiltin.cpp
index a1d5af19dd..27c82e8cd0 100644
--- a/CodeGen/CGBuiltin.cpp
+++ b/CodeGen/CGBuiltin.cpp
@@ -100,6 +100,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
llvm::Value *Condition = EmitScalarExpr(E->getArg(0));
return RValue::get(Condition);
}
+ case Builtin::BI__builtin_bswap32:
+ case Builtin::BI__builtin_bswap64: {
+ llvm::Value *ArgValue = EmitScalarExpr(E->getArg(0));
+ const llvm::Type *ArgType = ArgValue->getType();
+ llvm::Value *F =
+ llvm::Intrinsic::getDeclaration(&CGM.getModule(),
+ llvm::Intrinsic::bswap,
+ &ArgType, 1);
+ llvm::Value *V = Builder.CreateCall(F, ArgValue, "tmp");
+
+ return RValue::get(V);
+ }
}
return RValue::get(0);
diff --git a/include/clang/AST/Builtins.def b/include/clang/AST/Builtins.def
index 29d0b06f89..501ab22f7a 100644
--- a/include/clang/AST/Builtins.def
+++ b/include/clang/AST/Builtins.def
@@ -74,6 +74,8 @@ BUILTIN(__builtin_ctzll, "iULLi", "nc")
// Random GCC builtins
+BUILTIN(__builtin_bswap32, "UiUi", "nc")
+BUILTIN(__builtin_bswap64, "ULLiULLi", "nc")
BUILTIN(__builtin_constant_p, "UsUs", "nc")
BUILTIN(__builtin_classify_type, "i.", "nc")
BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc")