]> granicus.if.org Git - clang/commitdiff
Implement __builtin_bswap32 and __builtin_bswap64.
authorAnders Carlsson <andersca@mac.com>
Sun, 2 Dec 2007 21:58:10 +0000 (21:58 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 2 Dec 2007 21:58:10 +0000 (21:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44521 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGBuiltin.cpp
include/clang/AST/Builtins.def

index a1d5af19dda399e7912eee264e10180a1cfd01e0..27c82e8cd03cb81702e25441ae726bbf9018c1f6 100644 (file)
@@ -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);
index 29d0b06f89dbb37fff30b6bed40882b434fd7f74..501ab22f7a04101be4626fdca8ad2a731bc5fe77 100644 (file)
@@ -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")