return Features.getString();
}
-static inline void overrideFunctionAttributes(StringRef CPU, StringRef Features,
- Module &M) {
- for (auto &F : M) {
- if (!CPU.empty())
- llvm::overrideFunctionAttribute("target-cpu", CPU, F);
-
- if (!Features.empty())
- llvm::overrideFunctionAttribute("target-features", Features, F);
- }
-}
-
#endif
return F ? &F->getValueSymbolTable() : nullptr;
}
-/// \brief Overwrite attribute Kind in function F.
-void overrideFunctionAttribute(StringRef Kind, StringRef Value, Function &F);
-
} // End llvm namespace
#endif
MCTargetOptions MCOptions;
};
+/// \brief Set function attributes of functions in Module M based on CPU and
+/// Features.
+void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M);
+
// Comparison operators:
StringRef TargetOptions::getTrapFunctionName() const {
return TrapFuncName;
}
+
+
+void llvm::setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
+ for (auto &F : M) {
+ auto &Ctx = F.getContext();
+ AttributeSet Attrs = F.getAttributes(), NewAttrs;
+
+ if (!CPU.empty())
+ NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
+ "target-cpu", CPU);
+
+ if (!Features.empty())
+ NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
+ "target-features", Features);
+
+ // Let NewAttrs override Attrs.
+ NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
+ F.setAttributes(NewAttrs);
+ }
+}
setValueSubclassData(PDData);
}
-void llvm::overrideFunctionAttribute(StringRef Kind, StringRef Value,
- Function &F) {
- auto &Ctx = F.getContext();
- AttributeSet Attrs = F.getAttributes(), AttrsToRemove;
-
- AttrsToRemove =
- AttrsToRemove.addAttribute(Ctx, AttributeSet::FunctionIndex, Kind);
- Attrs = Attrs.removeAttributes(Ctx, AttributeSet::FunctionIndex,
- AttrsToRemove);
- Attrs = Attrs.addAttribute(Ctx, AttributeSet::FunctionIndex, Kind, Value);
- F.setAttributes(Attrs);
-}
-
void Function::setEntryCount(uint64_t Count) {
MDBuilder MDB(getContext());
setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count));
if (const DataLayout *DL = Target->getDataLayout())
M->setDataLayout(*DL);
- // Override function attributes.
- overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
+ // Override function attributes based on CPUStr and FeaturesStr.
+ setFunctionAttributes(CPUStr, FeaturesStr, *M);
if (RelaxAll.getNumOccurrences() > 0 &&
FileType != TargetMachine::CGFT_ObjectFile)
Triple ModuleTriple(M->getTargetTriple());
std::string CPUStr, FeaturesStr;
TargetMachine *Machine = nullptr;
+
if (ModuleTriple.getArch()) {
CPUStr = getCPUStr();
FeaturesStr = getFeaturesStr();
std::unique_ptr<TargetMachine> TM(Machine);
- // Override function attributes.
- overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
+ // Override function attributes based on CPUStr and FeaturesStr.
+ setFunctionAttributes(CPUStr, FeaturesStr, *M);
// If the output is set to be emitted to standard out, and standard out is a
// console, print out a warning message and refuse to do it. We don't