Go to the documentation of this file.
36 #define DEBUG_TYPE "gen-pred"
50 struct RegisterSubReg {
54 RegisterSubReg(
unsigned r = 0,
unsigned s = 0) :
R(r),
S(
s) {}
67 struct PrintRegister {
80 return OS <<
printReg(PR.Reg.R, &PR.TRI, PR.Reg.S);
92 return "Hexagon generate predicate operations";
105 using SetOfReg = std::set<RegisterSubReg>;
106 using RegToRegMap = std::map<RegisterSubReg, RegisterSubReg>;
117 void processPredicateGPR(
const RegisterSubReg &
Reg);
118 unsigned getPredForm(
unsigned Opc);
120 bool isScalarCmp(
unsigned Opc);
121 bool isScalarPred(RegisterSubReg PredReg);
122 RegisterSubReg getPredRegFor(
const RegisterSubReg &
Reg);
132 "Hexagon generate predicate operations",
false,
false)
141 return RC == &Hexagon::PredRegsRegClass;
144 unsigned HexagonGenPredicate::getPredForm(
unsigned Opc) {
145 using namespace Hexagon;
184 static_assert(PHI == 0,
"Use different value for <none>");
188 bool HexagonGenPredicate::isConvertibleToPredForm(
const MachineInstr *
MI) {
189 unsigned Opc =
MI->getOpcode();
190 if (getPredForm(Opc) != 0)
198 case Hexagon::C2_cmpeqi:
199 case Hexagon::C4_cmpneqi:
200 if (
MI->getOperand(2).isImm() &&
MI->getOperand(2).getImm() == 0)
210 unsigned Opc =
MI.getOpcode();
212 case Hexagon::C2_tfrpr:
213 case TargetOpcode::COPY:
215 RegisterSubReg RD =
MI.getOperand(0);
216 if (RD.R.isVirtual())
225 void HexagonGenPredicate::processPredicateGPR(
const RegisterSubReg &
Reg) {
237 for (;
I !=
E; ++
I) {
239 if (isConvertibleToPredForm(UseI))
244 RegisterSubReg HexagonGenPredicate::getPredRegFor(
const RegisterSubReg &
Reg) {
249 RegToRegMap::iterator
F = G2P.find(
Reg);
257 if (Opc == Hexagon::C2_tfrpr || Opc == TargetOpcode::COPY) {
260 G2P.insert(std::make_pair(
Reg, PR));
272 if (isConvertibleToPredForm(DefI)) {
274 BuildMI(
B, std::next(DefIt),
DL,
TII->get(TargetOpcode::COPY), NewPR)
276 G2P.insert(std::make_pair(
Reg, RegisterSubReg(NewPR)));
279 return RegisterSubReg(NewPR);
285 bool HexagonGenPredicate::isScalarCmp(
unsigned Opc) {
287 case Hexagon::C2_cmpeq:
288 case Hexagon::C2_cmpgt:
289 case Hexagon::C2_cmpgtu:
290 case Hexagon::C2_cmpeqp:
291 case Hexagon::C2_cmpgtp:
292 case Hexagon::C2_cmpgtup:
293 case Hexagon::C2_cmpeqi:
294 case Hexagon::C2_cmpgti:
295 case Hexagon::C2_cmpgtui:
296 case Hexagon::C2_cmpgei:
297 case Hexagon::C2_cmpgeui:
298 case Hexagon::C4_cmpneqi:
299 case Hexagon::C4_cmpltei:
300 case Hexagon::C4_cmplteui:
301 case Hexagon::C4_cmpneq:
302 case Hexagon::C4_cmplte:
303 case Hexagon::C4_cmplteu:
304 case Hexagon::A4_cmpbeq:
305 case Hexagon::A4_cmpbeqi:
306 case Hexagon::A4_cmpbgtu:
307 case Hexagon::A4_cmpbgtui:
308 case Hexagon::A4_cmpbgt:
309 case Hexagon::A4_cmpbgti:
310 case Hexagon::A4_cmpheq:
311 case Hexagon::A4_cmphgt:
312 case Hexagon::A4_cmphgtu:
313 case Hexagon::A4_cmpheqi:
314 case Hexagon::A4_cmphgti:
315 case Hexagon::A4_cmphgtui:
321 bool HexagonGenPredicate::isScalarPred(RegisterSubReg PredReg) {
322 std::queue<RegisterSubReg> WorkQ;
325 while (!WorkQ.empty()) {
326 RegisterSubReg PR = WorkQ.front();
333 case TargetOpcode::COPY: {
340 case Hexagon::C2_and:
341 case Hexagon::C2_andn:
342 case Hexagon::C4_and_and:
343 case Hexagon::C4_and_andn:
344 case Hexagon::C4_and_or:
346 case Hexagon::C2_orn:
347 case Hexagon::C4_or_and:
348 case Hexagon::C4_or_andn:
349 case Hexagon::C4_or_or:
350 case Hexagon::C4_or_orn:
351 case Hexagon::C2_xor:
354 if (MO.isReg() && MO.isUse())
355 WorkQ.push(RegisterSubReg(MO.getReg()));
360 return isScalarCmp(DefOpc);
370 unsigned Opc =
MI->getOpcode();
371 assert(isConvertibleToPredForm(
MI));
372 unsigned NumOps =
MI->getNumOperands();
373 for (
unsigned i = 0;
i < NumOps; ++
i) {
377 RegisterSubReg
Reg(MO);
378 if (
Reg.S &&
Reg.S != Hexagon::isub_lo)
380 if (!PredGPRs.count(
Reg))
387 unsigned NewOpc = getPredForm(Opc);
391 case Hexagon::C2_cmpeqi:
392 NewOpc = Hexagon::C2_not;
394 case Hexagon::C4_cmpneqi:
395 NewOpc = TargetOpcode::COPY;
404 RegisterSubReg PR = getPredRegFor(
MI->getOperand(1));
405 if (!isScalarPred(PR))
415 RegisterSubReg OutR(Op0);
425 for (
unsigned i = 1;
i < NumOps; ++
i) {
426 RegisterSubReg GPR =
MI->getOperand(
i);
427 RegisterSubReg Pred = getPredRegFor(GPR);
428 MIB.
addReg(Pred.R, 0, Pred.S);
437 .
addReg(NewPR.R, 0, NewPR.S);
439 MI->eraseFromParent();
445 RegisterSubReg
R(NewOutR);
447 processPredicateGPR(R);
455 bool Changed =
false;
470 if (
MI.getOpcode() != TargetOpcode::COPY)
472 RegisterSubReg DR =
MI.getOperand(0);
473 RegisterSubReg SR =
MI.getOperand(1);
474 if (!DR.R.isVirtual())
476 if (!SR.R.isVirtual())
482 assert(!DR.S && !SR.S &&
"Unexpected subregister");
490 MI->eraseFromParent();
506 bool Changed =
false;
507 collectPredicateGPR(MF);
508 for (
const RegisterSubReg &R : PredGPRs)
509 processPredicateGPR(R);
514 VectOfInst Processed,
Copy;
518 bool Done = convertToPredForm(
MI);
520 Processed.insert(
MI);
527 return Processed.count(
MI);
529 PUsers.remove_if(Done);
532 Changed |= eliminatePredCopies(MF);
537 return new HexagonGenPredicate();
This is an optimization pass for GlobalISel generic memory operations.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isPredReg(MCRegisterInfo const &MRI, unsigned Reg)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Reg
All possible values of the reg field in the ModR/M byte.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define LLVM_ATTRIBUTE_UNUSED
unsigned const TargetRegisterInfo * TRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
INITIALIZE_PASS_BEGIN(HexagonGenPredicate, "hexagon-gen-pred", "Hexagon generate predicate operations", false, false) INITIALIZE_PASS_END(HexagonGenPredicate
hexagon gen Hexagon generate predicate operations
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static unsigned getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const MachineOperand & getOperand(unsigned i) const
Represent the analysis usage information of a pass.
const HexagonInstrInfo * TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineOperand class - Representation of each machine instruction operand.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
defusechain_iterator< true, false, false, true, false, false > use_iterator
use_iterator/use_begin/use_end - Walk all uses of the specified register.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Representation of each machine instruction.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
multiplies can be turned into SHL s
bool operator<(int64_t V1, const APSInt &V2)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator==(uint64_t V1, const APInt &V2)
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
StringRef - Represent a constant reference to a string, i.e.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
use_iterator use_begin(Register RegNo) const
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
const MachineBasicBlock * getParent() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned const MachineRegisterInfo * MRI
Wrapper class representing virtual and physical registers.
void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
Function & getFunction()
Return the LLVM function that this machine code represents.
static use_iterator use_end()
A global registry used in conjunction with static constructors to make pluggable components (like tar...
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
FunctionPass class - This class is used to implement most global optimizations.
AnalysisUsage & addRequired()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
A vector that has set insertion semantics.
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
iterator_range< mop_iterator > operands()
FunctionPass * createHexagonGenPredicate()
void initializeHexagonGenPredicatePass(PassRegistry &Registry)