Commit 9bb188d8 by Karl Schimpf

Reduce one layer of decoding for binary operations in bitcode reading.

Removes the need to call function llvm::DecodeBinaryOp. In turn, this removes the need for enum type llvm::Instruction::BinaryOps, llvm::Type.isFPOrFPVectorTy, and one call to llvm::convertToLLVMType. BUG= None R=jvoung@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/788283002
parent f875d45f
...@@ -1510,10 +1510,6 @@ private: ...@@ -1510,10 +1510,6 @@ private:
return VectorIndexValid; return VectorIndexValid;
} }
// Reports that the given binary Opcode, for the given type Ty,
// is not understood.
void ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty);
// Returns true if the Str begins with Prefix. // Returns true if the Str begins with Prefix.
bool isStringPrefix(Ice::IceString &Str, Ice::IceString &Prefix) { bool isStringPrefix(Ice::IceString &Str, Ice::IceString &Prefix) {
const size_t PrefixSize = Prefix.size(); const size_t PrefixSize = Prefix.size();
...@@ -1531,73 +1527,78 @@ private: ...@@ -1531,73 +1527,78 @@ private:
// opcode. Returns true if able to convert, false otherwise. // opcode. Returns true if able to convert, false otherwise.
bool convertBinopOpcode(unsigned Opcode, Ice::Type Ty, bool convertBinopOpcode(unsigned Opcode, Ice::Type Ty,
Ice::InstArithmetic::OpKind &Op) { Ice::InstArithmetic::OpKind &Op) {
Instruction::BinaryOps LLVMOpcode; switch (Opcode) {
if (!naclbitc::DecodeBinaryOpcode(Opcode, Context->convertToLLVMType(Ty),
LLVMOpcode)) {
ReportInvalidBinopOpcode(Opcode, Ty);
// TODO(kschimpf) Remove error recovery once implementation complete.
Op = Ice::InstArithmetic::Add;
return false;
}
switch (LLVMOpcode) {
default: { default: {
ReportInvalidBinopOpcode(Opcode, Ty); std::string Buffer;
raw_string_ostream StrBuf(Buffer);
StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty;
Error(StrBuf.str());
// TODO(kschimpf) Remove error recovery once implementation complete. // TODO(kschimpf) Remove error recovery once implementation complete.
Op = Ice::InstArithmetic::Add; Op = Ice::InstArithmetic::Add;
return false; return false;
} }
case Instruction::Add: case naclbitc::BINOP_ADD:
Op = Ice::InstArithmetic::Add; if (Ice::isIntegerType(Ty)) {
return isValidIntegerArithOp(Op, Ty); Op = Ice::InstArithmetic::Add;
case Instruction::FAdd: return isValidIntegerArithOp(Op, Ty);
Op = Ice::InstArithmetic::Fadd; } else {
return isValidFloatingArithOp(Op, Ty); Op = Ice::InstArithmetic::Fadd;
case Instruction::Sub: return isValidFloatingArithOp(Op, Ty);
Op = Ice::InstArithmetic::Sub; }
return isValidIntegerArithOp(Op, Ty); case naclbitc::BINOP_SUB:
case Instruction::FSub: if (Ice::isIntegerType(Ty)) {
Op = Ice::InstArithmetic::Fsub; Op = Ice::InstArithmetic::Sub;
return isValidFloatingArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::Mul: } else {
Op = Ice::InstArithmetic::Mul; Op = Ice::InstArithmetic::Fsub;
return isValidIntegerArithOp(Op, Ty); return isValidFloatingArithOp(Op, Ty);
case Instruction::FMul: }
Op = Ice::InstArithmetic::Fmul; case naclbitc::BINOP_MUL:
return isValidFloatingArithOp(Op, Ty); if (Ice::isIntegerType(Ty)) {
case Instruction::UDiv: Op = Ice::InstArithmetic::Mul;
return isValidIntegerArithOp(Op, Ty);
} else {
Op = Ice::InstArithmetic::Fmul;
return isValidFloatingArithOp(Op, Ty);
}
case naclbitc::BINOP_UDIV:
Op = Ice::InstArithmetic::Udiv; Op = Ice::InstArithmetic::Udiv;
return isValidIntegerArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::SDiv: case naclbitc::BINOP_SDIV:
Op = Ice::InstArithmetic::Sdiv; if (Ice::isIntegerType(Ty)) {
return isValidIntegerArithOp(Op, Ty); Op = Ice::InstArithmetic::Sdiv;
case Instruction::FDiv: return isValidIntegerArithOp(Op, Ty);
Op = Ice::InstArithmetic::Fdiv; } else {
return isValidFloatingArithOp(Op, Ty); Op = Ice::InstArithmetic::Fdiv;
case Instruction::URem: return isValidFloatingArithOp(Op, Ty);
}
case naclbitc::BINOP_UREM:
Op = Ice::InstArithmetic::Urem; Op = Ice::InstArithmetic::Urem;
return isValidIntegerArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::SRem: case naclbitc::BINOP_SREM:
Op = Ice::InstArithmetic::Srem; if (Ice::isIntegerType(Ty)) {
return isValidIntegerArithOp(Op, Ty); Op = Ice::InstArithmetic::Srem;
case Instruction::FRem: return isValidIntegerArithOp(Op, Ty);
Op = Ice::InstArithmetic::Frem; } else {
return isValidFloatingArithOp(Op, Ty); Op = Ice::InstArithmetic::Frem;
case Instruction::Shl: return isValidFloatingArithOp(Op, Ty);
}
case naclbitc::BINOP_SHL:
Op = Ice::InstArithmetic::Shl; Op = Ice::InstArithmetic::Shl;
return isValidIntegerArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::LShr: case naclbitc::BINOP_LSHR:
Op = Ice::InstArithmetic::Lshr; Op = Ice::InstArithmetic::Lshr;
return isValidIntegerArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::AShr: case naclbitc::BINOP_ASHR:
Op = Ice::InstArithmetic::Ashr; Op = Ice::InstArithmetic::Ashr;
return isValidIntegerArithOp(Op, Ty); return isValidIntegerArithOp(Op, Ty);
case Instruction::And: case naclbitc::BINOP_AND:
Op = Ice::InstArithmetic::And; Op = Ice::InstArithmetic::And;
return isValidIntegerLogicalOp(Op, Ty); return isValidIntegerLogicalOp(Op, Ty);
case Instruction::Or: case naclbitc::BINOP_OR:
Op = Ice::InstArithmetic::Or; Op = Ice::InstArithmetic::Or;
return isValidIntegerLogicalOp(Op, Ty); return isValidIntegerLogicalOp(Op, Ty);
case Instruction::Xor: case naclbitc::BINOP_XOR:
Op = Ice::InstArithmetic::Xor; Op = Ice::InstArithmetic::Xor;
return isValidIntegerLogicalOp(Op, Ty); return isValidIntegerLogicalOp(Op, Ty);
} }
...@@ -1764,13 +1765,6 @@ private: ...@@ -1764,13 +1765,6 @@ private:
} }
}; };
void FunctionParser::ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty;
Error(StrBuf.str());
}
void FunctionParser::ExitBlock() { void FunctionParser::ExitBlock() {
if (isIRGenerationDisabled()) { if (isIRGenerationDisabled()) {
popTimerIfTimingEachFunction(); popTimerIfTimingEachFunction();
...@@ -1868,8 +1862,10 @@ void FunctionParser::ProcessRecord() { ...@@ -1868,8 +1862,10 @@ void FunctionParser::ProcessRecord() {
} }
Ice::InstArithmetic::OpKind Opcode; Ice::InstArithmetic::OpKind Opcode;
if (!convertBinopOpcode(Values[2], Type1, Opcode)) if (!convertBinopOpcode(Values[2], Type1, Opcode)) {
appendErrorInstruction(Type1);
return; return;
}
CurrentNode->appendInst(Ice::InstArithmetic::create( CurrentNode->appendInst(Ice::InstArithmetic::create(
Func, Opcode, getNextInstVar(Type1), Op1, Op2)); Func, Opcode, getNextInstVar(Type1), Op1, Op2));
return; return;
......
; Tests the Subzero "name mangling" when using the "llvm2ice --prefix" ; Tests the Subzero "name mangling" when using the "llvm2ice --prefix"
; option. Also does a quick smoke test of -ffunction-sections. ; option. Also does a quick smoke test of -ffunction-sections.
; REQUIRES: allow_dump
; RUN: %p2i -i %s --args --verbose none -ffunction-sections | FileCheck %s ; RUN: %p2i -i %s --args --verbose none -ffunction-sections | FileCheck %s
; TODO(stichnot): The following line causes this test to fail. ; TODO(stichnot): The following line causes this test to fail.
; RUIN: %p2i -i %s --args --verbose none \ ; RUIN: %p2i -i %s --args --verbose none \
......
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