@@ -1001,42 +1001,22 @@ void IRGenModule::setHasFramePointer(llvm::Function *F,
10011001// / Construct initial function attributes from options.
10021002void IRGenModule::constructInitialFnAttributes (llvm::AttrBuilder &Attrs,
10031003 OptimizationMode FuncOptMode) {
1004+ // Add the default attributes for the Clang configuration.
1005+ clang::CodeGen::addDefaultFunctionDefinitionAttributes (getClangCGM (), Attrs);
1006+
10041007 // Add frame pointer attributes.
1008+ // FIXME: why are we doing this?
10051009 setHasFramePointer (Attrs, IRGen.Opts .DisableFPElim );
10061010
1007- // Add target-cpu and target-features if they are non-null.
1008- auto *Clang = static_cast <ClangImporter *>(Context.getClangModuleLoader ());
1009- clang::TargetOptions &ClangOpts = Clang->getTargetInfo ().getTargetOpts ();
1010-
1011- std::string &CPU = ClangOpts.CPU ;
1012- if (CPU != " " )
1013- Attrs.addAttribute (" target-cpu" , CPU);
1014-
1015- std::vector<std::string> Features;
1016- for (auto &F : ClangOpts.Features )
1017- if (!shouldRemoveTargetFeature (F))
1018- Features.push_back (F);
1019-
1020- if (!Features.empty ()) {
1021- SmallString<64 > allFeatures;
1022- // Sort so that the target features string is canonical.
1023- std::sort (Features.begin (), Features.end ());
1024- llvm::interleave (Features, [&](const std::string &s) {
1025- allFeatures.append (s);
1026- }, [&]{
1027- allFeatures.push_back (' ,' );
1028- });
1029- Attrs.addAttribute (" target-features" , allFeatures);
1030- }
1011+ // Add/remove MinSize based on the appropriate setting.
10311012 if (FuncOptMode == OptimizationMode::NotSet)
10321013 FuncOptMode = IRGen.Opts .OptMode ;
1033- if (FuncOptMode == OptimizationMode::ForSize)
1014+ if (FuncOptMode == OptimizationMode::ForSize) {
1015+ Attrs.addAttribute (llvm::Attribute::OptimizeForSize);
10341016 Attrs.addAttribute (llvm::Attribute::MinSize);
1035-
1036- auto triple = llvm::Triple (ClangOpts.Triple );
1037- if (triple.getArchName () == " arm64e" ) {
1038- Attrs.addAttribute (" ptrauth-returns" );
1039- Attrs.addAttribute (" ptrauth-calls" );
1017+ } else {
1018+ Attrs.removeAttribute (llvm::Attribute::MinSize);
1019+ Attrs.removeAttribute (llvm::Attribute::OptimizeForSize);
10401020 }
10411021}
10421022
0 commit comments