diff options
author | Artem Belevich <tra@google.com> | 2015-09-22 17:23:22 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2015-09-22 17:23:22 +0000 |
commit | b5bc923af407cbe7e1d96fcb884c7ef5c6897bc0 (patch) | |
tree | a9c6e261ed99150fc40f767d7ec017ca104b6b8d /clang/lib/Frontend | |
parent | ccf0d699f02710c75556bf74229a1bc4ce85547c (diff) | |
download | bcm5719-llvm-b5bc923af407cbe7e1d96fcb884c7ef5c6897bc0.tar.gz bcm5719-llvm-b5bc923af407cbe7e1d96fcb884c7ef5c6897bc0.zip |
[CUDA] Allow parsing of host and device code simultaneously.
* adds -aux-triple option to specify target triple
* propagates aux target info to AST context and Preprocessor
* pulls in target specific preprocessor macros.
* pulls in target-specific builtins from aux target.
* sets appropriate host or device attribute on builtins.
Differential Revision: http://reviews.llvm.org/D12917
llvm-svn: 248299
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/InitPreprocessor.cpp | 4 |
3 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 3326b81e609..d6e5732607e 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -78,9 +78,8 @@ void CompilerInstance::setDiagnostics(DiagnosticsEngine *Value) { Diagnostics = Value; } -void CompilerInstance::setTarget(TargetInfo *Value) { - Target = Value; -} +void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; } +void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; } void CompilerInstance::setFileManager(FileManager *Value) { FileMgr = Value; @@ -312,7 +311,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { PP = new Preprocessor(&getPreprocessorOpts(), getDiagnostics(), getLangOpts(), getSourceManager(), *HeaderInfo, *this, PTHMgr, /*OwnsHeaderSearch=*/true, TUKind); - PP->Initialize(getTarget()); + PP->Initialize(getTarget(), getAuxTarget()); // Note that this is different then passing PTHMgr to Preprocessor's ctor. // That argument is used as the IdentifierInfoLookup argument to @@ -396,7 +395,7 @@ void CompilerInstance::createASTContext() { auto *Context = new ASTContext(getLangOpts(), PP.getSourceManager(), PP.getIdentifierTable(), PP.getSelectorTable(), PP.getBuiltinInfo()); - Context->InitBuiltinTypes(getTarget()); + Context->InitBuiltinTypes(getTarget(), getAuxTarget()); setASTContext(Context); } @@ -800,6 +799,13 @@ bool CompilerInstance::ExecuteAction(FrontendAction &Act) { if (!hasTarget()) return false; + // Create TargetInfo for the other side of CUDA compilation. + if (getLangOpts().CUDA && !getFrontendOpts().AuxTriple.empty()) { + std::shared_ptr<TargetOptions> TO(new TargetOptions); + TO->Triple = getFrontendOpts().AuxTriple; + setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO)); + } + // Inform the target of the language options. // // FIXME: We shouldn't need to do this, the target should be immutable once diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d7995627ac7..a9071339038 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -975,6 +975,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.OverrideRecordLayoutsFile = Args.getLastArgValue(OPT_foverride_record_layout_EQ); + Opts.AuxTriple = + llvm::Triple::normalize(Args.getLastArgValue(OPT_aux_triple)); + if (const Arg *A = Args.getLastArg(OPT_arcmt_check, OPT_arcmt_modify, OPT_arcmt_migrate)) { diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 0791494f791..0b445e8b65c 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -918,6 +918,10 @@ void clang::InitializePreprocessor( // Install things like __POWERPC__, __GNUC__, etc into the macro table. if (InitOpts.UsePredefines) { + if (LangOpts.CUDA && PP.getAuxTargetInfo()) + InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, + Builder); + InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder); // Install definitions to make Objective-C++ ARC work well with various |