Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: src/PNaClTranslator.cpp

Issue 789483003: Remove call to PNaClABIProps::isAllowedAlignment from subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 // translator. 11 // translator.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "llvm/ADT/SmallString.h" 15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/Analysis/NaCl/PNaClABIProps.h"
17 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h" 16 #include "llvm/Bitcode/NaCl/NaClBitcodeDecoders.h"
18 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" 17 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h"
19 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h" 18 #include "llvm/Bitcode/NaCl/NaClBitcodeParser.h"
20 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" 19 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h"
21 #include "llvm/IR/Constants.h" 20 #include "llvm/IR/Constants.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/LLVMContext.h" 21 #include "llvm/IR/LLVMContext.h"
24 #include "llvm/IR/Module.h" 22 #include "llvm/IR/Module.h"
25 #include "llvm/Support/Format.h" 23 #include "llvm/Support/Format.h"
26 #include "llvm/Support/MemoryBuffer.h" 24 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/raw_ostream.h" 25 #include "llvm/Support/raw_ostream.h"
28 26
29 #include "IceCfg.h" 27 #include "IceCfg.h"
30 #include "IceCfgNode.h" 28 #include "IceCfgNode.h"
31 #include "IceClFlags.h" 29 #include "IceClFlags.h"
32 #include "IceDefs.h" 30 #include "IceDefs.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 TopLevelParser(const TopLevelParser &) = delete; 166 TopLevelParser(const TopLevelParser &) = delete;
169 TopLevelParser &operator=(const TopLevelParser &) = delete; 167 TopLevelParser &operator=(const TopLevelParser &) = delete;
170 168
171 public: 169 public:
172 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; 170 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType;
173 171
174 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, 172 TopLevelParser(Ice::Translator &Translator, const std::string &InputName,
175 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, 173 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor,
176 bool &ErrorStatus) 174 bool &ErrorStatus)
177 : NaClBitcodeParser(Cursor), Translator(Translator), 175 : NaClBitcodeParser(Cursor), Translator(Translator),
178 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), 176 Mod(new Module(InputName, getGlobalContext())),
179 Header(Header), TypeConverter(Mod->getContext()), 177 Header(Header), TypeConverter(Mod->getContext()),
180 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), 178 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0),
181 NumFunctionBlocks(0), BlockParser(nullptr) { 179 NumFunctionBlocks(0), BlockParser(nullptr) {
182 Mod->setDataLayout(PNaClDataLayout);
183 setErrStream(Translator.getContext()->getStrDump()); 180 setErrStream(Translator.getContext()->getStrDump());
184 } 181 }
185 182
186 ~TopLevelParser() override {} 183 ~TopLevelParser() override {}
187 184
188 Ice::Translator &getTranslator() { return Translator; } 185 Ice::Translator &getTranslator() { return Translator; }
189 186
190 void setBlockParser(BlockParserBaseClass *NewBlockParser) { 187 void setBlockParser(BlockParserBaseClass *NewBlockParser) {
191 BlockParser = NewBlockParser; 188 BlockParser = NewBlockParser;
192 } 189 }
193 190
194 // Generates error with given Message. Always returns true. 191 // Generates error with given Message. Always returns true.
195 bool Error(const std::string &Message) override; 192 bool Error(const std::string &Message) override;
196 193
197 // Generates error message with respect to the current block parser. 194 // Generates error message with respect to the current block parser.
198 bool BlockError(const std::string &Message); 195 bool BlockError(const std::string &Message);
199 196
200 /// Returns the number of errors found while parsing the bitcode 197 /// Returns the number of errors found while parsing the bitcode
201 /// file. 198 /// file.
202 unsigned getNumErrors() const { return NumErrors; } 199 unsigned getNumErrors() const { return NumErrors; }
203 200
204 /// Returns the LLVM module associated with the translation. 201 /// Returns the LLVM module associated with the translation.
205 Module *getModule() const { return Mod.get(); } 202 Module *getModule() const { return Mod.get(); }
206 203
207 const DataLayout &getDataLayout() const { return DL; }
208
209 /// Returns the number of bytes in the bitcode header. 204 /// Returns the number of bytes in the bitcode header.
210 size_t getHeaderSize() const { return Header.getHeaderSize(); } 205 size_t getHeaderSize() const { return Header.getHeaderSize(); }
211 206
212 /// Changes the size of the type list to the given size. 207 /// Changes the size of the type list to the given size.
213 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } 208 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); }
214 209
215 /// Returns true if generation of Subzero IR is disabled. 210 /// Returns true if generation of Subzero IR is disabled.
216 bool isIRGenerationDisabled() const { 211 bool isIRGenerationDisabled() const {
217 return ALLOW_DISABLE_IR_GEN ? Translator.getFlags().DisableIRGeneration 212 return ALLOW_DISABLE_IR_GEN ? Translator.getFlags().DisableIRGeneration
218 : false; 213 : false;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 /// Returns the model for pointer types in ICE. 393 /// Returns the model for pointer types in ICE.
399 Ice::Type getIcePointerType() const { 394 Ice::Type getIcePointerType() const {
400 return TypeConverter.getIcePointerType(); 395 return TypeConverter.getIcePointerType();
401 } 396 }
402 397
403 private: 398 private:
404 // The translator associated with the parser. 399 // The translator associated with the parser.
405 Ice::Translator &Translator; 400 Ice::Translator &Translator;
406 // The parsed module. 401 // The parsed module.
407 std::unique_ptr<Module> Mod; 402 std::unique_ptr<Module> Mod;
408 // The data layout to use.
409 DataLayout DL;
410 // The bitcode header. 403 // The bitcode header.
411 NaClBitcodeHeader &Header; 404 NaClBitcodeHeader &Header;
412 // Converter between LLVM and ICE types. 405 // Converter between LLVM and ICE types.
413 Ice::TypeConverter TypeConverter; 406 Ice::TypeConverter TypeConverter;
414 // The exit status that should be set to true if an error occurs. 407 // The exit status that should be set to true if an error occurs.
415 bool &ErrorStatus; 408 bool &ErrorStatus;
416 // The number of errors reported. 409 // The number of errors reported.
417 unsigned NumErrors; 410 unsigned NumErrors;
418 // The types associated with each type ID. 411 // The types associated with each type ID.
419 std::vector<ExtendedType> TypeIDValues; 412 std::vector<ExtendedType> TypeIDValues;
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 std::string Buffer; 1428 std::string Buffer;
1436 raw_string_ostream StrBuf(Buffer); 1429 raw_string_ostream StrBuf(Buffer);
1437 StrBuf << InstructionName << " type not allowed: " << Ty << "*"; 1430 StrBuf << InstructionName << " type not allowed: " << Ty << "*";
1438 Error(StrBuf.str()); 1431 Error(StrBuf.str());
1439 return false; 1432 return false;
1440 } 1433 }
1441 1434
1442 // Checks if loading/storing a value of type Ty is allowed for 1435 // Checks if loading/storing a value of type Ty is allowed for
1443 // the given Alignment. Otherwise generates an error message and 1436 // the given Alignment. Otherwise generates an error message and
1444 // returns false. 1437 // returns false.
1445 bool isValidLoadStoreAlignment(unsigned Alignment, Ice::Type Ty, 1438 bool isValidLoadStoreAlignment(size_t Alignment, Ice::Type Ty,
Jim Stichnoth 2014/12/08 23:14:47 If you change the type of Alignment, should you al
Karl 2014/12/09 21:20:45 Done.
1446 const char *InstructionName) { 1439 const char *InstructionName) {
1447 if (!isValidLoadStoreType(Ty, InstructionName)) 1440 if (!isValidLoadStoreType(Ty, InstructionName))
1448 return false; 1441 return false;
1449 if (PNaClABIProps::isAllowedAlignment(&Context->getDataLayout(), Alignment, 1442 if (isAllowedAlignment(Alignment, Ty)) return true;
Jim Stichnoth 2014/12/08 23:14:47 return on separate line (i.e., make format-diff)
Karl 2014/12/09 21:20:45 Done.
1450 Context->convertToLLVMType(Ty)))
1451 return true;
1452 std::string Buffer; 1443 std::string Buffer;
1453 raw_string_ostream StrBuf(Buffer); 1444 raw_string_ostream StrBuf(Buffer);
1454 StrBuf << InstructionName << " " << Ty << "*: not allowed for alignment " 1445 StrBuf << InstructionName << " " << Ty << "*: not allowed for alignment "
1455 << Alignment; 1446 << Alignment;
1456 Error(StrBuf.str()); 1447 Error(StrBuf.str());
1457 return false; 1448 return false;
1458 } 1449 }
1459 1450
1451 // Defines if the given alignment is valid for the given type. Simplified
1452 // version of PNaClABIProps::isAllowedAlignment, based on API's offered
1453 // for Ice::Type.
1454 bool isAllowedAlignment(size_t Alignment, Ice::Type Ty) {
Jim Stichnoth 2014/12/08 23:14:47 Can this be const?
Karl 2014/12/09 21:20:45 Done.
1455 return Alignment == typeAlignInBytes(Ty) ||
Jim Stichnoth 2014/12/08 23:14:47 This implementation doesn't seem to match the orig
Karl 2014/12/09 21:20:45 This code doesn't match the comment (which is out
Jim Stichnoth 2014/12/09 21:48:24 Thanks, my world-view is restored. :)
1456 (Alignment == 1 && !isVectorType(Ty));
1457 }
1458
1460 // Types of errors that can occur for insertelement and extractelement 1459 // Types of errors that can occur for insertelement and extractelement
1461 // instructions. 1460 // instructions.
1462 enum VectorIndexCheckValue { 1461 enum VectorIndexCheckValue {
1463 VectorIndexNotVector, 1462 VectorIndexNotVector,
1464 VectorIndexNotConstant, 1463 VectorIndexNotConstant,
1465 VectorIndexNotInRange, 1464 VectorIndexNotInRange,
1466 VectorIndexNotI32, 1465 VectorIndexNotI32,
1467 VectorIndexValid 1466 VectorIndexValid
1468 }; 1467 };
1469 1468
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 2941
2943 if (TopLevelBlocks != 1) { 2942 if (TopLevelBlocks != 1) {
2944 errs() << IRFilename 2943 errs() << IRFilename
2945 << ": Contains more than one module. Found: " << TopLevelBlocks 2944 << ": Contains more than one module. Found: " << TopLevelBlocks
2946 << "\n"; 2945 << "\n";
2947 ErrorStatus = true; 2946 ErrorStatus = true;
2948 } 2947 }
2949 } 2948 }
2950 2949
2951 } // end of namespace Ice 2950 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698