diff options
Diffstat (limited to 'llvm/lib/CodeGen/IfConversion.cpp')
-rw-r--r-- | llvm/lib/CodeGen/IfConversion.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp index 05600bbc0a8..ccb992d92e5 100644 --- a/llvm/lib/CodeGen/IfConversion.cpp +++ b/llvm/lib/CodeGen/IfConversion.cpp @@ -1,4 +1,4 @@ -//===-- IfConversion.cpp - Machine code if conversion pass. ---------------===// +//===- IfConversion.cpp - Machine code if conversion pass -----------------===// // // The LLVM Compiler Infrastructure // @@ -16,16 +16,26 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/SparseSet.h" #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/CodeGen/LivePhysRegs.h" +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" +#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/MachineOperand.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetSchedule.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/BranchProbability.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -35,7 +45,12 @@ #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Target/TargetSubtargetInfo.h" #include <algorithm> +#include <cassert> +#include <functional> +#include <iterator> +#include <memory> #include <utility> +#include <vector> using namespace llvm; @@ -77,6 +92,7 @@ STATISTIC(NumDupBBs, "Number of duplicated blocks"); STATISTIC(NumUnpred, "Number of true blocks of diamonds unpredicated"); namespace { + class IfConverter : public MachineFunctionPass { enum IfcvtKind { ICNotClassfied, // BB data valid, but not classified. @@ -125,21 +141,20 @@ namespace { bool IsUnpredicable : 1; bool CannotBeCopied : 1; bool ClobbersPred : 1; - unsigned NonPredSize; - unsigned ExtraCost; - unsigned ExtraCost2; - MachineBasicBlock *BB; - MachineBasicBlock *TrueBB; - MachineBasicBlock *FalseBB; + unsigned NonPredSize = 0; + unsigned ExtraCost = 0; + unsigned ExtraCost2 = 0; + MachineBasicBlock *BB = nullptr; + MachineBasicBlock *TrueBB = nullptr; + MachineBasicBlock *FalseBB = nullptr; SmallVector<MachineOperand, 4> BrCond; SmallVector<MachineOperand, 4> Predicate; + BBInfo() : IsDone(false), IsBeingAnalyzed(false), IsAnalyzed(false), IsEnqueued(false), IsBrAnalyzable(false), IsBrReversible(false), HasFallThrough(false), IsUnpredicable(false), CannotBeCopied(false), - ClobbersPred(false), NonPredSize(0), ExtraCost(0), - ExtraCost2(0), BB(nullptr), TrueBB(nullptr), - FalseBB(nullptr) {} + ClobbersPred(false) {} }; /// Record information about pending if-conversions to attempt: @@ -161,6 +176,7 @@ namespace { bool NeedSubsumption : 1; bool TClobbersPred : 1; bool FClobbersPred : 1; + IfcvtToken(BBInfo &b, IfcvtKind k, bool s, unsigned d, unsigned d2 = 0, bool tc = false, bool fc = false) : BBI(b), Kind(k), NumDups(d), NumDups2(d2), NeedSubsumption(s), @@ -182,13 +198,14 @@ namespace { bool PreRegAlloc; bool MadeChange; - int FnNum; + int FnNum = -1; std::function<bool(const MachineFunction &)> PredicateFtor; public: static char ID; + IfConverter(std::function<bool(const MachineFunction &)> Ftor = nullptr) - : MachineFunctionPass(ID), FnNum(-1), PredicateFtor(std::move(Ftor)) { + : MachineFunctionPass(ID), PredicateFtor(std::move(Ftor)) { initializeIfConverterPass(*PassRegistry::getPassRegistry()); } @@ -309,8 +326,9 @@ namespace { } }; - char IfConverter::ID = 0; -} +} // end anonymous namespace + +char IfConverter::ID = 0; char &llvm::IfConverterID = IfConverter::ID; @@ -433,7 +451,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) { } break; } - case ICDiamond: { + case ICDiamond: if (DisableDiamond) break; DEBUG(dbgs() << "Ifcvt (Diamond): BB#" << BBI.BB->getNumber() << " (T:" << BBI.TrueBB->getNumber() << ",F:" @@ -444,8 +462,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) { DEBUG(dbgs() << (RetVal ? "succeeded!" : "failed!") << "\n"); if (RetVal) ++NumDiamonds; break; - } - case ICForkedDiamond: { + case ICForkedDiamond: if (DisableForkedDiamond) break; DEBUG(dbgs() << "Ifcvt (Forked Diamond): BB#" << BBI.BB->getNumber() << " (T:" @@ -458,7 +475,6 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) { if (RetVal) ++NumForkedDiamonds; break; } - } if (RetVal && MRI->tracksLiveness()) recomputeLivenessFlags(*BBI.BB); @@ -617,7 +633,6 @@ bool IfConverter::CountDuplicatedInstructions( unsigned &Dups1, unsigned &Dups2, MachineBasicBlock &TBB, MachineBasicBlock &FBB, bool SkipUnconditionalBranches) const { - while (TIB != TIE && FIB != FIE) { // Skip dbg_value instructions. These do not count. TIB = skipDebugInstructionsForward(TIB, TIE); |