summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2015-05-23 01:12:26 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2015-05-23 01:12:26 +0000
commitc17da7166dba20e3f644220e99b0accfc206e2e4 (patch)
treed9201c0cf0f90a600f6a3708a0b9491d9a05176c
parent4ea4cb31974720364c440bba63f255c5990c7316 (diff)
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
-rw-r--r--include/llvm/CodeGen/CommandFlags.h11
-rw-r--r--include/llvm/IR/Function.h3
-rw-r--r--include/llvm/Target/TargetOptions.h4
-rw-r--r--lib/CodeGen/TargetOptionsImpl.cpp20
-rw-r--r--lib/IR/Function.cpp13
-rw-r--r--tools/llc/llc.cpp4
-rw-r--r--tools/opt/opt.cpp5
7 files changed, 29 insertions, 31 deletions
diff --git a/include/llvm/CodeGen/CommandFlags.h b/include/llvm/CodeGen/CommandFlags.h
index fda2bddf841..d38129be1f4 100644
--- a/include/llvm/CodeGen/CommandFlags.h
+++ b/include/llvm/CodeGen/CommandFlags.h
@@ -287,15 +287,4 @@ static inline std::string getFeaturesStr() {
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
diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h
index 99e4d55f266..73f22b129ad 100644
--- a/include/llvm/IR/Function.h
+++ b/include/llvm/IR/Function.h
@@ -591,9 +591,6 @@ ilist_traits<Argument>::getSymTab(Function *F) {
return F ? &F->getValueSymbolTable() : nullptr;
}
-/// \brief Overwrite attribute Kind in function F.
-void overrideFunctionAttribute(StringRef Kind, StringRef Value, Function &F);
-
} // End llvm namespace
#endif
diff --git a/include/llvm/Target/TargetOptions.h b/include/llvm/Target/TargetOptions.h
index d70fe94a9bb..8180f5a0c3b 100644
--- a/include/llvm/Target/TargetOptions.h
+++ b/include/llvm/Target/TargetOptions.h
@@ -222,6 +222,10 @@ namespace llvm {
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:
diff --git a/lib/CodeGen/TargetOptionsImpl.cpp b/lib/CodeGen/TargetOptionsImpl.cpp
index 3ca2017550c..c855ae51ce4 100644
--- a/lib/CodeGen/TargetOptionsImpl.cpp
+++ b/lib/CodeGen/TargetOptionsImpl.cpp
@@ -51,3 +51,23 @@ bool TargetOptions::HonorSignDependentRoundingFPMath() const {
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);
+ }
+}
diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp
index cbba2ee90a1..c579b6bf1b1 100644
--- a/lib/IR/Function.cpp
+++ b/lib/IR/Function.cpp
@@ -959,19 +959,6 @@ void Function::setPrologueData(Constant *PrologueData) {
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));
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index ca86a99524b..145d957890c 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -304,8 +304,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
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)
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 2aa84a8c8a8..15b24cf5072 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -386,6 +386,7 @@ int main(int argc, char **argv) {
Triple ModuleTriple(M->getTargetTriple());
std::string CPUStr, FeaturesStr;
TargetMachine *Machine = nullptr;
+
if (ModuleTriple.getArch()) {
CPUStr = getCPUStr();
FeaturesStr = getFeaturesStr();
@@ -394,8 +395,8 @@ int main(int argc, char **argv) {
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