Remove TypeConverter and Module from minimal subzero build.

Removes the need to model LLVM types from the minimal subzero build.
It isn't removed from the nonminimal build because IceConverter still needs
to be able to convert LLVM types to corresponding Ice types.

Note that this CL reduces the size of Release+Min/llvm2ice (after
strip) to about 638K bytes.

BUG=None
R=jvoung@chromium.org, stichnot@chromium.org

Review URL: https://codereview.chromium.org/805943002
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 9e003ef..2e6021b 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -349,8 +349,7 @@
 
   Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Inst) {
     Ice::Operand *Src = convertOperand(Inst, 0);
-    Ice::Variable *Dest =
-        mapValueToIceVar(Inst, TypeConverter.getIcePointerType());
+    Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType());
     return Ice::InstAssign::create(Func, Dest, Src);
   }
 
@@ -568,8 +567,7 @@
     // PNaCl bitcode only contains allocas of byte-granular objects.
     Ice::Operand *ByteCount = convertValue(Inst->getArraySize());
     uint32_t Align = Inst->getAlignment();
-    Ice::Variable *Dest =
-        mapValueToIceVar(Inst, TypeConverter.getIcePointerType());
+    Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType());
 
     return Ice::InstAlloca::create(Func, ByteCount, Align, Dest);
   }
@@ -766,7 +764,7 @@
       return;
     case Instruction::PtrToInt: {
       assert(TypeConverter.convertToIceType(Exp->getType()) ==
-             TypeConverter.getIcePointerType());
+             Ice::getPointerType());
       const auto GV = dyn_cast<GlobalValue>(Exp->getOperand(0));
       assert(GV);
       const Ice::GlobalDeclaration *Addr =
diff --git a/src/IceTypeConverter.cpp b/src/IceTypeConverter.cpp
index 75e79b8..ddb6cc7 100644
--- a/src/IceTypeConverter.cpp
+++ b/src/IceTypeConverter.cpp
@@ -20,26 +20,29 @@
 
 TypeConverter::TypeConverter(llvm::LLVMContext &Context) {
   addLLVMType(IceType_void, llvm::Type::getVoidTy(Context));
-  addLLVMType(IceType_i1, llvm::IntegerType::get(Context, 1));
-  addLLVMType(IceType_i8, llvm::IntegerType::get(Context, 8));
-  addLLVMType(IceType_i16, llvm::IntegerType::get(Context, 16));
-  addLLVMType(IceType_i32, llvm::IntegerType::get(Context, 32));
+  llvm::Type *Type_i1 = llvm::IntegerType::get(Context, 1);
+  llvm::Type *Type_i8 = llvm::IntegerType::get(Context, 8);
+  llvm::Type *Type_i16 = llvm::IntegerType::get(Context, 16);
+  llvm::Type *Type_i32 = llvm::IntegerType::get(Context, 32);
+  llvm::Type *Type_f32 = llvm::Type::getFloatTy(Context);
+  addLLVMType(IceType_i1, Type_i1);
+  addLLVMType(IceType_i8, Type_i8);
+  addLLVMType(IceType_i16, Type_i16);
+  addLLVMType(IceType_i32, Type_i32);
   addLLVMType(IceType_i64, llvm::IntegerType::get(Context, 64));
-  addLLVMType(IceType_f32, llvm::Type::getFloatTy(Context));
+  addLLVMType(IceType_f32, Type_f32);
   addLLVMType(IceType_f64, llvm::Type::getDoubleTy(Context));
-  addLLVMType(IceType_v4i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 4));
-  addLLVMType(IceType_v8i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 8));
-  addLLVMType(IceType_v16i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 16));
-  addLLVMType(IceType_v16i8, llvm::VectorType::get(LLVMTypes[IceType_i8], 16));
-  addLLVMType(IceType_v8i16, llvm::VectorType::get(LLVMTypes[IceType_i16], 8));
-  addLLVMType(IceType_v4i32, llvm::VectorType::get(LLVMTypes[IceType_i32], 4));
-  addLLVMType(IceType_v4f32, llvm::VectorType::get(LLVMTypes[IceType_f32], 4));
-  assert(LLVMTypes.size() == static_cast<size_t>(IceType_NUM));
+  addLLVMType(IceType_v4i1, llvm::VectorType::get(Type_i1, 4));
+  addLLVMType(IceType_v8i1, llvm::VectorType::get(Type_i1, 8));
+  addLLVMType(IceType_v16i1, llvm::VectorType::get(Type_i1, 16));
+  addLLVMType(IceType_v16i8, llvm::VectorType::get(Type_i8, 16));
+  addLLVMType(IceType_v8i16, llvm::VectorType::get(Type_i16, 8));
+  addLLVMType(IceType_v4i32, llvm::VectorType::get(Type_i32, 4));
+  addLLVMType(IceType_v4f32, llvm::VectorType::get(Type_f32, 4));
+  assert(LLVM2IceMap.size() == static_cast<size_t>(IceType_NUM));
 }
 
 void TypeConverter::addLLVMType(Type Ty, llvm::Type *LLVMTy) {
-  assert(static_cast<size_t>(Ty) == LLVMTypes.size());
-  LLVMTypes.push_back(LLVMTy);
   LLVM2IceMap[LLVMTy] = Ty;
 }
 
