Skip to content

Commit 78931e2

Browse files
author
Michael Skvortsov
committed
Support a large number of BBs
1 parent c7feb0d commit 78931e2

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

llvm/lib/Target/TVM/TVMAsmPrinter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ void TVMAsmPrinter::EmitFunctionBodyEnd() {
176176
}
177177
}
178178

179-
OutStreamer->EmitRawText(" PUSH s" + Twine(Blocks + Arguments - 1));
179+
unsigned Entry = Blocks + Arguments - 1;
180+
if (Entry < 256) {
181+
OutStreamer->EmitRawText(" PUSH s" + Twine(Entry));
182+
} else {
183+
OutStreamer->EmitRawText(" PUSHINT " + Twine(Entry));
184+
OutStreamer->EmitRawText(" PUSHX");
185+
}
180186
OutStreamer->EmitRawText(" EXECUTE");
181187

182188
if (ReturnValues > 0) {

llvm/lib/Target/TVM/TVMInstrInfo.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ defm NOP : I<(outs), (ins), (outs), (ins), [(int_tvm_nop)], "NOP", "NOP", 0x00>;
198198

199199
let mayLoad = 1, isAsCheapAsAMove = 1 in {
200200
defm PUSH : SI<(ins stack_op:$local), "PUSH\t$local", 0x20>;
201+
defm PUSHX : SI<(ins), "PUSHX", 0x60>;
201202
defm SWAP : SI<(ins), "SWAP", 0x01>;
202203
defm XCHG_TOP : SI<(ins stack_op:$src), "XCHG\ts0, $src", 0x01>;
203204
defm XCHG_TOP_DEEP : SI<(ins stack_op:$src), "XCHG\ts0, $src", 0x11>;

llvm/lib/Target/TVM/TVMStackModel.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,19 +651,41 @@ void TVMStackModel::rewriteToSForm(MachineInstr &MI,
651651
MFI->addStackModelComment(MIB.getInstr(), Then->getName());
652652
MFI->addStackModelComment(MIB.getInstr(), Else->getName());
653653
} else {
654-
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
655-
TII->get(TVM::PUSH)).addImm(ThenID);
654+
if (ThenID < 256) {
655+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
656+
TII->get(TVM::PUSH)).addImm(ThenID);
657+
} else {
658+
BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
659+
TII->get(TVM::CONST_I257_S)).addImm(ThenID);
660+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
661+
TII->get(TVM::PUSHX));
662+
}
656663
MFI->addStackModelComment(MIB.getInstr(), Then->getName());
657-
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
658-
TII->get(TVM::PUSH)).addImm(ElseID + 1);
664+
if (ElseID < 255) {
665+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
666+
TII->get(TVM::PUSH)).addImm(ElseID + 1);
667+
} else {
668+
BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
669+
TII->get(TVM::CONST_I257_S)).addImm(ElseID + 1);
670+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
671+
TII->get(TVM::PUSHX));
672+
}
659673
MFI->addStackModelComment(MIB.getInstr(), Else->getName());
660674
}
661675
} else if (MI.getOpcode() == TVM::JMPX) {
662676
auto Dest = MI.getOperand(0).getMBB();
663677
unsigned DestID = TheStack.size() + BBInfo[Dest].getID();
664678

665-
auto MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
666-
TII->get(TVM::PUSH)).addImm(DestID);
679+
MachineInstrBuilder MIB;
680+
if (DestID < 256) {
681+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
682+
TII->get(TVM::PUSH)).addImm(DestID);
683+
} else {
684+
BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
685+
TII->get(TVM::CONST_I257_S)).addImm(DestID);
686+
MIB = BuildMI(*MI.getParent(), MI, MI.getDebugLoc(),
687+
TII->get(TVM::PUSHX));
688+
}
667689
MFI->addStackModelComment(MIB.getInstr(), Dest->getName());
668690
}
669691

0 commit comments

Comments
 (0)