mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
[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
This commit is contained in:
parent
66b4435388
commit
c32df1f868
@ -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); }
|
||||
|
||||
|
@ -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())) {
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -728,7 +728,7 @@ void SafeStack::TryInlinePointerAddress() {
|
||||
if (!isa<CallInst>(UnsafeStackPtr))
|
||||
return;
|
||||
|
||||
if(F.hasFnAttribute(Attribute::OptimizeNone))
|
||||
if(F.optForNone())
|
||||
return;
|
||||
|
||||
CallSite CS(UnsafeStackPtr);
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user