llvm.org GIT mirror llvm / c17da71
Simplify and rename function overrideFunctionAttributes. NFC. This is in preparation to making changes needed to stop resetting NoFramePointerElim in resetTargetOptions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238079 91177308-0d34-0410-b5e6-96231b3b80d8 Akira Hatanaka 5 years ago
7 changed file(s) with 29 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
286286 return Features.getString();
287287 }
288288
289 static inline void overrideFunctionAttributes(StringRef CPU, StringRef Features,
290 Module &M) {
291 for (auto &F : M) {
292 if (!CPU.empty())
293 llvm::overrideFunctionAttribute("target-cpu", CPU, F);
294
295 if (!Features.empty())
296 llvm::overrideFunctionAttribute("target-features", Features, F);
297 }
298 }
299
300289 #endif
590590 return F ? &F->getValueSymbolTable() : nullptr;
591591 }
592592
593 /// \brief Overwrite attribute Kind in function F.
594 void overrideFunctionAttribute(StringRef Kind, StringRef Value, Function &F);
595
596593 } // End llvm namespace
597594
598595 #endif
220220 /// Machine level options.
221221 MCTargetOptions MCOptions;
222222 };
223
224 /// \brief Set function attributes of functions in Module M based on CPU and
225 /// Features.
226 void setFunctionAttributes(StringRef CPU, StringRef Features, Module &M);
223227
224228 // Comparison operators:
225229
5050 StringRef TargetOptions::getTrapFunctionName() const {
5151 return TrapFuncName;
5252 }
53
54
55 void llvm::setFunctionAttributes(StringRef CPU, StringRef Features, Module &M) {
56 for (auto &F : M) {
57 auto &Ctx = F.getContext();
58 AttributeSet Attrs = F.getAttributes(), NewAttrs;
59
60 if (!CPU.empty())
61 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
62 "target-cpu", CPU);
63
64 if (!Features.empty())
65 NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
66 "target-features", Features);
67
68 // Let NewAttrs override Attrs.
69 NewAttrs = Attrs.addAttributes(Ctx, AttributeSet::FunctionIndex, NewAttrs);
70 F.setAttributes(NewAttrs);
71 }
72 }
958958 setValueSubclassData(PDData);
959959 }
960960
961 void llvm::overrideFunctionAttribute(StringRef Kind, StringRef Value,
962 Function &F) {
963 auto &Ctx = F.getContext();
964 AttributeSet Attrs = F.getAttributes(), AttrsToRemove;
965
966 AttrsToRemove =
967 AttrsToRemove.addAttribute(Ctx, AttributeSet::FunctionIndex, Kind);
968 Attrs = Attrs.removeAttributes(Ctx, AttributeSet::FunctionIndex,
969 AttrsToRemove);
970 Attrs = Attrs.addAttribute(Ctx, AttributeSet::FunctionIndex, Kind, Value);
971 F.setAttributes(Attrs);
972 }
973
974961 void Function::setEntryCount(uint64_t Count) {
975962 MDBuilder MDB(getContext());
976963 setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count));
303303 if (const DataLayout *DL = Target->getDataLayout())
304304 M->setDataLayout(*DL);
305305
306 // Override function attributes.
307 overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
306 // Override function attributes based on CPUStr and FeaturesStr.
307 setFunctionAttributes(CPUStr, FeaturesStr, *M);
308308
309309 if (RelaxAll.getNumOccurrences() > 0 &&
310310 FileType != TargetMachine::CGFT_ObjectFile)
385385 Triple ModuleTriple(M->getTargetTriple());
386386 std::string CPUStr, FeaturesStr;
387387 TargetMachine *Machine = nullptr;
388
388389 if (ModuleTriple.getArch()) {
389390 CPUStr = getCPUStr();
390391 FeaturesStr = getFeaturesStr();
393394
394395 std::unique_ptr TM(Machine);
395396
396 // Override function attributes.
397 overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
397 // Override function attributes based on CPUStr and FeaturesStr.
398 setFunctionAttributes(CPUStr, FeaturesStr, *M);
398399
399400 // If the output is set to be emitted to standard out, and standard out is a
400401 // console, print out a warning message and refuse to do it. We don't