23 #define DEBUG_TYPE "hexmux"
67 return "Hexagon generate mux instructions";
87 unsigned TrueX = std::numeric_limits<unsigned>::max();
88 unsigned FalseX = std::numeric_limits<unsigned>::max();
90 CondsetInfo() =
default;
96 DefUseInfo() =
default;
102 unsigned DefR, PredR;
109 : At(It), DefR(DR), PredR(PR), SrcT(TOp), SrcF(FOp), Def1(&D1),
117 bool isRegPair(
unsigned Reg)
const {
118 return Hexagon::DoubleRegsRegClass.contains(Reg);
122 void expandReg(
unsigned Reg,
BitVector &Set)
const;
127 bool isCondTransfer(
unsigned Opc)
const;
138 "Hexagon generate mux instructions",
false,
false)
145 void HexagonGenMux::expandReg(
unsigned Reg,
BitVector &Set)
const {
147 getSubRegs(Reg, Set);
159 expandReg(*R++, Defs);
162 expandReg(*R++, Uses);
166 if (!MO.isReg() || MO.isImplicit())
168 unsigned R = MO.getReg();
169 BitVector &Set = MO.isDef() ? Defs : Uses;
175 DefUseInfoMap &DUM) {
177 unsigned NR = HRI->getNumRegs();
182 I2X.insert(std::make_pair(MI, Index));
185 getDefsUses(MI, Defs, Uses);
186 DUM.insert(std::make_pair(Index, DefUseInfo(Defs, Uses)));
191 bool HexagonGenMux::isCondTransfer(
unsigned Opc)
const {
193 case Hexagon::A2_tfrt:
194 case Hexagon::A2_tfrf:
195 case Hexagon::C2_cmoveit:
196 case Hexagon::C2_cmoveif:
204 bool IsReg1 = Src1.
isReg(), IsReg2 = Src2.
isReg();
206 return IsReg2 ? Hexagon::C2_mux : Hexagon::C2_muxir;
208 return Hexagon::C2_muxri;
213 return Hexagon::C2_muxii;
219 bool Changed =
false;
222 buildMaps(B, I2X, DUM);
231 NextI = std::next(
I);
233 if (!isCondTransfer(Opc))
240 unsigned Idx = I2X.lookup(MI);
241 CondsetMap::iterator
F = CM.find(DR);
242 bool IfTrue = HII->isPredicatedTrue(Opc);
246 if (F != CM.end() && F->second.PredR != PR) {
251 auto It = CM.insert(std::make_pair(DR, CondsetInfo()));
253 F->second.PredR = PR;
255 CondsetInfo &CI = F->second;
260 if (CI.TrueX == std::numeric_limits<unsigned>::max() ||
261 CI.FalseX == std::numeric_limits<unsigned>::max())
269 unsigned MinX =
std::min(CI.TrueX, CI.FalseX);
270 unsigned MaxX = std::max(CI.TrueX, CI.FalseX);
271 unsigned SearchX = (MaxX > 4) ? MaxX-4 : 0;
272 bool NearDef =
false;
273 for (
unsigned X = SearchX;
X < MaxX; ++
X) {
274 const DefUseInfo &DU = DUM.lookup(
X);
296 bool Failure =
false, CanUp =
true, CanDown =
true;
297 for (
unsigned X = MinX+1;
X < MaxX;
X++) {
298 const DefUseInfo &DU = DUM.lookup(
X);
299 if (DU.Defs[PR] || DU.Defs[DR] || DU.Uses[DR]) {
303 if (CanDown && DU.Defs[SR1])
305 if (CanUp && DU.Defs[SR2])
308 if (Failure || (!CanUp && !CanDown))
316 ML.push_back(MuxInfo(At, DR, PR, SrcT, SrcF, Def1, Def2));
319 for (
unsigned I = 0,
N = ML.size();
I <
N; ++
I) {
323 unsigned MxOpc = getMuxOpcode(*MX.SrcT, *MX.SrcF);
326 BuildMI(B, MX.At, DL, HII->
get(MxOpc), MX.DefR)
343 bool Changed =
false;
345 Changed |= genMuxInBlock(
I);
350 return new HexagonGenMux();
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
constexpr bool isInt< 8 >(int64_t x)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
iterator_range< mop_iterator > operands()
void initializeHexagonGenMuxPass(PassRegistry &Registry)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static void advance(T &it, size_t Val)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
Reg
All possible values of the reg field in the ModR/M byte.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const MachineOperand & getOperand(unsigned i) const
const MCPhysReg * ImplicitDefs
Represent the analysis usage information of a pass.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static const unsigned End
FunctionPass class - This class is used to implement most global optimizations.
MCSubRegIterator enumerates all sub-registers of Reg.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
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()
MachineFunctionProperties & set(Property P)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Representation of each machine instruction.
unsigned getReg() const
getReg - Returns the register number.
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
StringRef - Represent a constant reference to a string, i.e.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Properties which a MachineFunction may have at a given point in time.
const MCPhysReg * ImplicitUses