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/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()) {