| 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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1045 |
| 1046 /// Parses function blocks in the bitcode file. | 1046 /// Parses function blocks in the bitcode file. |
| 1047 class FunctionParser : public BlockParserBaseClass { | 1047 class FunctionParser : public BlockParserBaseClass { |
| 1048 FunctionParser(const FunctionParser &) = delete; | 1048 FunctionParser(const FunctionParser &) = delete; |
| 1049 FunctionParser &operator=(const FunctionParser &) = delete; | 1049 FunctionParser &operator=(const FunctionParser &) = delete; |
| 1050 | 1050 |
| 1051 public: | 1051 public: |
| 1052 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1052 FunctionParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 1053 : BlockParserBaseClass(BlockID, EnclosingParser), | 1053 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 1054 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), | 1054 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), |
| 1055 Func(isIRGenerationDisabled() | 1055 Func(nullptr), CurrentBbIndex(0), |
| 1056 ? nullptr | 1056 FcnId(Context->getNextFunctionBlockValueID()), |
| 1057 : Ice::Cfg::create(getTranslator().getContext())), | |
| 1058 CurrentBbIndex(0), FcnId(Context->getNextFunctionBlockValueID()), | |
| 1059 FuncDecl(Context->getFunctionByID(FcnId)), | 1057 FuncDecl(Context->getFunctionByID(FcnId)), |
| 1060 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), | 1058 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), |
| 1061 NextLocalInstIndex(Context->getNumGlobalIDs()), | 1059 NextLocalInstIndex(Context->getNumGlobalIDs()), |
| 1062 InstIsTerminating(false) { | 1060 InstIsTerminating(false) {} |
| 1063 if (ALLOW_DUMP && getFlags().TimeEachFunction) | 1061 |
| 1064 getTranslator().getContext()->pushTimer( | 1062 bool convertFunction() { |
| 1065 getTranslator().getContext()->getTimerID( | 1063 const Ice::TimerStackIdT StackID = Ice::GlobalContext::TSK_Funcs; |
| 1066 Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()), | 1064 Ice::TimerIdT TimerID = 0; |
| 1067 Ice::GlobalContext::TSK_Funcs); | 1065 const bool TimeThisFunction = ALLOW_DUMP && getFlags().TimeEachFunction; |
| 1066 if (TimeThisFunction) { |
| 1067 TimerID = getTranslator().getContext()->getTimerID(StackID, |
| 1068 FuncDecl->getName()); |
| 1069 getTranslator().getContext()->pushTimer(TimerID, StackID); |
| 1070 } |
| 1071 |
| 1072 if (!isIRGenerationDisabled()) |
| 1073 Func = Ice::Cfg::create(getTranslator().getContext()); |
| 1074 Ice::Cfg::setCurrentCfg(Func.get()); |
| 1075 |
| 1068 // TODO(kschimpf) Clean up API to add a function signature to | 1076 // TODO(kschimpf) Clean up API to add a function signature to |
| 1069 // a CFG. | 1077 // a CFG. |
| 1070 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); | 1078 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); |
| 1071 if (isIRGenerationDisabled()) { | 1079 if (isIRGenerationDisabled()) { |
| 1072 CurrentNode = nullptr; | 1080 CurrentNode = nullptr; |
| 1073 for (Ice::Type ArgType : Signature.getArgList()) { | 1081 for (Ice::Type ArgType : Signature.getArgList()) { |
| 1074 (void)ArgType; | 1082 (void)ArgType; |
| 1075 setNextLocalInstIndex(nullptr); | 1083 setNextLocalInstIndex(nullptr); |
| 1076 } | 1084 } |
| 1077 } else { | 1085 } else { |
| 1078 Func->setFunctionName(FuncDecl->getName()); | 1086 Func->setFunctionName(FuncDecl->getName()); |
| 1079 Func->setReturnType(Signature.getReturnType()); | 1087 Func->setReturnType(Signature.getReturnType()); |
| 1080 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); | 1088 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); |
| 1081 CurrentNode = InstallNextBasicBlock(); | 1089 CurrentNode = InstallNextBasicBlock(); |
| 1082 Func->setEntryNode(CurrentNode); | 1090 Func->setEntryNode(CurrentNode); |
| 1083 for (Ice::Type ArgType : Signature.getArgList()) { | 1091 for (Ice::Type ArgType : Signature.getArgList()) { |
| 1084 Func->addArg(getNextInstVar(ArgType)); | 1092 Func->addArg(getNextInstVar(ArgType)); |
| 1085 } | 1093 } |
| 1086 } | 1094 } |
| 1095 bool ParserResult = ParseThisBlock(); |
| 1096 |
| 1097 // Temporarily end per-function timing, which will be resumed by |
| 1098 // the translator function. This is because translation may be |
| 1099 // done asynchronously in a separate thread. |
| 1100 if (TimeThisFunction) |
| 1101 getTranslator().getContext()->popTimer(TimerID, StackID); |
| 1102 |
| 1103 Ice::Cfg::setCurrentCfg(nullptr); |
| 1104 // Note: Once any errors have been found, we turn off all |
| 1105 // translation of all remaining functions. This allows successive |
| 1106 // parsing errors to be reported, without adding extra checks to |
| 1107 // the translator for such parsing errors. |
| 1108 if (Context->getNumErrors() == 0) { |
| 1109 getTranslator().translateFcn(std::move(Func)); |
| 1110 // The translator now has ownership of Func. |
| 1111 } else { |
| 1112 Func.reset(); |
| 1113 } |
| 1114 |
| 1115 return ParserResult; |
| 1087 } | 1116 } |
| 1088 | 1117 |
| 1089 ~FunctionParser() final {} | 1118 ~FunctionParser() final {} |
| 1090 | 1119 |
| 1091 const char *getBlockName() const override { return "function"; } | 1120 const char *getBlockName() const override { return "function"; } |
| 1092 | 1121 |
| 1093 Ice::Cfg *getFunc() const { return Func; } | 1122 Ice::Cfg *getFunc() const { return Func.get(); } |
| 1094 | 1123 |
| 1095 uint32_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; } | 1124 uint32_t getNumGlobalIDs() const { return CachedNumGlobalValueIDs; } |
| 1096 | 1125 |
| 1097 void setNextLocalInstIndex(Ice::Operand *Op) { | 1126 void setNextLocalInstIndex(Ice::Operand *Op) { |
| 1098 setOperand(NextLocalInstIndex++, Op); | 1127 setOperand(NextLocalInstIndex++, Op); |
| 1099 } | 1128 } |
| 1100 | 1129 |
| 1101 // Set the next constant ID to the given constant C. | 1130 // Set the next constant ID to the given constant C. |
| 1102 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1131 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
| 1103 | 1132 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1123 StrBuf << "Value index " << Index << " not defined!"; | 1152 StrBuf << "Value index " << Index << " not defined!"; |
| 1124 Error(StrBuf.str()); | 1153 Error(StrBuf.str()); |
| 1125 report_fatal_error("Unable to continue"); | 1154 report_fatal_error("Unable to continue"); |
| 1126 } | 1155 } |
| 1127 return Op; | 1156 return Op; |
| 1128 } | 1157 } |
| 1129 | 1158 |
| 1130 private: | 1159 private: |
| 1131 Ice::TimerMarker Timer; | 1160 Ice::TimerMarker Timer; |
| 1132 // The corresponding ICE function defined by the function block. | 1161 // The corresponding ICE function defined by the function block. |
| 1133 Ice::Cfg *Func; | 1162 std::unique_ptr<Ice::Cfg> Func; |
| 1134 // The index to the current basic block being built. | 1163 // The index to the current basic block being built. |
| 1135 uint32_t CurrentBbIndex; | 1164 uint32_t CurrentBbIndex; |
| 1136 // The basic block being built. | 1165 // The basic block being built. |
| 1137 Ice::CfgNode *CurrentNode; | 1166 Ice::CfgNode *CurrentNode; |
| 1138 // The ID for the function. | 1167 // The ID for the function. |
| 1139 unsigned FcnId; | 1168 unsigned FcnId; |
| 1140 // The corresponding function declaration. | 1169 // The corresponding function declaration. |
| 1141 Ice::FunctionDeclaration *FuncDecl; | 1170 Ice::FunctionDeclaration *FuncDecl; |
| 1142 // Holds the dividing point between local and global absolute value indices. | 1171 // Holds the dividing point between local and global absolute value indices. |
| 1143 uint32_t CachedNumGlobalValueIDs; | 1172 uint32_t CachedNumGlobalValueIDs; |
| 1144 // Holds operands local to the function block, based on indices | 1173 // Holds operands local to the function block, based on indices |
| 1145 // defined in the bitcode file. | 1174 // defined in the bitcode file. |
| 1146 std::vector<Ice::Operand *> LocalOperands; | 1175 std::vector<Ice::Operand *> LocalOperands; |
| 1147 // Holds the index within LocalOperands corresponding to the next | 1176 // Holds the index within LocalOperands corresponding to the next |
| 1148 // instruction that generates a value. | 1177 // instruction that generates a value. |
| 1149 uint32_t NextLocalInstIndex; | 1178 uint32_t NextLocalInstIndex; |
| 1150 // True if the last processed instruction was a terminating | 1179 // True if the last processed instruction was a terminating |
| 1151 // instruction. | 1180 // instruction. |
| 1152 bool InstIsTerminating; | 1181 bool InstIsTerminating; |
| 1153 // Upper limit of alignment power allowed by LLVM | 1182 // Upper limit of alignment power allowed by LLVM |
| 1154 static const uint32_t AlignPowerLimit = 29; | 1183 static const uint32_t AlignPowerLimit = 29; |
| 1155 | 1184 |
| 1156 void popTimerIfTimingEachFunction() const { | |
| 1157 if (ALLOW_DUMP && getFlags().TimeEachFunction) { | |
| 1158 getTranslator().getContext()->popTimer( | |
| 1159 getTranslator().getContext()->getTimerID( | |
| 1160 Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()), | |
| 1161 Ice::GlobalContext::TSK_Funcs); | |
| 1162 } | |
| 1163 } | |
| 1164 | |
| 1165 // Extracts the corresponding Alignment to use, given the AlignPower | 1185 // Extracts the corresponding Alignment to use, given the AlignPower |
| 1166 // (i.e. 2**(AlignPower-1), or 0 if AlignPower == 0). InstName is the | 1186 // (i.e. 2**(AlignPower-1), or 0 if AlignPower == 0). InstName is the |
| 1167 // name of the instruction the alignment appears in. | 1187 // name of the instruction the alignment appears in. |
| 1168 void extractAlignment(const char *InstName, uint32_t AlignPower, | 1188 void extractAlignment(const char *InstName, uint32_t AlignPower, |
| 1169 uint32_t &Alignment) { | 1189 uint32_t &Alignment) { |
| 1170 if (AlignPower <= AlignPowerLimit + 1) { | 1190 if (AlignPower <= AlignPowerLimit + 1) { |
| 1171 Alignment = (1 << AlignPower) >> 1; | 1191 Alignment = (1 << AlignPower) >> 1; |
| 1172 return; | 1192 return; |
| 1173 } | 1193 } |
| 1174 std::string Buffer; | 1194 std::string Buffer; |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 // if the return type is void. In such cases, a placeholder value | 1833 // if the return type is void. In such cases, a placeholder value |
| 1814 // for the badly formed instruction is not needed. Hence, if Ty is | 1834 // for the badly formed instruction is not needed. Hence, if Ty is |
| 1815 // void, an error instruction is not appended. | 1835 // void, an error instruction is not appended. |
| 1816 // TODO(kschimpf) Remove error recovery once implementation complete. | 1836 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1817 void appendErrorInstruction(Ice::Type Ty) { | 1837 void appendErrorInstruction(Ice::Type Ty) { |
| 1818 // Note: we don't worry about downstream translation errors because | 1838 // Note: we don't worry about downstream translation errors because |
| 1819 // the function will not be translated if any errors occur. | 1839 // the function will not be translated if any errors occur. |
| 1820 if (Ty == Ice::IceType_void) | 1840 if (Ty == Ice::IceType_void) |
| 1821 return; | 1841 return; |
| 1822 Ice::Variable *Var = getNextInstVar(Ty); | 1842 Ice::Variable *Var = getNextInstVar(Ty); |
| 1823 CurrentNode->appendInst(Ice::InstAssign::create(Func, Var, Var)); | 1843 CurrentNode->appendInst(Ice::InstAssign::create(Func.get(), Var, Var)); |
| 1824 } | 1844 } |
| 1825 }; | 1845 }; |
| 1826 | 1846 |
| 1827 void FunctionParser::ExitBlock() { | 1847 void FunctionParser::ExitBlock() { |
| 1828 if (isIRGenerationDisabled()) { | 1848 if (isIRGenerationDisabled()) { |
| 1829 popTimerIfTimingEachFunction(); | |
| 1830 delete Func; | |
| 1831 return; | 1849 return; |
| 1832 } | 1850 } |
| 1833 // Before translating, check for blocks without instructions, and | 1851 // Before translating, check for blocks without instructions, and |
| 1834 // insert unreachable. This shouldn't happen, but be safe. | 1852 // insert unreachable. This shouldn't happen, but be safe. |
| 1835 unsigned Index = 0; | 1853 unsigned Index = 0; |
| 1836 for (Ice::CfgNode *Node : Func->getNodes()) { | 1854 for (Ice::CfgNode *Node : Func->getNodes()) { |
| 1837 if (Node->getInsts().empty()) { | 1855 if (Node->getInsts().empty()) { |
| 1838 std::string Buffer; | 1856 std::string Buffer; |
| 1839 raw_string_ostream StrBuf(Buffer); | 1857 raw_string_ostream StrBuf(Buffer); |
| 1840 StrBuf << "Basic block " << Index << " contains no instructions"; | 1858 StrBuf << "Basic block " << Index << " contains no instructions"; |
| 1841 Error(StrBuf.str()); | 1859 Error(StrBuf.str()); |
| 1842 // TODO(kschimpf) Remove error recovery once implementation complete. | 1860 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1843 Node->appendInst(Ice::InstUnreachable::create(Func)); | 1861 Node->appendInst(Ice::InstUnreachable::create(Func.get())); |
| 1844 } | 1862 } |
| 1845 ++Index; | 1863 ++Index; |
| 1846 } | 1864 } |
| 1847 Func->computePredecessors(); | 1865 Func->computePredecessors(); |
| 1848 // Temporarily end per-function timing, which will be resumed by the | |
| 1849 // translator function. This is because translation may be done | |
| 1850 // asynchronously in a separate thread. | |
| 1851 popTimerIfTimingEachFunction(); | |
| 1852 // Note: Once any errors have been found, we turn off all | |
| 1853 // translation of all remaining functions. This allows use to see | |
| 1854 // multiple errors, without adding extra checks to the translator | |
| 1855 // for such parsing errors. | |
| 1856 if (Context->getNumErrors() == 0) | |
| 1857 getTranslator().translateFcn(Func); | |
| 1858 } | 1866 } |
| 1859 | 1867 |
| 1860 void FunctionParser::ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, | 1868 void FunctionParser::ReportInvalidBinaryOp(Ice::InstArithmetic::OpKind Op, |
| 1861 Ice::Type OpTy) { | 1869 Ice::Type OpTy) { |
| 1862 std::string Buffer; | 1870 std::string Buffer; |
| 1863 raw_string_ostream StrBuf(Buffer); | 1871 raw_string_ostream StrBuf(Buffer); |
| 1864 StrBuf << "Invalid operator type for " << Ice::InstArithmetic::getOpName(Op) | 1872 StrBuf << "Invalid operator type for " << Ice::InstArithmetic::getOpName(Op) |
| 1865 << ". Found " << OpTy; | 1873 << ". Found " << OpTy; |
| 1866 Error(StrBuf.str()); | 1874 Error(StrBuf.str()); |
| 1867 } | 1875 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 appendErrorInstruction(Type1); | 1931 appendErrorInstruction(Type1); |
| 1924 return; | 1932 return; |
| 1925 } | 1933 } |
| 1926 | 1934 |
| 1927 Ice::InstArithmetic::OpKind Opcode; | 1935 Ice::InstArithmetic::OpKind Opcode; |
| 1928 if (!convertBinopOpcode(Values[2], Type1, Opcode)) { | 1936 if (!convertBinopOpcode(Values[2], Type1, Opcode)) { |
| 1929 appendErrorInstruction(Type1); | 1937 appendErrorInstruction(Type1); |
| 1930 return; | 1938 return; |
| 1931 } | 1939 } |
| 1932 CurrentNode->appendInst(Ice::InstArithmetic::create( | 1940 CurrentNode->appendInst(Ice::InstArithmetic::create( |
| 1933 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); | 1941 Func.get(), Opcode, getNextInstVar(Type1), Op1, Op2)); |
| 1934 return; | 1942 return; |
| 1935 } | 1943 } |
| 1936 case naclbitc::FUNC_CODE_INST_CAST: { | 1944 case naclbitc::FUNC_CODE_INST_CAST: { |
| 1937 // CAST: [opval, destty, castopc] | 1945 // CAST: [opval, destty, castopc] |
| 1938 if (!isValidRecordSize(3, "cast")) | 1946 if (!isValidRecordSize(3, "cast")) |
| 1939 return; | 1947 return; |
| 1940 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); | 1948 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); |
| 1941 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); | 1949 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); |
| 1942 Ice::InstCast::OpKind CastKind; | 1950 Ice::InstCast::OpKind CastKind; |
| 1943 if (isIRGenerationDisabled()) { | 1951 if (isIRGenerationDisabled()) { |
| 1944 assert(Src == nullptr); | 1952 assert(Src == nullptr); |
| 1945 setNextLocalInstIndex(nullptr); | 1953 setNextLocalInstIndex(nullptr); |
| 1946 return; | 1954 return; |
| 1947 } | 1955 } |
| 1948 if (!convertCastOpToIceOp(Values[2], Src->getType(), CastType, CastKind)) { | 1956 if (!convertCastOpToIceOp(Values[2], Src->getType(), CastType, CastKind)) { |
| 1949 appendErrorInstruction(CastType); | 1957 appendErrorInstruction(CastType); |
| 1950 return; | 1958 return; |
| 1951 } | 1959 } |
| 1952 CurrentNode->appendInst( | 1960 CurrentNode->appendInst(Ice::InstCast::create( |
| 1953 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); | 1961 Func.get(), CastKind, getNextInstVar(CastType), Src)); |
| 1954 return; | 1962 return; |
| 1955 } | 1963 } |
| 1956 case naclbitc::FUNC_CODE_INST_VSELECT: { | 1964 case naclbitc::FUNC_CODE_INST_VSELECT: { |
| 1957 // VSELECT: [opval, opval, pred] | 1965 // VSELECT: [opval, opval, pred] |
| 1958 if (!isValidRecordSize(3, "select")) | 1966 if (!isValidRecordSize(3, "select")) |
| 1959 return; | 1967 return; |
| 1960 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); | 1968 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); |
| 1961 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); | 1969 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); |
| 1962 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); | 1970 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); |
| 1963 if (isIRGenerationDisabled()) { | 1971 if (isIRGenerationDisabled()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1992 } else if (CondVal->getType() != Ice::IceType_i1) { | 2000 } else if (CondVal->getType() != Ice::IceType_i1) { |
| 1993 std::string Buffer; | 2001 std::string Buffer; |
| 1994 raw_string_ostream StrBuf(Buffer); | 2002 raw_string_ostream StrBuf(Buffer); |
| 1995 StrBuf << "Select condition " << CondVal | 2003 StrBuf << "Select condition " << CondVal |
| 1996 << " not type i1. Found: " << CondVal->getType(); | 2004 << " not type i1. Found: " << CondVal->getType(); |
| 1997 Error(StrBuf.str()); | 2005 Error(StrBuf.str()); |
| 1998 appendErrorInstruction(ThenType); | 2006 appendErrorInstruction(ThenType); |
| 1999 return; | 2007 return; |
| 2000 } | 2008 } |
| 2001 CurrentNode->appendInst(Ice::InstSelect::create( | 2009 CurrentNode->appendInst(Ice::InstSelect::create( |
| 2002 Func, getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); | 2010 Func.get(), getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); |
| 2003 return; | 2011 return; |
| 2004 } | 2012 } |
| 2005 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { | 2013 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { |
| 2006 // EXTRACTELT: [opval, opval] | 2014 // EXTRACTELT: [opval, opval] |
| 2007 if (!isValidRecordSize(2, "extract element")) | 2015 if (!isValidRecordSize(2, "extract element")) |
| 2008 return; | 2016 return; |
| 2009 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 2017 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
| 2010 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); | 2018 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); |
| 2011 if (isIRGenerationDisabled()) { | 2019 if (isIRGenerationDisabled()) { |
| 2012 assert(Vec == nullptr && Index == nullptr); | 2020 assert(Vec == nullptr && Index == nullptr); |
| 2013 setNextLocalInstIndex(nullptr); | 2021 setNextLocalInstIndex(nullptr); |
| 2014 return; | 2022 return; |
| 2015 } | 2023 } |
| 2016 Ice::Type VecType = Vec->getType(); | 2024 Ice::Type VecType = Vec->getType(); |
| 2017 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 2025 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
| 2018 if (IndexCheckValue != VectorIndexValid) { | 2026 if (IndexCheckValue != VectorIndexValid) { |
| 2019 std::string Buffer; | 2027 std::string Buffer; |
| 2020 raw_string_ostream StrBuf(Buffer); | 2028 raw_string_ostream StrBuf(Buffer); |
| 2021 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 2029 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
| 2022 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " | 2030 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " |
| 2023 << Index->getType() << " " << *Index; | 2031 << Index->getType() << " " << *Index; |
| 2024 Error(StrBuf.str()); | 2032 Error(StrBuf.str()); |
| 2025 appendErrorInstruction(VecType); | 2033 appendErrorInstruction(VecType); |
| 2026 return; | 2034 return; |
| 2027 } | 2035 } |
| 2028 CurrentNode->appendInst(Ice::InstExtractElement::create( | 2036 CurrentNode->appendInst(Ice::InstExtractElement::create( |
| 2029 Func, getNextInstVar(typeElementType(VecType)), Vec, Index)); | 2037 Func.get(), getNextInstVar(typeElementType(VecType)), Vec, Index)); |
| 2030 return; | 2038 return; |
| 2031 } | 2039 } |
| 2032 case naclbitc::FUNC_CODE_INST_INSERTELT: { | 2040 case naclbitc::FUNC_CODE_INST_INSERTELT: { |
| 2033 // INSERTELT: [opval, opval, opval] | 2041 // INSERTELT: [opval, opval, opval] |
| 2034 if (!isValidRecordSize(3, "insert element")) | 2042 if (!isValidRecordSize(3, "insert element")) |
| 2035 return; | 2043 return; |
| 2036 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 2044 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
| 2037 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); | 2045 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); |
| 2038 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); | 2046 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); |
| 2039 if (isIRGenerationDisabled()) { | 2047 if (isIRGenerationDisabled()) { |
| 2040 assert(Vec == nullptr && Elt == nullptr && Index == nullptr); | 2048 assert(Vec == nullptr && Elt == nullptr && Index == nullptr); |
| 2041 setNextLocalInstIndex(nullptr); | 2049 setNextLocalInstIndex(nullptr); |
| 2042 return; | 2050 return; |
| 2043 } | 2051 } |
| 2044 Ice::Type VecType = Vec->getType(); | 2052 Ice::Type VecType = Vec->getType(); |
| 2045 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 2053 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
| 2046 if (IndexCheckValue != VectorIndexValid) { | 2054 if (IndexCheckValue != VectorIndexValid) { |
| 2047 std::string Buffer; | 2055 std::string Buffer; |
| 2048 raw_string_ostream StrBuf(Buffer); | 2056 raw_string_ostream StrBuf(Buffer); |
| 2049 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 2057 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
| 2050 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " | 2058 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " |
| 2051 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " | 2059 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " |
| 2052 << *Index; | 2060 << *Index; |
| 2053 Error(StrBuf.str()); | 2061 Error(StrBuf.str()); |
| 2054 appendErrorInstruction(Elt->getType()); | 2062 appendErrorInstruction(Elt->getType()); |
| 2055 return; | 2063 return; |
| 2056 } | 2064 } |
| 2057 CurrentNode->appendInst(Ice::InstInsertElement::create( | 2065 CurrentNode->appendInst(Ice::InstInsertElement::create( |
| 2058 Func, getNextInstVar(VecType), Vec, Elt, Index)); | 2066 Func.get(), getNextInstVar(VecType), Vec, Elt, Index)); |
| 2059 return; | 2067 return; |
| 2060 } | 2068 } |
| 2061 case naclbitc::FUNC_CODE_INST_CMP2: { | 2069 case naclbitc::FUNC_CODE_INST_CMP2: { |
| 2062 // CMP2: [opval, opval, pred] | 2070 // CMP2: [opval, opval, pred] |
| 2063 if (!isValidRecordSize(3, "compare")) | 2071 if (!isValidRecordSize(3, "compare")) |
| 2064 return; | 2072 return; |
| 2065 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 2073 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
| 2066 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 2074 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
| 2067 if (isIRGenerationDisabled()) { | 2075 if (isIRGenerationDisabled()) { |
| 2068 assert(Op1 == nullptr && Op2 == nullptr); | 2076 assert(Op1 == nullptr && Op2 == nullptr); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2093 Ice::InstIcmp::ICond Cond; | 2101 Ice::InstIcmp::ICond Cond; |
| 2094 if (!convertNaClBitcICmpOpToIce(Values[2], Cond)) { | 2102 if (!convertNaClBitcICmpOpToIce(Values[2], Cond)) { |
| 2095 std::string Buffer; | 2103 std::string Buffer; |
| 2096 raw_string_ostream StrBuf(Buffer); | 2104 raw_string_ostream StrBuf(Buffer); |
| 2097 StrBuf << "Compare record contains unknown integer predicate index: " | 2105 StrBuf << "Compare record contains unknown integer predicate index: " |
| 2098 << Values[2]; | 2106 << Values[2]; |
| 2099 Error(StrBuf.str()); | 2107 Error(StrBuf.str()); |
| 2100 appendErrorInstruction(DestType); | 2108 appendErrorInstruction(DestType); |
| 2101 } | 2109 } |
| 2102 CurrentNode->appendInst( | 2110 CurrentNode->appendInst( |
| 2103 Ice::InstIcmp::create(Func, Cond, Dest, Op1, Op2)); | 2111 Ice::InstIcmp::create(Func.get(), Cond, Dest, Op1, Op2)); |
| 2104 } else if (isFloatingType(Op1Type)) { | 2112 } else if (isFloatingType(Op1Type)) { |
| 2105 Ice::InstFcmp::FCond Cond; | 2113 Ice::InstFcmp::FCond Cond; |
| 2106 if (!convertNaClBitcFCompOpToIce(Values[2], Cond)) { | 2114 if (!convertNaClBitcFCompOpToIce(Values[2], Cond)) { |
| 2107 std::string Buffer; | 2115 std::string Buffer; |
| 2108 raw_string_ostream StrBuf(Buffer); | 2116 raw_string_ostream StrBuf(Buffer); |
| 2109 StrBuf << "Compare record contains unknown float predicate index: " | 2117 StrBuf << "Compare record contains unknown float predicate index: " |
| 2110 << Values[2]; | 2118 << Values[2]; |
| 2111 Error(StrBuf.str()); | 2119 Error(StrBuf.str()); |
| 2112 appendErrorInstruction(DestType); | 2120 appendErrorInstruction(DestType); |
| 2113 } | 2121 } |
| 2114 CurrentNode->appendInst( | 2122 CurrentNode->appendInst( |
| 2115 Ice::InstFcmp::create(Func, Cond, Dest, Op1, Op2)); | 2123 Ice::InstFcmp::create(Func.get(), Cond, Dest, Op1, Op2)); |
| 2116 } else { | 2124 } else { |
| 2117 // Not sure this can happen, but be safe. | 2125 // Not sure this can happen, but be safe. |
| 2118 std::string Buffer; | 2126 std::string Buffer; |
| 2119 raw_string_ostream StrBuf(Buffer); | 2127 raw_string_ostream StrBuf(Buffer); |
| 2120 StrBuf << "Compare on type not understood: " << Op1Type; | 2128 StrBuf << "Compare on type not understood: " << Op1Type; |
| 2121 Error(StrBuf.str()); | 2129 Error(StrBuf.str()); |
| 2122 appendErrorInstruction(DestType); | 2130 appendErrorInstruction(DestType); |
| 2123 return; | 2131 return; |
| 2124 } | 2132 } |
| 2125 return; | 2133 return; |
| 2126 } | 2134 } |
| 2127 case naclbitc::FUNC_CODE_INST_RET: { | 2135 case naclbitc::FUNC_CODE_INST_RET: { |
| 2128 // RET: [opval?] | 2136 // RET: [opval?] |
| 2129 if (!isValidRecordSizeInRange(0, 1, "return")) | 2137 if (!isValidRecordSizeInRange(0, 1, "return")) |
| 2130 return; | 2138 return; |
| 2131 if (Values.empty()) { | 2139 if (Values.empty()) { |
| 2132 if (isIRGenerationDisabled()) | 2140 if (isIRGenerationDisabled()) |
| 2133 return; | 2141 return; |
| 2134 CurrentNode->appendInst(Ice::InstRet::create(Func)); | 2142 CurrentNode->appendInst(Ice::InstRet::create(Func.get())); |
| 2135 } else { | 2143 } else { |
| 2136 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); | 2144 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); |
| 2137 if (isIRGenerationDisabled()) { | 2145 if (isIRGenerationDisabled()) { |
| 2138 assert(RetVal == nullptr); | 2146 assert(RetVal == nullptr); |
| 2139 return; | 2147 return; |
| 2140 } | 2148 } |
| 2141 CurrentNode->appendInst(Ice::InstRet::create(Func, RetVal)); | 2149 CurrentNode->appendInst(Ice::InstRet::create(Func.get(), RetVal)); |
| 2142 } | 2150 } |
| 2143 InstIsTerminating = true; | 2151 InstIsTerminating = true; |
| 2144 return; | 2152 return; |
| 2145 } | 2153 } |
| 2146 case naclbitc::FUNC_CODE_INST_BR: { | 2154 case naclbitc::FUNC_CODE_INST_BR: { |
| 2147 if (Values.size() == 1) { | 2155 if (Values.size() == 1) { |
| 2148 // BR: [bb#] | 2156 // BR: [bb#] |
| 2149 if (isIRGenerationDisabled()) | 2157 if (isIRGenerationDisabled()) |
| 2150 return; | 2158 return; |
| 2151 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | 2159 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); |
| 2152 if (Block == nullptr) | 2160 if (Block == nullptr) |
| 2153 return; | 2161 return; |
| 2154 CurrentNode->appendInst(Ice::InstBr::create(Func, Block)); | 2162 CurrentNode->appendInst(Ice::InstBr::create(Func.get(), Block)); |
| 2155 } else { | 2163 } else { |
| 2156 // BR: [bb#, bb#, opval] | 2164 // BR: [bb#, bb#, opval] |
| 2157 if (!isValidRecordSize(3, "branch")) | 2165 if (!isValidRecordSize(3, "branch")) |
| 2158 return; | 2166 return; |
| 2159 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); | 2167 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); |
| 2160 if (isIRGenerationDisabled()) { | 2168 if (isIRGenerationDisabled()) { |
| 2161 assert(Cond == nullptr); | 2169 assert(Cond == nullptr); |
| 2162 return; | 2170 return; |
| 2163 } | 2171 } |
| 2164 if (Cond->getType() != Ice::IceType_i1) { | 2172 if (Cond->getType() != Ice::IceType_i1) { |
| 2165 std::string Buffer; | 2173 std::string Buffer; |
| 2166 raw_string_ostream StrBuf(Buffer); | 2174 raw_string_ostream StrBuf(Buffer); |
| 2167 StrBuf << "Branch condition " << *Cond | 2175 StrBuf << "Branch condition " << *Cond |
| 2168 << " not i1. Found: " << Cond->getType(); | 2176 << " not i1. Found: " << Cond->getType(); |
| 2169 Error(StrBuf.str()); | 2177 Error(StrBuf.str()); |
| 2170 return; | 2178 return; |
| 2171 } | 2179 } |
| 2172 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); | 2180 Ice::CfgNode *ThenBlock = getBranchBasicBlock(Values[0]); |
| 2173 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); | 2181 Ice::CfgNode *ElseBlock = getBranchBasicBlock(Values[1]); |
| 2174 if (ThenBlock == nullptr || ElseBlock == nullptr) | 2182 if (ThenBlock == nullptr || ElseBlock == nullptr) |
| 2175 return; | 2183 return; |
| 2176 CurrentNode->appendInst( | 2184 CurrentNode->appendInst( |
| 2177 Ice::InstBr::create(Func, Cond, ThenBlock, ElseBlock)); | 2185 Ice::InstBr::create(Func.get(), Cond, ThenBlock, ElseBlock)); |
| 2178 } | 2186 } |
| 2179 InstIsTerminating = true; | 2187 InstIsTerminating = true; |
| 2180 return; | 2188 return; |
| 2181 } | 2189 } |
| 2182 case naclbitc::FUNC_CODE_INST_SWITCH: { | 2190 case naclbitc::FUNC_CODE_INST_SWITCH: { |
| 2183 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] | 2191 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] |
| 2184 // where Case = [1, 1, Value, BbIndex]. | 2192 // where Case = [1, 1, Value, BbIndex]. |
| 2185 // | 2193 // |
| 2186 // Note: Unlike most instructions, we don't infer the type of | 2194 // Note: Unlike most instructions, we don't infer the type of |
| 2187 // Cond, but provide it as a separate field. There are also | 2195 // Cond, but provide it as a separate field. There are also |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2214 return; | 2222 return; |
| 2215 } | 2223 } |
| 2216 Ice::CfgNode *DefaultLabel = | 2224 Ice::CfgNode *DefaultLabel = |
| 2217 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); | 2225 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); |
| 2218 unsigned NumCases = Values[3]; | 2226 unsigned NumCases = Values[3]; |
| 2219 | 2227 |
| 2220 // Now recognize each of the cases. | 2228 // Now recognize each of the cases. |
| 2221 if (!isValidRecordSize(4 + NumCases * 4, "switch")) | 2229 if (!isValidRecordSize(4 + NumCases * 4, "switch")) |
| 2222 return; | 2230 return; |
| 2223 Ice::InstSwitch *Switch = | 2231 Ice::InstSwitch *Switch = |
| 2224 isIRGenDisabled ? nullptr : Ice::InstSwitch::create(Func, NumCases, | 2232 isIRGenDisabled |
| 2225 Cond, DefaultLabel); | 2233 ? nullptr |
| 2234 : Ice::InstSwitch::create(Func.get(), NumCases, Cond, DefaultLabel); |
| 2226 unsigned ValCaseIndex = 4; // index to beginning of case entry. | 2235 unsigned ValCaseIndex = 4; // index to beginning of case entry. |
| 2227 for (unsigned CaseIndex = 0; CaseIndex < NumCases; | 2236 for (unsigned CaseIndex = 0; CaseIndex < NumCases; |
| 2228 ++CaseIndex, ValCaseIndex += 4) { | 2237 ++CaseIndex, ValCaseIndex += 4) { |
| 2229 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { | 2238 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex + 1] != 1) { |
| 2230 std::string Buffer; | 2239 std::string Buffer; |
| 2231 raw_string_ostream StrBuf(Buffer); | 2240 raw_string_ostream StrBuf(Buffer); |
| 2232 StrBuf << "Sequence [1, 1, value, label] expected for case entry " | 2241 StrBuf << "Sequence [1, 1, value, label] expected for case entry " |
| 2233 << "in switch record. (at index" << ValCaseIndex << ")"; | 2242 << "in switch record. (at index" << ValCaseIndex << ")"; |
| 2234 Error(StrBuf.str()); | 2243 Error(StrBuf.str()); |
| 2235 return; | 2244 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2246 CurrentNode->appendInst(Switch); | 2255 CurrentNode->appendInst(Switch); |
| 2247 InstIsTerminating = true; | 2256 InstIsTerminating = true; |
| 2248 return; | 2257 return; |
| 2249 } | 2258 } |
| 2250 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2259 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
| 2251 // UNREACHABLE: [] | 2260 // UNREACHABLE: [] |
| 2252 if (!isValidRecordSize(0, "unreachable")) | 2261 if (!isValidRecordSize(0, "unreachable")) |
| 2253 return; | 2262 return; |
| 2254 if (isIRGenerationDisabled()) | 2263 if (isIRGenerationDisabled()) |
| 2255 return; | 2264 return; |
| 2256 CurrentNode->appendInst(Ice::InstUnreachable::create(Func)); | 2265 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); |
| 2257 InstIsTerminating = true; | 2266 InstIsTerminating = true; |
| 2258 return; | 2267 return; |
| 2259 } | 2268 } |
| 2260 case naclbitc::FUNC_CODE_INST_PHI: { | 2269 case naclbitc::FUNC_CODE_INST_PHI: { |
| 2261 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. | 2270 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. |
| 2262 if (!isValidRecordSizeAtLeast(3, "phi")) | 2271 if (!isValidRecordSizeAtLeast(3, "phi")) |
| 2263 return; | 2272 return; |
| 2264 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); | 2273 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
| 2265 if ((Values.size() & 0x1) == 0) { | 2274 if ((Values.size() & 0x1) == 0) { |
| 2266 // Not an odd number of values. | 2275 // Not an odd number of values. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2278 if (isIRGenerationDisabled()) { | 2287 if (isIRGenerationDisabled()) { |
| 2279 // Verify arguments are defined before quitting. | 2288 // Verify arguments are defined before quitting. |
| 2280 for (unsigned i = 1; i < Values.size(); i += 2) { | 2289 for (unsigned i = 1; i < Values.size(); i += 2) { |
| 2281 assert(getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), | 2290 assert(getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), |
| 2282 BaseIndex) == nullptr); | 2291 BaseIndex) == nullptr); |
| 2283 } | 2292 } |
| 2284 setNextLocalInstIndex(nullptr); | 2293 setNextLocalInstIndex(nullptr); |
| 2285 return; | 2294 return; |
| 2286 } | 2295 } |
| 2287 Ice::Variable *Dest = getNextInstVar(Ty); | 2296 Ice::Variable *Dest = getNextInstVar(Ty); |
| 2288 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); | 2297 Ice::InstPhi *Phi = |
| 2298 Ice::InstPhi::create(Func.get(), Values.size() >> 1, Dest); |
| 2289 for (unsigned i = 1; i < Values.size(); i += 2) { | 2299 for (unsigned i = 1; i < Values.size(); i += 2) { |
| 2290 Ice::Operand *Op = | 2300 Ice::Operand *Op = |
| 2291 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); | 2301 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); |
| 2292 if (Op->getType() != Ty) { | 2302 if (Op->getType() != Ty) { |
| 2293 std::string Buffer; | 2303 std::string Buffer; |
| 2294 raw_string_ostream StrBuf(Buffer); | 2304 raw_string_ostream StrBuf(Buffer); |
| 2295 StrBuf << "Value " << *Op << " not type " << Ty | 2305 StrBuf << "Value " << *Op << " not type " << Ty |
| 2296 << " in phi instruction. Found: " << Op->getType(); | 2306 << " in phi instruction. Found: " << Op->getType(); |
| 2297 Error(StrBuf.str()); | 2307 Error(StrBuf.str()); |
| 2298 appendErrorInstruction(Ty); | 2308 appendErrorInstruction(Ty); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2317 } | 2327 } |
| 2318 Ice::Type PtrTy = Ice::getPointerType(); | 2328 Ice::Type PtrTy = Ice::getPointerType(); |
| 2319 if (ByteCount->getType() != Ice::IceType_i32) { | 2329 if (ByteCount->getType() != Ice::IceType_i32) { |
| 2320 std::string Buffer; | 2330 std::string Buffer; |
| 2321 raw_string_ostream StrBuf(Buffer); | 2331 raw_string_ostream StrBuf(Buffer); |
| 2322 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; | 2332 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; |
| 2323 Error(StrBuf.str()); | 2333 Error(StrBuf.str()); |
| 2324 appendErrorInstruction(PtrTy); | 2334 appendErrorInstruction(PtrTy); |
| 2325 return; | 2335 return; |
| 2326 } | 2336 } |
| 2327 CurrentNode->appendInst(Ice::InstAlloca::create(Func, ByteCount, Alignment, | 2337 CurrentNode->appendInst(Ice::InstAlloca::create( |
| 2328 getNextInstVar(PtrTy))); | 2338 Func.get(), ByteCount, Alignment, getNextInstVar(PtrTy))); |
| 2329 return; | 2339 return; |
| 2330 } | 2340 } |
| 2331 case naclbitc::FUNC_CODE_INST_LOAD: { | 2341 case naclbitc::FUNC_CODE_INST_LOAD: { |
| 2332 // LOAD: [address, align, ty] | 2342 // LOAD: [address, align, ty] |
| 2333 if (!isValidRecordSize(3, "load")) | 2343 if (!isValidRecordSize(3, "load")) |
| 2334 return; | 2344 return; |
| 2335 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2345 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
| 2336 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); | 2346 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); |
| 2337 uint32_t Alignment; | 2347 uint32_t Alignment; |
| 2338 extractAlignment("Load", Values[1], Alignment); | 2348 extractAlignment("Load", Values[1], Alignment); |
| 2339 if (isIRGenerationDisabled()) { | 2349 if (isIRGenerationDisabled()) { |
| 2340 assert(Address == nullptr); | 2350 assert(Address == nullptr); |
| 2341 setNextLocalInstIndex(nullptr); | 2351 setNextLocalInstIndex(nullptr); |
| 2342 return; | 2352 return; |
| 2343 } | 2353 } |
| 2344 if (!isValidPointerType(Address, "Load")) { | 2354 if (!isValidPointerType(Address, "Load")) { |
| 2345 appendErrorInstruction(Ty); | 2355 appendErrorInstruction(Ty); |
| 2346 return; | 2356 return; |
| 2347 } | 2357 } |
| 2348 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { | 2358 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { |
| 2349 appendErrorInstruction(Ty); | 2359 appendErrorInstruction(Ty); |
| 2350 return; | 2360 return; |
| 2351 } | 2361 } |
| 2352 CurrentNode->appendInst( | 2362 CurrentNode->appendInst(Ice::InstLoad::create( |
| 2353 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); | 2363 Func.get(), getNextInstVar(Ty), Address, Alignment)); |
| 2354 return; | 2364 return; |
| 2355 } | 2365 } |
| 2356 case naclbitc::FUNC_CODE_INST_STORE: { | 2366 case naclbitc::FUNC_CODE_INST_STORE: { |
| 2357 // STORE: [address, value, align] | 2367 // STORE: [address, value, align] |
| 2358 if (!isValidRecordSize(3, "store")) | 2368 if (!isValidRecordSize(3, "store")) |
| 2359 return; | 2369 return; |
| 2360 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2370 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
| 2361 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); | 2371 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); |
| 2362 uint32_t Alignment; | 2372 uint32_t Alignment; |
| 2363 extractAlignment("Store", Values[2], Alignment); | 2373 extractAlignment("Store", Values[2], Alignment); |
| 2364 if (isIRGenerationDisabled()) { | 2374 if (isIRGenerationDisabled()) { |
| 2365 assert(Address == nullptr && Value == nullptr); | 2375 assert(Address == nullptr && Value == nullptr); |
| 2366 return; | 2376 return; |
| 2367 } | 2377 } |
| 2368 if (!isValidPointerType(Address, "Store")) | 2378 if (!isValidPointerType(Address, "Store")) |
| 2369 return; | 2379 return; |
| 2370 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) | 2380 if (!isValidLoadStoreAlignment(Alignment, Value->getType(), "Store")) |
| 2371 return; | 2381 return; |
| 2372 CurrentNode->appendInst( | 2382 CurrentNode->appendInst( |
| 2373 Ice::InstStore::create(Func, Value, Address, Alignment)); | 2383 Ice::InstStore::create(Func.get(), Value, Address, Alignment)); |
| 2374 return; | 2384 return; |
| 2375 } | 2385 } |
| 2376 case naclbitc::FUNC_CODE_INST_CALL: | 2386 case naclbitc::FUNC_CODE_INST_CALL: |
| 2377 case naclbitc::FUNC_CODE_INST_CALL_INDIRECT: { | 2387 case naclbitc::FUNC_CODE_INST_CALL_INDIRECT: { |
| 2378 // CALL: [cc, fnid, arg0, arg1...] | 2388 // CALL: [cc, fnid, arg0, arg1...] |
| 2379 // CALL_INDIRECT: [cc, fn, returnty, args...] | 2389 // CALL_INDIRECT: [cc, fn, returnty, args...] |
| 2380 // | 2390 // |
| 2381 // Note: The difference between CALL and CALL_INDIRECT is that | 2391 // Note: The difference between CALL and CALL_INDIRECT is that |
| 2382 // CALL has a reference to an explicit function declaration, while | 2392 // CALL has a reference to an explicit function declaration, while |
| 2383 // the CALL_INDIRECT is just an address. For CALL, we can infer | 2393 // the CALL_INDIRECT is just an address. For CALL, we can infer |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2452 setNextLocalInstIndex(nullptr); | 2462 setNextLocalInstIndex(nullptr); |
| 2453 return; | 2463 return; |
| 2454 } | 2464 } |
| 2455 | 2465 |
| 2456 // Create the call instruction. | 2466 // Create the call instruction. |
| 2457 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) | 2467 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) |
| 2458 ? nullptr | 2468 ? nullptr |
| 2459 : getNextInstVar(ReturnType); | 2469 : getNextInstVar(ReturnType); |
| 2460 Ice::InstCall *Inst = nullptr; | 2470 Ice::InstCall *Inst = nullptr; |
| 2461 if (IntrinsicInfo) { | 2471 if (IntrinsicInfo) { |
| 2462 Inst = Ice::InstIntrinsicCall::create(Func, NumParams, Dest, Callee, | 2472 Inst = Ice::InstIntrinsicCall::create(Func.get(), NumParams, Dest, Callee, |
| 2463 IntrinsicInfo->Info); | 2473 IntrinsicInfo->Info); |
| 2464 } else { | 2474 } else { |
| 2465 Inst = Ice::InstCall::create(Func, NumParams, Dest, Callee, IsTailCall); | 2475 Inst = Ice::InstCall::create(Func.get(), NumParams, Dest, Callee, |
| 2476 IsTailCall); |
| 2466 } | 2477 } |
| 2467 | 2478 |
| 2468 // Add parameters. | 2479 // Add parameters. |
| 2469 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { | 2480 for (Ice::SizeT ParamIndex = 0; ParamIndex < NumParams; ++ParamIndex) { |
| 2470 Inst->addArg( | 2481 Inst->addArg( |
| 2471 getRelativeOperand(Values[ParamsStartIndex + ParamIndex], BaseIndex)); | 2482 getRelativeOperand(Values[ParamsStartIndex + ParamIndex], BaseIndex)); |
| 2472 } | 2483 } |
| 2473 | 2484 |
| 2474 // If intrinsic call, validate call signature. | 2485 // If intrinsic call, validate call signature. |
| 2475 if (IntrinsicInfo) { | 2486 if (IntrinsicInfo) { |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 GlobalsParser Parser(BlockID, this); | 2861 GlobalsParser Parser(BlockID, this); |
| 2851 return Parser.ParseThisBlock(); | 2862 return Parser.ParseThisBlock(); |
| 2852 } | 2863 } |
| 2853 case naclbitc::VALUE_SYMTAB_BLOCK_ID: { | 2864 case naclbitc::VALUE_SYMTAB_BLOCK_ID: { |
| 2854 ModuleValuesymtabParser Parser(BlockID, this); | 2865 ModuleValuesymtabParser Parser(BlockID, this); |
| 2855 return Parser.ParseThisBlock(); | 2866 return Parser.ParseThisBlock(); |
| 2856 } | 2867 } |
| 2857 case naclbitc::FUNCTION_BLOCK_ID: { | 2868 case naclbitc::FUNCTION_BLOCK_ID: { |
| 2858 InstallGlobalNamesAndGlobalVarInitializers(); | 2869 InstallGlobalNamesAndGlobalVarInitializers(); |
| 2859 FunctionParser Parser(BlockID, this); | 2870 FunctionParser Parser(BlockID, this); |
| 2860 return Parser.ParseThisBlock(); | 2871 return Parser.convertFunction(); |
| 2861 } | 2872 } |
| 2862 default: | 2873 default: |
| 2863 return BlockParserBaseClass::ParseBlock(BlockID); | 2874 return BlockParserBaseClass::ParseBlock(BlockID); |
| 2864 } | 2875 } |
| 2865 } | 2876 } |
| 2866 | 2877 |
| 2867 void ModuleParser::ProcessRecord() { | 2878 void ModuleParser::ProcessRecord() { |
| 2868 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 2879 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 2869 switch (Record.GetCode()) { | 2880 switch (Record.GetCode()) { |
| 2870 case naclbitc::MODULE_CODE_VERSION: { | 2881 case naclbitc::MODULE_CODE_VERSION: { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2977 | 2988 |
| 2978 if (TopLevelBlocks != 1) { | 2989 if (TopLevelBlocks != 1) { |
| 2979 errs() << IRFilename | 2990 errs() << IRFilename |
| 2980 << ": Contains more than one module. Found: " << TopLevelBlocks | 2991 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 2981 << "\n"; | 2992 << "\n"; |
| 2982 ErrorStatus.assign(EC_Bitcode); | 2993 ErrorStatus.assign(EC_Bitcode); |
| 2983 } | 2994 } |
| 2984 } | 2995 } |
| 2985 | 2996 |
| 2986 } // end of namespace Ice | 2997 } // end of namespace Ice |
| OLD | NEW |