[llvm] r357638 - [IR] Create new method in `Function` class (NFC)
Evandro Menezes via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 3 14:27:03 PDT 2019
Author: evandro
Date: Wed Apr 3 14:27:03 2019
New Revision: 357638
URL: http://llvm.org/viewvc/llvm-project?rev=357638&view=rev
Log:
[IR] Create new method in `Function` class (NFC)
Create method `optForNone()` testing for the function level equivalent of
`-O0` and refactor appropriately.
Differential revision: https://reviews.llvm.org/D59852
Modified:
llvm/trunk/include/llvm/IR/Function.h
llvm/trunk/lib/Analysis/GlobalsModRef.cpp
llvm/trunk/lib/Analysis/InlineCost.cpp
llvm/trunk/lib/Analysis/LoopPass.cpp
llvm/trunk/lib/Analysis/RegionPass.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
llvm/trunk/lib/CodeGen/SafeStack.cpp
llvm/trunk/lib/IR/Pass.cpp
llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp
llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp
llvm/trunk/lib/Transforms/IPO/Inliner.cpp
llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
llvm/trunk/lib/Transforms/Scalar/WarnMissedTransforms.cpp
Modified: llvm/trunk/include/llvm/IR/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Function.h?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Function.h (original)
+++ llvm/trunk/include/llvm/IR/Function.h Wed Apr 3 14:27:03 2019
@@ -590,6 +590,9 @@ public:
addAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
}
+ /// Do not optimize this function (-O0).
+ bool optForNone() const { return hasFnAttribute(Attribute::OptimizeNone); }
+
/// Optimize this function for minimum size (-Oz).
bool optForMinSize() const { return hasFnAttribute(Attribute::MinSize); }
Modified: llvm/trunk/lib/Analysis/GlobalsModRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GlobalsModRef.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/GlobalsModRef.cpp (original)
+++ llvm/trunk/lib/Analysis/GlobalsModRef.cpp Wed Apr 3 14:27:03 2019
@@ -513,7 +513,7 @@ void GlobalsAAResult::AnalyzeCallGraph(C
break;
}
- if (F->isDeclaration() || F->hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F->isDeclaration() || F->optForNone()) {
// Try to get mod/ref behaviour from function attributes.
if (F->doesNotAccessMemory()) {
// Can't do better than that!
@@ -566,7 +566,7 @@ void GlobalsAAResult::AnalyzeCallGraph(C
// Don't prove any properties based on the implementation of an optnone
// function. Function attributes were already used as a best approximation
// above.
- if (Node->getFunction()->hasFnAttribute(Attribute::OptimizeNone))
+ if (Node->getFunction()->optForNone())
continue;
for (Instruction &I : instructions(Node->getFunction())) {
Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Wed Apr 3 14:27:03 2019
@@ -2036,7 +2036,7 @@ InlineCost llvm::getInlineCost(
return llvm::InlineCost::getNever("conflicting attributes");
// Don't inline this call if the caller has the optnone attribute.
- if (Caller->hasFnAttribute(Attribute::OptimizeNone))
+ if (Caller->optForNone())
return llvm::InlineCost::getNever("optnone attribute");
// Don't inline a function that treats null pointer as valid into a caller
Modified: llvm/trunk/lib/Analysis/LoopPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopPass.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopPass.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopPass.cpp Wed Apr 3 14:27:03 2019
@@ -396,7 +396,7 @@ bool LoopPass::skipLoop(const Loop *L) c
if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(*L)))
return true;
// Check for the OptimizeNone attribute.
- if (F->hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F->optForNone()) {
// FIXME: Report this to dbgs() only once per function.
LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' in function "
<< F->getName() << "\n");
Modified: llvm/trunk/lib/Analysis/RegionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionPass.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionPass.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionPass.cpp Wed Apr 3 14:27:03 2019
@@ -288,7 +288,7 @@ bool RegionPass::skipRegion(Region &R) c
if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(R)))
return true;
- if (F.hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F.optForNone()) {
// Report this only once per function.
if (R.getEntry() == &F.getEntryBlock())
LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName()
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Wed Apr 3 14:27:03 2019
@@ -1341,8 +1341,8 @@ void CodeViewDebug::beginFunctionImpl(co
FPO |= FrameProcedureOptions::SecurityChecks;
FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedLocalFramePtrReg) << 14U);
FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedParamFramePtrReg) << 16U);
- if (Asm->TM.getOptLevel() != CodeGenOpt::None && !GV.optForSize() &&
- !GV.hasFnAttribute(Attribute::OptimizeNone))
+ if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
+ !GV.optForSize() && !GV.optForNone())
FPO |= FrameProcedureOptions::OptimizedForSpeed;
// FIXME: Set GuardCfg when it is implemented.
CurFn->FrameProcOpts = FPO;
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp Wed Apr 3 14:27:03 2019
@@ -657,7 +657,7 @@ bool RegBankSelect::runOnMachineFunction
LLVM_DEBUG(dbgs() << "Assign register banks for: " << MF.getName() << '\n');
const Function &F = MF.getFunction();
Mode SaveOptMode = OptMode;
- if (F.hasFnAttribute(Attribute::OptimizeNone))
+ if (F.optForNone())
OptMode = Mode::Fast;
init(MF);
Modified: llvm/trunk/lib/CodeGen/SafeStack.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SafeStack.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SafeStack.cpp (original)
+++ llvm/trunk/lib/CodeGen/SafeStack.cpp Wed Apr 3 14:27:03 2019
@@ -728,7 +728,7 @@ void SafeStack::TryInlinePointerAddress(
if (!isa<CallInst>(UnsafeStackPtr))
return;
- if(F.hasFnAttribute(Attribute::OptimizeNone))
+ if(F.optForNone())
return;
CallSite CS(UnsafeStackPtr);
Modified: llvm/trunk/lib/IR/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Pass.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Pass.cpp (original)
+++ llvm/trunk/lib/IR/Pass.cpp Wed Apr 3 14:27:03 2019
@@ -168,7 +168,7 @@ bool FunctionPass::skipFunction(const Fu
if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(F)))
return true;
- if (F.hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F.optForNone()) {
LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName() << "' on function "
<< F.getName() << "\n");
return true;
@@ -207,7 +207,7 @@ bool BasicBlockPass::skipBasicBlock(cons
OptPassGate &Gate = F->getContext().getOptPassGate();
if (Gate.isEnabled() && !Gate.shouldRunPass(this, getDescription(BB)))
return true;
- if (F->hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F->optForNone()) {
// Report this only once per function.
if (&BB == &F->getEntryBlock())
LLVM_DEBUG(dbgs() << "Skipping pass '" << getPassName()
Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Wed Apr 3 14:27:03 2019
@@ -119,7 +119,7 @@ bool ARMAsmPrinter::runOnMachineFunction
// Calculate this function's optimization goal.
unsigned OptimizationGoal;
- if (F.hasFnAttribute(Attribute::OptimizeNone))
+ if (F.optForNone())
// For best debugging illusion, speed and small size sacrificed
OptimizationGoal = 6;
else if (F.optForMinSize())
Modified: llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonFrameLowering.cpp Wed Apr 3 14:27:03 2019
@@ -374,7 +374,7 @@ static bool isRestoreCall(unsigned Opc)
}
static inline bool isOptNone(const MachineFunction &MF) {
- return MF.getFunction().hasFnAttribute(Attribute::OptimizeNone) ||
+ return MF.getFunction().optForNone() ||
MF.getTarget().getOptLevel() == CodeGenOpt::None;
}
Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Wed Apr 3 14:27:03 2019
@@ -1366,8 +1366,7 @@ PreservedAnalyses PostOrderFunctionAttrs
bool HasUnknownCall = false;
for (LazyCallGraph::Node &N : C) {
Function &F = N.getFunction();
- if (F.hasFnAttribute(Attribute::OptimizeNone) ||
- F.hasFnAttribute(Attribute::Naked)) {
+ if (F.optForNone() || F.hasFnAttribute(Attribute::Naked)) {
// Treat any function we're trying not to optimize as if it were an
// indirect call and omit it from the node set used below.
HasUnknownCall = true;
@@ -1440,8 +1439,7 @@ static bool runImpl(CallGraphSCC &SCC, A
bool ExternalNode = false;
for (CallGraphNode *I : SCC) {
Function *F = I->getFunction();
- if (!F || F->hasFnAttribute(Attribute::OptimizeNone) ||
- F->hasFnAttribute(Attribute::Naked)) {
+ if (!F || F->optForNone() || F->hasFnAttribute(Attribute::Naked)) {
// External node or function we're trying not to optimize - we both avoid
// transform them and avoid leveraging information they provide.
ExternalNode = true;
Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Wed Apr 3 14:27:03 2019
@@ -149,7 +149,7 @@ static bool mayExtractBlock(const BasicB
/// module has profile data), set entry count to 0 to ensure treated as cold.
/// Return true if the function is changed.
static bool markFunctionCold(Function &F, bool UpdateEntryCount = false) {
- assert(!F.hasFnAttribute(Attribute::OptimizeNone) && "Can't mark this cold");
+ assert(!F.optForNone() && "Can't mark this cold");
bool Changed = false;
if (!F.hasFnAttribute(Attribute::Cold)) {
F.addFnAttr(Attribute::Cold);
@@ -673,7 +673,7 @@ bool HotColdSplitting::run(Module &M) {
continue;
// Do not modify `optnone` functions.
- if (F.hasFnAttribute(Attribute::OptimizeNone))
+ if (F.optForNone())
continue;
// Detect inherently cold functions and mark them as such.
Modified: llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp Wed Apr 3 14:27:03 2019
@@ -25,7 +25,7 @@ static bool inferAllPrototypeAttributes(
for (Function &F : M.functions())
// We only infer things using the prototype and the name; we don't need
// definitions.
- if (F.isDeclaration() && !F.hasFnAttribute((Attribute::OptimizeNone)))
+ if (F.isDeclaration() && !F.optForNone())
Changed |= inferLibFuncAttributes(F, TLI);
return Changed;
Modified: llvm/trunk/lib/Transforms/IPO/Inliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Inliner.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Inliner.cpp Wed Apr 3 14:27:03 2019
@@ -973,7 +973,7 @@ PreservedAnalyses InlinerPass::run(LazyC
LazyCallGraph::Node &N = *CG.lookup(F);
if (CG.lookupSCC(N) != C)
continue;
- if (F.hasFnAttribute(Attribute::OptimizeNone)) {
+ if (F.optForNone()) {
setInlineRemark(Calls[i].first, "optnone attribute");
continue;
}
Modified: llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp Wed Apr 3 14:27:03 2019
@@ -393,9 +393,7 @@ static bool promoteIndirectCalls(Module
}
bool Changed = false;
for (auto &F : M) {
- if (F.isDeclaration())
- continue;
- if (F.hasFnAttribute(Attribute::OptimizeNone))
+ if (F.isDeclaration() || F.optForNone())
continue;
std::unique_ptr<OptimizationRemarkEmitter> OwnedORE;
Modified: llvm/trunk/lib/Transforms/Scalar/WarnMissedTransforms.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/WarnMissedTransforms.cpp?rev=357638&r1=357637&r2=357638&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/WarnMissedTransforms.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/WarnMissedTransforms.cpp Wed Apr 3 14:27:03 2019
@@ -92,7 +92,7 @@ PreservedAnalyses
WarnMissedTransformationsPass::run(Function &F, FunctionAnalysisManager &AM) {
// Do not warn about not applied transformations if optimizations are
// disabled.
- if (F.hasFnAttribute(Attribute::OptimizeNone))
+ if (F.optForNone())
return PreservedAnalyses::all();
auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F);
More information about the llvm-commits
mailing list