From 3951a73490df0f3dd307e8ea6aa52d2776259a4c Mon Sep 17 00:00:00 2001 From: Usman Nadeem Date: Wed, 30 Nov 2022 13:15:43 -0800 Subject: [Flang][Driver] Handle target CPU and features This patch: - Adds target-feature and target-cpu to FC1Options. - Moves getTargetFeatures() from Clang.cpp to CommonArgs.cpp. - Processes target cpu and features in the flang driver. Right now features are only added for AArch64/x86 because I only did basic testing on them but it should generally work for others as well. Option handling is similar to clang. - Adds appropriate structures in TargetOptions and passes them to the target machine. What's missing: - Adding the CPU info and the features as attributes in the LLVM IR module. - Processing target specific flags, e.g. SVE vector bits for AArch64, ABI etc. Differential Revision: https://reviews.llvm.org/D137995 Change-Id: Ib081a74ea98617674845518a5d2754edba596418 --- flang/lib/Frontend/CompilerInvocation.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index b8f4ad7..e24d816 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -171,6 +171,14 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) { if (const llvm::opt::Arg *a = args.getLastArg(clang::driver::options::OPT_triple)) opts.triple = a->getValue(); + + if (const llvm::opt::Arg *a = + args.getLastArg(clang::driver::options::OPT_target_cpu)) + opts.cpu = a->getValue(); + + for (const llvm::opt::Arg *currentArg : + args.filtered(clang::driver::options::OPT_target_feature)) + opts.featuresAsWritten.emplace_back(currentArg->getValue()); } // Tweak the frontend configuration based on the frontend action -- cgit v1.1