]> granicus.if.org Git - llvm/commitdiff
[IR] Create new method in `Function` class (NFC)
authorEvandro Menezes <e.menezes@samsung.com>
Wed, 3 Apr 2019 21:27:03 +0000 (21:27 +0000)
committerEvandro Menezes <e.menezes@samsung.com>
Wed, 3 Apr 2019 21:27:03 +0000 (21:27 +0000)
Create method `optForNone()` testing for the function level equivalent of
`-O0` and refactor appropriately.

Differential revision: https://reviews.llvm.org/D59852

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357638 91177308-0d34-0410-b5e6-96231b3b80d8

17 files changed:
include/llvm/IR/Function.h
lib/Analysis/GlobalsModRef.cpp
lib/Analysis/InlineCost.cpp
lib/Analysis/LoopPass.cpp
lib/Analysis/RegionPass.cpp
lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
lib/CodeGen/GlobalISel/RegBankSelect.cpp
lib/CodeGen/SafeStack.cpp
lib/IR/Pass.cpp
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/Hexagon/HexagonFrameLowering.cpp
lib/Transforms/IPO/FunctionAttrs.cpp
lib/Transforms/IPO/HotColdSplitting.cpp
lib/Transforms/IPO/InferFunctionAttrs.cpp
lib/Transforms/IPO/Inliner.cpp
lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
lib/Transforms/Scalar/WarnMissedTransforms.cpp

index 7184cb49af97c83ea6510a394a24b33580332e3f..48307967b5873baf5a35b14d31260d00cb19b295 100644 (file)
@@ -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); }
 
index c6f54c208a6228ee6f6a8b761811cc5360a4ae1f..2ded6be4ba47f8fb6d87f7b695cf47cf42d4c414 100644 (file)
@@ -513,7 +513,7 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
         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(CallGraph &CG, Module &M) {
       // 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())) {
index 574a1b6c8410a8d4ec29fd6edc877e374cea354a..d1fbfafbe4d1d11428f7e58dee9f9c3499a46742 100644 (file)
@@ -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
index c801b9a2d1ada1d52e9aad784ae46ed68b6d24e1..0fd9849ba885809ca3b59cd14bdff258f9c0e9e6 100644 (file)
@@ -396,7 +396,7 @@ bool LoopPass::skipLoop(const Loop *L) const {
   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");
index f2bb1044abd36b7204b75d76fa43ee61de63986d..ea117eaee1c6fe344c1ac530da04b08c0d49586e 100644 (file)
@@ -288,7 +288,7 @@ bool RegionPass::skipRegion(Region &R) const {
   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()
index 9bce1c4275777bf3b79e783bfd409809a9b56e7f..6693fe4a653c962d00ab8ba61bdc797641a4347e 100644 (file)
@@ -1341,8 +1341,8 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
     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;
index bd66d82e9b12864825c1ce901e523b90d8432808..250a1db0666e1943b7a36a506d484ad233c83643 100644 (file)
@@ -657,7 +657,7 @@ bool RegBankSelect::runOnMachineFunction(MachineFunction &MF) {
   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);
 
index f792fc6db912a7756bedd57f7eca7e0142b0af42..fc110c683f4d524292213c36315f33074c95761d 100644 (file)
@@ -728,7 +728,7 @@ void SafeStack::TryInlinePointerAddress() {
   if (!isa<CallInst>(UnsafeStackPtr))
     return;
 
-  if(F.hasFnAttribute(Attribute::OptimizeNone))
+  if(F.optForNone())
     return;
 
   CallSite CS(UnsafeStackPtr);
index 4038205e044912740d6adac5e9420e051a964dba..f7815584fc4a0c3ac9683be02ea0299a0db40369 100644 (file)
@@ -168,7 +168,7 @@ bool FunctionPass::skipFunction(const Function &F) const {
   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(const BasicBlock &BB) const {
   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()
index 5a33c2028070d973673a8cb1188729d6a1a93fcc..300bc861a38ea7f058be0fd963c211753dbc2662 100644 (file)
@@ -119,7 +119,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   // 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())
index 1a9ca4e040fdc944a8d65972d4c4c4c529b74a75..537da2a6cfdcd1a37510f71e037e4cd4490c5c6e 100644 (file)
@@ -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;
 }
 
index 77e98ecd9103cfa7d4bd10294fe808985c53bb91..d396882cc7e1bcd1bdf47efc959222a012cf828d 100644 (file)
@@ -1366,8 +1366,7 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
   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, AARGetterT AARGetter) {
   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;
index 5d6add5431941a5c0648c73d4d93ceedf3074977..c4348c3685e911fde3dcc77b04ace61bc7544096 100644 (file)
@@ -149,7 +149,7 @@ static bool mayExtractBlock(const BasicBlock &BB) {
 /// 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.
index cac83f5aecbed1caad8c1d8cd1bef5aa0c76c51c..dfe375de65d95030432a4d055ed35468612680c5 100644 (file)
@@ -25,7 +25,7 @@ static bool inferAllPrototypeAttributes(Module &M,
   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;
index 8ea6d154be5b0c9ecdec4f76d2140384914661e5..b647b27642c95401807b8f871249b4d15fa1c5fe 100644 (file)
@@ -973,7 +973,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
     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;
     }
index 79c219aeed5cf79d84b6af12e11ed7264b4fc52f..c9e3a15267f1728f332a40aaf95471659dd21b69 100644 (file)
@@ -393,9 +393,7 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI,
   }
   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;
index 73687e1e5dfdc315eefd603daa1008efcb7732c1..bcb877acfcdadf104117a130d940a6cc49dc2e5e 100644 (file)
@@ -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);