Skip to content

[SPIR-V][Codegen] Add isPhi bit to MCInstrDesc/MIR definitions #110019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,19 @@ class MachineInstr
return getOpcode() == TargetOpcode::JUMP_TABLE_DEBUG_INFO;
}

bool isPHI() const {
return getOpcode() == TargetOpcode::PHI ||
getOpcode() == TargetOpcode::G_PHI;
bool isPHI() const { return getDesc().isPhi(); }

unsigned getIndexFirstPHIPair() const {
assert(isPHI());

if (getOpcode() == TargetOpcode::G_PHI || getOpcode() == TargetOpcode::PHI)
return 1;
// The only other instruction marked as PHI node is OpPhi, in the SPIR-V
// backend. The only difference is the [reg, BB] pairs starts at index 2,
// not 1.
return 2;
}

bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
bool isInlineAsm() const {
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/MC/MCInstrDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ enum Flag {
Trap,
VariadicOpsAreDefs,
Authenticated,
Phi,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bits are precious and it would be best to avoid spending one on this

};
} // namespace MCID

Expand Down Expand Up @@ -292,6 +293,10 @@ class MCInstrDesc {
/// unconditional branches and return instructions.
bool isBarrier() const { return Flags & (1ULL << MCID::Barrier); }

/// Returns true if this instruction acts as a PHI node.
/// Not all PHI operands need to dominates the definition.
bool isPhi() const { return Flags & (1ULL << MCID::Phi); }

/// Returns true if this instruction part of the terminator for
/// a basic block. Typically this is things like return and branch
/// instructions.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Target/GenericOpcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def G_PHI : GenericInstruction {
let OutOperandList = (outs type0:$dst);
let InOperandList = (ins variable_ops);
let hasSideEffects = false;
let isPhi = true;
}

def G_FRAME_INDEX : GenericInstruction {
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ class Instruction : InstructionEncoding {
bit isBitcast = false; // Is this instruction a bitcast instruction?
bit isSelect = false; // Is this instruction a select instruction?
bit isBarrier = false; // Can control flow fall through this instruction?
bit isPhi = false; // Is this instruction a phi instruction?
bit isCall = false; // Is this instruction a call instruction?
bit isAdd = false; // Is this instruction an add instruction?
bit isTrap = false; // Is this instruction a trap instruction?
Expand Down Expand Up @@ -1174,6 +1175,7 @@ def PHI : StandardPseudoInstruction {
let InOperandList = (ins variable_ops);
let AsmString = "PHINODE";
let hasSideEffects = false;
let isPhi = true;
}
def INLINEASM : StandardPseudoInstruction {
let OutOperandList = (outs);
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/MachineVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,8 @@ void MachineVerifier::calcRegsRequired() {

// Handle the PHI node.
for (const MachineInstr &MI : MBB.phis()) {
for (unsigned i = 1, e = MI.getNumOperands(); i != e; i += 2) {
for (unsigned i = MI.getIndexFirstPHIPair(), e = MI.getNumOperands();
i != e; i += 2) {
// Skip those Operands which are undef regs or not regs.
if (!MI.getOperand(i).isReg() || !MI.getOperand(i).readsReg())
continue;
Expand Down Expand Up @@ -3268,7 +3269,8 @@ void MachineVerifier::checkPHIOps(const MachineBasicBlock &MBB) {
if (!DefReg.isVirtual())
report("Expected first PHI operand to be a virtual register", &MODef, 0);

for (unsigned I = 1, E = Phi.getNumOperands(); I != E; I += 2) {
for (unsigned I = Phi.getIndexFirstPHIPair(), E = Phi.getNumOperands();
I != E; I += 2) {
const MachineOperand &MO0 = Phi.getOperand(I);
if (!MO0.isReg()) {
report("Expected PHI operand to be a register", &MO0, I);
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Target/SPIRV/SPIRVInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,10 @@ def OpFwidthCoarse: UnOp<"OpFwidthCoarse", 215>;

// 3.42.17 Control-Flow Instructions

def OpPhi: Op<245, (outs ID:$res), (ins TYPE:$type, ID:$var0, ID:$block0, variable_ops),
"$res = OpPhi $type $var0 $block0">;
let isPhi = 1 in {
def OpPhi: Op<245, (outs ID:$res), (ins TYPE:$type, ID:$var0, ID:$block0, variable_ops),
"$res = OpPhi $type $var0 $block0">;
}
def OpLoopMerge: Op<246, (outs), (ins unknown:$merge, unknown:$continue, LoopControl:$lc, variable_ops),
"OpLoopMerge $merge $continue $lc">;
def OpSelectionMerge: Op<247, (outs), (ins unknown:$merge, SelectionControl:$sc),
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/Common/CodeGenInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ CodeGenInstruction::CodeGenInstruction(const Record *R)
FastISelShouldIgnore = R->getValueAsBit("FastISelShouldIgnore");
variadicOpsAreDefs = R->getValueAsBit("variadicOpsAreDefs");
isAuthenticated = R->getValueAsBit("isAuthenticated");
isPhi = R->getValueAsBit("isPhi");

bool Unset;
mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/Common/CodeGenInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class CodeGenInstruction {
bool hasChain_Inferred : 1;
bool variadicOpsAreDefs : 1;
bool isAuthenticated : 1;
bool isPhi : 1;

std::string DeprecatedReason;
bool HasComplexDeprecationPredicate;
Expand Down
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,8 @@ void InstrInfoEmitter::emitRecord(
OS << "|(1ULL<<MCID::Select)";
if (Inst.isBarrier)
OS << "|(1ULL<<MCID::Barrier)";
if (Inst.isPhi)
OS << "|(1ULL<<MCID::Phi)";
if (Inst.hasDelaySlot)
OS << "|(1ULL<<MCID::DelaySlot)";
if (Inst.isCall)
Expand Down
Loading