done
[oota-llvm.git] / lib / Target / X86 / X86TargetAsmInfo.cpp
index c66862aec6292380a92f4695cb9a8442032a47fc..8b0ad03b0a0cb01213fafc8c33a9d539fc901c49 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
+#include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/StringExtras.h"
 using namespace llvm;
@@ -56,6 +57,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     EightByteConstantSection = "\t.literal8\n";
     if (Subtarget->is64Bit())
       SixteenByteConstantSection = "\t.literal16\n";
+    ReadOnlySection = "\t.const\n";
     LCOMMDirective = "\t.lcomm\t";
     COMMDirectiveTakesAlignment = false;
     HasDotTypeDotSizeDirective = false;
@@ -103,6 +105,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     // bool HasDotLoc; // Defaults to false.
     // HasDotFile - True if target asm supports .file directives.
     // bool HasDotFile; // Defaults to false.
+    ReadOnlySection = "\t.section\t.rodata\n";
     PrivateGlobalPrefix = ".L";
     WeakRefDirective = "\t.weak\t";
     DwarfRequiresFrameSection = false;
@@ -197,24 +200,14 @@ bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
       !CI->getType()->isInteger())
     return false;
   
-  const Type *Ty = CI->getType();
-  const char *IntName;
-  if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
-    unsigned BitWidth = ITy->getBitWidth();
-    if (BitWidth == 16)
-      IntName = "llvm.bswap.i16";
-    else if (BitWidth == 32)
-      IntName = "llvm.bswap.i32";
-    else if (BitWidth == 64)
-      IntName = "llvm.bswap.i64";
-    else
-      return false;
-  } else
+  const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
+  if (!Ty || Ty->getBitWidth() % 16 != 0)
     return false;
-
+  
   // Okay, we can do this xform, do so now.
+  const Type *Tys[] = { Ty, Ty };
   Module *M = CI->getParent()->getParent()->getParent();
-  Constant *Int = M->getOrInsertFunction(IntName, Ty, Ty, (Type*)0);
+  Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 2);
   
   Value *Op = CI->getOperand(1);
   Op = new CallInst(Int, Op, CI->getName(), CI);