diff options
author | Evandro Menezes <e.menezes@samsung.com> | 2019-04-03 21:27:03 +0000 |
---|---|---|
committer | Evandro Menezes <e.menezes@samsung.com> | 2019-04-03 21:27:03 +0000 |
commit | 7c711ccf36e0a818f76d711715956ffe831f53b6 (patch) | |
tree | cfbd36f2d353a8c2eed5a47196fb39821ac5ec1f | |
parent | 4d50879d9c93cdadfd6b0918931907c821d06520 (diff) | |
download | llvm-7c711ccf36e0a818f76d711715956ffe831f53b6.zip llvm-7c711ccf36e0a818f76d711715956ffe831f53b6.tar.gz llvm-7c711ccf36e0a818f76d711715956ffe831f53b6.tar.bz2 |
[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
llvm-svn: 357638
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 3 | ||||
-rw-r--r-- | llvm/include/llvm/IR/Function.h | 3 | ||||
-rw-r--r-- | llvm/lib/Analysis/GlobalsModRef.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Analysis/LoopPass.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Analysis/RegionPass.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SafeStack.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/Pass.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/HotColdSplitting.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/Inliner.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp | 2 |
18 files changed, 25 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index e48fa5e..7dd3128 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1809,8 +1809,7 @@ void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name, bool HasOptnone, void CodeGenModule::AddDefaultFnAttrs(llvm::Function &F) { llvm::AttrBuilder FuncAttrs; - ConstructDefaultFnAttrList(F.getName(), - F.hasFnAttribute(llvm::Attribute::OptimizeNone), + ConstructDefaultFnAttrList(F.getName(), F.optForNone(), /* AttrOnCallsite = */ false, FuncAttrs); F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs); } diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index 7184cb4..4830796 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -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); } diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp index c6f54c2..2ded6be 100644 --- a/llvm/lib/Analysis/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/GlobalsModRef.cpp @@ -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())) { diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 574a1b6..d1fbfaf 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -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 diff --git a/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp index c801b9a..0fd9849 100644 --- a/llvm/lib/Analysis/LoopPass.cpp +++ b/llvm/lib/Analysis/LoopPass.cpp @@ -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"); diff --git a/llvm/lib/Analysis/RegionPass.cpp b/llvm/lib/Analysis/RegionPass.cpp index f2bb104..ea117ea 100644 --- a/llvm/lib/Analysis/RegionPass.cpp +++ b/llvm/lib/Analysis/RegionPass.cpp @@ -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() diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 9bce1c4..6693fe4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -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; diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp index bd66d82..250a1db 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -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); diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index f792fc6..fc110c6 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -728,7 +728,7 @@ void SafeStack::TryInlinePointerAddress() { if (!isa<CallInst>(UnsafeStackPtr)) return; - if(F.hasFnAttribute(Attribute::OptimizeNone)) + if(F.optForNone()) return; CallSite CS(UnsafeStackPtr); diff --git a/llvm/lib/IR/Pass.cpp b/llvm/lib/IR/Pass.cpp index 4038205..f781558 100644 --- a/llvm/lib/IR/Pass.cpp +++ b/llvm/lib/IR/Pass.cpp @@ -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() diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index 5a33c20..300bc86 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -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()) diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp index 1a9ca4e0..537da2a 100644 --- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp @@ -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; } diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 77e98ec..d396882 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -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; diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp index 5d6add5..c4348c3 100644 --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -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. diff --git a/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp b/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp index cac83f5..dfe375d 100644 --- a/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/InferFunctionAttrs.cpp @@ -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; diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp index 8ea6d15..b647b27 100644 --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -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; } diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp index 79c219a..c9e3a15 100644 --- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp +++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp @@ -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; diff --git a/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp b/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp index 73687e1..bcb877a 100644 --- a/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp +++ b/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp @@ -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); |