15 #define DEBUG_TYPE "cseinfo" 24 "Analysis containing CSE Info",
false,
true)
40 case TargetOpcode::G_ADD:
41 case TargetOpcode::G_AND:
42 case TargetOpcode::G_ASHR:
43 case TargetOpcode::G_LSHR:
44 case TargetOpcode::G_MUL:
45 case TargetOpcode::G_OR:
46 case TargetOpcode::G_SHL:
47 case TargetOpcode::G_SUB:
48 case TargetOpcode::G_XOR:
49 case TargetOpcode::G_UDIV:
50 case TargetOpcode::G_SDIV:
51 case TargetOpcode::G_UREM:
52 case TargetOpcode::G_SREM:
53 case TargetOpcode::G_CONSTANT:
54 case TargetOpcode::G_FCONSTANT:
55 case TargetOpcode::G_ZEXT:
56 case TargetOpcode::G_SEXT:
57 case TargetOpcode::G_ANYEXT:
58 case TargetOpcode::G_UNMERGE_VALUES:
59 case TargetOpcode::G_TRUNC:
60 case TargetOpcode::G_PTR_ADD:
67 return Opc == TargetOpcode::G_CONSTANT;
70 std::unique_ptr<CSEConfigBase>
72 std::unique_ptr<CSEConfigBase> Config;
74 Config = std::make_unique<CSEConfigConstantOnly>();
76 Config = std::make_unique<CSEConfigFull>();
90 bool GISelCSEInfo::isUniqueMachineInstValid(
100 bool Removed = CSEMap.RemoveNode(UMI);
102 assert(Removed &&
"Invalidation called on invalid UMI");
109 auto *Node = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
111 if (!isUniqueMachineInstValid(*Node)) {
112 invalidateUniqueMachineInstr(Node);
116 if (Node->MI->getParent() != MBB)
123 handleRecordedInsts();
127 CSEMap.InsertNode(UMI, InsertPos);
129 MaybeNewNode = CSEMap.GetOrInsertNode(UMI);
130 if (MaybeNewNode != UMI) {
134 assert(InstrMapping.count(UMI->MI) == 0 &&
135 "This instruction should not be in the map");
136 InstrMapping[UMI->MI] = MaybeNewNode;
140 assert(shouldCSE(MI->
getOpcode()) &&
"Trying to CSE an unsupported Node");
145 void GISelCSEInfo::insertInstr(
MachineInstr *MI,
void *InsertPos) {
148 TemporaryInsts.remove(MI);
149 auto *Node = getUniqueInstrForMI(MI);
150 insertNode(Node, InsertPos);
156 handleRecordedInsts();
157 if (
auto *Inst = getNodeIfExists(ID, MBB, InsertPos)) {
166 if (OpcodeHitTable.count(Opc))
167 OpcodeHitTable[Opc] += 1;
169 OpcodeHitTable[Opc] = 1;
176 TemporaryInsts.insert(MI);
183 auto *UMI = InstrMapping.lookup(MI);
187 invalidateUniqueMachineInstr(UMI);
188 InstrMapping.erase(MI);
195 insertNode(UMI,
nullptr);
204 if (
auto *UMI = InstrMapping.lookup(MI)) {
205 invalidateUniqueMachineInstr(UMI);
206 InstrMapping.erase(MI);
208 TemporaryInsts.remove(MI);
212 while (!TemporaryInsts.empty()) {
213 auto *MI = TemporaryInsts.pop_back_val();
214 handleRecordedInst(MI);
222 assert(CSEOpt.get() &&
"CSEConfig not set");
223 return CSEOpt->shouldCSEOpc(Opc);
237 for (
auto &MBB : MF) {
252 InstrMapping.clear();
253 UniqueInstrAllocator.Reset();
254 TemporaryInsts.clear();
259 OpcodeHitTable.clear();
266 dbgs() <<
"CSEInfo::CSE Hit for Opc " << It.first <<
" : " << It.second
277 addNodeIDMachineOperand(
Op);
290 uint64_t Val = Ty.getUniqueRAWLLTData();
343 addNodeIDRegNum(Reg);
344 LLT Ty =
MRI.getType(Reg);
346 addNodeIDRegType(Ty);
347 auto *RB =
MRI.getRegBankOrNull(Reg);
349 addNodeIDRegType(RB);
350 auto *RC =
MRI.getRegClassOrNull(Reg);
352 addNodeIDRegType(RC);
354 }
else if (MO.
isImm())
371 if (!AlreadyComputed || Recompute) {
372 Info.setCSEConfig(std::move(CSEOpt));
374 AlreadyComputed =
true;
void changedInstr(MachineInstr &MI) override
This instruction was mutated in some way.
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GISelCSEAnalysisWrapperPass()
This class represents lattice values for constants.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const GISelInstProfileBuilder & addNodeIDImmediate(int64_t Imm) const
void initializeGISelCSEAnalysisWrapperPassPass(PassRegistry &)
The actual analysis pass wrapper.
block Block Frequency true
void setMF(MachineFunction &MF)
iterator_range< mop_iterator > operands()
const GISelInstProfileBuilder & addNodeIDRegNum(unsigned Reg) const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const GISelInstProfileBuilder & addNodeIDFlag(unsigned Flag) const
void changingInstr(MachineInstr &MI) override
This instruction is about to be mutated in some way.
const GISelInstProfileBuilder & addNodeIDOpcode(unsigned Opc) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const ConstantFP * getFPImm() const
separate const offset from Split GEPs to a variadic base and a constant offset for better CSE
void AddInteger(signed I)
virtual bool shouldCSEOpc(unsigned Opc) override
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const GISelInstProfileBuilder & addNodeIDRegType(const LLT &Ty) const
void erasingInstr(MachineInstr &MI) override
An instruction is about to be erased.
void setMF(MachineFunction &MFunc)
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
bool shouldCSE(unsigned Opc) const
void handleRemoveInst(MachineInstr *MI)
Remove this inst from the CSE map.
Analysis containing CSE Info
virtual bool shouldCSEOpc(unsigned Opc) override
Flag
These should be considered private to the implementation of the MCInstrDesc class.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
std::unique_ptr< CSEConfigBase > getStandardCSEConfigForOpt(CodeGenOpt::Level Level)
INITIALIZE_PASS_BEGIN(GISelCSEAnalysisWrapperPass, DEBUG_TYPE, "Analysis containing CSE Info", false, true) INITIALIZE_PASS_END(GISelCSEAnalysisWrapperPass
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
const GISelInstProfileBuilder & addNodeID(const MachineInstr *MI) const
Represent the analysis usage information of a pass.
void countOpcodeHit(unsigned Opc)
GISelCSEInfo & get(std::unique_ptr< CSEConfigBase > CSEOpt, bool ReCompute=false)
Takes a CSEConfigBase object that defines what opcodes get CSEd.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void handleRecordedInst(MachineInstr *MI)
Use this callback to inform CSE about a newly fully created instruction.
void recordNewInstruction(MachineInstr *MI)
Records a newly created inst in a list and lazily insert it to the CSEMap.
MachineOperand class - Representation of each machine instruction operand.
void analyze(MachineFunction &MF)
This class implements the register bank concept.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void setPreservesAll()
Set by analyses that do not transform their input at all.
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const GISelInstProfileBuilder & addNodeIDMBB(const MachineBasicBlock *MBB) const
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
uint16_t getFlags() const
Return the MI flags bitvector.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel...
const GISelInstProfileBuilder & addNodeIDMachineOperand(const MachineOperand &MO) const
void createdInstr(MachineInstr &MI) override
An instruction has been created and inserted into the function.
A class that wraps MachineInstrs and derives from FoldingSetNode in order to be uniqued in a CSEMap...
Register getReg() const
getReg - Returns the register number.
void handleRecordedInsts()
Use this callback to insert all the recorded instructions.
const ConstantInt * getCImm() const
Wrapper class representing virtual and physical registers.
unsigned getPredicate() const