Skip to content

Commit

Permalink
Pass finalizer options through VCApi interface
Browse files Browse the repository at this point in the history
  • Loading branch information
skachkov-intel committed Sep 22, 2021
1 parent 240b587 commit da9bc6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
23 changes: 8 additions & 15 deletions include/clang/FrontendWrapper/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,24 @@ struct InputArgs final : public Intel::CM::ClangFE::IInputArgs {
};

using StringVect_t = std::vector<std::string>;
inline StringVect_t
convertBackendArgsToVcOpts(const StringVect_t &BackendArgs) {
std::vector<std::string> VcOpts;
std::vector<std::string> AllFinalizerOpts;
inline std::pair<StringVect_t, StringVect_t>
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;
Expand Down
9 changes: 7 additions & 2 deletions tools/cmoc/cmoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,17 @@ void CmocContext::runVCOpt(const BinaryData &In, InputKind IK,
}
assert(!BinFormat.empty());

std::vector<std::string> VcOpts =
IGC::AdaptorCM::Frontend::convertBackendArgsToVcOpts(DriverInvocation->getBEArgs());
std::vector<std::string> VcOpts;
std::vector<std::string> 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();
Expand Down

0 comments on commit da9bc6f

Please sign in to comment.