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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 587893003: Test generation of global initializers in Subzero bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit Created 6 years, 3 months 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 | « src/IceTranslator.cpp ('k') | tests_lit/reader_tests/globalinit.pnacl.ll » ('j') | 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
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 protected: 344 protected:
345 // The context parser that contains the decoded state. 345 // The context parser that contains the decoded state.
346 TopLevelParser *Context; 346 TopLevelParser *Context;
347 347
348 // Constructor for nested block parsers. 348 // Constructor for nested block parsers.
349 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 349 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
350 : NaClBitcodeParser(BlockID, EnclosingParser), 350 : NaClBitcodeParser(BlockID, EnclosingParser),
351 Context(EnclosingParser->Context) {} 351 Context(EnclosingParser->Context) {}
352 352
353 // Gets the translator associated with the bitcode parser. 353 // Gets the translator associated with the bitcode parser.
354 Ice::Translator &getTranslator() { return Context->getTranslator(); } 354 Ice::Translator &getTranslator() const { return Context->getTranslator(); }
355
356 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); }
355 357
356 // Generates an error Message with the bit address prefixed to it. 358 // Generates an error Message with the bit address prefixed to it.
357 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { 359 virtual bool Error(const std::string &Message) LLVM_OVERRIDE {
358 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; 360 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8;
359 std::string Buffer; 361 std::string Buffer;
360 raw_string_ostream StrBuf(Buffer); 362 raw_string_ostream StrBuf(Buffer);
361 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), 363 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8),
362 static_cast<unsigned>(Bit % 8)) << ") " << Message; 364 static_cast<unsigned>(Bit % 8)) << ") " << Message;
363 return Context->Error(StrBuf.str()); 365 return Context->Error(StrBuf.str());
364 } 366 }
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 case naclbitc::FCMP_TRUE: 1371 case naclbitc::FCMP_TRUE:
1370 Cond = Ice::InstFcmp::True; 1372 Cond = Ice::InstFcmp::True;
1371 return true; 1373 return true;
1372 default: 1374 default:
1373 return false; 1375 return false;
1374 } 1376 }
1375 } 1377 }
1376 }; 1378 };
1377 1379
1378 FunctionParser::~FunctionParser() { 1380 FunctionParser::~FunctionParser() {
1379 if (getTranslator().getFlags().SubzeroTimingEnabled) { 1381 if (getFlags().SubzeroTimingEnabled) {
1380 errs() << "[Subzero timing] Convert function " << Func->getFunctionName() 1382 errs() << "[Subzero timing] Convert function " << Func->getFunctionName()
1381 << ": " << TConvert.getElapsedSec() << " sec\n"; 1383 << ": " << TConvert.getElapsedSec() << " sec\n";
1382 } 1384 }
1383 } 1385 }
1384 1386
1385 void FunctionParser::ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty) { 1387 void FunctionParser::ReportInvalidBinopOpcode(unsigned Opcode, Ice::Type Ty) {
1386 std::string Buffer; 1388 std::string Buffer;
1387 raw_string_ostream StrBuf(Buffer); 1389 raw_string_ostream StrBuf(Buffer);
1388 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty; 1390 StrBuf << "Binary opcode " << Opcode << "not understood for type " << Ty;
1389 Error(StrBuf.str()); 1391 Error(StrBuf.str());
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 default: 2211 default:
2210 break; 2212 break;
2211 } 2213 }
2212 return BlockParserBaseClass::ParseBlock(BlockID); 2214 return BlockParserBaseClass::ParseBlock(BlockID);
2213 } 2215 }
2214 2216
2215 /// Parses the module block in the bitcode file. 2217 /// Parses the module block in the bitcode file.
2216 class ModuleParser : public BlockParserBaseClass { 2218 class ModuleParser : public BlockParserBaseClass {
2217 public: 2219 public:
2218 ModuleParser(unsigned BlockID, TopLevelParser *Context) 2220 ModuleParser(unsigned BlockID, TopLevelParser *Context)
2219 : BlockParserBaseClass(BlockID, Context), FoundFirstFunctionBlock(false) { 2221 : BlockParserBaseClass(BlockID, Context),
2220 } 2222 GlobalAddressNamesAndInitializersInstalled(false) {}
2221 2223
2222 virtual ~ModuleParser() LLVM_OVERRIDE {} 2224 virtual ~ModuleParser() LLVM_OVERRIDE {}
2223 2225
2224 private: 2226 private:
2225 // True if we have parsed a function block. 2227 // True if we have already instaledl names for unnamed global addresses,
2226 bool FoundFirstFunctionBlock; 2228 // and generated global constant initializers.
2229 bool GlobalAddressNamesAndInitializersInstalled;
2230
2231 // Temporary hack to generate names for unnamed global addresses,
2232 // and generate global constant initializers. May be called multiple
2233 // times. Only the first call will do the installation.
2234 // NOTE: Doesn't handle relocations for global constant initializers.
2235 void InstallGlobalAddressNamesAndInitializers() {
2236 if (!GlobalAddressNamesAndInitializersInstalled) {
2237 getTranslator().nameUnnamedGlobalAddresses(Context->getModule());
2238 if (!getFlags().DisableGlobals)
2239 getTranslator().convertGlobals(Context->getModule());
2240 GlobalAddressNamesAndInitializersInstalled = true;
2241 }
2242 }
2243
2227 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; 2244 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE;
2228 2245
2246 virtual void ExitBlock() LLVM_OVERRIDE {
2247 InstallGlobalAddressNamesAndInitializers();
2248 getTranslator().emitConstants();
2249 }
2250
2229 virtual void ProcessRecord() LLVM_OVERRIDE; 2251 virtual void ProcessRecord() LLVM_OVERRIDE;
2230 }; 2252 };
2231 2253
2232 class ModuleValuesymtabParser : public ValuesymtabParser { 2254 class ModuleValuesymtabParser : public ValuesymtabParser {
2233 ModuleValuesymtabParser(const ModuleValuesymtabParser &) 2255 ModuleValuesymtabParser(const ModuleValuesymtabParser &)
2234 LLVM_DELETED_FUNCTION; 2256 LLVM_DELETED_FUNCTION;
2235 void operator=(const ModuleValuesymtabParser &) LLVM_DELETED_FUNCTION; 2257 void operator=(const ModuleValuesymtabParser &) LLVM_DELETED_FUNCTION;
2236 2258
2237 public: 2259 public:
2238 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) 2260 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 } 2297 }
2276 case naclbitc::GLOBALVAR_BLOCK_ID: { 2298 case naclbitc::GLOBALVAR_BLOCK_ID: {
2277 GlobalsParser Parser(BlockID, this); 2299 GlobalsParser Parser(BlockID, this);
2278 return Parser.ParseThisBlock(); 2300 return Parser.ParseThisBlock();
2279 } 2301 }
2280 case naclbitc::VALUE_SYMTAB_BLOCK_ID: { 2302 case naclbitc::VALUE_SYMTAB_BLOCK_ID: {
2281 ModuleValuesymtabParser Parser(BlockID, this); 2303 ModuleValuesymtabParser Parser(BlockID, this);
2282 return Parser.ParseThisBlock(); 2304 return Parser.ParseThisBlock();
2283 } 2305 }
2284 case naclbitc::FUNCTION_BLOCK_ID: { 2306 case naclbitc::FUNCTION_BLOCK_ID: {
2285 if (!FoundFirstFunctionBlock) { 2307 InstallGlobalAddressNamesAndInitializers();
2286 getTranslator().nameUnnamedGlobalAddresses(Context->getModule());
2287 FoundFirstFunctionBlock = true;
2288 }
2289 FunctionParser Parser(BlockID, this); 2308 FunctionParser Parser(BlockID, this);
2290 return Parser.ParseThisBlock(); 2309 return Parser.ParseThisBlock();
2291 } 2310 }
2292 default: 2311 default:
2293 return BlockParserBaseClass::ParseBlock(BlockID); 2312 return BlockParserBaseClass::ParseBlock(BlockID);
2294 } 2313 }
2295 } 2314 }
2296 2315
2297 void ModuleParser::ProcessRecord() { 2316 void ModuleParser::ProcessRecord() {
2298 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); 2317 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 2431
2413 if (TopLevelBlocks != 1) { 2432 if (TopLevelBlocks != 1) {
2414 errs() << IRFilename 2433 errs() << IRFilename
2415 << ": Contains more than one module. Found: " << TopLevelBlocks 2434 << ": Contains more than one module. Found: " << TopLevelBlocks
2416 << "\n"; 2435 << "\n";
2417 ErrorStatus = true; 2436 ErrorStatus = true;
2418 } 2437 }
2419 } 2438 }
2420 2439
2421 } // end of namespace Ice 2440 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTranslator.cpp ('k') | tests_lit/reader_tests/globalinit.pnacl.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698