OLD | NEW |
---|---|
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 std::string Buffer; | 902 std::string Buffer; |
903 raw_string_ostream StrBuf(Buffer); | 903 raw_string_ostream StrBuf(Buffer); |
904 StrBuf << "Value index " << Index << " out of range. Must be less than " | 904 StrBuf << "Value index " << Index << " out of range. Must be less than " |
905 << (LocalOperands.size() + CachedNumGlobalValueIDs); | 905 << (LocalOperands.size() + CachedNumGlobalValueIDs); |
906 Error(StrBuf.str()); | 906 Error(StrBuf.str()); |
907 report_fatal_error("Unable to continue"); | 907 report_fatal_error("Unable to continue"); |
908 } | 908 } |
909 return LocalOperands[LocalIndex]; | 909 return LocalOperands[LocalIndex]; |
910 } | 910 } |
911 | 911 |
912 // Returns the relative operand (wrt to next instruction) referenced by | |
913 // the given value index. | |
914 Ice::Operand *getRelativeOperand(uint32_t Index) { | |
jvoung (off chromium)
2014/09/02 21:06:46
could these methods have been const?
Karl
2014/09/02 22:45:11
No. The parser needs to be able to generate an err
| |
915 return getOperand(convertRelativeToAbsIndex(Index)); | |
916 } | |
917 | |
912 // Generates type error message for binary operator Op | 918 // Generates type error message for binary operator Op |
913 // operating on Type OpTy. | 919 // operating on Type OpTy. |
914 void ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy); | 920 void ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy); |
915 | 921 |
916 // Validates if integer logical Op, for type OpTy, is valid. | 922 // Validates if integer logical Op, for type OpTy, is valid. |
917 // Returns true if valid. Otherwise generates error message and | 923 // Returns true if valid. Otherwise generates error message and |
918 // returns false. | 924 // returns false. |
919 bool isValidIntegerLogicalOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy) { | 925 bool isValidIntegerLogicalOp(Ice::InstArithmetic::OpKind Op, Ice::Type OpTy) { |
920 if (Ice::isIntegerType(OpTy)) | 926 if (Ice::isIntegerType(OpTy)) |
921 return true; | 927 return true; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 // Install the basic blocks, skipping bb0 which was created in the | 1142 // Install the basic blocks, skipping bb0 which was created in the |
1137 // constructor. | 1143 // constructor. |
1138 for (size_t i = 1; i < NumBbs; ++i) | 1144 for (size_t i = 1; i < NumBbs; ++i) |
1139 InstallNextBasicBlock(); | 1145 InstallNextBasicBlock(); |
1140 break; | 1146 break; |
1141 } | 1147 } |
1142 case naclbitc::FUNC_CODE_INST_BINOP: { | 1148 case naclbitc::FUNC_CODE_INST_BINOP: { |
1143 // BINOP: [opval, opval, opcode] | 1149 // BINOP: [opval, opval, opcode] |
1144 if (!isValidRecordSize(3, "function block binop")) | 1150 if (!isValidRecordSize(3, "function block binop")) |
1145 return; | 1151 return; |
1146 Ice::Operand *Op1 = getOperand(convertRelativeToAbsIndex(Values[0])); | 1152 Ice::Operand *Op1 = getRelativeOperand(Values[0]); |
1147 Ice::Operand *Op2 = getOperand(convertRelativeToAbsIndex(Values[1])); | 1153 Ice::Operand *Op2 = getRelativeOperand(Values[1]); |
1148 Ice::Type Type1 = Op1->getType(); | 1154 Ice::Type Type1 = Op1->getType(); |
1149 Ice::Type Type2 = Op2->getType(); | 1155 Ice::Type Type2 = Op2->getType(); |
1150 if (Type1 != Type2) { | 1156 if (Type1 != Type2) { |
1151 std::string Buffer; | 1157 std::string Buffer; |
1152 raw_string_ostream StrBuf(Buffer); | 1158 raw_string_ostream StrBuf(Buffer); |
1153 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; | 1159 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; |
1154 Error(StrBuf.str()); | 1160 Error(StrBuf.str()); |
1155 // TODO(kschimpf) Remove error recovery once implementation complete. | 1161 // TODO(kschimpf) Remove error recovery once implementation complete. |
1156 Op2 = Op1; | 1162 Op2 = Op1; |
1157 } | 1163 } |
1158 | 1164 |
1159 Ice::InstArithmetic::OpKind Opcode; | 1165 Ice::InstArithmetic::OpKind Opcode; |
1160 if (!convertBinopOpcode(Values[2], Type1, Opcode)) | 1166 if (!convertBinopOpcode(Values[2], Type1, Opcode)) |
1161 return; | 1167 return; |
1162 Ice::Variable *Dest = NextInstVar(Type1); | 1168 Ice::Variable *Dest = NextInstVar(Type1); |
1163 Inst = Ice::InstArithmetic::create(Func, Opcode, Dest, Op1, Op2); | 1169 Inst = Ice::InstArithmetic::create(Func, Opcode, Dest, Op1, Op2); |
1164 break; | 1170 break; |
1165 } | 1171 } |
1166 case naclbitc::FUNC_CODE_INST_CAST: { | 1172 case naclbitc::FUNC_CODE_INST_CAST: { |
1167 // CAST: [opval, destty, castopc] | 1173 // CAST: [opval, destty, castopc] |
1168 if (!isValidRecordSize(3, "function block cast")) | 1174 if (!isValidRecordSize(3, "function block cast")) |
1169 return; | 1175 return; |
1170 Ice::Operand *Src = getOperand(convertRelativeToAbsIndex(Values[0])); | 1176 Ice::Operand *Src = getRelativeOperand(Values[0]); |
1171 Type *CastType = Context->getTypeByID(Values[1]); | 1177 Type *CastType = Context->getTypeByID(Values[1]); |
1172 Instruction::CastOps LLVMCastOp; | 1178 Instruction::CastOps LLVMCastOp; |
1173 Ice::InstCast::OpKind CastKind; | 1179 Ice::InstCast::OpKind CastKind; |
1174 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || | 1180 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || |
1175 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { | 1181 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { |
1176 std::string Buffer; | 1182 std::string Buffer; |
1177 raw_string_ostream StrBuf(Buffer); | 1183 raw_string_ostream StrBuf(Buffer); |
1178 StrBuf << "Cast opcode not understood: " << Values[2]; | 1184 StrBuf << "Cast opcode not understood: " << Values[2]; |
1179 Error(StrBuf.str()); | 1185 Error(StrBuf.str()); |
1180 return; | 1186 return; |
1181 } | 1187 } |
1182 Type *SrcType = Context->convertToLLVMType(Src->getType()); | 1188 Type *SrcType = Context->convertToLLVMType(Src->getType()); |
1183 if (!CastInst::castIsValid(LLVMCastOp, SrcType, CastType)) { | 1189 if (!CastInst::castIsValid(LLVMCastOp, SrcType, CastType)) { |
1184 std::string Buffer; | 1190 std::string Buffer; |
1185 raw_string_ostream StrBuf(Buffer); | 1191 raw_string_ostream StrBuf(Buffer); |
1186 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp) | 1192 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp) |
1187 << " " << *SrcType << " to " << *CastType; | 1193 << " " << *SrcType << " to " << *CastType; |
1188 Error(StrBuf.str()); | 1194 Error(StrBuf.str()); |
1189 return; | 1195 return; |
1190 } | 1196 } |
1191 Ice::Variable *Dest = NextInstVar(Context->convertToIceType(CastType)); | 1197 Ice::Variable *Dest = NextInstVar(Context->convertToIceType(CastType)); |
1192 Inst = Ice::InstCast::create(Func, CastKind, Dest, Src); | 1198 Inst = Ice::InstCast::create(Func, CastKind, Dest, Src); |
1193 break; | 1199 break; |
1194 } | 1200 } |
1201 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { | |
1202 // EXTRACTELT: [opval, opval] | |
1203 Ice::Operand *Vec = getRelativeOperand(Values[0]); | |
1204 Ice::Type VecType = Vec->getType(); | |
1205 if (!Ice::isVectorType(VecType)) { | |
1206 std::string Buffer; | |
1207 raw_string_ostream StrBuf(Buffer); | |
1208 StrBuf << "Extractelement not on vector. Found: " << Vec; | |
1209 Error(StrBuf.str()); | |
1210 } | |
1211 Ice::Operand *Index = getRelativeOperand(Values[1]); | |
1212 if (Index->getType() != Ice::IceType_i32) { | |
1213 std::string Buffer; | |
1214 raw_string_ostream StrBuf(Buffer); | |
1215 StrBuf << "Extractlement index not i32. Found: " << Index; | |
jvoung (off chromium)
2014/09/02 21:06:46
Extractelement
Karl
2014/09/02 22:45:11
Done.
| |
1216 Error(StrBuf.str()); | |
1217 } | |
1218 Ice::Variable *Dest = NextInstVar(typeElementType(VecType)); | |
1219 Inst = Ice::InstExtractElement::create(Func, Dest, Vec, Index); | |
1220 break; | |
1221 } | |
1222 case naclbitc::FUNC_CODE_INST_INSERTELT: { | |
1223 // INSERTELT: [opval,opval,opval] | |
jvoung (off chromium)
2014/09/02 21:06:46
spaces between , opval ?
Karl
2014/09/02 22:45:11
Done.
| |
1224 Ice::Operand *Vec = getRelativeOperand(Values[0]); | |
1225 Ice::Type VecType = Vec->getType(); | |
1226 if (!Ice::isVectorType(VecType)) { | |
1227 std::string Buffer; | |
1228 raw_string_ostream StrBuf(Buffer); | |
1229 StrBuf << "Insertelement not on vector. Found: " << Vec; | |
1230 Error(StrBuf.str()); | |
1231 } | |
1232 Ice::Operand *Elt = getRelativeOperand(Values[1]); | |
1233 Ice::Type EltType = Elt->getType(); | |
1234 if (EltType != typeElementType(VecType)) { | |
1235 std::string Buffer; | |
1236 raw_string_ostream StrBuf(Buffer); | |
1237 StrBuf << "Insertelement element not " << typeElementType(VecType) | |
1238 << ". Found: " << Elt; | |
1239 Error(StrBuf.str()); | |
1240 } | |
1241 Ice::Operand *Index = getRelativeOperand(Values[2]); | |
1242 if (Index->getType() != Ice::IceType_i32) { | |
1243 std::string Buffer; | |
1244 raw_string_ostream StrBuf(Buffer); | |
1245 StrBuf << "Insertelement index not i32. Found: " << Index; | |
1246 Error(StrBuf.str()); | |
1247 } | |
1248 Ice::Variable *Dest = NextInstVar(EltType); | |
1249 Inst = Ice::InstInsertElement::create(Func, Dest, Vec, Elt, Index); | |
1250 break; | |
1251 } | |
1195 case naclbitc::FUNC_CODE_INST_RET: { | 1252 case naclbitc::FUNC_CODE_INST_RET: { |
1196 // RET: [opval?] | 1253 // RET: [opval?] |
1197 InstIsTerminating = true; | 1254 InstIsTerminating = true; |
1198 if (!isValidRecordSizeInRange(0, 1, "function block ret")) | 1255 if (!isValidRecordSizeInRange(0, 1, "function block ret")) |
1199 return; | 1256 return; |
1200 if (Values.size() == 0) { | 1257 if (Values.size() == 0) { |
1201 Inst = Ice::InstRet::create(Func); | 1258 Inst = Ice::InstRet::create(Func); |
1202 } else { | 1259 } else { |
1203 Inst = Ice::InstRet::create( | 1260 Inst = Ice::InstRet::create( |
1204 Func, getOperand(convertRelativeToAbsIndex(Values[0]))); | 1261 Func, getRelativeOperand(Values[0])); |
1205 } | 1262 } |
1206 break; | 1263 break; |
1207 } | 1264 } |
1208 default: | 1265 default: |
1209 // Generate error message! | 1266 // Generate error message! |
1210 BlockParserBaseClass::ProcessRecord(); | 1267 BlockParserBaseClass::ProcessRecord(); |
1211 break; | 1268 break; |
1212 } | 1269 } |
1213 if (Inst) | 1270 if (Inst) |
1214 CurrentNode->appendInst(Inst); | 1271 CurrentNode->appendInst(Inst); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1372 if (TopLevelBlocks != 1) { | 1429 if (TopLevelBlocks != 1) { |
1373 errs() << IRFilename | 1430 errs() << IRFilename |
1374 << ": Contains more than one module. Found: " << TopLevelBlocks | 1431 << ": Contains more than one module. Found: " << TopLevelBlocks |
1375 << "\n"; | 1432 << "\n"; |
1376 ErrorStatus = true; | 1433 ErrorStatus = true; |
1377 } | 1434 } |
1378 return; | 1435 return; |
1379 } | 1436 } |
1380 | 1437 |
1381 } // end of namespace Ice | 1438 } // end of namespace Ice |
OLD | NEW |