Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 using namespace llvm; | 39 using namespace llvm; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // TODO(kschimpf) Remove error recovery once implementation complete. | 43 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 44 static cl::opt<bool> AllowErrorRecovery( | 44 static cl::opt<bool> AllowErrorRecovery( |
| 45 "allow-pnacl-reader-error-recovery", | 45 "allow-pnacl-reader-error-recovery", |
| 46 cl::desc("Allow error recovery when reading PNaCl bitcode."), | 46 cl::desc("Allow error recovery when reading PNaCl bitcode."), |
| 47 cl::init(false)); | 47 cl::init(false)); |
| 48 | 48 |
| 49 // Models elements in the list of types defined in the types block. | |
| 50 // These elements can be undefined, a (simple) type, or a function type | |
| 51 // signature. Note that an extended type is undefined on construction. | |
| 52 // Use methods setAsSimpleType and setAsFuncSigType to define | |
| 53 // the extended type. | |
| 54 class ExtendedType { | |
| 55 // ExtendedType(const ExtendedType &Ty) = delete; | |
| 56 ExtendedType &operator=(const ExtendedType &Ty) = delete; | |
| 57 public: | |
| 58 /// Discriminator for LLVM-style RTTI. | |
| 59 enum TypeKind { Undefined, Simple, FuncSig }; | |
| 60 | |
| 61 ExtendedType() : Kind(Undefined) {} | |
| 62 | |
| 63 virtual ~ExtendedType() {} | |
| 64 | |
| 65 ExtendedType::TypeKind getKind() const { return Kind; } | |
| 66 void Dump(Ice::Ostream &Stream) const; | |
| 67 | |
| 68 /// Changes the extended type to a simple type with the given | |
| 69 /// value. | |
| 70 void setAsSimpleType(Ice::Type Ty) { | |
| 71 assert(Kind == Undefined); | |
| 72 Kind = Simple; | |
| 73 Signature.setReturnType(Ty); | |
| 74 } | |
| 75 | |
| 76 /// Changes the extended type to an (empty) function signature type. | |
| 77 void setAsFunctionType() { | |
| 78 assert(Kind == Undefined); | |
| 79 Kind = FuncSig; | |
| 80 } | |
| 81 | |
| 82 protected: | |
| 83 // Note: For simple types, the return type of the signature will | |
| 84 // be used to hold the simple type. | |
| 85 Ice::FuncSigType Signature; | |
| 86 | |
| 87 private: | |
| 88 ExtendedType::TypeKind Kind; | |
| 89 }; | |
| 90 | |
| 91 Ice::Ostream &operator<<(Ice::Ostream &Stream, const ExtendedType &Ty) { | |
| 92 Ty.Dump(Stream); | |
| 93 return Stream; | |
| 94 } | |
| 95 | |
| 96 Ice::Ostream &operator<<(Ice::Ostream &Stream, ExtendedType::TypeKind Kind) { | |
| 97 Stream << "ExtendedType::"; | |
| 98 switch (Kind) { | |
| 99 case ExtendedType::Undefined: | |
| 100 Stream << "Undefined"; | |
| 101 break; | |
| 102 case ExtendedType::Simple: | |
| 103 Stream << "Simple"; | |
| 104 break; | |
| 105 case ExtendedType::FuncSig: | |
| 106 Stream << "FuncSig"; | |
| 107 break; | |
| 108 default: | |
| 109 Stream << "??"; | |
| 110 break; | |
| 111 } | |
| 112 return Stream; | |
| 113 } | |
| 114 | |
| 115 // Models an ICE type as an extended type. | |
| 116 class SimpleExtendedType : public ExtendedType { | |
| 117 SimpleExtendedType(const SimpleExtendedType &) = delete; | |
| 118 SimpleExtendedType &operator=(const SimpleExtendedType &) = delete; | |
| 119 public: | |
| 120 Ice::Type getType() const { return Signature.getReturnType(); } | |
| 121 | |
| 122 static bool classof(const ExtendedType *Ty) { | |
| 123 return Ty->getKind() == Simple; | |
| 124 } | |
| 125 }; | |
| 126 | |
| 127 // Models a function signature as an extended type. | |
| 128 class FuncSigExtendedType : public ExtendedType { | |
| 129 FuncSigExtendedType(const FuncSigExtendedType &) = delete; | |
| 130 FuncSigExtendedType &operator=(const FuncSigExtendedType &) = delete; | |
| 131 public: | |
| 132 const Ice::FuncSigType &getSignature() const { return Signature; } | |
| 133 void setReturnType(Ice::Type ReturnType) { | |
| 134 Signature.setReturnType(ReturnType); | |
| 135 } | |
| 136 void appendArgType(Ice::Type ArgType) { Signature.appendArgType(ArgType); } | |
| 137 static bool classof(const ExtendedType *Ty) { | |
| 138 return Ty->getKind() == FuncSig; | |
| 139 } | |
| 140 }; | |
| 141 | |
| 142 void ExtendedType::Dump(Ice::Ostream &Stream) const { | |
| 143 Stream << Kind; | |
| 144 switch (Kind) { | |
| 145 case Simple: { | |
| 146 Stream << " " << Signature.getReturnType(); | |
| 147 break; | |
| 148 } | |
| 149 case FuncSig: { | |
| 150 Stream << " " << Signature; | |
| 151 } | |
| 152 default: | |
| 153 break; | |
| 154 } | |
| 155 } | |
| 156 | |
| 49 // Top-level class to read PNaCl bitcode files, and translate to ICE. | 157 // Top-level class to read PNaCl bitcode files, and translate to ICE. |
| 50 class TopLevelParser : public NaClBitcodeParser { | 158 class TopLevelParser : public NaClBitcodeParser { |
| 51 TopLevelParser(const TopLevelParser &) = delete; | 159 TopLevelParser(const TopLevelParser &) = delete; |
| 52 TopLevelParser &operator=(const TopLevelParser &) = delete; | 160 TopLevelParser &operator=(const TopLevelParser &) = delete; |
| 53 | 161 |
| 54 public: | 162 public: |
| 55 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, | 163 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, |
| 56 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, | 164 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, |
| 57 bool &ErrorStatus) | 165 bool &ErrorStatus) |
| 58 : NaClBitcodeParser(Cursor), Translator(Translator), | 166 : NaClBitcodeParser(Cursor), Translator(Translator), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 89 | 197 |
| 90 /// Returns the number of bytes in the bitcode header. | 198 /// Returns the number of bytes in the bitcode header. |
| 91 size_t getHeaderSize() const { return Header.getHeaderSize(); } | 199 size_t getHeaderSize() const { return Header.getHeaderSize(); } |
| 92 | 200 |
| 93 /// Returns the llvm context to use. | 201 /// Returns the llvm context to use. |
| 94 LLVMContext &getLLVMContext() const { return Mod->getContext(); } | 202 LLVMContext &getLLVMContext() const { return Mod->getContext(); } |
| 95 | 203 |
| 96 /// Changes the size of the type list to the given size. | 204 /// Changes the size of the type list to the given size. |
| 97 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } | 205 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } |
| 98 | 206 |
| 99 /// Returns the type associated with the given index. | 207 /// Returns the undefined type associated with type ID. |
| 100 Type *getTypeByID(unsigned ID) { | 208 /// Note: Returns extended type ready to be defined. |
| 101 // Note: method resizeTypeIDValues expands TypeIDValues | 209 ExtendedType *getTypeByIDForDefining(unsigned ID) { |
| 102 // to the specified size, and fills elements with nullptr. | 210 // Get corresponding element, verifying the value is still undefined |
| 103 Type *Ty = ID < TypeIDValues.size() ? TypeIDValues[ID] : nullptr; | 211 // (and hence allowed to be defined). |
| 212 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); | |
| 104 if (Ty) | 213 if (Ty) |
| 105 return Ty; | 214 return Ty; |
| 106 return reportTypeIDAsUndefined(ID); | 215 if (ID >= TypeIDValues.size()) |
| 216 TypeIDValues.resize(ID+1); | |
| 217 return &TypeIDValues[ID]; | |
| 107 } | 218 } |
| 108 | 219 |
| 109 /// Defines type for ID. | 220 /// Returns the type associated with the given index. |
| 110 void setTypeID(unsigned ID, Type *Ty) { | 221 Ice::Type getSimpleTypeByID(unsigned ID) { |
| 111 if (ID < TypeIDValues.size() && TypeIDValues[ID] == nullptr) { | 222 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Simple); |
| 112 TypeIDValues[ID] = Ty; | 223 if (Ty == nullptr) |
| 113 return; | 224 // Return error recovery value. |
| 114 } | 225 return Ice::IceType_void; |
| 115 reportBadSetTypeID(ID, Ty); | 226 return cast<SimpleExtendedType>(Ty)->getType(); |
| 227 } | |
| 228 | |
| 229 /// Returns the type signature associated with the given index. | |
| 230 const Ice::FuncSigType &getFuncSigTypeByID(unsigned ID) { | |
| 231 const ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::FuncSig); | |
| 232 if (Ty == nullptr) | |
| 233 // Return error recovery value. | |
| 234 return UndefinedFuncSigType; | |
| 235 return cast<FuncSigExtendedType>(Ty)->getSignature(); | |
| 116 } | 236 } |
| 117 | 237 |
| 118 /// Sets the next function ID to the given LLVM function. | 238 /// Sets the next function ID to the given LLVM function. |
| 119 void setNextFunctionID(Function *Fcn) { | 239 void setNextFunctionID(Function *Fcn) { |
| 120 ++NumFunctionIds; | 240 ++NumFunctionIds; |
| 121 FunctionIDValues.push_back(Fcn); | 241 FunctionIDValues.push_back(Fcn); |
| 122 } | 242 } |
| 123 | 243 |
| 124 /// Defines the next function ID as one that has an implementation | 244 /// Defines the next function ID as one that has an implementation |
| 125 /// (i.e a corresponding function block in the bitcode). | 245 /// (i.e a corresponding function block in the bitcode). |
| 126 void setNextValueIDAsImplementedFunction() { | 246 void setNextValueIDAsImplementedFunction() { |
| 127 DefiningFunctionsList.push_back(FunctionIDValues.size()); | 247 DefiningFunctionsList.push_back(FunctionIDValues.size()); |
| 128 } | 248 } |
| 129 | 249 |
| 130 /// Returns the value id that should be associated with the the | 250 /// Returns the value id that should be associated with the the |
| 131 /// current function block. Increments internal counters during call | 251 /// current function block. Increments internal counters during call |
| 132 /// so that it will be in correct position for next function block. | 252 /// so that it will be in correct position for next function block. |
| 133 unsigned getNextFunctionBlockValueID() { | 253 unsigned getNextFunctionBlockValueID() { |
| 134 if (NumFunctionBlocks >= DefiningFunctionsList.size()) | 254 if (NumFunctionBlocks >= DefiningFunctionsList.size()) |
| 135 report_fatal_error( | 255 report_fatal_error( |
| 136 "More function blocks than defined function addresses"); | 256 "More function blocks than defined function addresses"); |
| 137 return DefiningFunctionsList[NumFunctionBlocks++]; | 257 return DefiningFunctionsList[NumFunctionBlocks++]; |
| 138 } | 258 } |
| 139 | 259 |
| 140 /// Returns the LLVM IR value associatd with the global value ID. | 260 /// Returns the LLVM Function address associated with ID. |
| 141 Function *getFunctionByID(unsigned ID) const { | 261 Function *getFunctionByID(unsigned ID) const { |
| 142 if (ID >= FunctionIDValues.size()) | 262 if (ID >= FunctionIDValues.size()) |
| 143 return nullptr; | 263 return nullptr; |
| 144 Value *V = FunctionIDValues[ID]; | 264 Value *V = FunctionIDValues[ID]; |
| 145 return cast<Function>(V); | 265 return cast<Function>(V); |
| 146 } | 266 } |
| 147 | 267 |
| 148 /// Returns the corresponding constant associated with a global value | 268 /// Returns the corresponding constant associated with a global value |
| 149 /// (i.e. relocatable). | 269 /// (i.e. relocatable). |
| 150 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) { | 270 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 return convertToIceTypeError(LLVMTy); | 354 return convertToIceTypeError(LLVMTy); |
| 235 } | 355 } |
| 236 return IceTy; | 356 return IceTy; |
| 237 } | 357 } |
| 238 | 358 |
| 239 /// Returns the corresponding LLVM type for IceTy. | 359 /// Returns the corresponding LLVM type for IceTy. |
| 240 Type *convertToLLVMType(Ice::Type IceTy) const { | 360 Type *convertToLLVMType(Ice::Type IceTy) const { |
| 241 return TypeConverter.convertToLLVMType(IceTy); | 361 return TypeConverter.convertToLLVMType(IceTy); |
| 242 } | 362 } |
| 243 | 363 |
| 244 /// Returns the LLVM integer type with the given number of Bits. If | |
| 245 /// Bits is not a valid PNaCl type, returns nullptr. | |
| 246 Type *getLLVMIntegerType(unsigned Bits) const { | |
| 247 return TypeConverter.getLLVMIntegerType(Bits); | |
| 248 } | |
| 249 | |
| 250 /// Returns the LLVM vector with the given Size and Ty. If not a | |
| 251 /// valid PNaCl vector type, returns nullptr. | |
| 252 Type *getLLVMVectorType(unsigned Size, Ice::Type Ty) const { | |
| 253 return TypeConverter.getLLVMVectorType(Size, Ty); | |
| 254 } | |
| 255 | |
| 256 /// Returns the model for pointer types in ICE. | 364 /// Returns the model for pointer types in ICE. |
| 257 Ice::Type getIcePointerType() const { | 365 Ice::Type getIcePointerType() const { |
| 258 return TypeConverter.getIcePointerType(); | 366 return TypeConverter.getIcePointerType(); |
| 259 } | 367 } |
| 260 | 368 |
| 261 private: | 369 private: |
| 262 // The translator associated with the parser. | 370 // The translator associated with the parser. |
| 263 Ice::Translator &Translator; | 371 Ice::Translator &Translator; |
| 264 // The parsed module. | 372 // The parsed module. |
| 265 std::unique_ptr<Module> Mod; | 373 std::unique_ptr<Module> Mod; |
| 266 // The data layout to use. | 374 // The data layout to use. |
| 267 DataLayout DL; | 375 DataLayout DL; |
| 268 // The bitcode header. | 376 // The bitcode header. |
| 269 NaClBitcodeHeader &Header; | 377 NaClBitcodeHeader &Header; |
| 270 // Converter between LLVM and ICE types. | 378 // Converter between LLVM and ICE types. |
| 271 Ice::TypeConverter TypeConverter; | 379 Ice::TypeConverter TypeConverter; |
| 272 // The exit status that should be set to true if an error occurs. | 380 // The exit status that should be set to true if an error occurs. |
| 273 bool &ErrorStatus; | 381 bool &ErrorStatus; |
| 274 // The number of errors reported. | 382 // The number of errors reported. |
| 275 unsigned NumErrors; | 383 unsigned NumErrors; |
| 276 // The types associated with each type ID. | 384 // The types associated with each type ID. |
| 277 std::vector<Type *> TypeIDValues; | 385 std::vector<ExtendedType> TypeIDValues; |
| 278 // The set of function value IDs. | 386 // The set of function value IDs. |
| 279 std::vector<WeakVH> FunctionIDValues; | 387 std::vector<WeakVH> FunctionIDValues; |
| 280 // The set of global addresses IDs. | 388 // The set of global addresses IDs. |
| 281 Ice::Translator::GlobalAddressList GlobalIDAddresses; | 389 Ice::Translator::GlobalAddressList GlobalIDAddresses; |
| 282 // Relocatable constants associated with FunctionIDValues and | 390 // Relocatable constants associated with FunctionIDValues and |
| 283 // GlobalIDAddresses. | 391 // GlobalIDAddresses. |
| 284 std::vector<Ice::Constant *> ValueIDConstants; | 392 std::vector<Ice::Constant *> ValueIDConstants; |
| 285 // The number of function IDs. | 393 // The number of function IDs. |
| 286 unsigned NumFunctionIds; | 394 unsigned NumFunctionIds; |
| 287 // The number of function blocks (processed so far). | 395 // The number of function blocks (processed so far). |
| 288 unsigned NumFunctionBlocks; | 396 unsigned NumFunctionBlocks; |
| 289 // The list of value IDs (in the order found) of defining function | 397 // The list of value IDs (in the order found) of defining function |
| 290 // addresses. | 398 // addresses. |
| 291 std::vector<unsigned> DefiningFunctionsList; | 399 std::vector<unsigned> DefiningFunctionsList; |
| 400 // Cached global variable placeholder type. Used for all forward | |
|
jvoung (off chromium)
2014/10/08 02:58:22
Used for all forward... references ?
Karl
2014/10/08 16:05:11
Fixing comment. It now is only used for error reco
| |
| 401 // Models an undefined function type signature. | |
| 402 Ice::FuncSigType UndefinedFuncSigType; | |
| 292 | 403 |
| 293 bool ParseBlock(unsigned BlockID) override; | 404 bool ParseBlock(unsigned BlockID) override; |
| 294 | 405 |
| 295 /// Reports that type ID is undefined, and then returns | 406 // Gets extended type associated with the given index, assuming the |
| 296 /// the void type. | 407 // extended type is of the WantedKind. Generates error message if |
| 297 Type *reportTypeIDAsUndefined(unsigned ID); | 408 // corresponding extended type of WantedKind can't be found, and |
| 409 // returns nullptr. | |
| 410 ExtendedType *getTypeByIDAsKind(unsigned ID, | |
| 411 ExtendedType::TypeKind WantedKind) { | |
| 412 ExtendedType *Ty = nullptr; | |
| 413 if (ID < TypeIDValues.size()) { | |
| 414 Ty = &TypeIDValues[ID]; | |
| 415 if (Ty->getKind() == WantedKind) | |
| 416 return Ty; | |
| 417 } | |
| 418 // Generate an error message and set ErrorStatus. | |
| 419 this->reportBadTypeIDAs(ID, Ty, WantedKind); | |
| 420 return nullptr; | |
| 421 } | |
| 298 | 422 |
| 299 /// Reports error about bad call to setTypeID. | 423 // Reports that type ID is undefined, or not of the WantedType. |
| 300 void reportBadSetTypeID(unsigned ID, Type *Ty); | 424 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
| 425 ExtendedType::TypeKind WantedType); | |
| 301 | 426 |
| 302 // Reports that there is no corresponding ICE type for LLVMTy, and | 427 // Reports that there is no corresponding ICE type for LLVMTy, and |
| 303 // returns ICE::IceType_void. | 428 // returns ICE::IceType_void. |
| 304 Ice::Type convertToIceTypeError(Type *LLVMTy); | 429 Ice::Type convertToIceTypeError(Type *LLVMTy); |
| 305 }; | 430 }; |
| 306 | 431 |
| 307 Type *TopLevelParser::reportTypeIDAsUndefined(unsigned ID) { | 432 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
| 433 ExtendedType::TypeKind WantedType) { | |
| 308 std::string Buffer; | 434 std::string Buffer; |
| 309 raw_string_ostream StrBuf(Buffer); | 435 raw_string_ostream StrBuf(Buffer); |
| 310 StrBuf << "Can't find type for type id: " << ID; | 436 if (Ty == nullptr) { |
| 311 Error(StrBuf.str()); | 437 StrBuf << "Can't find extend type for type id: " << ID; |
|
Jim Stichnoth
2014/10/08 00:36:07
extended?
Karl
2014/10/08 16:05:12
Done.
| |
| 312 // TODO(kschimpf) Remove error recovery once implementation complete. | |
| 313 Type *Ty = TypeConverter.convertToLLVMType(Ice::IceType_void); | |
| 314 // To reduce error messages, update type list if possible. | |
| 315 if (ID < TypeIDValues.size()) | |
| 316 TypeIDValues[ID] = Ty; | |
| 317 return Ty; | |
| 318 } | |
| 319 | |
| 320 void TopLevelParser::reportBadSetTypeID(unsigned ID, Type *Ty) { | |
| 321 std::string Buffer; | |
| 322 raw_string_ostream StrBuf(Buffer); | |
| 323 if (ID >= TypeIDValues.size()) { | |
| 324 StrBuf << "Type index " << ID << " out of range: can't install."; | |
| 325 } else { | 438 } else { |
| 326 // Must be case that index already defined. | 439 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty; |
| 327 StrBuf << "Type index " << ID << " defined as " << *TypeIDValues[ID] | |
| 328 << " and " << *Ty << "."; | |
| 329 } | 440 } |
| 330 Error(StrBuf.str()); | 441 Error(StrBuf.str()); |
| 331 } | 442 } |
| 332 | 443 |
| 333 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { | 444 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { |
| 334 std::string Buffer; | 445 std::string Buffer; |
| 335 raw_string_ostream StrBuf(Buffer); | 446 raw_string_ostream StrBuf(Buffer); |
| 336 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 447 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
| 337 Error(StrBuf.str()); | 448 Error(StrBuf.str()); |
| 338 return Ice::IceType_void; | 449 return Ice::IceType_void; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} | 586 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} |
| 476 | 587 |
| 477 ~TypesParser() override {} | 588 ~TypesParser() override {} |
| 478 | 589 |
| 479 private: | 590 private: |
| 480 // The type ID that will be associated with the next type defining | 591 // The type ID that will be associated with the next type defining |
| 481 // record in the types block. | 592 // record in the types block. |
| 482 unsigned NextTypeId; | 593 unsigned NextTypeId; |
| 483 | 594 |
| 484 void ProcessRecord() override; | 595 void ProcessRecord() override; |
| 596 | |
| 597 void setNextTypeIDAsSimpleType(Ice::Type Ty) { | |
| 598 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); | |
| 599 } | |
| 485 }; | 600 }; |
| 486 | 601 |
| 487 void TypesParser::ProcessRecord() { | 602 void TypesParser::ProcessRecord() { |
| 488 Type *Ty = nullptr; | |
| 489 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 603 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 490 switch (Record.GetCode()) { | 604 switch (Record.GetCode()) { |
| 491 case naclbitc::TYPE_CODE_NUMENTRY: | 605 case naclbitc::TYPE_CODE_NUMENTRY: |
| 492 // NUMENTRY: [numentries] | 606 // NUMENTRY: [numentries] |
| 493 if (!isValidRecordSize(1, "Type count")) | 607 if (!isValidRecordSize(1, "Type count")) |
| 494 return; | 608 return; |
| 495 Context->resizeTypeIDValues(Values[0]); | 609 Context->resizeTypeIDValues(Values[0]); |
| 496 return; | 610 return; |
| 497 case naclbitc::TYPE_CODE_VOID: | 611 case naclbitc::TYPE_CODE_VOID: |
| 498 // VOID | 612 // VOID |
| 499 if (!isValidRecordSize(0, "Type void")) | 613 if (!isValidRecordSize(0, "Type void")) |
| 500 return; | 614 return; |
| 501 Ty = Context->convertToLLVMType(Ice::IceType_void); | 615 setNextTypeIDAsSimpleType(Ice::IceType_void); |
| 502 break; | 616 return; |
| 503 case naclbitc::TYPE_CODE_FLOAT: | 617 case naclbitc::TYPE_CODE_FLOAT: |
| 504 // FLOAT | 618 // FLOAT |
| 505 if (!isValidRecordSize(0, "Type float")) | 619 if (!isValidRecordSize(0, "Type float")) |
| 506 return; | 620 return; |
| 507 Ty = Context->convertToLLVMType(Ice::IceType_f32); | 621 setNextTypeIDAsSimpleType(Ice::IceType_f32); |
| 508 break; | 622 return; |
| 509 case naclbitc::TYPE_CODE_DOUBLE: | 623 case naclbitc::TYPE_CODE_DOUBLE: |
| 510 // DOUBLE | 624 // DOUBLE |
| 511 if (!isValidRecordSize(0, "Type double")) | 625 if (!isValidRecordSize(0, "Type double")) |
| 512 return; | 626 return; |
| 513 Ty = Context->convertToLLVMType(Ice::IceType_f64); | 627 setNextTypeIDAsSimpleType(Ice::IceType_f64); |
| 514 break; | 628 return; |
| 515 case naclbitc::TYPE_CODE_INTEGER: | 629 case naclbitc::TYPE_CODE_INTEGER: |
| 516 // INTEGER: [width] | 630 // INTEGER: [width] |
| 517 if (!isValidRecordSize(1, "Type integer")) | 631 if (!isValidRecordSize(1, "Type integer")) |
| 518 return; | 632 return; |
| 519 Ty = Context->getLLVMIntegerType(Values[0]); | 633 switch (Values[0]) { |
| 520 if (Ty == nullptr) { | 634 case 1: |
| 635 setNextTypeIDAsSimpleType(Ice::IceType_i1); | |
| 636 return; | |
| 637 case 8: | |
| 638 setNextTypeIDAsSimpleType(Ice::IceType_i8); | |
| 639 return; | |
| 640 case 16: | |
| 641 setNextTypeIDAsSimpleType(Ice::IceType_i16); | |
| 642 return; | |
| 643 case 32: | |
| 644 setNextTypeIDAsSimpleType(Ice::IceType_i32); | |
| 645 return; | |
| 646 case 64: | |
| 647 setNextTypeIDAsSimpleType(Ice::IceType_i64); | |
| 648 return; | |
| 649 default: | |
| 650 break; | |
| 651 } | |
| 652 { | |
| 521 std::string Buffer; | 653 std::string Buffer; |
| 522 raw_string_ostream StrBuf(Buffer); | 654 raw_string_ostream StrBuf(Buffer); |
| 523 StrBuf << "Type integer record with invalid bitsize: " << Values[0]; | 655 StrBuf << "Type integer record with invalid bitsize: " << Values[0]; |
| 524 Error(StrBuf.str()); | 656 Error(StrBuf.str()); |
| 525 // TODO(kschimpf) Remove error recovery once implementation complete. | |
| 526 // Fix type so that we can continue. | |
| 527 Ty = Context->convertToLLVMType(Ice::IceType_i32); | |
| 528 } | 657 } |
| 529 break; | 658 return; |
| 530 case naclbitc::TYPE_CODE_VECTOR: { | 659 case naclbitc::TYPE_CODE_VECTOR: { |
| 531 // VECTOR: [numelts, eltty] | 660 // VECTOR: [numelts, eltty] |
| 532 if (!isValidRecordSize(2, "Type vector")) | 661 if (!isValidRecordSize(2, "Type vector")) |
| 533 return; | 662 return; |
| 534 Type *BaseTy = Context->getTypeByID(Values[1]); | 663 Ice::Type BaseTy = Context->getSimpleTypeByID(Values[1]); |
| 535 Ty = Context->getLLVMVectorType(Values[0], | 664 Ice::SizeT Size = Values[0]; |
| 536 Context->convertToIceType(BaseTy)); | 665 switch (BaseTy) { |
| 537 if (Ty == nullptr) { | 666 case Ice::IceType_i1: |
| 667 switch (Size) { | |
| 668 case 4: | |
| 669 setNextTypeIDAsSimpleType(Ice::IceType_v4i1); | |
| 670 return; | |
| 671 case 8: | |
| 672 setNextTypeIDAsSimpleType(Ice::IceType_v8i1); | |
| 673 return; | |
| 674 case 16: | |
| 675 setNextTypeIDAsSimpleType(Ice::IceType_v16i1); | |
| 676 return; | |
| 677 default: | |
| 678 break; | |
| 679 } | |
| 680 break; | |
| 681 case Ice::IceType_i8: | |
| 682 if (Size == 16) { | |
| 683 setNextTypeIDAsSimpleType(Ice::IceType_v16i8); | |
| 684 return; | |
| 685 } | |
| 686 break; | |
| 687 case Ice::IceType_i16: | |
| 688 if (Size == 8) { | |
| 689 setNextTypeIDAsSimpleType(Ice::IceType_v8i16); | |
| 690 return; | |
| 691 } | |
| 692 break; | |
| 693 case Ice::IceType_i32: | |
| 694 if (Size == 4) { | |
| 695 setNextTypeIDAsSimpleType(Ice::IceType_v4i32); | |
| 696 return; | |
| 697 } | |
| 698 break; | |
| 699 case Ice::IceType_f32: | |
| 700 if (Size == 4) { | |
| 701 setNextTypeIDAsSimpleType(Ice::IceType_v4f32); | |
| 702 return; | |
| 703 } | |
| 704 break; | |
| 705 default: | |
| 706 break; | |
| 707 } | |
| 708 { | |
| 538 std::string Buffer; | 709 std::string Buffer; |
| 539 raw_string_ostream StrBuf(Buffer); | 710 raw_string_ostream StrBuf(Buffer); |
| 540 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << *BaseTy | 711 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << BaseTy |
| 541 << ">"; | 712 << ">"; |
| 542 Error(StrBuf.str()); | 713 Error(StrBuf.str()); |
| 543 Ty = Context->convertToLLVMType(Ice::IceType_void); | |
| 544 } | 714 } |
| 545 break; | 715 return; |
| 546 } | 716 } |
| 547 case naclbitc::TYPE_CODE_FUNCTION: { | 717 case naclbitc::TYPE_CODE_FUNCTION: { |
| 548 // FUNCTION: [vararg, retty, paramty x N] | 718 // FUNCTION: [vararg, retty, paramty x N] |
| 549 if (!isValidRecordSizeAtLeast(2, "Type signature")) | 719 if (!isValidRecordSizeAtLeast(2, "Type signature")) |
| 550 return; | 720 return; |
| 551 SmallVector<Type *, 8> ArgTys; | 721 if (Values[0]) |
| 722 Error("Function type can't define varargs"); | |
| 723 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++); | |
| 724 Ty->setAsFunctionType(); | |
| 725 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty); | |
| 726 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1])); | |
| 552 for (unsigned i = 2, e = Values.size(); i != e; ++i) { | 727 for (unsigned i = 2, e = Values.size(); i != e; ++i) { |
| 553 ArgTys.push_back(Context->getTypeByID(Values[i])); | 728 // Check that type void not used as argument type. |
| 729 // Note: PNaCl restrictions can't be checked until we | |
| 730 // know the name, because we have to check for intrinsic signatures. | |
| 731 Ice::Type ArgTy = Context->getSimpleTypeByID(Values[i]); | |
| 732 if (ArgTy == Ice::IceType_void) { | |
| 733 std::string Buffer; | |
| 734 raw_string_ostream StrBuf(Buffer); | |
| 735 StrBuf << "Type for parameter " << (i - 1) | |
| 736 << " not valid. Found: " << ArgTy; | |
| 737 // TODO(kschimpf) Remove error recovery once implementation complete. | |
| 738 ArgTy = Ice::IceType_i32; | |
| 739 } | |
| 740 FuncTy->appendArgType(ArgTy); | |
| 554 } | 741 } |
| 555 Ty = FunctionType::get(Context->getTypeByID(Values[1]), ArgTys, Values[0]); | 742 return; |
| 556 break; | |
| 557 } | 743 } |
| 558 default: | 744 default: |
| 559 BlockParserBaseClass::ProcessRecord(); | 745 BlockParserBaseClass::ProcessRecord(); |
| 560 return; | 746 return; |
| 561 } | 747 } |
| 562 // If Ty not defined, assume error. Use void as filler. | 748 // We shoudn't reach here! |
| 563 if (Ty == nullptr) | 749 assert(false); |
|
jvoung (off chromium)
2014/10/08 02:58:22
llvm_unreachable?
Karl
2014/10/08 16:05:12
Done.
| |
| 564 Ty = Context->convertToLLVMType(Ice::IceType_void); | |
| 565 Context->setTypeID(NextTypeId++, Ty); | |
| 566 } | 750 } |
| 567 | 751 |
| 568 /// Parses the globals block (i.e. global variables). | 752 /// Parses the globals block (i.e. global variables). |
| 569 class GlobalsParser : public BlockParserBaseClass { | 753 class GlobalsParser : public BlockParserBaseClass { |
| 570 public: | 754 public: |
| 571 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 755 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 572 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), | 756 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), |
| 573 NextGlobalID(0), CurrentAddress(&DummyAddress) {} | 757 NextGlobalID(0), CurrentAddress(&DummyAddress) {} |
| 574 | 758 |
| 575 ~GlobalsParser() override {} | 759 ~GlobalsParser() override {} |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 return; | 1604 return; |
| 1421 CurrentNode->appendInst(Ice::InstArithmetic::create( | 1605 CurrentNode->appendInst(Ice::InstArithmetic::create( |
| 1422 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); | 1606 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); |
| 1423 break; | 1607 break; |
| 1424 } | 1608 } |
| 1425 case naclbitc::FUNC_CODE_INST_CAST: { | 1609 case naclbitc::FUNC_CODE_INST_CAST: { |
| 1426 // CAST: [opval, destty, castopc] | 1610 // CAST: [opval, destty, castopc] |
| 1427 if (!isValidRecordSize(3, "function block cast")) | 1611 if (!isValidRecordSize(3, "function block cast")) |
| 1428 return; | 1612 return; |
| 1429 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); | 1613 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); |
| 1430 Type *CastType = Context->getTypeByID(Values[1]); | 1614 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); |
| 1431 Instruction::CastOps LLVMCastOp; | 1615 Instruction::CastOps LLVMCastOp; |
| 1432 Ice::InstCast::OpKind CastKind; | 1616 Ice::InstCast::OpKind CastKind; |
| 1433 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || | 1617 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || |
| 1434 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { | 1618 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { |
| 1435 std::string Buffer; | 1619 std::string Buffer; |
| 1436 raw_string_ostream StrBuf(Buffer); | 1620 raw_string_ostream StrBuf(Buffer); |
| 1437 StrBuf << "Cast opcode not understood: " << Values[2]; | 1621 StrBuf << "Cast opcode not understood: " << Values[2]; |
| 1438 Error(StrBuf.str()); | 1622 Error(StrBuf.str()); |
| 1439 return; | 1623 return; |
| 1440 } | 1624 } |
| 1441 Type *SrcType = Context->convertToLLVMType(Src->getType()); | 1625 Ice::Type SrcType = Src->getType(); |
| 1442 if (!CastInst::castIsValid(LLVMCastOp, SrcType, CastType)) { | 1626 if (!CastInst::castIsValid(LLVMCastOp, Context->convertToLLVMType(SrcType), |
| 1627 Context->convertToLLVMType(CastType))) { | |
| 1443 std::string Buffer; | 1628 std::string Buffer; |
| 1444 raw_string_ostream StrBuf(Buffer); | 1629 raw_string_ostream StrBuf(Buffer); |
| 1445 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp) | 1630 StrBuf << "Illegal cast: " << Instruction::getOpcodeName(LLVMCastOp) |
| 1446 << " " << *SrcType << " to " << *CastType; | 1631 << " " << SrcType << " to " << CastType; |
| 1447 Error(StrBuf.str()); | 1632 Error(StrBuf.str()); |
| 1448 return; | 1633 return; |
| 1449 } | 1634 } |
| 1450 CurrentNode->appendInst(Ice::InstCast::create( | 1635 CurrentNode->appendInst( |
| 1451 Func, CastKind, getNextInstVar(Context->convertToIceType(CastType)), | 1636 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); |
| 1452 Src)); | |
| 1453 break; | 1637 break; |
| 1454 } | 1638 } |
| 1455 case naclbitc::FUNC_CODE_INST_VSELECT: { | 1639 case naclbitc::FUNC_CODE_INST_VSELECT: { |
| 1456 // VSELECT: [opval, opval, pred] | 1640 // VSELECT: [opval, opval, pred] |
| 1457 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); | 1641 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); |
| 1458 Ice::Type ThenType = ThenVal->getType(); | 1642 Ice::Type ThenType = ThenVal->getType(); |
| 1459 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); | 1643 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); |
| 1460 Ice::Type ElseType = ElseVal->getType(); | 1644 Ice::Type ElseType = ElseVal->getType(); |
| 1461 if (ThenType != ElseType) { | 1645 if (ThenType != ElseType) { |
| 1462 std::string Buffer; | 1646 std::string Buffer; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1662 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] | 1846 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] |
| 1663 // where Case = [1, 1, Value, BbIndex]. | 1847 // where Case = [1, 1, Value, BbIndex]. |
| 1664 // | 1848 // |
| 1665 // Note: Unlike most instructions, we don't infer the type of | 1849 // Note: Unlike most instructions, we don't infer the type of |
| 1666 // Cond, but provide it as a separate field. There are also | 1850 // Cond, but provide it as a separate field. There are also |
| 1667 // unnecesary data fields (i.e. constants 1). These were not | 1851 // unnecesary data fields (i.e. constants 1). These were not |
| 1668 // cleaned up in PNaCl bitcode because the bitcode format was | 1852 // cleaned up in PNaCl bitcode because the bitcode format was |
| 1669 // already frozen when the problem was noticed. | 1853 // already frozen when the problem was noticed. |
| 1670 if (!isValidRecordSizeAtLeast(4, "function block switch")) | 1854 if (!isValidRecordSizeAtLeast(4, "function block switch")) |
| 1671 return; | 1855 return; |
| 1672 Ice::Type CondTy = | 1856 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); |
| 1673 Context->convertToIceType(Context->getTypeByID(Values[0])); | |
| 1674 if (!Ice::isScalarIntegerType(CondTy)) { | 1857 if (!Ice::isScalarIntegerType(CondTy)) { |
| 1675 std::string Buffer; | 1858 std::string Buffer; |
| 1676 raw_string_ostream StrBuf(Buffer); | 1859 raw_string_ostream StrBuf(Buffer); |
| 1677 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; | 1860 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; |
| 1678 Error(StrBuf.str()); | 1861 Error(StrBuf.str()); |
| 1679 return; | 1862 return; |
| 1680 } | 1863 } |
| 1681 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); | 1864 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); |
| 1682 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); | 1865 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); |
| 1683 if (CondTy != Cond->getType()) { | 1866 if (CondTy != Cond->getType()) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1731 if (!isValidRecordSizeAtLeast(3, "function block phi")) | 1914 if (!isValidRecordSizeAtLeast(3, "function block phi")) |
| 1732 return; | 1915 return; |
| 1733 if ((Values.size() & 0x1) == 0) { | 1916 if ((Values.size() & 0x1) == 0) { |
| 1734 // Not an odd number of values. | 1917 // Not an odd number of values. |
| 1735 std::string Buffer; | 1918 std::string Buffer; |
| 1736 raw_string_ostream StrBuf(Buffer); | 1919 raw_string_ostream StrBuf(Buffer); |
| 1737 StrBuf << "function block phi record size not valid: " << Values.size(); | 1920 StrBuf << "function block phi record size not valid: " << Values.size(); |
| 1738 Error(StrBuf.str()); | 1921 Error(StrBuf.str()); |
| 1739 return; | 1922 return; |
| 1740 } | 1923 } |
| 1741 Ice::Type Ty = Context->convertToIceType(Context->getTypeByID(Values[0])); | 1924 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
| 1742 if (Ty == Ice::IceType_void) { | 1925 if (Ty == Ice::IceType_void) { |
| 1743 Error("Phi record using type void not allowed"); | 1926 Error("Phi record using type void not allowed"); |
| 1744 return; | 1927 return; |
| 1745 } | 1928 } |
| 1746 Ice::Variable *Dest = getNextInstVar(Ty); | 1929 Ice::Variable *Dest = getNextInstVar(Ty); |
| 1747 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); | 1930 Ice::InstPhi *Phi = Ice::InstPhi::create(Func, Values.size() >> 1, Dest); |
| 1748 for (unsigned i = 1; i < Values.size(); i += 2) { | 1931 for (unsigned i = 1; i < Values.size(); i += 2) { |
| 1749 Ice::Operand *Op = | 1932 Ice::Operand *Op = |
| 1750 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); | 1933 getRelativeOperand(NaClDecodeSignRotatedValue(Values[i]), BaseIndex); |
| 1751 if (Op->getType() != Ty) { | 1934 if (Op->getType() != Ty) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1782 } | 1965 } |
| 1783 case naclbitc::FUNC_CODE_INST_LOAD: { | 1966 case naclbitc::FUNC_CODE_INST_LOAD: { |
| 1784 // LOAD: [address, align, ty] | 1967 // LOAD: [address, align, ty] |
| 1785 if (!isValidRecordSize(3, "function block load")) | 1968 if (!isValidRecordSize(3, "function block load")) |
| 1786 return; | 1969 return; |
| 1787 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 1970 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
| 1788 if (!isValidPointerType(Address, "Load")) | 1971 if (!isValidPointerType(Address, "Load")) |
| 1789 return; | 1972 return; |
| 1790 unsigned Alignment; | 1973 unsigned Alignment; |
| 1791 extractAlignment("Load", Values[1], Alignment); | 1974 extractAlignment("Load", Values[1], Alignment); |
| 1792 Ice::Type Ty = Context->convertToIceType(Context->getTypeByID(Values[2])); | 1975 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); |
| 1793 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) | 1976 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) |
| 1794 return; | 1977 return; |
| 1795 CurrentNode->appendInst( | 1978 CurrentNode->appendInst( |
| 1796 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); | 1979 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); |
| 1797 break; | 1980 break; |
| 1798 } | 1981 } |
| 1799 case naclbitc::FUNC_CODE_INST_STORE: { | 1982 case naclbitc::FUNC_CODE_INST_STORE: { |
| 1800 // STORE: [address, value, align] | 1983 // STORE: [address, value, align] |
| 1801 if (!isValidRecordSize(3, "function block store")) | 1984 if (!isValidRecordSize(3, "function block store")) |
| 1802 return; | 1985 return; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1874 getTranslator().getContext()->getIntrinsicsInfo().find(Suffix); | 2057 getTranslator().getContext()->getIntrinsicsInfo().find(Suffix); |
| 1875 if (!IntrinsicInfo) { | 2058 if (!IntrinsicInfo) { |
| 1876 std::string Buffer; | 2059 std::string Buffer; |
| 1877 raw_string_ostream StrBuf(Buffer); | 2060 raw_string_ostream StrBuf(Buffer); |
| 1878 StrBuf << "Invalid PNaCl intrinsic call to " << Name; | 2061 StrBuf << "Invalid PNaCl intrinsic call to " << Name; |
| 1879 Error(StrBuf.str()); | 2062 Error(StrBuf.str()); |
| 1880 return; | 2063 return; |
| 1881 } | 2064 } |
| 1882 } | 2065 } |
| 1883 } else { | 2066 } else { |
| 1884 ReturnType = Context->convertToIceType(Context->getTypeByID(Values[2])); | 2067 ReturnType = Context->getSimpleTypeByID(Values[2]); |
| 1885 } | 2068 } |
| 1886 | 2069 |
| 1887 // Create the call instruction. | 2070 // Create the call instruction. |
| 1888 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) | 2071 Ice::Variable *Dest = (ReturnType == Ice::IceType_void) |
| 1889 ? nullptr | 2072 ? nullptr |
| 1890 : getNextInstVar(ReturnType); | 2073 : getNextInstVar(ReturnType); |
| 1891 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; | 2074 Ice::SizeT NumParams = Values.size() - ParamsStartIndex; |
| 1892 Ice::InstCall *Inst = nullptr; | 2075 Ice::InstCall *Inst = nullptr; |
| 1893 if (IntrinsicInfo) { | 2076 if (IntrinsicInfo) { |
| 1894 Inst = | 2077 Inst = |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1946 } | 2129 } |
| 1947 } | 2130 } |
| 1948 | 2131 |
| 1949 CurrentNode->appendInst(Inst); | 2132 CurrentNode->appendInst(Inst); |
| 1950 return; | 2133 return; |
| 1951 } | 2134 } |
| 1952 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { | 2135 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { |
| 1953 // FORWARDTYPEREF: [opval, ty] | 2136 // FORWARDTYPEREF: [opval, ty] |
| 1954 if (!isValidRecordSize(2, "function block forward type ref")) | 2137 if (!isValidRecordSize(2, "function block forward type ref")) |
| 1955 return; | 2138 return; |
| 1956 setOperand(Values[0], createInstVar(Context->convertToIceType( | 2139 setOperand(Values[0], createInstVar(Context->getSimpleTypeByID(Values[1]))); |
| 1957 Context->getTypeByID(Values[1])))); | |
| 1958 break; | 2140 break; |
| 1959 } | 2141 } |
| 1960 default: | 2142 default: |
| 1961 // Generate error message! | 2143 // Generate error message! |
| 1962 BlockParserBaseClass::ProcessRecord(); | 2144 BlockParserBaseClass::ProcessRecord(); |
| 1963 break; | 2145 break; |
| 1964 } | 2146 } |
| 1965 } | 2147 } |
| 1966 | 2148 |
| 1967 /// Parses constants within a function block. | 2149 /// Parses constants within a function block. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1996 } | 2178 } |
| 1997 }; | 2179 }; |
| 1998 | 2180 |
| 1999 void ConstantsParser::ProcessRecord() { | 2181 void ConstantsParser::ProcessRecord() { |
| 2000 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 2182 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 2001 switch (Record.GetCode()) { | 2183 switch (Record.GetCode()) { |
| 2002 case naclbitc::CST_CODE_SETTYPE: { | 2184 case naclbitc::CST_CODE_SETTYPE: { |
| 2003 // SETTYPE: [typeid] | 2185 // SETTYPE: [typeid] |
| 2004 if (!isValidRecordSize(1, "constants block set type")) | 2186 if (!isValidRecordSize(1, "constants block set type")) |
| 2005 return; | 2187 return; |
| 2006 NextConstantType = | 2188 NextConstantType = Context->getSimpleTypeByID(Values[0]); |
| 2007 Context->convertToIceType(Context->getTypeByID(Values[0])); | |
| 2008 if (NextConstantType == Ice::IceType_void) | 2189 if (NextConstantType == Ice::IceType_void) |
| 2009 Error("constants block set type not allowed for void type"); | 2190 Error("constants block set type not allowed for void type"); |
| 2010 return; | 2191 return; |
| 2011 } | 2192 } |
| 2012 case naclbitc::CST_CODE_UNDEF: { | 2193 case naclbitc::CST_CODE_UNDEF: { |
| 2013 // UNDEF | 2194 // UNDEF |
| 2014 if (!isValidRecordSize(0, "constants block undef")) | 2195 if (!isValidRecordSize(0, "constants block undef")) |
| 2015 return; | 2196 return; |
| 2016 if (!isValidNextConstantType()) | 2197 if (!isValidNextConstantType()) |
| 2017 return; | 2198 return; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2291 raw_string_ostream StrBuf(Buffer); | 2472 raw_string_ostream StrBuf(Buffer); |
| 2292 StrBuf << "Unknown bitstream version: " << Version; | 2473 StrBuf << "Unknown bitstream version: " << Version; |
| 2293 Error(StrBuf.str()); | 2474 Error(StrBuf.str()); |
| 2294 } | 2475 } |
| 2295 return; | 2476 return; |
| 2296 } | 2477 } |
| 2297 case naclbitc::MODULE_CODE_FUNCTION: { | 2478 case naclbitc::MODULE_CODE_FUNCTION: { |
| 2298 // FUNCTION: [type, callingconv, isproto, linkage] | 2479 // FUNCTION: [type, callingconv, isproto, linkage] |
| 2299 if (!isValidRecordSize(4, "Function heading")) | 2480 if (!isValidRecordSize(4, "Function heading")) |
| 2300 return; | 2481 return; |
| 2301 Type *Ty = Context->getTypeByID(Values[0]); | 2482 const Ice::FuncSigType &Ty = Context->getFuncSigTypeByID(Values[0]); |
| 2302 FunctionType *FTy = dyn_cast<FunctionType>(Ty); | |
| 2303 if (FTy == nullptr) { | |
| 2304 std::string Buffer; | |
| 2305 raw_string_ostream StrBuf(Buffer); | |
| 2306 StrBuf << "Function heading expects function type. Found: " << Ty; | |
| 2307 Error(StrBuf.str()); | |
| 2308 return; | |
| 2309 } | |
| 2310 CallingConv::ID CallingConv; | 2483 CallingConv::ID CallingConv; |
| 2311 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) { | 2484 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) { |
| 2312 std::string Buffer; | 2485 std::string Buffer; |
| 2313 raw_string_ostream StrBuf(Buffer); | 2486 raw_string_ostream StrBuf(Buffer); |
| 2314 StrBuf << "Function heading has unknown calling convention: " | 2487 StrBuf << "Function heading has unknown calling convention: " |
| 2315 << Values[1]; | 2488 << Values[1]; |
| 2316 Error(StrBuf.str()); | 2489 Error(StrBuf.str()); |
| 2317 return; | 2490 return; |
| 2318 } | 2491 } |
| 2319 GlobalValue::LinkageTypes Linkage; | 2492 GlobalValue::LinkageTypes Linkage; |
| 2320 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { | 2493 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { |
| 2321 std::string Buffer; | 2494 std::string Buffer; |
| 2322 raw_string_ostream StrBuf(Buffer); | 2495 raw_string_ostream StrBuf(Buffer); |
| 2323 StrBuf << "Function heading has unknown linkage. Found " << Values[3]; | 2496 StrBuf << "Function heading has unknown linkage. Found " << Values[3]; |
| 2324 Error(StrBuf.str()); | 2497 Error(StrBuf.str()); |
| 2325 return; | 2498 return; |
| 2326 } | 2499 } |
| 2327 Function *Func = Function::Create(FTy, Linkage, "", Context->getModule()); | 2500 SmallVector<Type *, 8> ArgTys; |
| 2501 for (Ice::Type ArgType : Ty.getArgList()) { | |
| 2502 ArgTys.push_back(Context->convertToLLVMType(ArgType)); | |
| 2503 } | |
| 2504 Function *Func = Function::Create( | |
| 2505 FunctionType::get(Context->convertToLLVMType(Ty.getReturnType()), | |
| 2506 ArgTys, false), | |
| 2507 Linkage, "", Context->getModule()); | |
| 2328 Func->setCallingConv(CallingConv); | 2508 Func->setCallingConv(CallingConv); |
| 2329 if (Values[2] == 0) | 2509 if (Values[2] == 0) |
| 2330 Context->setNextValueIDAsImplementedFunction(); | 2510 Context->setNextValueIDAsImplementedFunction(); |
| 2331 Context->setNextFunctionID(Func); | 2511 Context->setNextFunctionID(Func); |
| 2332 // TODO(kschimpf) verify if Func matches PNaCl ABI. | 2512 // TODO(kschimpf) verify if Func matches PNaCl ABI. |
| 2333 return; | 2513 return; |
| 2334 } | 2514 } |
| 2335 default: | 2515 default: |
| 2336 BlockParserBaseClass::ProcessRecord(); | 2516 BlockParserBaseClass::ProcessRecord(); |
| 2337 return; | 2517 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2396 | 2576 |
| 2397 if (TopLevelBlocks != 1) { | 2577 if (TopLevelBlocks != 1) { |
| 2398 errs() << IRFilename | 2578 errs() << IRFilename |
| 2399 << ": Contains more than one module. Found: " << TopLevelBlocks | 2579 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 2400 << "\n"; | 2580 << "\n"; |
| 2401 ErrorStatus = true; | 2581 ErrorStatus = true; |
| 2402 } | 2582 } |
| 2403 } | 2583 } |
| 2404 | 2584 |
| 2405 } // end of namespace Ice | 2585 } // end of namespace Ice |
| OLD | NEW |