@@ -642,6 +642,79 @@ void logArgv(raw_ostream &OS, StringRef ProgramName,
642642 OS << ' \n ' ;
643643 OS.flush ();
644644}
645+
646+ amd_comgr_status_t executeCommand (const Command &Job, raw_ostream &LogS,
647+ TextDiagnosticPrinter *DiagClient,
648+ DiagnosticsEngine &Diags) {
649+ auto Arguments = Job.getArguments ();
650+ SmallVector<const char *, 128 > Argv;
651+ initializeCommandLineArgs (Argv);
652+ Argv.append (Arguments.begin (), Arguments.end ());
653+ Argv.push_back (nullptr );
654+
655+ // By default clang driver will ask CC1 to leak memory.
656+ auto *IT = find (Argv, StringRef (" -disable-free" ));
657+ if (IT != Argv.end ()) {
658+ Argv.erase (IT);
659+ }
660+
661+ clearLLVMOptions ();
662+
663+ if (Argv[1 ] == StringRef (" -cc1" )) {
664+ if (env::shouldEmitVerboseLogs ()) {
665+ logArgv (LogS, " clang" , Argv);
666+ }
667+
668+ std::unique_ptr<CompilerInstance> Clang (new CompilerInstance ());
669+ Clang->setVerboseOutputStream (LogS);
670+ if (!Argv.back ()) {
671+ Argv.pop_back ();
672+ }
673+ if (!CompilerInvocation::CreateFromArgs (Clang->getInvocation (), Argv,
674+ Diags)) {
675+ return AMD_COMGR_STATUS_ERROR;
676+ }
677+ // Internally this call refers to the invocation created above, so at
678+ // this point the DiagnosticsEngine should accurately reflect all user
679+ // requested configuration from Argv.
680+ Clang->createDiagnostics (DiagClient, /* ShouldOwnClient */ false );
681+ if (!Clang->hasDiagnostics ()) {
682+ return AMD_COMGR_STATUS_ERROR;
683+ }
684+ if (!ExecuteCompilerInvocation (Clang.get ())) {
685+ return AMD_COMGR_STATUS_ERROR;
686+ }
687+ } else if (Argv[1 ] == StringRef (" -cc1as" )) {
688+ if (env::shouldEmitVerboseLogs ()) {
689+ logArgv (LogS, " clang" , Argv);
690+ }
691+ Argv.erase (Argv.begin () + 1 );
692+ if (!Argv.back ()) {
693+ Argv.pop_back ();
694+ }
695+ AssemblerInvocation Asm;
696+ if (!AssemblerInvocation::createFromArgs (Asm, Argv, Diags)) {
697+ return AMD_COMGR_STATUS_ERROR;
698+ }
699+ if (auto Status = parseLLVMOptions (Asm.LLVMArgs )) {
700+ return Status;
701+ }
702+ if (executeAssembler (Asm, Diags, LogS)) {
703+ return AMD_COMGR_STATUS_ERROR;
704+ }
705+ } else if (Job.getCreator ().getName () == LinkerJobName) {
706+ if (env::shouldEmitVerboseLogs ()) {
707+ logArgv (LogS, " lld" , Argv);
708+ }
709+ if (auto Status = linkWithLLD (Arguments, LogS, LogS)) {
710+ return Status;
711+ }
712+ } else {
713+ return AMD_COMGR_STATUS_ERROR;
714+ }
715+ return AMD_COMGR_STATUS_SUCCESS;
716+ }
717+
645718} // namespace
646719
647720amd_comgr_status_t
@@ -693,71 +766,8 @@ AMDGPUCompiler::executeInProcessDriver(ArrayRef<const char *> Args) {
693766 }
694767
695768 for (auto &Job : C->getJobs ()) {
696- auto Arguments = Job.getArguments ();
697- SmallVector<const char *, 128 > Argv;
698- initializeCommandLineArgs (Argv);
699- Argv.append (Arguments.begin (), Arguments.end ());
700- Argv.push_back (nullptr );
701-
702- // By default clang driver will ask CC1 to leak memory.
703- auto *IT = find (Argv, StringRef (" -disable-free" ));
704- if (IT != Argv.end ()) {
705- Argv.erase (IT);
706- }
707-
708- clearLLVMOptions ();
709-
710- if (Argv[1 ] == StringRef (" -cc1" )) {
711- if (env::shouldEmitVerboseLogs ()) {
712- logArgv (LogS, " clang" , Argv);
713- }
714-
715- std::unique_ptr<CompilerInstance> Clang (new CompilerInstance ());
716- Clang->setVerboseOutputStream (LogS);
717- if (!Argv.back ()) {
718- Argv.pop_back ();
719- }
720- if (!CompilerInvocation::CreateFromArgs (Clang->getInvocation (), Argv,
721- Diags)) {
722- return AMD_COMGR_STATUS_ERROR;
723- }
724- // Internally this call refers to the invocation created above, so at
725- // this point the DiagnosticsEngine should accurately reflect all user
726- // requested configuration from Argv.
727- Clang->createDiagnostics (DiagClient, /* ShouldOwnClient */ false );
728- if (!Clang->hasDiagnostics ()) {
729- return AMD_COMGR_STATUS_ERROR;
730- }
731- if (!ExecuteCompilerInvocation (Clang.get ())) {
732- return AMD_COMGR_STATUS_ERROR;
733- }
734- } else if (Argv[1 ] == StringRef (" -cc1as" )) {
735- if (env::shouldEmitVerboseLogs ()) {
736- logArgv (LogS, " clang" , Argv);
737- }
738- Argv.erase (Argv.begin () + 1 );
739- if (!Argv.back ()) {
740- Argv.pop_back ();
741- }
742- AssemblerInvocation Asm;
743- if (!AssemblerInvocation::createFromArgs (Asm, Argv, Diags)) {
744- return AMD_COMGR_STATUS_ERROR;
745- }
746- if (auto Status = parseLLVMOptions (Asm.LLVMArgs )) {
747- return Status;
748- }
749- if (executeAssembler (Asm, Diags, LogS)) {
750- return AMD_COMGR_STATUS_ERROR;
751- }
752- } else if (Job.getCreator ().getName () == LinkerJobName) {
753- if (env::shouldEmitVerboseLogs ()) {
754- logArgv (LogS, " lld" , Argv);
755- }
756- if (auto Status = linkWithLLD (Arguments, LogS, LogS)) {
757- return Status;
758- }
759- } else {
760- return AMD_COMGR_STATUS_ERROR;
769+ if (auto Status = executeCommand (Job, LogS, DiagClient, Diags)) {
770+ return Status;
761771 }
762772 }
763773 return AMD_COMGR_STATUS_SUCCESS;
0 commit comments