22 #define DEBUG_TYPE "hexmux" 62 "farther of the two predicated uses"));
73 return "Hexagon generate mux instructions";
96 CondsetInfo() =
default;
102 DefUseInfo() =
default;
108 unsigned DefR, PredR;
115 : At(It), DefR(DR), PredR(PR), SrcT(TOp), SrcF(FOp), Def1(&D1),
123 bool isRegPair(
unsigned Reg)
const {
124 return Hexagon::DoubleRegsRegClass.contains(Reg);
127 void getSubRegs(
unsigned Reg,
BitVector &SRs)
const;
128 void expandReg(
unsigned Reg,
BitVector &Set)
const;
133 bool isCondTransfer(
unsigned Opc)
const;
144 "Hexagon generate mux instructions",
false,
false)
146 void HexagonGenMux::getSubRegs(
unsigned Reg,
BitVector &SRs)
const {
151 void HexagonGenMux::expandReg(
unsigned Reg,
BitVector &Set)
const {
153 getSubRegs(Reg, Set);
165 expandReg(*R++, Defs);
168 expandReg(*R++, Uses);
172 if (!MO.isReg() || MO.isImplicit())
175 BitVector &Set = MO.isDef() ? Defs : Uses;
181 DefUseInfoMap &DUM) {
183 unsigned NR = HRI->getNumRegs();
188 I2X.insert(std::make_pair(MI, Index));
191 getDefsUses(MI, Defs, Uses);
192 DUM.insert(std::make_pair(Index, DefUseInfo(Defs, Uses)));
197 bool HexagonGenMux::isCondTransfer(
unsigned Opc)
const {
199 case Hexagon::A2_tfrt:
200 case Hexagon::A2_tfrf:
201 case Hexagon::C2_cmoveit:
202 case Hexagon::C2_cmoveif:
210 bool IsReg1 = Src1.
isReg(), IsReg2 = Src2.
isReg();
212 return IsReg2 ? Hexagon::C2_mux : Hexagon::C2_muxir;
214 return Hexagon::C2_muxri;
219 return Hexagon::C2_muxii;
225 bool Changed =
false;
228 buildMaps(B, I2X, DUM);
238 NextI = std::next(
I);
240 if (!isCondTransfer(Opc))
250 unsigned Idx = I2X.lookup(MI);
251 CondsetMap::iterator
F = CM.find(DR);
252 bool IfTrue = HII->isPredicatedTrue(Opc);
256 if (F != CM.end() && F->second.PredR != PR) {
261 auto It = CM.insert(std::make_pair(DR, CondsetInfo()));
263 F->second.PredR = PR;
265 CondsetInfo &CI = F->second;
279 unsigned MinX = std::min(CI.TrueX, CI.FalseX);
280 unsigned MaxX =
std::max(CI.TrueX, CI.FalseX);
283 unsigned SearchX = (MaxX >=
MinPredDist) ? MaxX-MinPredDist : 0;
284 bool NearDef =
false;
285 for (
unsigned X = SearchX;
X < MaxX; ++
X) {
286 const DefUseInfo &DU = DUM.lookup(
X);
302 std::advance(It1, MinX);
303 std::advance(It2, MaxX);
308 bool Failure =
false, CanUp =
true, CanDown =
true;
309 for (
unsigned X = MinX+1;
X < MaxX;
X++) {
310 const DefUseInfo &DU = DUM.lookup(
X);
311 if (DU.Defs[PR] || DU.Defs[DR] || DU.Uses[DR]) {
315 if (CanDown && DU.Defs[SR1])
317 if (CanUp && DU.Defs[SR2])
320 if (Failure || (!CanUp && !CanDown))
328 ML.push_back(MuxInfo(At, DR, PR, SrcT, SrcF, Def1, Def2));
331 for (MuxInfo &MX : ML) {
332 unsigned MxOpc = getMuxOpcode(*MX.SrcT, *MX.SrcF);
338 if (!MX.At->getParent() || !MX.Def1->getParent() || !MX.Def2->getParent())
343 auto NewMux =
BuildMI(B, MX.At, DL, HII->
get(MxOpc), MX.DefR)
357 auto IsLive = [&LPR,
this] (
unsigned Reg) ->
bool {
364 if (
I->isDebugInstr())
371 if (!
Op.isReg() || !
Op.isUse())
373 assert(
Op.getSubReg() == 0 &&
"Should have physical registers only");
374 bool Live = IsLive(
Op.getReg());
388 bool Changed =
false;
390 Changed |= genMuxInBlock(
I);
395 return new HexagonGenMux();
const MachineInstrBuilder & add(const MachineOperand &MO) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Describe properties that are true of each instruction in the target description file.
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)
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.
Align max(MaybeAlign Lhs, Align Rhs)
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()
Promote Memory to Register
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
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...
Register getReg() const
getReg - Returns the register number.
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.
Wrapper class representing virtual and physical registers.
const MCPhysReg * ImplicitUses