diff options
author | Eric Christopher <echristo@gmail.com> | 2015-03-21 06:15:15 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2015-03-21 06:15:15 +0000 |
commit | ea00c2a06f5135b88c8331f35108d174d412725b (patch) | |
tree | d55a704a7b5f9c46af27cce8411b493072296bfa /clang/lib/CodeGen/CGCall.cpp | |
parent | ec6c06610fe41ee78261efc06ea86a8e87af12ed (diff) | |
download | bcm5719-llvm-ea00c2a06f5135b88c8331f35108d174d412725b.tar.gz bcm5719-llvm-ea00c2a06f5135b88c8331f35108d174d412725b.zip |
Add CodeGen support for adding cpu attributes on functions based on
the target-cpu, if different from the triple's cpu, and
target-features as they're written that are passed down from the
driver.
Together with LLVM r232885 this should allow the LTO'ing of binaries
that contain modules compiled with different code generation options
on a subset of architectures with full backend support (x86, powerpc,
aarch64).
llvm-svn: 232888
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 3cb72bd1512..4b4fa7cd780 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -31,6 +31,7 @@ #include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/Transforms/Utils/Local.h" +#include <sstream> using namespace clang; using namespace CodeGen; @@ -1475,6 +1476,26 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, if (!CodeGenOpts.StackRealignment) FuncAttrs.addAttribute("no-realign-stack"); + + // Add target-cpu and target-features work if they differ from the defaults. + std::string &CPU = getTarget().getTargetOpts().CPU; + if (CPU != "" && CPU != getTarget().getTriple().getArchName()) + FuncAttrs.addAttribute("target-cpu", getTarget().getTargetOpts().CPU); + + // TODO: FeaturesAsWritten gets us the features on the command line, + // for canonicalization purposes we might want to avoid putting features + // in the target-features set if we know it'll be one of the default + // features in the backend, e.g. corei7-avx and +avx. + std::vector<std::string> &Features = + getTarget().getTargetOpts().FeaturesAsWritten; + if (!Features.empty()) { + std::stringstream S; + std::copy(Features.begin(), Features.end(), + std::ostream_iterator<std::string>(S, ",")); + // The drop_back gets rid of the trailing space. + FuncAttrs.addAttribute("target-features", + StringRef(S.str()).drop_back(1)); + } } ClangToLLVMArgMapping IRFunctionArgs(getContext(), FI); |