f785676f2a
all of the features in the current working draft of the upcoming C++ standard, provisionally named C++1y. The code generator's performance is greatly increased, and the loop auto-vectorizer is now enabled at -Os and -O2 in addition to -O3. The PowerPC backend has made several major improvements to code generation quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ backends have all seen major feature work. Release notes for llvm and clang can be found here: <http://llvm.org/releases/3.4/docs/ReleaseNotes.html> <http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html> MFC after: 1 month
126 lines
4.2 KiB
C++
126 lines
4.2 KiB
C++
//===-- 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/ADT/SmallPtrSet.h"
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
class MachineFunction;
|
|
class MachineModuleInfo;
|
|
class RegScavenger;
|
|
class TargetInstrInfo;
|
|
class TargetRegisterInfo;
|
|
|
|
class BranchFolder {
|
|
public:
|
|
explicit BranchFolder(bool defaultEnableTailMerge, bool CommonHoist);
|
|
|
|
bool OptimizeFunction(MachineFunction &MF,
|
|
const TargetInstrInfo *tii,
|
|
const TargetRegisterInfo *tri,
|
|
MachineModuleInfo *mmi);
|
|
private:
|
|
class MergePotentialsElt {
|
|
unsigned Hash;
|
|
MachineBasicBlock *Block;
|
|
public:
|
|
MergePotentialsElt(unsigned h, MachineBasicBlock *b)
|
|
: Hash(h), Block(b) {}
|
|
|
|
unsigned getHash() const { return Hash; }
|
|
MachineBasicBlock *getBlock() const { return Block; }
|
|
|
|
void setBlock(MachineBasicBlock *MBB) {
|
|
Block = MBB;
|
|
}
|
|
|
|
bool operator<(const MergePotentialsElt &) const;
|
|
};
|
|
typedef std::vector<MergePotentialsElt>::iterator MPIterator;
|
|
std::vector<MergePotentialsElt> MergePotentials;
|
|
SmallPtrSet<const MachineBasicBlock*, 2> TriedMerging;
|
|
|
|
class SameTailElt {
|
|
MPIterator MPIter;
|
|
MachineBasicBlock::iterator TailStartPos;
|
|
public:
|
|
SameTailElt(MPIterator mp, MachineBasicBlock::iterator tsp)
|
|
: MPIter(mp), TailStartPos(tsp) {}
|
|
|
|
MPIterator getMPIter() const {
|
|
return MPIter;
|
|
}
|
|
MergePotentialsElt &getMergePotentialsElt() const {
|
|
return *getMPIter();
|
|
}
|
|
MachineBasicBlock::iterator getTailStartPos() const {
|
|
return TailStartPos;
|
|
}
|
|
unsigned getHash() const {
|
|
return getMergePotentialsElt().getHash();
|
|
}
|
|
MachineBasicBlock *getBlock() const {
|
|
return getMergePotentialsElt().getBlock();
|
|
}
|
|
bool tailIsWholeBlock() const {
|
|
return TailStartPos == getBlock()->begin();
|
|
}
|
|
|
|
void setBlock(MachineBasicBlock *MBB) {
|
|
getMergePotentialsElt().setBlock(MBB);
|
|
}
|
|
void setTailStartPos(MachineBasicBlock::iterator Pos) {
|
|
TailStartPos = Pos;
|
|
}
|
|
};
|
|
std::vector<SameTailElt> SameTails;
|
|
|
|
bool EnableTailMerge;
|
|
bool EnableHoistCommonCode;
|
|
const TargetInstrInfo *TII;
|
|
const TargetRegisterInfo *TRI;
|
|
MachineModuleInfo *MMI;
|
|
RegScavenger *RS;
|
|
|
|
bool TailMergeBlocks(MachineFunction &MF);
|
|
bool TryTailMergeBlocks(MachineBasicBlock* SuccBB,
|
|
MachineBasicBlock* PredBB);
|
|
void MaintainLiveIns(MachineBasicBlock *CurMBB,
|
|
MachineBasicBlock *NewMBB);
|
|
void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
|
MachineBasicBlock *NewDest);
|
|
MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
|
|
MachineBasicBlock::iterator BBI1,
|
|
const BasicBlock *BB);
|
|
unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength,
|
|
MachineBasicBlock *SuccBB,
|
|
MachineBasicBlock *PredBB);
|
|
void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB,
|
|
MachineBasicBlock* PredBB);
|
|
bool CreateCommonTailOnlyBlock(MachineBasicBlock *&PredBB,
|
|
MachineBasicBlock *SuccBB,
|
|
unsigned maxCommonTailLength,
|
|
unsigned &commonTailIndex);
|
|
|
|
bool OptimizeBranches(MachineFunction &MF);
|
|
bool OptimizeBlock(MachineBasicBlock *MBB);
|
|
void RemoveDeadBlock(MachineBasicBlock *MBB);
|
|
bool OptimizeImpDefsBlock(MachineBasicBlock *MBB);
|
|
|
|
bool HoistCommonCode(MachineFunction &MF);
|
|
bool HoistCommonCodeInSuccs(MachineBasicBlock *MBB);
|
|
};
|
|
}
|
|
|
|
#endif /* LLVM_CODEGEN_BRANCHFOLDING_HPP */
|