[llvm] r238079 - Simplify and rename function overrideFunctionAttributes. NFC.
Akira Hatanaka
ahatanaka at apple.com
Fri May 22 18:12:27 PDT 2015
Author: ahatanak
Date: Fri May 22 20:12:26 2015
New Revision: 238079
URL: http://llvm.org/viewvc/llvm-project?rev=238079&view=rev
Log:
Simplify and rename function overrideFunctionAttributes. NFC.
This is in preparation to making changes needed to stop resetting
NoFramePointerElim in resetTargetOptions.
Modified:
llvm/trunk/include/llvm/CodeGen/CommandFlags.h
llvm/trunk/include/llvm/IR/Function.h
llvm/trunk/include/llvm/Target/TargetOptions.h
llvm/trunk/lib/CodeGen/TargetOptionsImpl.cpp
llvm/trunk/lib/IR/Function.cpp
llvm/trunk/tools/llc/llc.cpp
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/include/llvm/CodeGen/CommandFlags.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CommandFlags.h?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CommandFlags.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CommandFlags.h Fri May 22 20:12:26 2015
@@ -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
Modified: llvm/trunk/include/llvm/IR/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Function.h?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Function.h (original)
+++ llvm/trunk/include/llvm/IR/Function.h Fri May 22 20:12:26 2015
@@ -591,9 +591,6 @@ ilist_traits<Argument>::getSymTab(Functi
return F ? &F->getValueSymbolTable() : nullptr;
}
-/// \brief Overwrite attribute Kind in function F.
-void overrideFunctionAttribute(StringRef Kind, StringRef Value, Function &F);
-
} // End llvm namespace
#endif
Modified: llvm/trunk/include/llvm/Target/TargetOptions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOptions.h?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOptions.h (original)
+++ llvm/trunk/include/llvm/Target/TargetOptions.h Fri May 22 20:12:26 2015
@@ -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:
Modified: llvm/trunk/lib/CodeGen/TargetOptionsImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetOptionsImpl.cpp?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetOptionsImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetOptionsImpl.cpp Fri May 22 20:12:26 2015
@@ -51,3 +51,23 @@ bool TargetOptions::HonorSignDependentRo
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);
+ }
+}
Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Fri May 22 20:12:26 2015
@@ -959,19 +959,6 @@ void Function::setPrologueData(Constant
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));
Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Fri May 22 20:12:26 2015
@@ -304,8 +304,8 @@ static int compileModule(char **argv, LL
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)
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=238079&r1=238078&r2=238079&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Fri May 22 20:12:26 2015
@@ -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
More information about the llvm-commits
mailing list