33 #define DEBUG_TYPE "si-mode-register" 35 STATISTIC(NumSetregInserted,
"Number of setreg of mode register inserted.");
47 Status(
unsigned NewMask,
unsigned NewMode) : Mask(NewMask), Mode(NewMode) {
60 return Status(Mask & ~newMask, Mode & ~newMask);
66 unsigned NewMask = (Mask & S.
Mask) & (Mode ^ ~S.
Mode);
67 unsigned NewMode = (Mode & NewMask);
68 return Status(NewMask, NewMode);
77 return (Mask == S.
Mask) && (Mode == S.
Mode);
87 return !(Mask & S.
Mask) || isCompatible(S);
122 std::vector<std::unique_ptr<BlockData>> BlockInfo;
123 std::queue<MachineBasicBlock *> Phase2List;
158 "Insert required mode register values",
false,
false)
174 case AMDGPU::V_INTERP_P1LL_F16:
175 case AMDGPU::V_INTERP_P1LV_F16:
176 case AMDGPU::V_INTERP_P2_F16:
181 return DefaultStatus;
194 while (InstrMode.
Mask) {
195 unsigned Offset = countTrailingZeros<unsigned>(InstrMode.
Mask);
196 unsigned Width = countTrailingOnes<unsigned>(InstrMode.
Mask >>
Offset);
198 BuildMI(MBB, MI, 0, TII->get(AMDGPU::S_SETREG_IMM32_B32))
229 auto NewInfo = std::make_unique<BlockData>();
236 bool RequirePending =
true;
239 Status InstrMode = getInstructionMode(MI, TII);
240 if ((MI.
getOpcode() == AMDGPU::S_SETREG_B32) ||
241 (MI.
getOpcode() == AMDGPU::S_SETREG_IMM32_B32)) {
258 if (InsertionPoint) {
259 insertSetreg(MBB, InsertionPoint, TII, IPChange.
delta(NewInfo->Change));
260 InsertionPoint =
nullptr;
265 if (MI.
getOpcode() == AMDGPU::S_SETREG_IMM32_B32) {
271 RequirePending =
false;
272 NewInfo->Change = NewInfo->Change.merge(Setreg);
274 NewInfo->Change = NewInfo->Change.mergeUnknown(Mask);
276 }
else if (!NewInfo->Change.isCompatible(InstrMode)) {
279 if (InsertionPoint) {
284 if (RequirePending) {
288 NewInfo->FirstInsertionPoint = InsertionPoint;
289 NewInfo->Require = NewInfo->Change;
290 RequirePending =
false;
292 insertSetreg(MBB, InsertionPoint, TII,
293 IPChange.
delta(NewInfo->Change));
294 IPChange = NewInfo->Change;
297 InsertionPoint = &
MI;
299 NewInfo->Change = NewInfo->Change.merge(InstrMode);
303 InsertionPoint = &
MI;
304 IPChange = NewInfo->Change;
305 NewInfo->Change = NewInfo->Change.
merge(InstrMode);
309 if (RequirePending) {
312 NewInfo->FirstInsertionPoint = InsertionPoint;
313 NewInfo->Require = NewInfo->Change;
314 }
else if (InsertionPoint) {
316 insertSetreg(MBB, InsertionPoint, TII, IPChange.
delta(NewInfo->Change));
318 NewInfo->Exit = NewInfo->Change;
319 BlockInfo[MBB.getNumber()] = std::move(NewInfo);
332 BlockInfo[ThisBlock]->Pred = DefaultStatus;
338 BlockInfo[ThisBlock]->Pred = BlockInfo[PB.
getNumber()]->Exit;
340 for (P = std::next(P); P !=
E; P = std::next(P)) {
342 BlockInfo[ThisBlock]->Pred = BlockInfo[ThisBlock]->Pred.intersect(BlockInfo[Pred->
getNumber()]->Exit);
345 Status TmpStatus = BlockInfo[ThisBlock]->Pred.
merge(BlockInfo[ThisBlock]->Change);
346 if (BlockInfo[ThisBlock]->Exit != TmpStatus) {
347 BlockInfo[ThisBlock]->Exit = TmpStatus;
352 S !=
E; S = std::next(S)) {
366 if (!BlockInfo[ThisBlock]->Pred.isCompatible(BlockInfo[ThisBlock]->Require)) {
367 Status Delta = BlockInfo[ThisBlock]->Pred.
delta(BlockInfo[ThisBlock]->Require);
368 if (BlockInfo[ThisBlock]->FirstInsertionPoint)
369 insertSetreg(MBB, BlockInfo[ThisBlock]->FirstInsertionPoint, TII, Delta);
385 processBlockPhase1(BB, TII);
391 Phase2List.push(&BB);
392 while (!Phase2List.empty()) {
393 processBlockPhase2(*Phase2List.front(),
TII);
400 processBlockPhase3(BB, TII);
404 return NumSetregInserted > 0;
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
MachineInstr & instr_front()
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
Status merge(const Status &S) const
const SIInstrInfo * getInstrInfo() const override
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
STATISTIC(NumSetregInserted, "Number of setreg of mode register inserted.")
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
#define FP_ROUND_ROUND_TO_ZERO
bool isCombinable(Status &S)
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool isCompatible(Status &S)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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")
MachineInstr * FirstInsertionPoint
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define FP_ROUND_MODE_DP(x)
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
FunctionPass * createSIModeRegisterPass()
std::vector< MachineBasicBlock * >::iterator pred_iterator
Status intersect(const Status &S) const
succ_iterator succ_begin()
pred_iterator pred_begin()
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
#define FP_ROUND_ROUND_TO_NEAREST
static bool usesFPDPRounding(const MachineInstr &MI)
bool operator!=(const Status &S) const
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Status delta(const Status &S) const
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
Status mergeUnknown(unsigned newMask)
Representation of each machine instruction.
Interface definition for SIInstrInfo.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Status(unsigned NewMask, unsigned NewMode)
LLVM Value Representation.
bool operator==(const Status &S) const
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
std::vector< MachineBasicBlock * >::iterator succ_iterator