[llvm] r343577 - [X86] Add APInt constant assembly printer helper

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 2 04:32:33 PDT 2018


Author: rksimon
Date: Tue Oct  2 04:32:33 2018
New Revision: 343577

URL: http://llvm.org/viewvc/llvm-project?rev=343577&view=rev
Log:
[X86] Add APInt constant assembly printer helper

Modified:
    llvm/trunk/lib/Target/X86/X86MCInstLower.cpp

Modified: llvm/trunk/lib/Target/X86/X86MCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCInstLower.cpp?rev=343577&r1=343576&r2=343577&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCInstLower.cpp Tue Oct  2 04:32:33 2018
@@ -1482,7 +1482,22 @@ static std::string getShuffleComment(con
   return Comment;
 }
 
-static void printConstant(const APFloat& Flt, raw_ostream &CS) {
+static void printConstant(const APInt &Val, raw_ostream &CS) {
+  if (Val.getBitWidth() <= 64) {
+    CS << Val.getZExtValue();
+  } else {
+    // print multi-word constant as (w0,w1)
+    CS << "(";
+    for (int i = 0, N = Val.getNumWords(); i < N; ++i) {
+      if (i > 0)
+        CS << ",";
+      CS << Val.getRawData()[i];
+    }
+    CS << ")";
+  }
+}
+
+static void printConstant(const APFloat &Flt, raw_ostream &CS) {
   SmallString<32> Str;
   Flt.toString(Str);
   CS << Str;
@@ -1492,19 +1507,7 @@ static void printConstant(const Constant
   if (isa<UndefValue>(COp)) {
     CS << "u";
   } else if (auto *CI = dyn_cast<ConstantInt>(COp)) {
-    if (CI->getBitWidth() <= 64) {
-      CS << CI->getZExtValue();
-    } else {
-      // print multi-word constant as (w0,w1)
-      const auto &Val = CI->getValue();
-      CS << "(";
-      for (int i = 0, N = Val.getNumWords(); i < N; ++i) {
-        if (i > 0)
-          CS << ",";
-        CS << Val.getRawData()[i];
-      }
-      CS << ")";
-    }
+    printConstant(CI->getValue(), CS);
   } else if (auto *CF = dyn_cast<ConstantFP>(COp)) {
     printConstant(CF->getValueAPF(), CS);
   } else {
@@ -2100,7 +2103,7 @@ void X86AsmPrinter::EmitInstruction(cons
             if (i != 0 || l != 0)
               CS << ",";
             if (CDS->getElementType()->isIntegerTy())
-              CS << CDS->getElementAsInteger(i);
+              printConstant(CDS->getElementAsAPInt(i), CS);
             else if (CDS->getElementType()->isHalfTy() ||
                      CDS->getElementType()->isFloatTy() ||
                      CDS->getElementType()->isDoubleTy())




More information about the llvm-commits mailing list