From da9bc6f8bb81a02159369c07d6b09d05893e2206 Mon Sep 17 00:00:00 2001 From: Sergei Kachkov Date: Thu, 9 Sep 2021 12:04:50 +0000 Subject: [PATCH] Pass finalizer options through VCApi interface --- include/clang/FrontendWrapper/Frontend.h | 23 ++++++++--------------- tools/cmoc/cmoc.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/clang/FrontendWrapper/Frontend.h b/include/clang/FrontendWrapper/Frontend.h index e17908da123c..c455f06974de 100755 --- a/include/clang/FrontendWrapper/Frontend.h +++ b/include/clang/FrontendWrapper/Frontend.h @@ -37,31 +37,24 @@ struct InputArgs final : public Intel::CM::ClangFE::IInputArgs { }; using StringVect_t = std::vector; -inline StringVect_t -convertBackendArgsToVcOpts(const StringVect_t &BackendArgs) { - std::vector VcOpts; - std::vector AllFinalizerOpts; +inline std::pair +convertBackendArgsToVcAndFinalizerOpts(const StringVect_t &BackendArgs) { + StringVect_t VcOpts; + StringVect_t FinalizerOpts; const std::string FinalizerOptPrefix = "-finalizer-opts="; auto IsFinalizerOpts = [&FinalizerOptPrefix](const std::string &Opt) { return Opt.find(FinalizerOptPrefix) == 0; }; std::partition_copy(BackendArgs.begin(), BackendArgs.end(), - std::back_inserter(AllFinalizerOpts), + std::back_inserter(FinalizerOpts), std::back_inserter(VcOpts), IsFinalizerOpts); - std::transform(AllFinalizerOpts.begin(), AllFinalizerOpts.end(), - AllFinalizerOpts.begin(), + std::transform(FinalizerOpts.begin(), FinalizerOpts.end(), + FinalizerOpts.begin(), [&FinalizerOptPrefix](const std::string &Opt) { return Opt.substr(FinalizerOptPrefix.size()); }); - if (!AllFinalizerOpts.empty()) { - // TODO: we should escape the joined finalizer options - VcOpts.emplace_back((llvm::StringRef(FinalizerOptPrefix) + "\"" + - llvm::join(AllFinalizerOpts, " ") + "\"") - .str()); - } - - return VcOpts; + return {VcOpts, FinalizerOpts}; } using IOutputArgs = Intel::CM::ClangFE::IOutputArgs; diff --git a/tools/cmoc/cmoc.cpp b/tools/cmoc/cmoc.cpp index ed083dfc6a27..d96cb7b7bfdb 100644 --- a/tools/cmoc/cmoc.cpp +++ b/tools/cmoc/cmoc.cpp @@ -253,12 +253,17 @@ void CmocContext::runVCOpt(const BinaryData &In, InputKind IK, } assert(!BinFormat.empty()); - std::vector VcOpts = - IGC::AdaptorCM::Frontend::convertBackendArgsToVcOpts(DriverInvocation->getBEArgs()); + std::vector VcOpts; + std::vector FinalizerOpts; + std::tie(VcOpts, FinalizerOpts) = + IGC::AdaptorCM::Frontend::convertBackendArgsToVcAndFinalizerOpts( + DriverInvocation->getBEArgs()); const auto &TargetFeatures = DriverInvocation->getTargetFeaturesStr(); std::string APIOptions = getVCApiOptions(); + if (!FinalizerOpts.empty()) + APIOptions += " -Xfinalizer '" + llvm::join(FinalizerOpts, " ") + "'"; int RevId = getRevId(); bool PrintStats = getPrintStats();