#include "BitTracker.h"
#include "HexagonBitTracker.h"
#include "HexagonInstrInfo.h"
#include "HexagonRegisterInfo.h"
#include "HexagonSubtarget.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <deque>
#include <iterator>
#include <limits>
#include <utility>
#include <vector>
#define DEBUG_TYPE …
usingnamespacellvm;
static cl::opt<bool> PreserveTiedOps("hexbit-keep-tied", cl::Hidden,
cl::init(true), cl::desc("Preserve subregisters in tied operands"));
static cl::opt<bool> GenExtract("hexbit-extract", cl::Hidden,
cl::init(true), cl::desc("Generate extract instructions"));
static cl::opt<bool> GenBitSplit("hexbit-bitsplit", cl::Hidden,
cl::init(true), cl::desc("Generate bitsplit instructions"));
static cl::opt<unsigned> MaxExtract("hexbit-max-extract", cl::Hidden,
cl::init(std::numeric_limits<unsigned>::max()));
static unsigned CountExtract = …;
static cl::opt<unsigned> MaxBitSplit("hexbit-max-bitsplit", cl::Hidden,
cl::init(std::numeric_limits<unsigned>::max()));
static unsigned CountBitSplit = …;
static cl::opt<unsigned> RegisterSetLimit("hexbit-registerset-limit",
cl::Hidden, cl::init(1000));
namespace llvm {
void initializeHexagonBitSimplifyPass(PassRegistry& Registry);
FunctionPass *createHexagonBitSimplify();
}
namespace {
struct RegisterSet { … };
struct PrintRegSet { … };
raw_ostream &operator<< (raw_ostream &OS, const PrintRegSet &P)
LLVM_ATTRIBUTE_UNUSED;
raw_ostream &operator<< (raw_ostream &OS, const PrintRegSet &P) { … }
class Transformation;
class HexagonBitSimplify : public MachineFunctionPass { … };
HBS;
class Transformation { … };
}
char HexagonBitSimplify::ID = …;
INITIALIZE_PASS_BEGIN(HexagonBitSimplify, "hexagon-bit-simplify",
"Hexagon bit simplification", false, false)
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
INITIALIZE_PASS_END(HexagonBitSimplify, "hexagon-bit-simplify",
"Hexagon bit simplification", false, false)
bool HexagonBitSimplify::visitBlock(MachineBasicBlock &B, Transformation &T,
RegisterSet &AVs) { … }
void HexagonBitSimplify::getInstrDefs(const MachineInstr &MI,
RegisterSet &Defs) { … }
void HexagonBitSimplify::getInstrUses(const MachineInstr &MI,
RegisterSet &Uses) { … }
bool HexagonBitSimplify::isEqual(const BitTracker::RegisterCell &RC1,
uint16_t B1, const BitTracker::RegisterCell &RC2, uint16_t B2,
uint16_t W) { … }
bool HexagonBitSimplify::isZero(const BitTracker::RegisterCell &RC,
uint16_t B, uint16_t W) { … }
bool HexagonBitSimplify::getConst(const BitTracker::RegisterCell &RC,
uint16_t B, uint16_t W, uint64_t &U) { … }
bool HexagonBitSimplify::replaceReg(Register OldR, Register NewR,
MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::replaceRegWithSub(Register OldR, Register NewR,
unsigned NewSR,
MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::replaceSubWithSub(Register OldR, unsigned OldSR,
Register NewR, unsigned NewSR,
MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::getSubregMask(const BitTracker::RegisterRef &RR,
unsigned &Begin, unsigned &Width, MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::parseRegSequence(const MachineInstr &I,
BitTracker::RegisterRef &SL, BitTracker::RegisterRef &SH,
const MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::getUsedBitsInStore(unsigned Opc, BitVector &Bits,
uint16_t Begin) { … }
bool HexagonBitSimplify::getUsedBits(unsigned Opc, unsigned OpN,
BitVector &Bits, uint16_t Begin, const HexagonInstrInfo &HII) { … }
const TargetRegisterClass *HexagonBitSimplify::getFinalVRegClass(
const BitTracker::RegisterRef &RR, MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::isTransparentCopy(const BitTracker::RegisterRef &RD,
const BitTracker::RegisterRef &RS, MachineRegisterInfo &MRI) { … }
bool HexagonBitSimplify::hasTiedUse(unsigned Reg, MachineRegisterInfo &MRI,
unsigned NewSub) { … }
namespace {
class DeadCodeElimination { … };
}
bool DeadCodeElimination::isDead(unsigned R) const { … }
bool DeadCodeElimination::runOnNode(MachineDomTreeNode *N) { … }
namespace {
class RedundantInstrElimination : public Transformation { … };
}
bool RedundantInstrElimination::isLossyShiftLeft(const MachineInstr &MI,
unsigned OpN, unsigned &LostB, unsigned &LostE) { … }
bool RedundantInstrElimination::isLossyShiftRight(const MachineInstr &MI,
unsigned OpN, unsigned &LostB, unsigned &LostE) { … }
bool RedundantInstrElimination::computeUsedBits(unsigned Reg, BitVector &Bits) { … }
bool RedundantInstrElimination::computeUsedBits(const MachineInstr &MI,
unsigned OpN, BitVector &Bits, uint16_t Begin) { … }
bool RedundantInstrElimination::usedBitsEqual(BitTracker::RegisterRef RD,
BitTracker::RegisterRef RS) { … }
bool RedundantInstrElimination::processBlock(MachineBasicBlock &B,
const RegisterSet&) { … }
namespace {
class ConstGeneration : public Transformation { … };
}
bool ConstGeneration::isTfrConst(const MachineInstr &MI) { … }
Register ConstGeneration::genTfrConst(const TargetRegisterClass *RC, int64_t C,
MachineBasicBlock &B,
MachineBasicBlock::iterator At,
DebugLoc &DL) { … }
bool ConstGeneration::processBlock(MachineBasicBlock &B, const RegisterSet&) { … }
namespace {
class CopyGeneration : public Transformation { … };
class CopyPropagation : public Transformation { … };
}
bool CopyGeneration::findMatch(const BitTracker::RegisterRef &Inp,
BitTracker::RegisterRef &Out, const RegisterSet &AVs) { … }
bool CopyGeneration::processBlock(MachineBasicBlock &B,
const RegisterSet &AVs) { … }
bool CopyPropagation::isCopyReg(unsigned Opc, bool NoConv) { … }
bool CopyPropagation::propagateRegCopy(MachineInstr &MI) { … }
bool CopyPropagation::processBlock(MachineBasicBlock &B, const RegisterSet&) { … }
namespace {
class BitSimplification : public Transformation { … };
}
bool BitSimplification::matchHalf(unsigned SelfR,
const BitTracker::RegisterCell &RC, unsigned B, RegHalf &RH) { … }
bool BitSimplification::validateReg(BitTracker::RegisterRef R, unsigned Opc,
unsigned OpNum) { … }
bool BitSimplification::matchPackhl(unsigned SelfR,
const BitTracker::RegisterCell &RC, BitTracker::RegisterRef &Rs,
BitTracker::RegisterRef &Rt) { … }
unsigned BitSimplification::getCombineOpcode(bool HLow, bool LLow) { … }
bool BitSimplification::genStoreUpperHalf(MachineInstr *MI) { … }
bool BitSimplification::genStoreImmediate(MachineInstr *MI) { … }
bool BitSimplification::genPackhl(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC) { … }
bool BitSimplification::genExtractHalf(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC) { … }
bool BitSimplification::genCombineHalf(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC) { … }
bool BitSimplification::genExtractLow(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC) { … }
bool BitSimplification::genBitSplit(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC,
const RegisterSet &AVs) { … }
bool BitSimplification::simplifyTstbit(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC) { … }
bool BitSimplification::simplifyExtractLow(MachineInstr *MI,
BitTracker::RegisterRef RD, const BitTracker::RegisterCell &RC,
const RegisterSet &AVs) { … }
bool BitSimplification::simplifyRCmp0(MachineInstr *MI,
BitTracker::RegisterRef RD) { … }
bool BitSimplification::processBlock(MachineBasicBlock &B,
const RegisterSet &AVs) { … }
bool HexagonBitSimplify::runOnMachineFunction(MachineFunction &MF) { … }
namespace llvm {
FunctionPass *createHexagonLoopRescheduling();
void initializeHexagonLoopReschedulingPass(PassRegistry&);
}
namespace {
class HexagonLoopRescheduling : public MachineFunctionPass { … };
}
char HexagonLoopRescheduling::ID = …;
INITIALIZE_PASS(…)
HexagonLoopRescheduling::PhiInfo::PhiInfo(MachineInstr &P,
MachineBasicBlock &B) { … }
unsigned HexagonLoopRescheduling::getDefReg(const MachineInstr *MI) { … }
bool HexagonLoopRescheduling::isConst(unsigned Reg) const { … }
bool HexagonLoopRescheduling::isBitShuffle(const MachineInstr *MI,
unsigned DefR) const { … }
bool HexagonLoopRescheduling::isStoreInput(const MachineInstr *MI,
unsigned InpR) const { … }
bool HexagonLoopRescheduling::isShuffleOf(unsigned OutR, unsigned InpR) const { … }
bool HexagonLoopRescheduling::isSameShuffle(unsigned OutR1, unsigned InpR1,
unsigned OutR2, unsigned &InpR2) const { … }
void HexagonLoopRescheduling::moveGroup(InstrGroup &G, MachineBasicBlock &LB,
MachineBasicBlock &PB, MachineBasicBlock::iterator At, unsigned OldPhiR,
unsigned NewPredR) { … }
bool HexagonLoopRescheduling::processLoop(LoopCand &C) { … }
bool HexagonLoopRescheduling::runOnMachineFunction(MachineFunction &MF) { … }
FunctionPass *llvm::createHexagonLoopRescheduling() { … }
FunctionPass *llvm::createHexagonBitSimplify() { … }