Skip to content

Commit

Permalink
Drop PUSH_GLOBAL_ADDRESS, PUSHCONT_LABEL
Browse files Browse the repository at this point in the history
Michael Skvortsov committed Mar 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 08d5901 commit bd9790e
Showing 5 changed files with 5 additions and 72 deletions.
21 changes: 0 additions & 21 deletions llvm/lib/Target/TVM/InstPrinter/TVMInstPrinter.cpp
Original file line number Diff line number Diff line change
@@ -32,25 +32,6 @@ using namespace llvm;

void TVMInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
StringRef Annot, const MCSubtargetInfo &STI) {
// TODO: A hack, we have the same logic in AsmPrinter, but it's not triggered
// for instructions in TVM::PUSHCONT_MBB. Need to find a better solution.
switch (MI->getOpcode()) {
case TVM::TO_TUPLE_COPY_S:
case TVM::TO_SLICE_COPY_S:
case TVM::TO_BUILDER_COPY_S:
case TVM::TO_CELL_COPY_S:
case TVM::FROM_TUPLE_COPY_S:
case TVM::FROM_SLICE_COPY_S:
case TVM::FROM_BUILDER_COPY_S:
case TVM::FROM_CELL_COPY_S:
case TVM::REG_TO_REG_COPY_S:
case TVM::PUSH_GLOBAL_ADDRESS_S:
case TVM::FALLTHROUGH_RETURN:
return;
default:
break;
}

{
std::string Str;
raw_string_ostream OStr(Str);
@@ -80,8 +61,6 @@ void TVMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
if (const auto *Expr = dyn_cast<TVMImmStringMCExpr>(Op.getExpr())) {
O << Expr->getString();
} else {
assert((Info.OperandType == TVM::OPERAND_FUNCTION) &&
"Unimplemented expression type");
// The actual label address is not known at the moment of
// code generation; to simplify further linking, the label name
// is surrounded with dollar signs ($callee$).
1 change: 0 additions & 1 deletion llvm/lib/Target/TVM/TVMAsmPrinter.cpp
Original file line number Diff line number Diff line change
@@ -116,7 +116,6 @@ void TVMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
case TVM::FROM_SLICE_COPY_S:
case TVM::FROM_BUILDER_COPY_S:
case TVM::FROM_CELL_COPY_S:
case TVM::PUSH_GLOBAL_ADDRESS_S:
break;
case TVM::FALLTHROUGH_RETURN:
if (isVerbose()) {
13 changes: 2 additions & 11 deletions llvm/lib/Target/TVM/TVMControlFlowInstrInfo.td
Original file line number Diff line number Diff line change
@@ -119,11 +119,6 @@ defm CONST_U257 : I<(outs I257:$res), (ins UImm257:$uimm),
"PUSHINT\t$res, $uimm", "PUSHINT\t$uimm", 0x82>;
}

// There are no labels in TVM, so this functionality is emulated
// using ```PUSHINT label; CALL 1```
defm PUSHCONT_LABEL: NRI<(outs), (ins function_op:$callee), [],
"PUSHINT\t$callee", 0x82>;

defm PUSHC : I<(outs I257 : $root), (ins uimm8 : $regno),
(outs), (ins uimm8 : $regno),
[(set I257 : $root, (int_tvm_getreg uimm8 : $regno))],
@@ -211,11 +206,7 @@ def : Pat<(store Cell : $value, I257 : $addr),
def : Pat<(truncstore I257 : $value, I257 : $addr),
(CALL_STORE_INT I257 : $addr, I257 : $value)>;

defm PUSH_GLOBAL_ADDRESS : I<(outs I257 : $res), (ins I257 : $in),
(outs), (ins I257 : $in),
[], "PUSHINT\t$res, $in", "PUSHINT\t$in", 0x82>;

def : Pat<(i257 (TVMGlobalAddressWrapper tglobaladdr : $addr)),
(PUSH_GLOBAL_ADDRESS tglobaladdr : $addr)>;
(CONST_I257 tglobaladdr : $addr)>;
def : Pat<(i257 (TVMGlobalAddressWrapper texternalsym : $addr)),
(PUSH_GLOBAL_ADDRESS texternalsym : $addr)>;
(CONST_I257 texternalsym : $addr)>;
2 changes: 0 additions & 2 deletions llvm/lib/Target/TVM/TVMRematerialize.cpp
Original file line number Diff line number Diff line change
@@ -62,8 +62,6 @@ FunctionPass *llvm::createTVMRematerialize() { return new TVMRematerialize(); }
// Test whether Def is safe and profitable to rematerialize.
static bool ShouldRematerialize(const MachineInstr &Def, AliasAnalysis &AA,
const TVMInstrInfo *TII) {
if (Def.getOpcode() == TVM::PUSH_GLOBAL_ADDRESS)
return true;
return Def.isAsCheapAsAMove() && TII->isTriviallyReMaterializable(Def, &AA);
}

40 changes: 3 additions & 37 deletions llvm/lib/Target/TVM/TVMStackModel.cpp
Original file line number Diff line number Diff line change
@@ -637,38 +637,6 @@ void TVMStackModel::rewriteToSForm(MachineInstr &MI,
});

if (NewOpcode >= 0) {
// Global operands and external symbols are represented using GlobalAddress
// and ExternalSymbol DAG nodes. Because of convention of instruction
// operands ordering global addresses and external symbols must be placed
// first before instruction. To avoid custom logic of stack reordering for
// global/external operands, we transfrom all GlobalAddress and
// ExternalSymbol nodes to the chain of PUSH_GLOBAL_ADDRESS(_S) instruction
// and TargetGlobalAddress / TargetExternalSymbol nodes. So by default only
// PUSH_GLOBAL_ADDRESS instruction may have global/external operand. This
// instruction has definition with address which can be normally processed
// using stack model for all further uses of the address result.
// There are may be exceptions when the transformation to
// PUSH_GLOBAL_ADDRESS is not needed (for example, for instructions with
// immediate string operands like LOGSTR). For such cases operands will be
// passed up to lowering to MCInst where they can be customly processed.

// add global addresses before the command
// TODO: continuation must be modelled in the stack then.
for (unsigned I = 0; I < NumGlobals; I++) {
const auto &Op = MI.getOperand(NumDefs + I);
assert((Op.isGlobal() || Op.isSymbol()) &&
"Expected GlobalAddress/ExternalSymbol");
if (NewOpcode == TVM::PUSH_GLOBAL_ADDRESS_S) {
if (Op.isGlobal()) {
BuildMI(&MI, TII->get(TVM::PUSHCONT_LABEL))
.addGlobalAddress(Op.getGlobal(), Op.getOffset());
} else {
BuildMI(&MI, TII->get(TVM::PUSHCONT_LABEL))
.addExternalSymbol(Op.getSymbolName(), Op.getOffset());
}
}
}

if (MI.getOpcode() == TVM::IFELSE) {
auto Then = MI.getOperand(1).getMBB();
unsigned ThenID = TheStack.size() + BBInfo[Then].getID() + 1;
@@ -701,11 +669,9 @@ void TVMStackModel::rewriteToSForm(MachineInstr &MI,

MachineInstrBuilder MIB = BuildMI(&MI, TII->get(NewOpcode));

if (NewOpcode != TVM::PUSH_GLOBAL_ADDRESS_S) {
for (unsigned I = 0; I < NumGlobals; I++) {
const auto &Op = MI.getOperand(NumDefs + I);
MIB->addOperand(Op);
}
for (unsigned I = 0; I < NumGlobals; I++) {
const auto &Op = MI.getOperand(NumDefs + I);
MIB->addOperand(Op);
}

for (unsigned I = 0; I < NumImms; I++) {

0 comments on commit bd9790e

Please sign in to comment.