Commit 645aa1a9 by Karl Schimpf

Convert Subzero's bitcode reader to generate ICE types.

Changes Subzero's bitcode reader to build and store ICE types, instead of using LLVM's types. Note: This code doesn't remove all uses of LLVM types. They are still used to check types for instructions and to generate function addresses. BUG=None R=jvoung@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/625243002
parent d14b1a02
......@@ -53,57 +53,4 @@ Type TypeConverter::convertToIceTypeOther(llvm::Type *LLVMTy) const {
}
}
llvm::Type *TypeConverter::getLLVMIntegerType(unsigned NumBits) const {
switch (NumBits) {
case 1:
return LLVMTypes[IceType_i1];
case 8:
return LLVMTypes[IceType_i8];
case 16:
return LLVMTypes[IceType_i16];
case 32:
return LLVMTypes[IceType_i32];
case 64:
return LLVMTypes[IceType_i64];
default:
return NULL;
}
}
llvm::Type *TypeConverter::getLLVMVectorType(unsigned Size, Type Ty) const {
switch (Ty) {
case IceType_i1:
switch (Size) {
case 4:
return convertToLLVMType(IceType_v4i1);
case 8:
return convertToLLVMType(IceType_v8i1);
case 16:
return convertToLLVMType(IceType_v16i1);
default:
break;
}
break;
case IceType_i8:
if (Size == 16)
return convertToLLVMType(IceType_v16i8);
break;
case IceType_i16:
if (Size == 8)
return convertToLLVMType(IceType_v8i16);
break;
case IceType_i32:
if (Size == 4)
return convertToLLVMType(IceType_v4i32);
break;
case IceType_f32:
if (Size == 4)
return convertToLLVMType(IceType_v4f32);
break;
default:
break;
}
return NULL;
}
} // end of Ice namespace.
......@@ -53,14 +53,6 @@ public:
/// Returns ICE model of pointer type.
Type getIcePointerType() const { return IceType_i32; }
/// Returns LLVM integer type with specified number of bits. Returns
/// NULL if not a valid PNaCl integer type.
llvm::Type *getLLVMIntegerType(unsigned NumBits) const;
/// Returns the LLVM vector type for Size and Ty arguments. Returns
/// NULL if not a valid PNaCl vector type.
llvm::Type *getLLVMVectorType(unsigned Size, Type Ty) const;
private:
// The list of allowable LLVM types. Indexed by ICE type.
std::vector<llvm::Type *> LLVMTypes;
......
......@@ -230,7 +230,7 @@ Type getCompareResultType(Type Ty) {
SizeT getScalarIntBitWidth(Type Ty) {
assert(isScalarIntegerType(Ty));
if (Ty == Ice::IceType_i1)
if (Ty == IceType_i1)
return 1;
return typeWidthInBytes(Ty) * CHAR_BIT;
}
......@@ -245,4 +245,18 @@ const char *typeString(Type Ty) {
return "???";
}
void FuncSigType::dump(Ostream &Stream) const {
Stream << ReturnType << " (";
bool IsFirst = true;
for (const Type ArgTy : ArgList) {
if (IsFirst) {
IsFirst = false;
} else {
Stream << ", ";
}
Stream << ArgTy;
}
Stream << ")";
}
} // end of namespace Ice
......@@ -103,6 +103,43 @@ inline StreamType &operator<<(StreamType &Str, const Type &Ty) {
return Str;
}
/// Models a type signature for a function.
/// TODO(kschimpf): Consider using arena memory allocation for
/// the contents of type signatures.
class FuncSigType {
// FuncSigType(const FuncSigType &Ty) = delete;
FuncSigType &operator=(const FuncSigType &Ty) = delete;
public:
typedef std::vector<Type> ArgListType;
// Creates a function signature type with the given return type.
// Parameter types should be added using calls to appendArgType.
FuncSigType() : ReturnType(IceType_void) {}
void appendArgType(Type ArgType) { ArgList.push_back(ArgType); }
Type getReturnType() const { return ReturnType; }
void setReturnType(Type NewType) { ReturnType = NewType; }
SizeT getNumArgs() const { return ArgList.size(); }
Type getArgType(SizeT Index) const {
assert(Index < ArgList.size());
return ArgList[Index];
}
const ArgListType &getArgList() const { return ArgList; }
void dump(Ostream &Stream) const;
private:
// The return type.
Type ReturnType;
// The list of parameters.
ArgListType ArgList;
};
inline Ostream &operator<<(Ostream &Stream, const FuncSigType &Sig) {
Sig.dump(Stream);
return Stream;
}
} // end of namespace Ice
#endif // SUBZERO_SRC_ICETYPES_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment