[Function Attribute] add target-cpu and target-features sets if they're non-null.

All llvm::Functions created during IRGen will have target-cpu and target-features
attributes if they are non-null.

Update testing cases to expect the attribute in function definition.
Add testing case function-target-features.swift to verify target-cpu and
target-features.

rdar://20772331


Swift SVN r28186
This commit is contained in:
Manman Ren
2015-05-05 23:19:48 +00:00
parent 0453656f31
commit e94aae06da
80 changed files with 493 additions and 411 deletions

View File

@@ -43,6 +43,7 @@
#include "Linking.h"
#include <initializer_list>
#include <sstream>
using namespace swift;
using namespace irgen;
@@ -452,6 +453,38 @@ llvm::AttributeSet IRGenModule::getAllocAttrs() {
return AllocAttrs;
}
/// Construct initial attributes from options.
llvm::AttributeSet IRGenModule::constructInitialAttributes() {
llvm::AttributeSet attrsUpdated;
// Add DisableFPElim.
if (!Opts.DisableFPElim) {
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
llvm::AttributeSet::FunctionIndex,
"no-frame-pointer-elim", "false");
}
// Add target-cpu and target-features if they are non-null.
auto *Clang = static_cast<ClangImporter *>(Context.getClangModuleLoader());
clang::TargetOptions &ClangOpts = Clang->getTargetInfo().getTargetOpts();
std::string &CPU = ClangOpts.CPU;
if (CPU != "")
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
llvm::AttributeSet::FunctionIndex, "target-cpu", CPU);
std::vector<std::string> &Features = ClangOpts.Features;
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.
attrsUpdated = attrsUpdated.addAttribute(LLVMContext,
llvm::AttributeSet::FunctionIndex, "target-features",
StringRef(S.str()).drop_back(1));
}
return attrsUpdated;
}
llvm::Constant *IRGenModule::getSize(Size size) {
return llvm::ConstantInt::get(SizeTy, size.getValue());
}