2009-09-04 07:47:40 +00:00
|
|
|
//===-- BranchFolding.h - Fold machine code branch instructions --*- C++ -*===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_BRANCHFOLDING_HPP
|
|
|
|
#define LLVM_CODEGEN_BRANCHFOLDING_HPP
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class MachineFunction;
|
|
|
|
class MachineModuleInfo;
|
|
|
|
class RegScavenger;
|
|
|
|
class TargetInstrInfo;
|
|
|
|
class TargetRegisterInfo;
|
|
|
|
|
|
|
|
class BranchFolder {
|
|
|
|
public:
|
2009-10-28 20:46:46 +00:00
|
|
|
explicit BranchFolder(bool defaultEnableTailMerge);
|
2009-09-04 07:47:40 +00:00
|
|
|
|
|
|
|
bool OptimizeFunction(MachineFunction &MF,
|
|
|
|
const TargetInstrInfo *tii,
|
|
|
|
const TargetRegisterInfo *tri,
|
|
|
|
MachineModuleInfo *mmi);
|
|
|
|
private:
|
|
|
|
typedef std::pair<unsigned,MachineBasicBlock*> MergePotentialsElt;
|
|
|
|
typedef std::vector<MergePotentialsElt>::iterator MPIterator;
|
|
|
|
std::vector<MergePotentialsElt> MergePotentials;
|
|
|
|
|
|
|
|
typedef std::pair<MPIterator, MachineBasicBlock::iterator> SameTailElt;
|
|
|
|
std::vector<SameTailElt> SameTails;
|
|
|
|
|
|
|
|
bool EnableTailMerge;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
MachineModuleInfo *MMI;
|
|
|
|
RegScavenger *RS;
|
|
|
|
|
|
|
|
bool TailMergeBlocks(MachineFunction &MF);
|
2009-11-11 19:49:34 +00:00
|
|
|
bool TryTailMergeBlocks(MachineBasicBlock* SuccBB,
|
|
|
|
MachineBasicBlock* PredBB);
|
2009-09-04 07:47:40 +00:00
|
|
|
void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
|
|
|
MachineBasicBlock *NewDest);
|
|
|
|
MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
|
|
|
|
MachineBasicBlock::iterator BBI1);
|
2009-11-11 19:49:34 +00:00
|
|
|
unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength,
|
|
|
|
MachineBasicBlock *SuccBB,
|
|
|
|
MachineBasicBlock *PredBB);
|
2009-09-04 07:47:40 +00:00
|
|
|
void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB,
|
|
|
|
MachineBasicBlock* PredBB);
|
|
|
|
unsigned CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
|
|
|
|
unsigned maxCommonTailLength);
|
|
|
|
|
2009-11-11 19:49:34 +00:00
|
|
|
bool TailDuplicate(MachineBasicBlock *TailBB,
|
|
|
|
bool PrevFallsThrough,
|
|
|
|
MachineFunction &MF);
|
|
|
|
|
2009-09-04 07:47:40 +00:00
|
|
|
bool OptimizeBranches(MachineFunction &MF);
|
|
|
|
bool OptimizeBlock(MachineBasicBlock *MBB);
|
|
|
|
void RemoveDeadBlock(MachineBasicBlock *MBB);
|
|
|
|
bool OptimizeImpDefsBlock(MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
bool CanFallThrough(MachineBasicBlock *CurBB);
|
|
|
|
bool CanFallThrough(MachineBasicBlock *CurBB, bool BranchUnAnalyzable,
|
|
|
|
MachineBasicBlock *TBB, MachineBasicBlock *FBB,
|
|
|
|
const SmallVectorImpl<MachineOperand> &Cond);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// BranchFolderPass - Wrap branch folder in a machine function pass.
|
|
|
|
class BranchFolderPass : public MachineFunctionPass,
|
|
|
|
public BranchFolder {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2009-10-28 20:46:46 +00:00
|
|
|
explicit BranchFolderPass(bool defaultEnableTailMerge)
|
|
|
|
: MachineFunctionPass(&ID), BranchFolder(defaultEnableTailMerge) {}
|
2009-09-04 07:47:40 +00:00
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
virtual const char *getPassName() const { return "Control Flow Optimizer"; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* LLVM_CODEGEN_BRANCHFOLDING_HPP */
|