mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-04 21:31:03 +00:00
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
This commit is contained in:
parent
4ea4cb3197
commit
c17da7166d
@ -287,15 +287,4 @@ static inline std::string getFeaturesStr() {
|
|||||||
return Features.getString();
|
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
|
#endif
|
||||||
|
@ -591,9 +591,6 @@ ilist_traits<Argument>::getSymTab(Function *F) {
|
|||||||
return F ? &F->getValueSymbolTable() : nullptr;
|
return F ? &F->getValueSymbolTable() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Overwrite attribute Kind in function F.
|
|
||||||
void overrideFunctionAttribute(StringRef Kind, StringRef Value, Function &F);
|
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -222,6 +222,10 @@ namespace llvm {
|
|||||||
MCTargetOptions MCOptions;
|
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:
|
// Comparison operators:
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,3 +51,23 @@ bool TargetOptions::HonorSignDependentRoundingFPMath() const {
|
|||||||
StringRef TargetOptions::getTrapFunctionName() const {
|
StringRef TargetOptions::getTrapFunctionName() const {
|
||||||
return TrapFuncName;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -959,19 +959,6 @@ void Function::setPrologueData(Constant *PrologueData) {
|
|||||||
setValueSubclassData(PDData);
|
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) {
|
void Function::setEntryCount(uint64_t Count) {
|
||||||
MDBuilder MDB(getContext());
|
MDBuilder MDB(getContext());
|
||||||
setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count));
|
setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count));
|
||||||
|
@ -304,8 +304,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||||||
if (const DataLayout *DL = Target->getDataLayout())
|
if (const DataLayout *DL = Target->getDataLayout())
|
||||||
M->setDataLayout(*DL);
|
M->setDataLayout(*DL);
|
||||||
|
|
||||||
// Override function attributes.
|
// Override function attributes based on CPUStr and FeaturesStr.
|
||||||
overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
|
setFunctionAttributes(CPUStr, FeaturesStr, *M);
|
||||||
|
|
||||||
if (RelaxAll.getNumOccurrences() > 0 &&
|
if (RelaxAll.getNumOccurrences() > 0 &&
|
||||||
FileType != TargetMachine::CGFT_ObjectFile)
|
FileType != TargetMachine::CGFT_ObjectFile)
|
||||||
|
@ -386,6 +386,7 @@ int main(int argc, char **argv) {
|
|||||||
Triple ModuleTriple(M->getTargetTriple());
|
Triple ModuleTriple(M->getTargetTriple());
|
||||||
std::string CPUStr, FeaturesStr;
|
std::string CPUStr, FeaturesStr;
|
||||||
TargetMachine *Machine = nullptr;
|
TargetMachine *Machine = nullptr;
|
||||||
|
|
||||||
if (ModuleTriple.getArch()) {
|
if (ModuleTriple.getArch()) {
|
||||||
CPUStr = getCPUStr();
|
CPUStr = getCPUStr();
|
||||||
FeaturesStr = getFeaturesStr();
|
FeaturesStr = getFeaturesStr();
|
||||||
@ -394,8 +395,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::unique_ptr<TargetMachine> TM(Machine);
|
std::unique_ptr<TargetMachine> TM(Machine);
|
||||||
|
|
||||||
// Override function attributes.
|
// Override function attributes based on CPUStr and FeaturesStr.
|
||||||
overrideFunctionAttributes(CPUStr, FeaturesStr, *M);
|
setFunctionAttributes(CPUStr, FeaturesStr, *M);
|
||||||
|
|
||||||
// If the output is set to be emitted to standard out, and standard out is a
|
// 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
|
// console, print out a warning message and refuse to do it. We don't
|
||||||
|
Loading…
x
Reference in New Issue
Block a user