Fix x86 floating-point constant emission.

Previously, the basis of constant pooling was implemented, but two things were lacking:

1. The constant pools were not being emitted in the asm file.

2. A direct FP value was emitted in an FP instruction, e.g. "addss xmm0, 1.0000e00".  Curiously, at least for some FP constants, llvm-mc was accepting this syntax.

BUG= none
R=jfb@chromium.org

Review URL: https://codereview.chromium.org/291213003
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp
index 08f90f8..e29637d 100644
--- a/src/llvm2ice.cpp
+++ b/src/llvm2ice.cpp
@@ -19,6 +19,7 @@
 #include "IceGlobalContext.h"
 #include "IceInst.h"
 #include "IceOperand.h"
+#include "IceTargetLowering.h"
 #include "IceTypes.h"
 
 #include "llvm/IR/Constant.h"
@@ -63,6 +64,7 @@
     SubzeroPointerType = Ice::IceType_i32;
   }
 
+  // Caller is expected to delete the returned Ice::Cfg object.
   Ice::Cfg *convertFunction(const Function *F) {
     VarMap.clear();
     NodeMap.clear();
@@ -618,14 +620,11 @@
 static cl::opt<bool> SubzeroTimingEnabled(
     "timing", cl::desc("Enable breakdown timing of Subzero translation"));
 
-static cl::opt<NaClFileFormat>
-InputFileFormat(
-    "bitcode-format",
-    cl::desc("Define format of input file:"),
-    cl::values(
-        clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
-        clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
-        clEnumValEnd),
+static cl::opt<NaClFileFormat> InputFileFormat(
+    "bitcode-format", cl::desc("Define format of input file:"),
+    cl::values(clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
+               clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
+               clEnumValEnd),
     cl::init(LLVMFormat));
 
 int main(int argc, char **argv) {
@@ -670,6 +669,15 @@
   raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
   Ls->SetUnbuffered();
 
+  // Ideally, Func would be declared inside the loop and its object
+  // would be automatically deleted at the end of the loop iteration.
+  // However, emitting the constant pool requires a valid Cfg object,
+  // so we need to defer deleting the last non-empty Cfg object until
+  // outside the loop and after emitting the constant pool.  TODO:
+  // Since all constants are globally pooled in the Ice::GlobalContext
+  // object, change all Ice::Constant related functions to use
+  // GlobalContext instead of Cfg, and then clean up this loop.
+  OwningPtr<Ice::Cfg> Func;
   Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
 
   for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
@@ -678,7 +686,7 @@
     LLVM2ICEConverter FunctionConverter(&Ctx);
 
     Ice::Timer TConvert;
-    Ice::Cfg *Func = FunctionConverter.convertFunction(I);
+    Func.reset(FunctionConverter.convertFunction(I));
     if (DisableInternal)
       Func->setInternal(false);
 
@@ -713,5 +721,8 @@
     }
   }
 
+  if (!DisableTranslation && Func)
+    Func->getTarget()->emitConstants();
+
   return ExitStatus;
 }