23 #define DEBUG_TYPE "hexmux" 63 "farther of the two predicated uses"));
74 return "Hexagon generate mux instructions";
97 CondsetInfo() =
default;
103 DefUseInfo() =
default;
109 unsigned DefR, PredR;
116 : At(It), DefR(DR), PredR(PR), SrcT(TOp), SrcF(FOp), Def1(&D1),
124 bool isRegPair(
unsigned Reg)
const {
125 return Hexagon::DoubleRegsRegClass.contains(Reg);
128 void getSubRegs(
unsigned Reg,
BitVector &SRs)
const;
129 void expandReg(
unsigned Reg,
BitVector &Set)
const;
134 bool isCondTransfer(
unsigned Opc)
const;
145 "Hexagon generate mux instructions",
false,
false)
147 void HexagonGenMux::getSubRegs(
unsigned Reg,
BitVector &SRs)
const {
152 void HexagonGenMux::expandReg(
unsigned Reg,
BitVector &Set)
const {
154 getSubRegs(Reg, Set);
166 expandReg(*R++, Defs);
169 expandReg(*R++, Uses);
173 if (!MO.isReg() || MO.isImplicit())
175 unsigned R = MO.getReg();
176 BitVector &Set = MO.isDef() ? Defs : Uses;
182 DefUseInfoMap &DUM) {
184 unsigned NR = HRI->getNumRegs();
189 I2X.insert(std::make_pair(MI, Index));
192 getDefsUses(MI, Defs, Uses);
193 DUM.insert(std::make_pair(Index, DefUseInfo(Defs, Uses)));
198 bool HexagonGenMux::isCondTransfer(
unsigned Opc)
const {
200 case Hexagon::A2_tfrt:
201 case Hexagon::A2_tfrf:
202 case Hexagon::C2_cmoveit:
203 case Hexagon::C2_cmoveif:
211 bool IsReg1 = Src1.
isReg(), IsReg2 = Src2.
isReg();
213 return IsReg2 ? Hexagon::C2_mux : Hexagon::C2_muxir;
215 return Hexagon::C2_muxri;
220 return Hexagon::C2_muxii;
226 bool Changed =
false;
229 buildMaps(B, I2X, DUM);
239 NextI = std::next(
I);
241 if (!isCondTransfer(Opc))
250 unsigned PR = PredOp.
getReg();
251 unsigned Idx = I2X.lookup(MI);
252 CondsetMap::iterator
F = CM.find(DR);
253 bool IfTrue = HII->isPredicatedTrue(Opc);
257 if (F != CM.end() && F->second.PredR != PR) {
262 auto It = CM.insert(std::make_pair(DR, CondsetInfo()));
264 F->second.PredR = PR;
266 CondsetInfo &CI = F->second;
280 unsigned MinX = std::min(CI.TrueX, CI.FalseX);
281 unsigned MaxX =
std::max(CI.TrueX, CI.FalseX);
284 unsigned SearchX = (MaxX >=
MinPredDist) ? MaxX-MinPredDist : 0;
285 bool NearDef =
false;
286 for (
unsigned X = SearchX;
X < MaxX; ++
X) {
287 const DefUseInfo &DU = DUM.lookup(
X);
303 std::advance(It1, MinX);
304 std::advance(It2, MaxX);
309 bool Failure =
false, CanUp =
true, CanDown =
true;
310 for (
unsigned X = MinX+1;
X < MaxX;
X++) {
311 const DefUseInfo &DU = DUM.lookup(
X);
312 if (DU.Defs[PR] || DU.Defs[DR] || DU.Uses[DR]) {
316 if (CanDown && DU.Defs[SR1])
318 if (CanUp && DU.Defs[SR2])
321 if (Failure || (!CanUp && !CanDown))
329 ML.push_back(MuxInfo(At, DR, PR, SrcT, SrcF, Def1, Def2));
332 for (MuxInfo &MX : ML) {
333 unsigned MxOpc = getMuxOpcode(*MX.SrcT, *MX.SrcF);
338 auto NewMux =
BuildMI(B, MX.At, DL, HII->
get(MxOpc), MX.DefR)
352 auto IsLive = [&LPR,
this] (
unsigned Reg) ->
bool {
359 if (
I->isDebugInstr())
366 if (!
Op.isReg() || !
Op.isUse())
368 assert(
Op.getSubReg() == 0 &&
"Should have physical registers only");
369 bool Live = IsLive(
Op.getReg());
383 bool Changed =
false;
385 Changed |= genMuxInBlock(
I);
390 return new HexagonGenMux();
const MachineInstrBuilder & add(const MachineOperand &MO) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents lattice values for constants.
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
A global registry used in conjunction with static constructors to make pluggable components (like tar...
constexpr bool isInt< 8 >(int64_t x)
INITIALIZE_PASS(HexagonGenMux, "hexagon-gen-mux", "Hexagon generate mux instructions", false, false) void HexagonGenMux
bool contains(MCPhysReg Reg) const
Returns true if register Reg is contained in the set.
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void clearKillInfo()
Clears kill flags on all operands.
void initializeHexagonGenMuxPass(PassRegistry &Registry)
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
reverse_iterator rbegin()
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void addLiveOuts(const MachineBasicBlock &MBB)
Adds all live-out registers of basic block MBB.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
const MCPhysReg * ImplicitDefs
Represent the analysis usage information of a pass.
void stepBackward(const MachineInstr &MI)
Simulates liveness when stepping backwards over an instruction(bundle).
FunctionPass class - This class is used to implement most global optimizations.
MCSubRegIterator enumerates all sub-registers of Reg.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
FunctionPass * createHexagonGenMux()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
const MachineOperand & getOperand(unsigned i) const
static cl::opt< unsigned > MinPredDist("hexagon-gen-mux-threshold", cl::Hidden, cl::init(0), cl::desc("Minimum distance between predicate definition and " "farther of the two predicated uses"))
Properties which a MachineFunction may have at a given point in time.
const MCPhysReg * ImplicitUses