@@ -47,7 +50,7 @@
   switch (LLVMTy->getTypeID()) {
   case llvm::Type::PointerTyID:
   case llvm::Type::FunctionTyID:
-    return getIcePointerType();
+    return getPointerType();
   default:
     return Ice::IceType_NUM;
   }
diff --git a/src/IceTypeConverter.h b/src/IceTypeConverter.h
index 32865a6..0450aac 100644
--- a/src/IceTypeConverter.h
+++ b/src/IceTypeConverter.h
@@ -35,12 +35,6 @@
   /// Context is the context to use to build llvm types.
   TypeConverter(llvm::LLVMContext &Context);
 
-  /// Returns the LLVM type for the corresponding ICE type Ty.
-  llvm::Type *convertToLLVMType(Type Ty) const {
-    // Note: We use "at" here in case Ty wasn't registered.
-    return LLVMTypes.at(Ty);
-  }
-
   /// Converts LLVM type LLVMTy to an ICE type. Returns
   /// Ice::IceType_NUM if unable to convert.
   Type convertToIceType(llvm::Type *LLVMTy) const {
@@ -50,13 +44,8 @@
     return Pos->second;
   }
 
-  /// Returns ICE model of pointer type.
-  Type getIcePointerType() const { return IceType_i32; }
-
 private:
-  // The list of allowable LLVM types. Indexed by ICE type.
-  std::vector<llvm::Type *> LLVMTypes;
-  // The inverse mapping of LLVMTypes.
+  // The mapping from LLVM types to corresopnding Ice types.
   std::map<llvm::Type *, Type> LLVM2IceMap;
 
   // Add LLVM/ICE pair to internal tables.
diff --git a/src/IceTypes.h b/src/IceTypes.h
index 662a31a..f3ad672 100644
--- a/src/IceTypes.h
+++ b/src/IceTypes.h
@@ -53,6 +53,8 @@
 Type typeElementType(Type Ty);
 const char *typeString(Type Ty);
 
+inline Type getPointerType() { return IceType_i32; }
+
 bool isVectorType(Type Ty);
 
 bool isIntegerType(Type Ty); // scalar or vector
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index bd25da7..0644582 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -17,8 +17,6 @@
 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h"
 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h"
 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
@@ -32,7 +30,6 @@
 #include "IceGlobalInits.h"
 #include "IceInst.h"
 #include "IceOperand.h"
-#include "IceTypeConverter.h"
 #include "PNaClTranslator.h"
 
 #include <memory>
@@ -170,14 +167,11 @@
 public:
   typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType;
 
