| OLD | NEW |
| 1 //===-- pnacl-llc.cpp - PNaCl-specific llc: pexe ---> nexe ---------------===// | 1 //===-- pnacl-llc.cpp - PNaCl-specific llc: pexe ---> nexe ---------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 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 // pnacl-llc: the core of the PNaCl translator, compiling a pexe into a nexe. | 10 // pnacl-llc: the core of the PNaCl translator, compiling a pexe into a nexe. |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 F.setVisibility(GlobalValue::HiddenVisibility); | 421 F.setVisibility(GlobalValue::HiddenVisibility); |
| 422 } | 422 } |
| 423 for (Module::global_iterator GI = ModuleRef->global_begin(), | 423 for (Module::global_iterator GI = ModuleRef->global_begin(), |
| 424 GE = ModuleRef->global_end(); | 424 GE = ModuleRef->global_end(); |
| 425 GI != GE; ++GI) { | 425 GI != GE; ++GI) { |
| 426 if (!GI->isWeakForLinker() && !GI->hasLocalLinkage()) | 426 if (!GI->isWeakForLinker() && !GI->hasLocalLinkage()) |
| 427 GI->setVisibility(GlobalValue::HiddenVisibility); | 427 GI->setVisibility(GlobalValue::HiddenVisibility); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // Build up all of the passes that we want to do to the module. | 430 // Build up all of the passes that we want to do to the module. |
| 431 std::unique_ptr<PassManagerBase> PM; | 431 // We always use a FunctionPassManager to divide up the functions |
| 432 if (LazyBitcode) | 432 // among threads (instead of a whole-module PassManager). |
| 433 PM.reset(new FunctionPassManager(ModuleRef)); | 433 std::unique_ptr<FunctionPassManager> PM(new FunctionPassManager(ModuleRef)); |
| 434 else | |
| 435 PM.reset(new PassManager()); | |
| 436 | 434 |
| 437 // Add the target data from the target machine, if it exists, or the module. | 435 // Add the target data from the target machine, if it exists, or the module. |
| 438 if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout()) | 436 if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout()) |
| 439 ModuleRef->setDataLayout(DL); | 437 ModuleRef->setDataLayout(DL); |
| 440 PM->add(new DataLayoutPass()); | 438 PM->add(new DataLayoutPass()); |
| 441 | 439 |
| 442 // For conformance with llc, we let the user disable LLVM IR verification with | 440 // For conformance with llc, we let the user disable LLVM IR verification with |
| 443 // -disable-verify. Unlike llc, when LLVM IR verification is enabled we only | 441 // -disable-verify. Unlike llc, when LLVM IR verification is enabled we only |
| 444 // run it once, before PNaCl ABI verification. | 442 // run it once, before PNaCl ABI verification. |
| 445 if (!NoVerify) | 443 if (!NoVerify) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 468 | 466 |
| 469 // Ask the target to add backend passes as necessary. We explicitly ask it | 467 // Ask the target to add backend passes as necessary. We explicitly ask it |
| 470 // not to add the verifier pass because we added it earlier. | 468 // not to add the verifier pass because we added it earlier. |
| 471 if (Target.addPassesToEmitFile(*PM, FOS, FileType, | 469 if (Target.addPassesToEmitFile(*PM, FOS, FileType, |
| 472 /* DisableVerify */ true)) { | 470 /* DisableVerify */ true)) { |
| 473 errs() << ProgramName | 471 errs() << ProgramName |
| 474 << ": target does not support generation of this file type!\n"; | 472 << ": target does not support generation of this file type!\n"; |
| 475 return 1; | 473 return 1; |
| 476 } | 474 } |
| 477 | 475 |
| 478 if (LazyBitcode) { | 476 PM->doInitialization(); |
| 479 auto FPM = static_cast<FunctionPassManager *>(PM.get()); | 477 unsigned FuncIndex = 0; |
| 480 FPM->doInitialization(); | 478 switch (SplitModuleSched) { |
| 481 unsigned FuncIndex = 0; | 479 case SplitModuleStatic: |
| 482 switch (SplitModuleSched) { | 480 for (Function &F : *ModuleRef) { |
| 483 case SplitModuleStatic: | 481 if (FuncQueue->GrabFunctionStatic(FuncIndex, ModuleIndex)) { |
| 484 for (Function &F : *ModuleRef) { | 482 PM->run(F); |
| 485 if (FuncQueue->GrabFunctionStatic(FuncIndex, ModuleIndex)) { | 483 CheckABIVerifyErrors(ABIErrorReporter, "Function " + F.getName()); |
| 486 FPM->run(F); | 484 F.Dematerialize(); |
| 487 CheckABIVerifyErrors(ABIErrorReporter, "Function " + F.getName()); | 485 } |
| 488 F.Dematerialize(); | 486 ++FuncIndex; |
| 487 } |
| 488 break; |
| 489 case SplitModuleDynamic: |
| 490 unsigned ChunkSize = 0; |
| 491 unsigned NumFunctions = FuncQueue->Size(); |
| 492 Module::iterator I = ModuleRef->begin(); |
| 493 while (FuncIndex < NumFunctions) { |
| 494 ChunkSize = FuncQueue->RecommendedChunkSize(); |
| 495 unsigned NextIndex; |
| 496 bool grabbed = |
| 497 FuncQueue->GrabFunctionDynamic(FuncIndex, ChunkSize, NextIndex); |
| 498 if (grabbed) { |
| 499 while (FuncIndex < NextIndex) { |
| 500 if (!I->isMaterializable() && I->isDeclaration()) { |
| 501 ++I; |
| 502 continue; |
| 503 } |
| 504 PM->run(*I); |
| 505 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName()); |
| 506 I->Dematerialize(); |
| 507 ++FuncIndex; |
| 508 ++I; |
| 489 } | 509 } |
| 490 ++FuncIndex; | 510 } else { |
| 491 } | 511 while (FuncIndex < NextIndex) { |
| 492 break; | 512 if (!I->isMaterializable() && I->isDeclaration()) { |
| 493 case SplitModuleDynamic: | |
| 494 unsigned ChunkSize = 0; | |
| 495 unsigned NumFunctions = FuncQueue->Size(); | |
| 496 Module::iterator I = ModuleRef->begin(); | |
| 497 while (FuncIndex < NumFunctions) { | |
| 498 ChunkSize = FuncQueue->RecommendedChunkSize(); | |
| 499 unsigned NextIndex; | |
| 500 bool grabbed = FuncQueue->GrabFunctionDynamic(FuncIndex, ChunkSize, | |
| 501 NextIndex); | |
| 502 if (grabbed) { | |
| 503 while (FuncIndex < NextIndex) { | |
| 504 if (!I->isMaterializable() && I->isDeclaration()) { | |
| 505 ++I; | |
| 506 continue; | |
| 507 } | |
| 508 FPM->run(*I); | |
| 509 CheckABIVerifyErrors(ABIErrorReporter, "Function " + I->getName()); | |
| 510 I->Dematerialize(); | |
| 511 ++FuncIndex; | |
| 512 ++I; | 513 ++I; |
| 514 continue; |
| 513 } | 515 } |
| 514 } else { | 516 ++FuncIndex; |
| 515 while (FuncIndex < NextIndex) { | 517 ++I; |
| 516 if (!I->isMaterializable() && I->isDeclaration()) { | |
| 517 ++I; | |
| 518 continue; | |
| 519 } | |
| 520 ++FuncIndex; | |
| 521 ++I; | |
| 522 } | |
| 523 } | 518 } |
| 524 } | 519 } |
| 525 break; | |
| 526 } | 520 } |
| 527 FPM->doFinalization(); | 521 break; |
| 528 } else | 522 } |
| 529 static_cast<PassManager *>(PM.get())->run(*ModuleRef); | 523 PM->doFinalization(); |
| 530 | |
| 531 return 0; | 524 return 0; |
| 532 } | 525 } |
| 533 | 526 |
| 534 static int compileSplitModule(const TargetOptions &Options, | 527 static int compileSplitModule(const TargetOptions &Options, |
| 535 const Triple &TheTriple, | 528 const Triple &TheTriple, |
| 536 const Target *TheTarget, | 529 const Target *TheTarget, |
| 537 const std::string &FeaturesStr, | 530 const std::string &FeaturesStr, |
| 538 CodeGenOpt::Level OLvl, | 531 CodeGenOpt::Level OLvl, |
| 539 const StringRef &ProgramName, | 532 const StringRef &ProgramName, |
| 540 Module *GlobalModuleRef, | 533 Module *GlobalModuleRef, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 return 0; | 769 return 0; |
| 777 } | 770 } |
| 778 | 771 |
| 779 int main(int argc, char **argv) { | 772 int main(int argc, char **argv) { |
| 780 #if defined(PNACL_BROWSER_TRANSLATOR) | 773 #if defined(PNACL_BROWSER_TRANSLATOR) |
| 781 return srpc_main(argc, argv); | 774 return srpc_main(argc, argv); |
| 782 #else | 775 #else |
| 783 return llc_main(argc, argv); | 776 return llc_main(argc, argv); |
| 784 #endif // PNACL_BROWSER_TRANSLATOR | 777 #endif // PNACL_BROWSER_TRANSLATOR |
| 785 } | 778 } |
| OLD | NEW |