23 #define DEBUG_TYPE "hexmux"
66 return "Hexagon generate mux instructions";
89 CondsetInfo() =
default;
95 DefUseInfo() =
default;
101 unsigned DefR, PredR;
108 : At(It), DefR(DR), PredR(PR), SrcT(TOp), SrcF(FOp), Def1(&D1),
116 bool isRegPair(
unsigned Reg)
const {
117 return Hexagon::DoubleRegsRegClass.contains(Reg);
121 void expandReg(
unsigned Reg,
BitVector &Set)
const;
126 bool isCondTransfer(
unsigned Opc)
const;
137 "Hexagon generate mux instructions",
false,
false)
144 void HexagonGenMux::expandReg(
unsigned Reg,
BitVector &Set)
const {
146 getSubRegs(Reg, Set);
158 expandReg(*R++, Defs);
161 expandReg(*R++, Uses);
165 if (!MO.isReg() || MO.isImplicit())
167 unsigned R = MO.getReg();
168 BitVector &Set = MO.isDef() ? Defs : Uses;
174 DefUseInfoMap &DUM) {
176 unsigned NR = HRI->getNumRegs();
181 I2X.insert(std::make_pair(MI, Index));
184 getDefsUses(MI, Defs, Uses);
185 DUM.insert(std::make_pair(Index, DefUseInfo(Defs, Uses)));
190 bool HexagonGenMux::isCondTransfer(
unsigned Opc)
const {
192 case Hexagon::A2_tfrt:
193 case Hexagon::A2_tfrf:
194 case Hexagon::C2_cmoveit:
195 case Hexagon::C2_cmoveif:
203 bool IsReg1 = Src1.
isReg(), IsReg2 = Src2.
isReg();
205 return IsReg2 ? Hexagon::C2_mux : Hexagon::C2_muxir;
207 return Hexagon::C2_muxri;
212 return Hexagon::C2_muxii;
218 bool Changed =
false;
221 buildMaps(B, I2X, DUM);
230 NextI = std::next(
I);
232 if (!isCondTransfer(Opc))
241 unsigned PR = PredOp.
getReg();
242 unsigned Idx = I2X.lookup(MI);
243 CondsetMap::iterator
F = CM.find(DR);
244 bool IfTrue = HII->isPredicatedTrue(Opc);
248 if (F != CM.end() && F->second.PredR != PR) {
253 auto It = CM.insert(std::make_pair(DR, CondsetInfo()));
255 F->second.PredR = PR;
257 CondsetInfo &CI = F->second;
271 unsigned MinX =
std::min(CI.TrueX, CI.FalseX);
272 unsigned MaxX =
std::max(CI.TrueX, CI.FalseX);
273 unsigned SearchX = (MaxX > 4) ? MaxX-4 : 0;
274 bool NearDef =
false;
275 for (
unsigned X = SearchX;
X < MaxX; ++
X) {
276 const DefUseInfo &DU = DUM.lookup(
X);
292 std::advance(It1, MinX);
293 std::advance(It2, MaxX);
298 bool Failure =
false, CanUp =
true, CanDown =
true;
299 for (
unsigned X = MinX+1;
X < MaxX;
X++) {
300 const DefUseInfo &DU = DUM.lookup(
X);
301 if (DU.Defs[PR] || DU.Defs[DR] || DU.Uses[DR]) {
305 if (CanDown && DU.Defs[SR1])
307 if (CanUp && DU.Defs[SR2])
310 if (Failure || (!CanUp && !CanDown))
318 ML.push_back(MuxInfo(At, DR, PR, SrcT, SrcF, Def1, Def2));
321 for (MuxInfo &MX : ML) {
322 unsigned MxOpc = getMuxOpcode(*MX.SrcT, *MX.SrcF);
327 auto NewMux =
BuildMI(B, MX.At, DL, HII->
get(MxOpc), MX.DefR)
341 auto IsLive = [&LPR,
this] (
unsigned Reg) ->
bool {
343 if (LPR.contains(*S))
348 if (
I->isDebugValue())
355 if (!
Op.isReg() || !
Op.isUse())
357 assert(
Op.getSubReg() == 0 &&
"Should have physical registers only");
358 bool Live = IsLive(
Op.getReg());
361 LPR.stepBackward(*
I);
372 bool Changed =
false;
374 Changed |= genMuxInBlock(
I);
379 return new HexagonGenMux();
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
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 tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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...
const MachineInstrBuilder & add(const MachineOperand &MO) const
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 clearKillInfo()
Clears kill flags on all operands.
void initializeHexagonGenMuxPass(PassRegistry &Registry)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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...
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Reg
All possible values of the reg field in the ModR/M byte.
reverse_iterator rbegin()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
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.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#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.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
unsigned getReg() const
getReg - Returns the register number.
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...
Properties which a MachineFunction may have at a given point in time.
const MCPhysReg * ImplicitUses