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