-  TopLevelParser(Ice::Translator &Translator, const std::string &InputName,
-                 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor,
-                 bool &ErrorStatus)
-      : NaClBitcodeParser(Cursor), Translator(Translator),
-        Mod(new Module(InputName, getGlobalContext())), Header(Header),
-        TypeConverter(Mod->getContext()), ErrorStatus(ErrorStatus),
-        NumErrors(0), NumFunctionIds(0), NumFunctionBlocks(0),
-        BlockParser(nullptr) {
+  TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header,
+                 NaClBitstreamCursor &Cursor, bool &ErrorStatus)
+      : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
+        ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0),
+        NumFunctionBlocks(0), BlockParser(nullptr) {
     setErrStream(Translator.getContext()->getStrDump());
   }
 
@@ -199,9 +193,6 @@
   /// file.
   unsigned getNumErrors() const { return NumErrors; }
 
-  /// Returns the LLVM module associated with the translation.
-  Module *getModule() const { return Mod.get(); }
-
   /// Returns the number of bytes in the bitcode header.
   size_t getHeaderSize() const { return Header.getHeaderSize(); }
 
@@ -377,34 +368,11 @@
     return VariableDeclarations;
   }
 
-  /// Returns the corresponding ICE type for LLVMTy.
-  Ice::Type convertToIceType(Type *LLVMTy) {
-    Ice::Type IceTy = TypeConverter.convertToIceType(LLVMTy);
-    if (IceTy >= Ice::IceType_NUM) {
-      return convertToIceTypeError(LLVMTy);
-    }
-    return IceTy;
-  }
-
-  /// Returns the corresponding LLVM type for IceTy.
-  Type *convertToLLVMType(Ice::Type IceTy) const {
-    return TypeConverter.convertToLLVMType(IceTy);
-  }
-
-  /// Returns the model for pointer types in ICE.
-  Ice::Type getIcePointerType() const {
-    return TypeConverter.getIcePointerType();
-  }
-
 private:
   // The translator associated with the parser.
   Ice::Translator &Translator;
-  // The parsed module.
-  std::unique_ptr<Module> Mod;
   // The bitcode header.
   NaClBitcodeHeader &Header;
-  // Converter between LLVM and ICE types.
-  Ice::TypeConverter TypeConverter;
   // The exit status that should be set to true if an error occurs.
   bool &ErrorStatus;
   // The number of errors reported.
@@ -1407,7 +1375,7 @@
   // the given InstructionName. Returns true if valid. Otherwise
   // generates an error message and returns false.
   bool isValidPointerType(Ice::Operand *Op, const char *InstructionName) {
-    Ice::Type PtrType = Context->getIcePointerType();
+    Ice::Type PtrType = Ice::getPointerType();
     if (Op->getType() == PtrType)
       return true;
     std::string Buffer;
@@ -2365,7 +2333,7 @@
       setNextLocalInstIndex(nullptr);
       return;
     }
-    Ice::Type PtrTy = Context->getIcePointerType();
+    Ice::Type PtrTy = Ice::getPointerType();
     if (ByteCount->getType() != Ice::IceType_i32) {
       std::string Buffer;
       raw_string_ostream StrBuf(Buffer);
@@ -2655,9 +2623,8 @@
       FuncParser->setNextConstantID(nullptr);
       return;
     }
-    if (auto IType = dyn_cast<IntegerType>(
-            Context->convertToLLVMType(NextConstantType))) {
-      Ice::APInt Value(IType->getBitWidth(),
+    if (Ice::isScalarIntegerType(NextConstantType)) {
+      Ice::APInt Value(Ice::getScalarIntBitWidth(NextConstantType),
                        NaClDecodeSignRotatedValue(Values[0]));
       if (Ice::Constant *C = getContext()->getConstantInt(
               NextConstantType, Value.getSExtValue())) {
@@ -3022,8 +2989,7 @@
   NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr);
   NaClBitstreamCursor InputStream(InputStreamFile);
 
-  TopLevelParser Parser(*this, MemBuf->getBufferIdentifier(), Header,
-                        InputStream, ErrorStatus);
+  TopLevelParser Parser(*this, Header, InputStream, ErrorStatus);
   int TopLevelBlocks = 0;
   while (!InputStream.AtEndOfStream()) {
     if (Parser.Parse()) {