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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 Module *getModule() const { return Mod.get(); } | 194 Module *getModule() const { return Mod.get(); } |
195 | 195 |
196 const DataLayout &getDataLayout() const { return DL; } | 196 const DataLayout &getDataLayout() const { return DL; } |
197 | 197 |
198 /// Returns the number of bytes in the bitcode header. | 198 /// Returns the number of bytes in the bitcode header. |
199 size_t getHeaderSize() const { return Header.getHeaderSize(); } | 199 size_t getHeaderSize() const { return Header.getHeaderSize(); } |
200 | 200 |
201 /// Changes the size of the type list to the given size. | 201 /// Changes the size of the type list to the given size. |
202 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } | 202 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } |
203 | 203 |
204 /// Returns true if generation of Subzero IR is disabled. | |
205 bool isIRGenerationDisabled() const { | |
206 return Translator.getFlags().DisableIRGeneration; | |
207 } | |
208 | |
204 /// Returns the undefined type associated with type ID. | 209 /// Returns the undefined type associated with type ID. |
205 /// Note: Returns extended type ready to be defined. | 210 /// Note: Returns extended type ready to be defined. |
206 ExtendedType *getTypeByIDForDefining(unsigned ID) { | 211 ExtendedType *getTypeByIDForDefining(unsigned ID) { |
207 // Get corresponding element, verifying the value is still undefined | 212 // Get corresponding element, verifying the value is still undefined |
208 // (and hence allowed to be defined). | 213 // (and hence allowed to be defined). |
209 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); | 214 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); |
210 if (Ty) | 215 if (Ty) |
211 return Ty; | 216 return Ty; |
212 if (ID >= TypeIDValues.size()) | 217 if (ID >= TypeIDValues.size()) |
213 TypeIDValues.resize(ID+1); | 218 TypeIDValues.resize(ID+1); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 FunctionDeclarationList.size() + VariableDeclarations.size(); | 282 FunctionDeclarationList.size() + VariableDeclarations.size(); |
278 if (ID >= ExpectedSize) | 283 if (ID >= ExpectedSize) |
279 ExpectedSize = ID; | 284 ExpectedSize = ID; |
280 ValueIDConstants.resize(ExpectedSize); | 285 ValueIDConstants.resize(ExpectedSize); |
281 } else { | 286 } else { |
282 C = ValueIDConstants[ID]; | 287 C = ValueIDConstants[ID]; |
283 } | 288 } |
284 if (C != nullptr) | 289 if (C != nullptr) |
285 return C; | 290 return C; |
286 | 291 |
292 if (isIRGenerationDisabled()) { | |
293 ValueIDConstants[ID] = nullptr; | |
294 return nullptr; | |
295 } | |
296 | |
287 // If reached, no such constant exists, create one. | 297 // If reached, no such constant exists, create one. |
288 // TODO(kschimpf) Don't get addresses of intrinsic function declarations. | 298 // TODO(kschimpf) Don't get addresses of intrinsic function declarations. |
289 Ice::GlobalDeclaration *Decl = nullptr; | 299 Ice::GlobalDeclaration *Decl = nullptr; |
290 unsigned FcnIDSize = FunctionDeclarationList.size(); | 300 unsigned FcnIDSize = FunctionDeclarationList.size(); |
291 if (ID < FcnIDSize) { | 301 if (ID < FcnIDSize) { |
292 Decl = FunctionDeclarationList[ID]; | 302 Decl = FunctionDeclarationList[ID]; |
293 } else if ((ID - FcnIDSize) < VariableDeclarations.size()) { | 303 } else if ((ID - FcnIDSize) < VariableDeclarations.size()) { |
294 Decl = VariableDeclarations[ID - FcnIDSize]; | 304 Decl = VariableDeclarations[ID - FcnIDSize]; |
295 } | 305 } |
296 std::string Name; | 306 std::string Name; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 // Constructor for nested block parsers. | 526 // Constructor for nested block parsers. |
517 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 527 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
518 : NaClBitcodeParser(BlockID, EnclosingParser), | 528 : NaClBitcodeParser(BlockID, EnclosingParser), |
519 Context(EnclosingParser->Context) {} | 529 Context(EnclosingParser->Context) {} |
520 | 530 |
521 // Gets the translator associated with the bitcode parser. | 531 // Gets the translator associated with the bitcode parser. |
522 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 532 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
523 | 533 |
524 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 534 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
525 | 535 |
536 bool isIRGenerationDisabled() const { | |
537 return getTranslator().getFlags().DisableIRGeneration; | |
538 } | |
539 | |
526 // Generates an error Message with the bit address prefixed to it. | 540 // Generates an error Message with the bit address prefixed to it. |
527 bool Error(const std::string &Message) override { | 541 bool Error(const std::string &Message) override { |
528 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | 542 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; |
529 std::string Buffer; | 543 std::string Buffer; |
530 raw_string_ostream StrBuf(Buffer); | 544 raw_string_ostream StrBuf(Buffer); |
531 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | 545 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), |
532 static_cast<unsigned>(Bit % 8)) << ") " << Message; | 546 static_cast<unsigned>(Bit % 8)) << ") " << Message; |
533 return Context->Error(StrBuf.str()); | 547 return Context->Error(StrBuf.str()); |
534 } | 548 } |
535 | 549 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 Error("Globals count record not first in block."); | 888 Error("Globals count record not first in block."); |
875 return; | 889 return; |
876 } | 890 } |
877 Context->CreateGlobalVariables(Values[0]); | 891 Context->CreateGlobalVariables(Values[0]); |
878 return; | 892 return; |
879 case naclbitc::GLOBALVAR_VAR: { | 893 case naclbitc::GLOBALVAR_VAR: { |
880 // VAR: [align, isconst] | 894 // VAR: [align, isconst] |
881 if (!isValidRecordSize(2, "Globals variable")) | 895 if (!isValidRecordSize(2, "Globals variable")) |
882 return; | 896 return; |
883 verifyNoMissingInitializers(); | 897 verifyNoMissingInitializers(); |
884 InitializersNeeded = 1; | 898 if (!isIRGenerationDisabled()) { |
885 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); | 899 InitializersNeeded = 1; |
886 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); | 900 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); |
887 CurGlobalVar->setIsConstant(Values[1] != 0); | 901 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); |
902 CurGlobalVar->setIsConstant(Values[1] != 0); | |
903 } | |
888 ++NextGlobalID; | 904 ++NextGlobalID; |
889 return; | 905 return; |
890 } | 906 } |
891 case naclbitc::GLOBALVAR_COMPOUND: | 907 case naclbitc::GLOBALVAR_COMPOUND: |
892 // COMPOUND: [size] | 908 // COMPOUND: [size] |
893 if (!isValidRecordSize(1, "globals compound")) | 909 if (!isValidRecordSize(1, "globals compound")) |
894 return; | 910 return; |
895 if (!CurGlobalVar->getInitializers().empty()) { | 911 if (!CurGlobalVar->getInitializers().empty()) { |
896 Error("Globals compound record not first initializer"); | 912 Error("Globals compound record not first initializer"); |
897 return; | 913 return; |
898 } | 914 } |
899 if (Values[0] < 2) { | 915 if (Values[0] < 2) { |
900 std::string Buffer; | 916 std::string Buffer; |
901 raw_string_ostream StrBuf(Buffer); | 917 raw_string_ostream StrBuf(Buffer); |
902 StrBuf << "Globals compound record size invalid. Found: " << Values[0]; | 918 StrBuf << "Globals compound record size invalid. Found: " << Values[0]; |
903 Error(StrBuf.str()); | 919 Error(StrBuf.str()); |
904 return; | 920 return; |
905 } | 921 } |
922 if (isIRGenerationDisabled()) | |
923 return; | |
906 InitializersNeeded = Values[0]; | 924 InitializersNeeded = Values[0]; |
907 return; | 925 return; |
908 case naclbitc::GLOBALVAR_ZEROFILL: { | 926 case naclbitc::GLOBALVAR_ZEROFILL: { |
909 // ZEROFILL: [size] | 927 // ZEROFILL: [size] |
910 if (!isValidRecordSize(1, "Globals zerofill")) | 928 if (!isValidRecordSize(1, "Globals zerofill")) |
911 return; | 929 return; |
930 if (isIRGenerationDisabled()) | |
931 return; | |
912 CurGlobalVar->addInitializer( | 932 CurGlobalVar->addInitializer( |
913 new Ice::VariableDeclaration::ZeroInitializer(Values[0])); | 933 new Ice::VariableDeclaration::ZeroInitializer(Values[0])); |
914 return; | 934 return; |
915 } | 935 } |
916 case naclbitc::GLOBALVAR_DATA: { | 936 case naclbitc::GLOBALVAR_DATA: { |
917 // DATA: [b0, b1, ...] | 937 // DATA: [b0, b1, ...] |
918 if (!isValidRecordSizeAtLeast(1, "Globals data")) | 938 if (!isValidRecordSizeAtLeast(1, "Globals data")) |
919 return; | 939 return; |
940 if (isIRGenerationDisabled()) | |
941 return; | |
920 CurGlobalVar->addInitializer( | 942 CurGlobalVar->addInitializer( |
921 new Ice::VariableDeclaration::DataInitializer(Values)); | 943 new Ice::VariableDeclaration::DataInitializer(Values)); |
922 return; | 944 return; |
923 } | 945 } |
924 case naclbitc::GLOBALVAR_RELOC: { | 946 case naclbitc::GLOBALVAR_RELOC: { |
925 // RELOC: [val, [addend]] | 947 // RELOC: [val, [addend]] |
926 if (!isValidRecordSizeInRange(1, 2, "Globals reloc")) | 948 if (!isValidRecordSizeInRange(1, 2, "Globals reloc")) |
927 return; | 949 return; |
950 if (isIRGenerationDisabled()) | |
951 return; | |
928 unsigned Index = Values[0]; | 952 unsigned Index = Values[0]; |
929 Ice::SizeT Offset = 0; | 953 Ice::SizeT Offset = 0; |
930 if (Values.size() == 2) | 954 if (Values.size() == 2) |
931 Offset = Values[1]; | 955 Offset = Values[1]; |
932 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( | 956 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( |
933 Context->getGlobalDeclarationByID(Index), Offset)); | 957 Context->getGlobalDeclarationByID(Index), Offset)); |
934 return; | 958 return; |
935 } | 959 } |
936 default: | 960 default: |
937 BlockParserBaseClass::ProcessRecord(); | 961 BlockParserBaseClass::ProcessRecord(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1004 /// Parses function blocks in the bitcode file. | 1028 /// Parses function blocks in the bitcode file. |
1005 class FunctionParser : public BlockParserBaseClass { | 1029 class FunctionParser : public BlockParserBaseClass { |
1006 FunctionParser(const FunctionParser &) = delete; | 1030 FunctionParser(const FunctionParser &) = delete; |
1007 FunctionParser &operator=(const FunctionParser &) = delete; | 1031 FunctionParser &operator=(const FunctionParser &) = delete; |
1008 friend class FunctionValuesymtabParser; | 1032 friend class FunctionValuesymtabParser; |
1009 | 1033 |
1010 public: | 1034 public: |
1011 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1035 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
1012 : BlockParserBaseClass(BlockID, EnclosingParser), | 1036 : BlockParserBaseClass(BlockID, EnclosingParser), |
1013 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), | 1037 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), |
1014 Func(new Ice::Cfg(getTranslator().getContext())), CurrentBbIndex(0), | 1038 Func(isIRGenerationDisabled() |
1015 FcnId(Context->getNextFunctionBlockValueID()), | 1039 ? nullptr |
1040 : new Ice::Cfg(getTranslator().getContext())), | |
1041 CurrentBbIndex(0), FcnId(Context->getNextFunctionBlockValueID()), | |
1016 FuncDecl(Context->getFunctionByID(FcnId)), | 1042 FuncDecl(Context->getFunctionByID(FcnId)), |
1017 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), | 1043 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), |
1018 NextLocalInstIndex(Context->getNumGlobalIDs()), | 1044 NextLocalInstIndex(Context->getNumGlobalIDs()), |
1019 InstIsTerminating(false) { | 1045 InstIsTerminating(false) { |
1020 Func->setFunctionName(FuncDecl->getName()); | |
1021 if (getFlags().TimeEachFunction) | 1046 if (getFlags().TimeEachFunction) |
1022 getTranslator().getContext()->pushTimer( | 1047 getTranslator().getContext()->pushTimer( |
1023 getTranslator().getContext()->getTimerID( | 1048 getTranslator().getContext()->getTimerID( |
1024 Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()), | 1049 Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()), |
1025 Ice::GlobalContext::TSK_Funcs); | 1050 Ice::GlobalContext::TSK_Funcs); |
1026 // TODO(kschimpf) Clean up API to add a function signature to | 1051 // TODO(kschimpf) Clean up API to add a function signature to |
1027 // a CFG. | 1052 // a CFG. |
1028 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); | 1053 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); |
1029 Func->setReturnType(Signature.getReturnType()); | 1054 if (isIRGenerationDisabled()) { |
1030 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); | 1055 CurrentNode = nullptr; |
1031 CurrentNode = InstallNextBasicBlock(); | 1056 for (Ice::Type ArgType : Signature.getArgList()) { |
1032 Func->setEntryNode(CurrentNode); | 1057 (void)ArgType; |
1033 for (Ice::Type ArgType : Signature.getArgList()) { | 1058 setNextLocalInstIndex(nullptr); |
1034 Func->addArg(getNextInstVar(ArgType)); | 1059 } |
1060 } else { | |
1061 Func->setFunctionName(FuncDecl->getName()); | |
1062 Func->setReturnType(Signature.getReturnType()); | |
1063 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); | |
1064 CurrentNode = InstallNextBasicBlock(); | |
1065 Func->setEntryNode(CurrentNode); | |
1066 for (Ice::Type ArgType : Signature.getArgList()) { | |
1067 Func->addArg(getNextInstVar(ArgType)); | |
1068 } | |
1035 } | 1069 } |
1036 } | 1070 } |
1037 | 1071 |
1038 ~FunctionParser() override {}; | 1072 ~FunctionParser() override {}; |
1039 | 1073 |
1074 void setNextLocalInstIndex(Ice::Operand *Op) { | |
1075 setOperand(NextLocalInstIndex++, Op); | |
1076 } | |
1077 | |
1040 // Set the next constant ID to the given constant C. | 1078 // Set the next constant ID to the given constant C. |
1041 void setNextConstantID(Ice::Constant *C) { | 1079 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
1042 setOperand(NextLocalInstIndex++, C); | |
1043 } | |
1044 | 1080 |
1045 private: | 1081 private: |
1046 Ice::TimerMarker Timer; | 1082 Ice::TimerMarker Timer; |
1047 // The corresponding ICE function defined by the function block. | 1083 // The corresponding ICE function defined by the function block. |
1048 Ice::Cfg *Func; | 1084 Ice::Cfg *Func; |
1049 // The index to the current basic block being built. | 1085 // The index to the current basic block being built. |
1050 uint32_t CurrentBbIndex; | 1086 uint32_t CurrentBbIndex; |
1051 // The basic block being built. | 1087 // The basic block being built. |
1052 Ice::CfgNode *CurrentNode; | 1088 Ice::CfgNode *CurrentNode; |
1053 // The ID for the function. | 1089 // The ID for the function. |
1054 unsigned FcnId; | 1090 unsigned FcnId; |
1055 // The corresponding function declaration. | 1091 // The corresponding function declaration. |
1056 Ice::FunctionDeclaration *FuncDecl; | 1092 Ice::FunctionDeclaration *FuncDecl; |
1057 // Holds the dividing point between local and global absolute value indices. | 1093 // Holds the dividing point between local and global absolute value indices. |
1058 uint32_t CachedNumGlobalValueIDs; | 1094 uint32_t CachedNumGlobalValueIDs; |
1059 // Holds operands local to the function block, based on indices | 1095 // Holds operands local to the function block, based on indices |
1060 // defined in the bitcode file. | 1096 // defined in the bitcode file. |
1061 std::vector<Ice::Operand *> LocalOperands; | 1097 std::vector<Ice::Operand *> LocalOperands; |
1062 // Holds the index within LocalOperands corresponding to the next | 1098 // Holds the index within LocalOperands corresponding to the next |
1063 // instruction that generates a value. | 1099 // instruction that generates a value. |
1064 uint32_t NextLocalInstIndex; | 1100 uint32_t NextLocalInstIndex; |
1065 // True if the last processed instruction was a terminating | 1101 // True if the last processed instruction was a terminating |
1066 // instruction. | 1102 // instruction. |
1067 bool InstIsTerminating; | 1103 bool InstIsTerminating; |
1068 // Upper limit of alignment power allowed by LLVM | 1104 // Upper limit of alignment power allowed by LLVM |
1069 static const uint64_t AlignPowerLimit = 29; | 1105 static const uint64_t AlignPowerLimit = 29; |
1070 | 1106 |
1107 void popTimerIfTimingEachFunction() const { | |
1108 if (getFlags().TimeEachFunction) | |
jvoung (off chromium)
2014/11/04 22:30:15
please use {
}
when the body if the if-then-stat
Karl
2014/11/05 21:13:34
Done.
| |
1109 getTranslator().getContext()->popTimer( | |
1110 getTranslator().getContext()->getTimerID( | |
1111 Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()), | |
1112 Ice::GlobalContext::TSK_Funcs); | |
1113 } | |
1114 | |
1071 // Extracts the corresponding Alignment to use, given the AlignPower | 1115 // Extracts the corresponding Alignment to use, given the AlignPower |
1072 // (i.e. 2**AlignPower, or 0 if AlignPower == 0). InstName is the | 1116 // (i.e. 2**AlignPower, or 0 if AlignPower == 0). InstName is the |
1073 // name of the instruction the alignment appears in. | 1117 // name of the instruction the alignment appears in. |
1074 void extractAlignment(const char *InstName, uint64_t AlignPower, | 1118 void extractAlignment(const char *InstName, uint64_t AlignPower, |
1075 unsigned &Alignment) { | 1119 unsigned &Alignment) { |
1076 if (AlignPower <= AlignPowerLimit) { | 1120 if (AlignPower <= AlignPowerLimit) { |
1077 Alignment = (1 << static_cast<unsigned>(AlignPower)) >> 1; | 1121 Alignment = (1 << static_cast<unsigned>(AlignPower)) >> 1; |
1078 return; | 1122 return; |
1079 } | 1123 } |
1080 std::string Buffer; | 1124 std::string Buffer; |
1081 raw_string_ostream StrBuf(Buffer); | 1125 raw_string_ostream StrBuf(Buffer); |
1082 StrBuf << InstName << " alignment greater than 2**" << AlignPowerLimit | 1126 StrBuf << InstName << " alignment greater than 2**" << AlignPowerLimit |
1083 << ". Found: 2**" << AlignPower; | 1127 << ". Found: 2**" << AlignPower; |
1084 Error(StrBuf.str()); | 1128 Error(StrBuf.str()); |
1085 // Error recover with value that is always acceptable. | 1129 // Error recover with value that is always acceptable. |
1086 Alignment = 1; | 1130 Alignment = 1; |
1087 } | 1131 } |
1088 | 1132 |
1089 bool ParseBlock(unsigned BlockID) override; | 1133 bool ParseBlock(unsigned BlockID) override; |
1090 | 1134 |
1091 void ProcessRecord() override; | 1135 void ProcessRecord() override; |
1092 | 1136 |
1093 void ExitBlock() override; | 1137 void ExitBlock() override; |
1094 | 1138 |
1095 // Creates and appends a new basic block to the list of basic blocks. | 1139 // Creates and appends a new basic block to the list of basic blocks. |
1096 Ice::CfgNode *InstallNextBasicBlock() { return Func->makeNode(); } | 1140 Ice::CfgNode *InstallNextBasicBlock() { |
1141 assert(!isIRGenerationDisabled()); | |
1142 return Func->makeNode(); | |
1143 } | |
1097 | 1144 |
1098 // Returns the Index-th basic block in the list of basic blocks. | 1145 // Returns the Index-th basic block in the list of basic blocks. |
1099 Ice::CfgNode *getBasicBlock(uint32_t Index) { | 1146 Ice::CfgNode *getBasicBlock(uint32_t Index) { |
1147 assert(!isIRGenerationDisabled()); | |
1100 const Ice::NodeList &Nodes = Func->getNodes(); | 1148 const Ice::NodeList &Nodes = Func->getNodes(); |
1101 if (Index >= Nodes.size()) { | 1149 if (Index >= Nodes.size()) { |
1102 std::string Buffer; | 1150 std::string Buffer; |
1103 raw_string_ostream StrBuf(Buffer); | 1151 raw_string_ostream StrBuf(Buffer); |
1104 StrBuf << "Reference to basic block " << Index | 1152 StrBuf << "Reference to basic block " << Index |
1105 << " not found. Must be less than " << Nodes.size(); | 1153 << " not found. Must be less than " << Nodes.size(); |
1106 Error(StrBuf.str()); | 1154 Error(StrBuf.str()); |
1107 // TODO(kschimpf) Remove error recovery once implementation complete. | 1155 // TODO(kschimpf) Remove error recovery once implementation complete. |
1108 Index = 0; | 1156 Index = 0; |
1109 } | 1157 } |
1110 return Nodes[Index]; | 1158 return Nodes[Index]; |
1111 } | 1159 } |
1112 | 1160 |
1113 // Returns the Index-th basic block in the list of basic blocks. | 1161 // Returns the Index-th basic block in the list of basic blocks. |
1114 // Assumes Index corresponds to a branch instruction. Hence, if | 1162 // Assumes Index corresponds to a branch instruction. Hence, if |
1115 // the branch references the entry block, it also generates a | 1163 // the branch references the entry block, it also generates a |
1116 // corresponding error. | 1164 // corresponding error. |
1117 Ice::CfgNode *getBranchBasicBlock(uint32_t Index) { | 1165 Ice::CfgNode *getBranchBasicBlock(uint32_t Index) { |
1166 assert(!isIRGenerationDisabled()); | |
1118 if (Index == 0) { | 1167 if (Index == 0) { |
1119 Error("Branch to entry block not allowed"); | 1168 Error("Branch to entry block not allowed"); |
1120 // TODO(kschimpf) Remove error recovery once implementation complete. | 1169 // TODO(kschimpf) Remove error recovery once implementation complete. |
1121 } | 1170 } |
1122 return getBasicBlock(Index); | 1171 return getBasicBlock(Index); |
1123 } | 1172 } |
1124 | 1173 |
1125 // Generate an instruction variable with type Ty. | 1174 // Generate an instruction variable with type Ty. |
1126 Ice::Variable *createInstVar(Ice::Type Ty) { | 1175 Ice::Variable *createInstVar(Ice::Type Ty) { |
1176 assert(!isIRGenerationDisabled()); | |
1127 if (Ty == Ice::IceType_void) { | 1177 if (Ty == Ice::IceType_void) { |
1128 Error("Can't define instruction value using type void"); | 1178 Error("Can't define instruction value using type void"); |
1129 // Recover since we can't throw an exception. | 1179 // Recover since we can't throw an exception. |
1130 Ty = Ice::IceType_i32; | 1180 Ty = Ice::IceType_i32; |
1131 } | 1181 } |
1132 return Func->makeVariable(Ty); | 1182 return Func->makeVariable(Ty); |
1133 } | 1183 } |
1134 | 1184 |
1135 // Generates the next available local variable using the given type. | 1185 // Generates the next available local variable using the given type. |
1136 Ice::Variable *getNextInstVar(Ice::Type Ty) { | 1186 Ice::Variable *getNextInstVar(Ice::Type Ty) { |
1187 assert(!isIRGenerationDisabled()); | |
1137 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); | 1188 assert(NextLocalInstIndex >= CachedNumGlobalValueIDs); |
1138 // Before creating one, see if a forwardtyperef has already defined it. | 1189 // Before creating one, see if a forwardtyperef has already defined it. |
1139 uint32_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; | 1190 uint32_t LocalIndex = NextLocalInstIndex - CachedNumGlobalValueIDs; |
1140 if (LocalIndex < LocalOperands.size()) { | 1191 if (LocalIndex < LocalOperands.size()) { |
1141 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1192 Ice::Operand *Op = LocalOperands[LocalIndex]; |
1142 if (Op != nullptr) { | 1193 if (Op != nullptr) { |
1143 if (Ice::Variable *Var = dyn_cast<Ice::Variable>(Op)) { | 1194 if (Ice::Variable *Var = dyn_cast<Ice::Variable>(Op)) { |
1144 if (Var->getType() == Ty) { | 1195 if (Var->getType() == Ty) { |
1145 ++NextLocalInstIndex; | 1196 ++NextLocalInstIndex; |
1146 return Var; | 1197 return Var; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1235 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; |
1185 if (LocalIndex >= LocalOperands.size()) { | 1236 if (LocalIndex >= LocalOperands.size()) { |
1186 std::string Buffer; | 1237 std::string Buffer; |
1187 raw_string_ostream StrBuf(Buffer); | 1238 raw_string_ostream StrBuf(Buffer); |
1188 StrBuf << "Value index " << Index << " not defined!"; | 1239 StrBuf << "Value index " << Index << " not defined!"; |
1189 Error(StrBuf.str()); | 1240 Error(StrBuf.str()); |
1190 report_fatal_error("Unable to continue"); | 1241 report_fatal_error("Unable to continue"); |
1191 } | 1242 } |
1192 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1243 Ice::Operand *Op = LocalOperands[LocalIndex]; |
1193 if (Op == nullptr) { | 1244 if (Op == nullptr) { |
1245 if (isIRGenerationDisabled()) | |
1246 return nullptr; | |
1194 std::string Buffer; | 1247 std::string Buffer; |
1195 raw_string_ostream StrBuf(Buffer); | 1248 raw_string_ostream StrBuf(Buffer); |
1196 StrBuf << "Value index " << Index << " not defined!"; | 1249 StrBuf << "Value index " << Index << " not defined!"; |
1197 Error(StrBuf.str()); | 1250 Error(StrBuf.str()); |
1198 report_fatal_error("Unable to continue"); | 1251 report_fatal_error("Unable to continue"); |
1199 } | 1252 } |
1200 return Op; | 1253 return Op; |
1201 } | 1254 } |
1202 | 1255 |
1203 // Sets element Index (in the local operands list) to Op. | 1256 // Sets element Index (in the local operands list) to Op. |
1204 void setOperand(uint32_t Index, Ice::Operand *Op) { | 1257 void setOperand(uint32_t Index, Ice::Operand *Op) { |
1205 assert(Op); | 1258 assert(Op || isIRGenerationDisabled()); |
1206 // Check if simple push works. | 1259 // Check if simple push works. |
1207 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1260 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; |
1208 if (LocalIndex == LocalOperands.size()) { | 1261 if (LocalIndex == LocalOperands.size()) { |
1209 LocalOperands.push_back(Op); | 1262 LocalOperands.push_back(Op); |
1210 return; | 1263 return; |
1211 } | 1264 } |
1212 | 1265 |
1213 // Must be forward reference, expand vector to accommodate. | 1266 // Must be forward reference, expand vector to accommodate. |
1214 if (LocalIndex >= LocalOperands.size()) | 1267 if (LocalIndex >= LocalOperands.size()) |
1215 LocalOperands.resize(LocalIndex + 1); | 1268 LocalOperands.resize(LocalIndex + 1); |
1216 | 1269 |
1217 // If element not defined, set it. | 1270 // If element not defined, set it. |
1218 Ice::Operand *OldOp = LocalOperands[LocalIndex]; | 1271 Ice::Operand *OldOp = LocalOperands[LocalIndex]; |
1219 if (OldOp == nullptr) { | 1272 if (OldOp == nullptr) { |
1273 if (isIRGenerationDisabled()) | |
jvoung (off chromium)
2014/11/04 22:30:15
It's sometimes not clear to me when something shou
Karl
2014/11/05 21:13:34
First, for setOperand, it should be called the sam
| |
1274 return; | |
1220 LocalOperands[LocalIndex] = Op; | 1275 LocalOperands[LocalIndex] = Op; |
1221 return; | 1276 return; |
1222 } | 1277 } |
1223 | 1278 |
1224 // See if forward reference matches. | 1279 // See if forward reference matches. |
1225 if (OldOp == Op) | 1280 if (OldOp == Op) |
1226 return; | 1281 return; |
1227 | 1282 |
1228 // Error has occurred. | 1283 // Error has occurred. |
1229 std::string Buffer; | 1284 std::string Buffer; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1626 }; | 1681 }; |
1627 | 1682 |
1628 void FunctionParser::ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty) { | 1683 void FunctionParser::ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty) { |
1629 std::string Buffer; | 1684 std::string Buffer; |
1630 raw_string_ostream StrBuf(Buffer); | 1685 raw_string_ostream StrBuf(Buffer); |
1631 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty; | 1686 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty; |
1632 Error(StrBuf.str()); | 1687 Error(StrBuf.str()); |
1633 } | 1688 } |
1634 | 1689 |
1635 void FunctionParser::ExitBlock() { | 1690 void FunctionParser::ExitBlock() { |
1691 if (isIRGenerationDisabled()) { | |
1692 popTimerIfTimingEachFunction(); | |
1693 return; | |
1694 } | |
1636 // Before translating, check for blocks without instructions, and | 1695 // Before translating, check for blocks without instructions, and |
1637 // insert unreachable. This shouldn't happen, but be safe. | 1696 // insert unreachable. This shouldn't happen, but be safe. |
1638 unsigned Index = 0; | 1697 unsigned Index = 0; |
1639 for (Ice::CfgNode *Node : Func->getNodes()) { | 1698 for (Ice::CfgNode *Node : Func->getNodes()) { |
1640 if (Node->getInsts().size() == 0) { | 1699 if (Node->getInsts().size() == 0) { |
1641 std::string Buffer; | 1700 std::string Buffer; |
1642 raw_string_ostream StrBuf(Buffer); | 1701 raw_string_ostream StrBuf(Buffer); |
1643 StrBuf << "Basic block " << Index << " contains no instructions"; | 1702 StrBuf << "Basic block " << Index << " contains no instructions"; |
1644 Error(StrBuf.str()); | 1703 Error(StrBuf.str()); |
1645 // TODO(kschimpf) Remove error recovery once implementation complete. | 1704 // TODO(kschimpf) Remove error recovery once implementation complete. |
1646 Node->appendInst(Ice::InstUnreachable::create(Func)); | 1705 Node->appendInst(Ice::InstUnreachable::create(Func)); |
1647 } | 1706 } |
1648 ++Index; | 1707 ++Index; |
1649 } | 1708 } |
1650 Func->computePredecessors(); | 1709 Func->computePredecessors(); |
1651 // Note: Once any errors have been found, we turn off all | 1710 // Note: Once any errors have been found, we turn off all |
1652 // translation of all remaining functions. This allows use to see | 1711 // translation of all remaining functions. This allows use to see |
1653 // multiple errors, without adding extra checks to the translator | 1712 // multiple errors, without adding extra checks to the translator |
1654 // for such parsing errors. | 1713 // for such parsing errors. |
1655 if (Context->getNumErrors() == 0) | 1714 if (Context->getNumErrors() == 0) |
1656 getTranslator().translateFcn(Func); | 1715 getTranslator().translateFcn(Func); |
1657 if (getFlags().TimeEachFunction) | 1716 popTimerIfTimingEachFunction(); |
1658 getTranslator().getContext()->popTimer( | |
1659 getTranslator().getContext()->getTimerID(Ice::GlobalContext::TSK_Funcs, | |
1660 Func->getFunctionName()), | |
1661 Ice::GlobalContext::TSK_Funcs); | |
1662 } | 1717 } |
1663 | 1718 |
1664 void FunctionParser::ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, | 1719 void FunctionParser::ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, |
1665 Ice::Type OpTy) { | 1720 Ice::Type OpTy) { |
1666 std::string Buffer; | 1721 std::string Buffer; |
1667 raw_string_ostream StrBuf(Buffer); | 1722 raw_string_ostream StrBuf(Buffer); |
1668 StrBuf << "Invalid operator type for " << Ice::InstArithmetic::getOpName(Op) | 1723 StrBuf << "Invalid operator type for " << Ice::InstArithmetic::getOpName(Op) |
1669 << ". Found " << OpTy; | 1724 << ". Found " << OpTy; |
1670 Error(StrBuf.str()); | 1725 Error(StrBuf.str()); |
1671 } | 1726 } |
1672 | 1727 |
1673 void FunctionParser::ProcessRecord() { | 1728 void FunctionParser::ProcessRecord() { |
1674 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1729 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
1675 if (InstIsTerminating) { | 1730 if (InstIsTerminating) { |
1676 InstIsTerminating = false; | 1731 InstIsTerminating = false; |
1677 CurrentNode = getBasicBlock(++CurrentBbIndex); | 1732 if (!isIRGenerationDisabled()) |
1733 CurrentNode = getBasicBlock(++CurrentBbIndex); | |
1678 } | 1734 } |
1679 // The base index for relative indexing. | 1735 // The base index for relative indexing. |
1680 int32_t BaseIndex = getNextInstIndex(); | 1736 int32_t BaseIndex = getNextInstIndex(); |
1681 switch (Record.GetCode()) { | 1737 switch (Record.GetCode()) { |
1682 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { | 1738 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { |
1683 // DECLAREBLOCKS: [n] | 1739 // DECLAREBLOCKS: [n] |
1684 if (!isValidRecordSize(1, "function block count")) | 1740 if (!isValidRecordSize(1, "function block count")) |
1685 return; | 1741 return; |
1742 if (isIRGenerationDisabled()) | |
1743 return; | |
1686 if (Func->getNodes().size() != 1) { | 1744 if (Func->getNodes().size() != 1) { |
1687 Error("Duplicate function block count record"); | 1745 Error("Duplicate function block count record"); |
1688 return; | 1746 return; |
1689 } | 1747 } |
1690 uint32_t NumBbs = Values[0]; | 1748 uint32_t NumBbs = Values[0]; |
1691 if (NumBbs == 0) { | 1749 if (NumBbs == 0) { |
1692 Error("Functions must contain at least one basic block."); | 1750 Error("Functions must contain at least one basic block."); |
1693 // TODO(kschimpf) Remove error recovery once implementation complete. | 1751 // TODO(kschimpf) Remove error recovery once implementation complete. |
1694 NumBbs = 1; | 1752 NumBbs = 1; |
1695 } | 1753 } |
1696 // Install the basic blocks, skipping bb0 which was created in the | 1754 // Install the basic blocks, skipping bb0 which was created in the |
1697 // constructor. | 1755 // constructor. |
1698 for (size_t i = 1; i < NumBbs; ++i) | 1756 for (size_t i = 1; i < NumBbs; ++i) |
1699 InstallNextBasicBlock(); | 1757 InstallNextBasicBlock(); |
1700 return; | 1758 return; |
1701 } | 1759 } |
1702 case naclbitc::FUNC_CODE_INST_BINOP: { | 1760 case naclbitc::FUNC_CODE_INST_BINOP: { |
1703 // BINOP: [opval, opval, opcode] | 1761 // BINOP: [opval, opval, opcode] |
1704 if (!isValidRecordSize(3, "function block binop")) | 1762 if (!isValidRecordSize(3, "function block binop")) |
1705 return; | 1763 return; |
1764 if (isIRGenerationDisabled()) { | |
1765 setNextLocalInstIndex(nullptr); | |
1766 return; | |
1767 } | |
1706 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 1768 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
1707 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 1769 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
1708 Ice::Type Type1 = Op1->getType(); | 1770 Ice::Type Type1 = Op1->getType(); |
1709 Ice::Type Type2 = Op2->getType(); | 1771 Ice::Type Type2 = Op2->getType(); |
1710 if (Type1 != Type2) { | 1772 if (Type1 != Type2) { |
1711 std::string Buffer; | 1773 std::string Buffer; |
1712 raw_string_ostream StrBuf(Buffer); | 1774 raw_string_ostream StrBuf(Buffer); |
1713 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; | 1775 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; |
1714 Error(StrBuf.str()); | 1776 Error(StrBuf.str()); |
1715 appendErrorInstruction(Type1); | 1777 appendErrorInstruction(Type1); |
1716 return; | 1778 return; |
1717 } | 1779 } |
1718 | 1780 |
1719 Ice::InstArithmetic::OpKind Opcode; | 1781 Ice::InstArithmetic::OpKind Opcode; |
1720 if (!convertBinopOpcode(Values[2], Type1, Opcode)) | 1782 if (!convertBinopOpcode(Values[2], Type1, Opcode)) |
1721 return; | 1783 return; |
1722 CurrentNode->appendInst(Ice::InstArithmetic::create( | 1784 CurrentNode->appendInst(Ice::InstArithmetic::create( |
1723 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); | 1785 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); |
1724 return; | 1786 return; |
1725 } | 1787 } |
1726 case naclbitc::FUNC_CODE_INST_CAST: { | 1788 case naclbitc::FUNC_CODE_INST_CAST: { |
1727 // CAST: [opval, destty, castopc] | 1789 // CAST: [opval, destty, castopc] |
1728 if (!isValidRecordSize(3, "function block cast")) | 1790 if (!isValidRecordSize(3, "function block cast")) |
1729 return; | 1791 return; |
1792 if (isIRGenerationDisabled()) { | |
1793 setNextLocalInstIndex(nullptr); | |
1794 return; | |
1795 } | |
1730 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); | 1796 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); |
1731 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); | 1797 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); |
1732 Instruction::CastOps LLVMCastOp; | 1798 Instruction::CastOps LLVMCastOp; |
1733 Ice::InstCast::OpKind CastKind; | 1799 Ice::InstCast::OpKind CastKind; |
1734 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || | 1800 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || |
1735 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { | 1801 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { |
1736 std::string Buffer; | 1802 std::string Buffer; |
1737 raw_string_ostream StrBuf(Buffer); | 1803 raw_string_ostream StrBuf(Buffer); |
1738 StrBuf << "Cast opcode not understood: " << Values[2]; | 1804 StrBuf << "Cast opcode not understood: " << Values[2]; |
1739 Error(StrBuf.str()); | 1805 Error(StrBuf.str()); |
(...skipping 10 matching lines...) Expand all Loading... | |
1750 Error(StrBuf.str()); | 1816 Error(StrBuf.str()); |
1751 appendErrorInstruction(CastType); | 1817 appendErrorInstruction(CastType); |
1752 return; | 1818 return; |
1753 } | 1819 } |
1754 CurrentNode->appendInst( | 1820 CurrentNode->appendInst( |
1755 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); | 1821 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); |
1756 return; | 1822 return; |
1757 } | 1823 } |
1758 case naclbitc::FUNC_CODE_INST_VSELECT: { | 1824 case naclbitc::FUNC_CODE_INST_VSELECT: { |
1759 // VSELECT: [opval, opval, pred] | 1825 // VSELECT: [opval, opval, pred] |
1826 if (!isValidRecordSize(3, "function block select")) | |
1827 return; | |
1828 if (isIRGenerationDisabled()) { | |
1829 setNextLocalInstIndex(nullptr); | |
1830 return; | |
1831 } | |
1760 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); | 1832 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); |
1761 Ice::Type ThenType = ThenVal->getType(); | 1833 Ice::Type ThenType = ThenVal->getType(); |
1762 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); | 1834 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); |
1763 Ice::Type ElseType = ElseVal->getType(); | 1835 Ice::Type ElseType = ElseVal->getType(); |
1764 if (ThenType != ElseType) { | 1836 if (ThenType != ElseType) { |
1765 std::string Buffer; | 1837 std::string Buffer; |
1766 raw_string_ostream StrBuf(Buffer); | 1838 raw_string_ostream StrBuf(Buffer); |
1767 StrBuf << "Select operands not same type. Found " << ThenType << " and " | 1839 StrBuf << "Select operands not same type. Found " << ThenType << " and " |
1768 << ElseType; | 1840 << ElseType; |
1769 Error(StrBuf.str()); | 1841 Error(StrBuf.str()); |
(...skipping 24 matching lines...) Expand all Loading... | |
1794 return; | 1866 return; |
1795 } | 1867 } |
1796 CurrentNode->appendInst(Ice::InstSelect::create( | 1868 CurrentNode->appendInst(Ice::InstSelect::create( |
1797 Func, getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); | 1869 Func, getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); |
1798 return; | 1870 return; |
1799 } | 1871 } |
1800 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { | 1872 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { |
1801 // EXTRACTELT: [opval, opval] | 1873 // EXTRACTELT: [opval, opval] |
1802 if (!isValidRecordSize(2, "function block extract element")) | 1874 if (!isValidRecordSize(2, "function block extract element")) |
1803 return; | 1875 return; |
1876 if (isIRGenerationDisabled()) { | |
1877 setNextLocalInstIndex(nullptr); | |
1878 return; | |
1879 } | |
1804 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 1880 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
1805 Ice::Type VecType = Vec->getType(); | 1881 Ice::Type VecType = Vec->getType(); |
1806 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); | 1882 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); |
1807 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 1883 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
1808 if (IndexCheckValue != VectorIndexValid) { | 1884 if (IndexCheckValue != VectorIndexValid) { |
1809 std::string Buffer; | 1885 std::string Buffer; |
1810 raw_string_ostream StrBuf(Buffer); | 1886 raw_string_ostream StrBuf(Buffer); |
1811 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 1887 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
1812 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " | 1888 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " |
1813 << Index->getType() << " " << *Index; | 1889 << Index->getType() << " " << *Index; |
1814 Error(StrBuf.str()); | 1890 Error(StrBuf.str()); |
1815 appendErrorInstruction(VecType); | 1891 appendErrorInstruction(VecType); |
1816 return; | 1892 return; |
1817 } | 1893 } |
1818 CurrentNode->appendInst(Ice::InstExtractElement::create( | 1894 CurrentNode->appendInst(Ice::InstExtractElement::create( |
1819 Func, getNextInstVar(typeElementType(VecType)), Vec, Index)); | 1895 Func, getNextInstVar(typeElementType(VecType)), Vec, Index)); |
1820 return; | 1896 return; |
1821 } | 1897 } |
1822 case naclbitc::FUNC_CODE_INST_INSERTELT: { | 1898 case naclbitc::FUNC_CODE_INST_INSERTELT: { |
1823 // INSERTELT: [opval, opval, opval] | 1899 // INSERTELT: [opval, opval, opval] |
1824 if (!isValidRecordSize(3, "function block insert element")) | 1900 if (!isValidRecordSize(3, "function block insert element")) |
1825 return; | 1901 return; |
1902 if (isIRGenerationDisabled()) { | |
1903 setNextLocalInstIndex(nullptr); | |
1904 return; | |
1905 } | |
1826 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 1906 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
1827 Ice::Type VecType = Vec->getType(); | 1907 Ice::Type VecType = Vec->getType(); |
1828 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); | 1908 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); |
1829 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); | 1909 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); |
1830 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 1910 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
1831 if (IndexCheckValue != VectorIndexValid) { | 1911 if (IndexCheckValue != VectorIndexValid) { |
1832 std::string Buffer; | 1912 std::string Buffer; |
1833 raw_string_ostream StrBuf(Buffer); | 1913 raw_string_ostream StrBuf(Buffer); |
1834 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 1914 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
1835 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " | 1915 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " |
1836 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " | 1916 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " |
1837 << *Index; | 1917 << *Index; |
1838 Error(StrBuf.str()); | 1918 Error(StrBuf.str()); |
1839 appendErrorInstruction(Elt->getType()); | 1919 appendErrorInstruction(Elt->getType()); |
1840 return; | 1920 return; |
1841 } | 1921 } |
1842 CurrentNode->appendInst(Ice::InstInsertElement::create( | 1922 CurrentNode->appendInst(Ice::InstInsertElement::create( |
1843 Func, getNextInstVar(VecType), Vec, Elt, Index)); | 1923 Func, getNextInstVar(VecType), Vec, Elt, Index)); |
1844 return; | 1924 return; |
1845 } | 1925 } |
1846 case naclbitc::FUNC_CODE_INST_CMP2: { | 1926 case naclbitc::FUNC_CODE_INST_CMP2: { |
1847 // CMP2: [opval, opval, pred] | 1927 // CMP2: [opval, opval, pred] |
1848 if (!isValidRecordSize(3, "function block compare")) | 1928 if (!isValidRecordSize(3, "function block compare")) |
1849 return; | 1929 return; |
1930 if (isIRGenerationDisabled()) { | |
1931 setNextLocalInstIndex(nullptr); | |
1932 return; | |
1933 } | |
1850 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 1934 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
1851 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 1935 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
1852 Ice::Type Op1Type = Op1->getType(); | 1936 Ice::Type Op1Type = Op1->getType(); |
1853 Ice::Type Op2Type = Op2->getType(); | 1937 Ice::Type Op2Type = Op2->getType(); |
1854 Ice::Type DestType = getCompareResultType(Op1Type); | 1938 Ice::Type DestType = getCompareResultType(Op1Type); |
1855 if (Op1Type != Op2Type) { | 1939 if (Op1Type != Op2Type) { |
1856 std::string Buffer; | 1940 std::string Buffer; |
1857 raw_string_ostream StrBuf(Buffer); | 1941 raw_string_ostream StrBuf(Buffer); |
1858 StrBuf << "Compare argument types differ: " << Op1Type | 1942 StrBuf << "Compare argument types differ: " << Op1Type |
1859 << " and " << Op2Type; | 1943 << " and " << Op2Type; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1901 Error(StrBuf.str()); | 1985 Error(StrBuf.str()); |
1902 appendErrorInstruction(DestType); | 1986 appendErrorInstruction(DestType); |
1903 return; | 1987 return; |
1904 } | 1988 } |
1905 return; | 1989 return; |
1906 } | 1990 } |
1907 case naclbitc::FUNC_CODE_INST_RET: { | 1991 case naclbitc::FUNC_CODE_INST_RET: { |
1908 // RET: [opval?] | 1992 // RET: [opval?] |
1909 if (!isValidRecordSizeInRange(0, 1, "function block ret")) | 1993 if (!isValidRecordSizeInRange(0, 1, "function block ret")) |
1910 return; | 1994 return; |
1995 if (isIRGenerationDisabled()) { | |
1996 setNextLocalInstIndex(nullptr); | |
1997 return; | |
1998 } | |
1911 if (Values.size() == 0) { | 1999 if (Values.size() == 0) { |
1912 CurrentNode->appendInst(Ice::InstRet::create(Func)); | 2000 CurrentNode->appendInst(Ice::InstRet::create(Func)); |
1913 } else { | 2001 } else { |
1914 CurrentNode->appendInst( | 2002 CurrentNode->appendInst( |
1915 Ice::InstRet::create(Func, getRelativeOperand(Values[0], BaseIndex))); | 2003 Ice::InstRet::create(Func, getRelativeOperand(Values[0], BaseIndex))); |
1916 } | 2004 } |
1917 InstIsTerminating = true; | 2005 InstIsTerminating = true; |
1918 return; | 2006 return; |
1919 } | 2007 } |
1920 case naclbitc::FUNC_CODE_INST_BR: { | 2008 case naclbitc::FUNC_CODE_INST_BR: { |
1921 if (Values.size() == 1) { | 2009 if (Values.size() == 1) { |
1922 // BR: [bb#] | 2010 // BR: [bb#] |
2011 if (isIRGenerationDisabled()) | |
2012 return; | |
1923 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | 2013 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); |
1924 if (Block == nullptr) | 2014 if (Block == nullptr) |
1925 return; | 2015 return; |
1926 CurrentNode->appendInst(Ice::InstBr::create(Func, Block)); | 2016 CurrentNode->appendInst(Ice::InstBr::create(Func, Block)); |
1927 } else { | 2017 } else { |
1928 // BR: [bb#, bb#, opval] | 2018 // BR: [bb#, bb#, opval] |
1929 if (!isValidRecordSize(3, "function block branch")) | 2019 if (!isValidRecordSize(3, "function block branch")) |
1930 return; | 2020 return; |
2021 if (isIRGenerationDisabled()) | |
2022 return; | |
1931 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); | 2023 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); |
1932 if (Cond->getType() != Ice::IceType_i1) { | 2024 if (Cond->getType() != Ice::IceType_i1) { |
1933 std::string Buffer; | 2025 std::string Buffer; |
1934 raw_string_ostream StrBuf(Buffer); | 2026 raw_string_ostream StrBuf(Buffer); |
1935 StrBuf << "Branch condition " << *Cond << " not i1. Found: " | 2027 StrBuf << "Branch condition " << *Cond << " not i1. Found: " |
1936 << Cond->getType(); | 2028 << Cond->getType(); |
1937 Error(StrBuf.str()); | 2029 Error(StrBuf.str()); |
1938 return; | 2030 return; |
1939 } | 2031 } |
1940 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); | 2032 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); |
(...skipping 10 matching lines...) Expand all Loading... | |
1951 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] | 2043 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] |
1952 // where Case = [1, 1, Value, BbIndex]. | 2044 // where Case = [1, 1, Value, BbIndex]. |
1953 // | 2045 // |
1954 // Note: Unlike most instructions, we don't infer the type of | 2046 // Note: Unlike most instructions, we don't infer the type of |
1955 // Cond, but provide it as a separate field. There are also | 2047 // Cond, but provide it as a separate field. There are also |
1956 // unnecesary data fields (i.e. constants 1). These were not | 2048 // unnecesary data fields (i.e. constants 1). These were not |
1957 // cleaned up in PNaCl bitcode because the bitcode format was | 2049 // cleaned up in PNaCl bitcode because the bitcode format was |
1958 // already frozen when the problem was noticed. | 2050 // already frozen when the problem was noticed. |
1959 if (!isValidRecordSizeAtLeast(4, "function block switch")) | 2051 if (!isValidRecordSizeAtLeast(4, "function block switch")) |
1960 return; | 2052 return; |
2053 if (isIRGenerationDisabled()) | |
2054 return; | |
jvoung (off chromium)
2014/11/04 22:30:15
Should this bail *after* checking the CondTy?
For
Karl
2014/11/05 21:13:34
Yes. I intended to check as much as possible (with
| |
1961 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); | 2055 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); |
1962 if (!Ice::isScalarIntegerType(CondTy)) { | 2056 if (!Ice::isScalarIntegerType(CondTy)) { |
1963 std::string Buffer; | 2057 std::string Buffer; |
1964 raw_string_ostream StrBuf(Buffer); | 2058 raw_string_ostream StrBuf(Buffer); |
1965 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; | 2059 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; |
1966 Error(StrBuf.str()); | 2060 Error(StrBuf.str()); |
1967 return; | 2061 return; |
1968 } | 2062 } |
1969 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); | 2063 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); |
1970 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); | 2064 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2002 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2096 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
2003 } | 2097 } |
2004 CurrentNode->appendInst(Switch); | 2098 CurrentNode->appendInst(Switch); |
2005 InstIsTerminating = true; | 2099 InstIsTerminating = true; |
2006 return; | 2100 return; |
2007 } | 2101 } |
2008 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2102 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
2009 // UNREACHABLE: [] | 2103 // UNREACHABLE: [] |
2010 if (!isValidRecordSize(0, "function block unreachable")) | 2104 if (!isValidRecordSize(0, "function block unreachable")) |
2011 return; | 2105 return; |
2106 if (isIRGenerationDisabled()) | |
2107 return; | |
2012 CurrentNode->appendInst( | 2108 CurrentNode->appendInst( |
2013 Ice::InstUnreachable::create(Func)); | 2109 Ice::InstUnreachable::create(Func)); |
2014 InstIsTerminating = true; | 2110 InstIsTerminating = true; |
2015 return; | 2111 return; |
2016 } | 2112 } |
2017 case naclbitc::FUNC_CODE_INST_PHI: { | 2113 case naclbitc::FUNC_CODE_INST_PHI: { |
2018 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. | 2114 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. |
2019 if (!isValidRecordSizeAtLeast(3, "function block phi")) | 2115 if (!isValidRecordSizeAtLeast(3, "function block phi")) |
2020 return; | 2116 return; |
2021 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); | 2117 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
2022 if ((Values.size() & 0x1) == 0) { | 2118 if ((Values.size() & 0x1) == 0) { |
2023 // Not an odd number of values. | 2119 // Not an odd number of values. |
2024 std::string Buffer; | 2120 std::string Buffer; |
2025 raw_string_ostream StrBuf(Buffer); | 2121 raw_string_ostream StrBuf(Buffer); |
2026 StrBuf << "function block phi record size not valid: " << Values.size(); | 2122 StrBuf << "function block phi record size not valid: " << Values.size(); |
2027 Error(StrBuf.str()); | 2123 Error(StrBuf.str()); |
2028 appendErrorInstruction(Ty); | 2124 appendErrorInstruction(Ty); |
2029 return; | 2125 return; |
2030 } | 2126 } |
2031 if (Ty == Ice::IceType_void) { | 2127 if (Ty == Ice::IceType_void) { |
2032 Error("Phi record using type void not allowed"); | 2128 Error("Phi record using type void not allowed"); |
2033 return; | 2129 return; |
2034 } | 2130 } |
2131 if (isIRGenerationDisabled()) { | |
2132 setNextLocalInstIndex(nullptr); | |
2133 return; | |
2134 } | |
2035 Ice::Variable *Dest = getNextInstVar(Ty); | 2135 Ice::Variable *Dest = getNextInstVar(Ty); |
2036 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); | 2136 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); |
2037 for (unsigned i = 1; i < Values.size(); i += 2) { | 2137 for (unsigned i = 1; i < Values.size(); i += 2) { |
2038 Ice::Operand *Op = | 2138 Ice::Operand *Op = |
2039 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); | 2139 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); |
2040 if (Op->getType() != Ty) { | 2140 if (Op->getType() != Ty) { |
2041 std::string Buffer; | 2141 std::string Buffer; |
2042 raw_string_ostream StrBuf(Buffer); | 2142 raw_string_ostream StrBuf(Buffer); |
2043 StrBuf << "Value " << *Op << " not type " << Ty | 2143 StrBuf << "Value " << *Op << " not type " << Ty |
2044 << " in phi instruction. Found: " << Op->getType(); | 2144 << " in phi instruction. Found: " << Op->getType(); |
2045 Error(StrBuf.str()); | 2145 Error(StrBuf.str()); |
2046 appendErrorInstruction(Ty); | 2146 appendErrorInstruction(Ty); |
2047 return; | 2147 return; |
2048 } | 2148 } |
2049 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); | 2149 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); |
2050 } | 2150 } |
2051 CurrentNode->appendInst(Phi); | 2151 CurrentNode->appendInst(Phi); |
2052 return; | 2152 return; |
2053 } | 2153 } |
2054 case naclbitc::FUNC_CODE_INST_ALLOCA: { | 2154 case naclbitc::FUNC_CODE_INST_ALLOCA: { |
2055 // ALLOCA: [Size, align] | 2155 // ALLOCA: [Size, align] |
2056 if (!isValidRecordSize(2, "function block alloca")) | 2156 if (!isValidRecordSize(2, "function block alloca")) |
2057 return; | 2157 return; |
2158 if (isIRGenerationDisabled()) { | |
2159 setNextLocalInstIndex(nullptr); | |
2160 return; | |
2161 } | |
2058 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); | 2162 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); |
2059 Ice::Type PtrTy = Context->getIcePointerType(); | 2163 Ice::Type PtrTy = Context->getIcePointerType(); |
2060 if (ByteCount->getType() != Ice::IceType_i32) { | 2164 if (ByteCount->getType() != Ice::IceType_i32) { |
2061 std::string Buffer; | 2165 std::string Buffer; |
2062 raw_string_ostream StrBuf(Buffer); | 2166 raw_string_ostream StrBuf(Buffer); |
2063 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; | 2167 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; |
2064 Error(StrBuf.str()); | 2168 Error(StrBuf.str()); |
2065 appendErrorInstruction(PtrTy); | 2169 appendErrorInstruction(PtrTy); |
2066 return; | 2170 return; |
2067 } | 2171 } |
2068 unsigned Alignment; | 2172 unsigned Alignment; |
2069 extractAlignment("Alloca", Values[1], Alignment); | 2173 extractAlignment("Alloca", Values[1], Alignment); |
2070 CurrentNode->appendInst(Ice::InstAlloca::create(Func, ByteCount, Alignment, | 2174 CurrentNode->appendInst(Ice::InstAlloca::create(Func, ByteCount, Alignment, |
2071 getNextInstVar(PtrTy))); | 2175 getNextInstVar(PtrTy))); |
2072 return; | 2176 return; |
2073 } | 2177 } |
2074 case naclbitc::FUNC_CODE_INST_LOAD: { | 2178 case naclbitc::FUNC_CODE_INST_LOAD: { |
2075 // LOAD: [address, align, ty] | 2179 // LOAD: [address, align, ty] |
2076 if (!isValidRecordSize(3, "function block load")) | 2180 if (!isValidRecordSize(3, "function block load")) |
2077 return; | 2181 return; |
2182 if (isIRGenerationDisabled()) { | |
2183 setNextLocalInstIndex(nullptr); | |
2184 return; | |
2185 } | |
2078 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2186 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
2079 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); | 2187 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); |
2080 if (!isValidPointerType(Address, "Load")) { | 2188 if (!isValidPointerType(Address, "Load")) { |
2081 appendErrorInstruction(Ty); | 2189 appendErrorInstruction(Ty); |
2082 return; | 2190 return; |
2083 } | 2191 } |
2084 unsigned Alignment; | 2192 unsigned Alignment; |
2085 extractAlignment("Load", Values[1], Alignment); | 2193 extractAlignment("Load", Values[1], Alignment); |
2086 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { | 2194 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { |
2087 appendErrorInstruction(Ty); | 2195 appendErrorInstruction(Ty); |
2088 return; | 2196 return; |
2089 } | 2197 } |
2090 CurrentNode->appendInst( | 2198 CurrentNode->appendInst( |
2091 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); | 2199 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); |
2092 return; | 2200 return; |
2093 } | 2201 } |
2094 case naclbitc::FUNC_CODE_INST_STORE: { | 2202 case naclbitc::FUNC_CODE_INST_STORE: { |
2095 // STORE: [address, value, align] | 2203 // STORE: [address, value, align] |
2096 if (!isValidRecordSize(3, "function block store")) | 2204 if (!isValidRecordSize(3, "function block store")) |
2097 return; | 2205 return; |
2206 if (isIRGenerationDisabled()) | |
2207 return; | |
2098 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2208 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
2099 if (!isValidPointerType(Address, "Store")) | 2209 if (!isValidPointerType(Address, "Store")) |
2100 return; | 2210 return; |
2101 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); | 2211 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); |
2102 unsigned Alignment; | 2212 unsigned Alignment; |
2103 extractAlignment("Store", Values[2], Alignment); | 2213 extractAlignment("Store", Values[2], Alignment); |
2104 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) | 2214 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) |
2105 return; | 2215 return; |
2106 CurrentNode->appendInst( | 2216 CurrentNode->appendInst( |
2107 Ice::InstStore::create(Func, Value, Address, Alignment)); | 2217 Ice::InstStore::create(Func, Value, Address, Alignment)); |
(...skipping 16 matching lines...) Expand all Loading... | |
2124 if (!isValidRecordSizeAtLeast(2, "function block call")) | 2234 if (!isValidRecordSizeAtLeast(2, "function block call")) |
2125 return; | 2235 return; |
2126 } else { | 2236 } else { |
2127 if (!isValidRecordSizeAtLeast(3, "function block call indirect")) | 2237 if (!isValidRecordSizeAtLeast(3, "function block call indirect")) |
2128 return; | 2238 return; |
2129 ParamsStartIndex = 3; | 2239 ParamsStartIndex = 3; |
2130 } | 2240 } |
2131 | 2241 |
2132 // Extract out the called function and its return type. | 2242 // Extract out the called function and its return type. |
2133 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); | 2243 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); |
2134 Ice::Operand *Callee = getOperand(CalleeIndex); | 2244 Ice::Operand *Callee = getOperand(CalleeIndex); |
jvoung (off chromium)
2014/11/04 22:30:15
nit: Maybe move getOperand() down to before the cr
Karl
2014/11/05 21:13:33
My original thinking was that we wanted to include
| |
2135 Ice::Type ReturnType = Ice::IceType_void; | 2245 Ice::Type ReturnType = Ice::IceType_void; |
2136 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; | 2246 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; |
2137 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2247 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
2138 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); | 2248 Ice::FunctionDeclaration *Fcn = Context->getFunctionByID(CalleeIndex); |
2139 const Ice::FuncSigType &Signature = Fcn->getSignature(); | 2249 const Ice::FuncSigType &Signature = Fcn->getSignature(); |
2140 ReturnType = Signature.getReturnType(); | 2250 ReturnType = Signature.getReturnType(); |
2141 | 2251 |
2142 // Check if this direct call is to an Intrinsic (starts with "llvm.") | 2252 // Check if this direct call is to an Intrinsic (starts with "llvm.") |
2143 static Ice::IceString LLVMPrefix("llvm."); | 2253 static Ice::IceString LLVMPrefix("llvm."); |
2144 Ice::IceString Name = Fcn->getName(); | 2254 Ice::IceString Name = Fcn->getName(); |
(...skipping 21 matching lines...) Expand all Loading... | |
2166 std::string Buffer; | 2276 std::string Buffer; |
2167 raw_string_ostream StrBuf(Buffer); | 2277 raw_string_ostream StrBuf(Buffer); |
2168 StrBuf << "Function call calling convention value " << (CCInfo >> 1) | 2278 StrBuf << "Function call calling convention value " << (CCInfo >> 1) |
2169 << " not understood."; | 2279 << " not understood."; |
2170 Error(StrBuf.str()); | 2280 Error(StrBuf.str()); |
2171 appendErrorInstruction(ReturnType); | 2281 appendErrorInstruction(ReturnType); |
2172 return; | 2282 return; |
2173 } | 2283 } |
2174 bool IsTailCall = static_cast<bool>(CCInfo & 1); | 2284 bool IsTailCall = static_cast<bool>(CCInfo & 1); |
2175 | 2285 |
2286 if (isIRGenerationDisabled()) { | |
2287 if (ReturnType != Ice::IceType_void) | |
2288 setNextLocalInstIndex(nullptr); | |
2289 return; | |
2290 } | |
2291 | |
2176 // Create the call instruction. | 2292 // Create the call instruction. |
2177 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) | 2293 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) |
2178 ? nullptr | 2294 ? nullptr |
2179 : getNextInstVar(ReturnType); | 2295 : getNextInstVar(ReturnType); |
2180 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; | 2296 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; |
2181 Ice::InstCall *Inst = nullptr; | 2297 Ice::InstCall *Inst = nullptr; |
2182 if (IntrinsicInfo) { | 2298 if (IntrinsicInfo) { |
2183 Inst = | 2299 Inst = |
2184 Ice::InstIntrinsicCall::create(Func, NumParams, Dest, Callee, | 2300 Ice::InstIntrinsicCall::create(Func, NumParams, Dest, Callee, |
2185 IntrinsicInfo->Info); | 2301 IntrinsicInfo->Info); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2235 } | 2351 } |
2236 } | 2352 } |
2237 | 2353 |
2238 CurrentNode->appendInst(Inst); | 2354 CurrentNode->appendInst(Inst); |
2239 return; | 2355 return; |
2240 } | 2356 } |
2241 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { | 2357 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { |
2242 // FORWARDTYPEREF: [opval, ty] | 2358 // FORWARDTYPEREF: [opval, ty] |
2243 if (!isValidRecordSize(2, "function block forward type ref")) | 2359 if (!isValidRecordSize(2, "function block forward type ref")) |
2244 return; | 2360 return; |
2245 setOperand(Values[0], createInstVar(Context->getSimpleTypeByID(Values[1]))); | 2361 if (isIRGenerationDisabled()) { |
2362 setOperand(Values[0], nullptr); | |
2363 } else { | |
2364 setOperand(Values[0], | |
2365 createInstVar(Context->getSimpleTypeByID(Values[1]))); | |
2366 } | |
2246 return; | 2367 return; |
2247 } | 2368 } |
2248 default: | 2369 default: |
2249 // Generate error message! | 2370 // Generate error message! |
2250 BlockParserBaseClass::ProcessRecord(); | 2371 BlockParserBaseClass::ProcessRecord(); |
2251 return; | 2372 return; |
2252 } | 2373 } |
2253 } | 2374 } |
2254 | 2375 |
2255 /// Parses constants within a function block. | 2376 /// Parses constants within a function block. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2297 if (NextConstantType == Ice::IceType_void) | 2418 if (NextConstantType == Ice::IceType_void) |
2298 Error("constants block set type not allowed for void type"); | 2419 Error("constants block set type not allowed for void type"); |
2299 return; | 2420 return; |
2300 } | 2421 } |
2301 case naclbitc::CST_CODE_UNDEF: { | 2422 case naclbitc::CST_CODE_UNDEF: { |
2302 // UNDEF | 2423 // UNDEF |
2303 if (!isValidRecordSize(0, "constants block undef")) | 2424 if (!isValidRecordSize(0, "constants block undef")) |
2304 return; | 2425 return; |
2305 if (!isValidNextConstantType()) | 2426 if (!isValidNextConstantType()) |
2306 return; | 2427 return; |
2428 if (isIRGenerationDisabled()) { | |
2429 FuncParser->setNextConstantID(nullptr); | |
2430 return; | |
2431 } | |
2307 FuncParser->setNextConstantID( | 2432 FuncParser->setNextConstantID( |
2308 getContext()->getConstantUndef(NextConstantType)); | 2433 getContext()->getConstantUndef(NextConstantType)); |
2309 return; | 2434 return; |
2310 } | 2435 } |
2311 case naclbitc::CST_CODE_INTEGER: { | 2436 case naclbitc::CST_CODE_INTEGER: { |
2312 // INTEGER: [intval] | 2437 // INTEGER: [intval] |
2313 if (!isValidRecordSize(1, "constants block integer")) | 2438 if (!isValidRecordSize(1, "constants block integer")) |
2314 return; | 2439 return; |
2315 if (!isValidNextConstantType()) | 2440 if (!isValidNextConstantType()) |
2316 return; | 2441 return; |
2317 if (IntegerType *IType = dyn_cast<IntegerType>( | 2442 if (IntegerType *IType = dyn_cast<IntegerType>( |
2318 Context->convertToLLVMType(NextConstantType))) { | 2443 Context->convertToLLVMType(NextConstantType))) { |
2319 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); | 2444 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); |
2320 Ice::Constant *C = (NextConstantType == Ice::IceType_i64) | 2445 Ice::Constant *C = (NextConstantType == Ice::IceType_i64) |
2321 ? getContext()->getConstantInt64( | 2446 ? getContext()->getConstantInt64( |
2322 NextConstantType, Value.getSExtValue()) | 2447 NextConstantType, Value.getSExtValue()) |
2323 : getContext()->getConstantInt32( | 2448 : getContext()->getConstantInt32( |
2324 NextConstantType, Value.getSExtValue()); | 2449 NextConstantType, Value.getSExtValue()); |
2325 FuncParser->setNextConstantID(C); | 2450 if (isIRGenerationDisabled()) { |
2451 FuncParser->setNextConstantID(nullptr); | |
jvoung (off chromium)
2014/11/04 22:30:15
Shouldn't there be a bailout before calling getCon
Karl
2014/11/05 21:13:34
Absolutely! Don't know how this bug got introduced
| |
2452 } else { | |
2453 FuncParser->setNextConstantID(C); | |
2454 } | |
2326 return; | 2455 return; |
2327 } | 2456 } |
2328 std::string Buffer; | 2457 std::string Buffer; |
2329 raw_string_ostream StrBuf(Buffer); | 2458 raw_string_ostream StrBuf(Buffer); |
2330 StrBuf << "constant block integer record for non-integer type " | 2459 StrBuf << "constant block integer record for non-integer type " |
2331 << NextConstantType; | 2460 << NextConstantType; |
2332 Error(StrBuf.str()); | 2461 Error(StrBuf.str()); |
2333 return; | 2462 return; |
2334 } | 2463 } |
2335 case naclbitc::CST_CODE_FLOAT: { | 2464 case naclbitc::CST_CODE_FLOAT: { |
2336 // FLOAT: [fpval] | 2465 // FLOAT: [fpval] |
2337 if (!isValidRecordSize(1, "constants block float")) | 2466 if (!isValidRecordSize(1, "constants block float")) |
2338 return; | 2467 return; |
2339 if (!isValidNextConstantType()) | 2468 if (!isValidNextConstantType()) |
2340 return; | 2469 return; |
2470 if (isIRGenerationDisabled()) { | |
2471 FuncParser->setNextConstantID(nullptr); | |
2472 return; | |
2473 } | |
2341 switch (NextConstantType) { | 2474 switch (NextConstantType) { |
2342 case Ice::IceType_f32: { | 2475 case Ice::IceType_f32: { |
2343 APFloat Value(APFloat::IEEEsingle, | 2476 APFloat Value(APFloat::IEEEsingle, |
2344 APInt(32, static_cast<uint32_t>(Values[0]))); | 2477 APInt(32, static_cast<uint32_t>(Values[0]))); |
2345 FuncParser->setNextConstantID( | 2478 FuncParser->setNextConstantID( |
2346 getContext()->getConstantFloat(Value.convertToFloat())); | 2479 getContext()->getConstantFloat(Value.convertToFloat())); |
2347 return; | 2480 return; |
2348 } | 2481 } |
2349 case Ice::IceType_f64: { | 2482 case Ice::IceType_f64: { |
2350 APFloat Value(APFloat::IEEEdouble, APInt(64, Values[0])); | 2483 APFloat Value(APFloat::IEEEdouble, APInt(64, Values[0])); |
2351 FuncParser->setNextConstantID( | 2484 if (isIRGenerationDisabled()) { |
jvoung (off chromium)
2014/11/04 22:30:15
Wouldn't the earlier check before the switch() mak
Karl
2014/11/05 21:13:33
Yes. removing redundant tests.
| |
2352 getContext()->getConstantDouble(Value.convertToDouble())); | 2485 FuncParser->setNextConstantID(nullptr); |
2486 } else { | |
2487 FuncParser->setNextConstantID( | |
2488 getContext()->getConstantDouble(Value.convertToDouble())); | |
2489 } | |
2353 return; | 2490 return; |
2354 } | 2491 } |
2355 default: { | 2492 default: { |
2356 std::string Buffer; | 2493 std::string Buffer; |
2357 raw_string_ostream StrBuf(Buffer); | 2494 raw_string_ostream StrBuf(Buffer); |
2358 StrBuf << "constant block float record for non-floating type " | 2495 StrBuf << "constant block float record for non-floating type " |
2359 << NextConstantType; | 2496 << NextConstantType; |
2360 Error(StrBuf.str()); | 2497 Error(StrBuf.str()); |
2361 return; | 2498 return; |
2362 } | 2499 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2403 }; | 2540 }; |
2404 | 2541 |
2405 void FunctionValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { | 2542 void FunctionValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { |
2406 // Note: We check when Index is too small, so that we can error recover | 2543 // Note: We check when Index is too small, so that we can error recover |
2407 // (FP->getOperand will create fatal error). | 2544 // (FP->getOperand will create fatal error). |
2408 if (Index < getFunctionParser()->CachedNumGlobalValueIDs) { | 2545 if (Index < getFunctionParser()->CachedNumGlobalValueIDs) { |
2409 reportUnableToAssign("instruction", Index, Name); | 2546 reportUnableToAssign("instruction", Index, Name); |
2410 // TODO(kschimpf) Remove error recovery once implementation complete. | 2547 // TODO(kschimpf) Remove error recovery once implementation complete. |
2411 return; | 2548 return; |
2412 } | 2549 } |
2550 if (isIRGenerationDisabled()) | |
2551 return; | |
2413 Ice::Operand *Op = getFunctionParser()->getOperand(Index); | 2552 Ice::Operand *Op = getFunctionParser()->getOperand(Index); |
2414 if (Ice::Variable *V = dyn_cast<Ice::Variable>(Op)) { | 2553 if (Ice::Variable *V = dyn_cast<Ice::Variable>(Op)) { |
2415 std::string Nm(Name.data(), Name.size()); | 2554 std::string Nm(Name.data(), Name.size()); |
2416 V->setName(Nm); | 2555 V->setName(Nm); |
2417 } else { | 2556 } else { |
2418 reportUnableToAssign("variable", Index, Name); | 2557 reportUnableToAssign("variable", Index, Name); |
2419 } | 2558 } |
2420 } | 2559 } |
2421 | 2560 |
2422 void FunctionValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { | 2561 void FunctionValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { |
2562 if (isIRGenerationDisabled()) | |
2563 return; | |
2423 if (Index >= getFunctionParser()->Func->getNumNodes()) { | 2564 if (Index >= getFunctionParser()->Func->getNumNodes()) { |
2424 reportUnableToAssign("block", Index, Name); | 2565 reportUnableToAssign("block", Index, Name); |
2425 return; | 2566 return; |
2426 } | 2567 } |
2427 std::string Nm(Name.data(), Name.size()); | 2568 std::string Nm(Name.data(), Name.size()); |
2428 getFunctionParser()->Func->getNodes()[Index]->setName(Nm); | 2569 getFunctionParser()->Func->getNodes()[Index]->setName(Nm); |
2429 } | 2570 } |
2430 | 2571 |
2431 bool FunctionParser::ParseBlock(unsigned BlockID) { | 2572 bool FunctionParser::ParseBlock(unsigned BlockID) { |
2432 switch (BlockID) { | 2573 switch (BlockID) { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2682 | 2823 |
2683 if (TopLevelBlocks != 1) { | 2824 if (TopLevelBlocks != 1) { |
2684 errs() << IRFilename | 2825 errs() << IRFilename |
2685 << ": Contains more than one module. Found: " << TopLevelBlocks | 2826 << ": Contains more than one module. Found: " << TopLevelBlocks |
2686 << "\n"; | 2827 << "\n"; |
2687 ErrorStatus = true; | 2828 ErrorStatus = true; |
2688 } | 2829 } |
2689 } | 2830 } |
2690 | 2831 |
2691 } // end of namespace Ice | 2832 } // end of namespace Ice |
OLD | NEW |