Skip to content

Commit

Permalink
Drop hiddenstack intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Skvortsov committed Mar 17, 2020
1 parent 8aeb1b0 commit 60c4d3c
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 68 deletions.
4 changes: 0 additions & 4 deletions llvm/include/llvm/IR/IntrinsicsTVM.td
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,4 @@ let TargetPrefix = "tvm" in {
foreach i = 1-255 in
def int_tvm_unpackfirst#i : GCCBuiltin<"__builtin_tvm_unpackfirst"#i>,
Intrinsic<!listsplat(llvm_i257_ty, i), [llvm_TVMTuple_ty], [IntrNoMem]>;

def int_tvm_hiddenstack :
GCCBuiltin<"__builtin_tvm_hiddenstack">,
Intrinsic<[llvm_i257_ty], [llvm_i257_ty], [IntrNoMem]>;
}
3 changes: 0 additions & 3 deletions llvm/lib/Target/TVM/TVMInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ defm PU2XC : SI<(ins stack_op:$i, stack_op:$j, stack_op:$k),
defm PUSH3 : SI<(ins stack_op:$i, stack_op:$j, stack_op:$k),
"PUSH3\t$i, $j, $k", 0x547>;

let isPseudo=1 in
def HIDDENSTACK : NI<(outs I257:$dst), (ins uimm8:$src), [(set I257:$dst, (int_tvm_hiddenstack uimm8:$src))], 1>;

defm POP : SI<(ins stack_op:$dst), "POP\t$dst", 0x30>;
defm DROP : SI<(ins), "DROP", 0x30>;
defm BLKDROP : SI<(ins uimm8:$sz), "BLKDROP\t$sz", 0x5F0>;
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/TVM/TVMStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ Stack& Stack::operator += (const StackFixup::Change &change) {
std::swap(Data[v.i], Data[v.j]);
},
[this](StackFixup::pushI v){ Data.push_front(Data[v.i]); },
[ ](StackFixup::pushHidden v){ },
[this](StackFixup::pushUndef){
Data.push_front(StackVreg(TVMFunctionInfo::UnusedReg));
},
Expand Down
9 changes: 0 additions & 9 deletions llvm/lib/Target/TVM/TVMStackFixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,6 @@ StackFixup StackFixup::DiffForArgs(const Stack &From, const MIArgs &Args,
return rv;
}

StackFixup StackFixup::DiffForHiddenStack(const Stack &Src, size_t Element,
unsigned OutRegister) {
Stack CurrentStack(Src);
StackFixup rv;
rv(CurrentStack += rv(pushHidden(Src.size() + Element, OutRegister)));
return rv;
}

void StackFixup::apply(Stack &stack) const {
for (auto p : Changes)
stack += p.first;
Expand Down Expand Up @@ -597,7 +589,6 @@ void StackFixup::printElem(raw_ostream &OS, const Change &change) const {
[&](xchgTop v) { OS << "xchg s(" << v.i << ")"; },
[&](xchg v) { OS << "xchg s(" << v.i << "), s(" << v.j << ")"; },
[&](pushI v) { OS << "push s(" << v.i << ")"; },
[&](pushHidden v) { OS << "push s(" << v.i << ")"; },
[&](pushUndef) { OS << "zero"; },
[&](blkswap v) { OS << "blkswap " << v.deepSz << ", " << v.topSz; },
[&](roll v) {
Expand Down
13 changes: 2 additions & 11 deletions llvm/lib/Target/TVM/TVMStackFixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class StackFixup {
static StackFixup DiffForArgs(const Stack &Src, const MIArgs &Args,
bool IsCommutative = false);

static StackFixup DiffForHiddenStack(const Stack &Src, size_t Element,
unsigned OutRegister);

void apply(Stack &stack) const;

// Remove one copy of this elem
Expand Down Expand Up @@ -109,12 +106,6 @@ class StackFixup {
}
unsigned i;
};
struct pushHidden : pushI {
explicit pushHidden(unsigned i, unsigned reg, bool checkLimits = true)
: pushI(i, checkLimits), reg(reg) {}
unsigned i;
unsigned reg;
};
struct dup : pushI {
dup() : pushI(0) {}
};
Expand Down Expand Up @@ -251,8 +242,8 @@ class StackFixup {
: tripleChange(true, true, false, i, j, k) {}
};
using Change =
std::variant<drop, nip, xchgTop, xchg, pushI, pushHidden, pushUndef,
blkswap, blkdrop, roll, reverse, doubleChange, tripleChange>;
std::variant<drop, nip, xchgTop, xchg, pushI, pushUndef, blkswap, blkdrop,
roll, reverse, doubleChange, tripleChange>;
using ChangesVec = std::vector<std::pair<Change, std::string>>;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Expand Down
9 changes: 0 additions & 9 deletions llvm/lib/Target/TVM/TVMStackModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,6 @@ StackFixup TVMStackModel::prepareStackFor(MachineInstr &MI,
if (MI.isImplicitDef())
return {};

if (MI.getOpcode() == TVM::HIDDENSTACK) {
auto Result = MI.getOperand(0);
auto Operand = MI.getOperand(1);
assert(Result.isReg() && Operand.isCImm() && "Unexpected instruction format");
return StackFixup::DiffForHiddenStack(StackBefore,
Operand.getCImm()->getZExtValue(),
Result.getReg());
}

auto *MBB = MI.getParent();

#ifndef NDEBUG
Expand Down
28 changes: 0 additions & 28 deletions llvm/test/CodeGen/TVM/hiddenstack.ll

This file was deleted.

1 change: 0 additions & 1 deletion llvm/tools/clang/include/clang/Basic/BuiltinsTVM.def
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,5 @@ BUILTIN(__builtin_tvm_unpackfirst252, "T252Tt", "nc")
BUILTIN(__builtin_tvm_unpackfirst253, "T253Tt", "nc")
BUILTIN(__builtin_tvm_unpackfirst254, "T254Tt", "nc")
BUILTIN(__builtin_tvm_unpackfirst255, "T255Tt", "nc")
BUILTIN(__builtin_tvm_hiddenstack, "WiWi", "nc")

#undef BUILTIN
8 changes: 8 additions & 0 deletions stdlib/stdlib_c.tvm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ tvm_sender_pubkey:

PUSH s1
SETGLOB 7
PUSH s2
SETGLOB 8
PUSH s3
SETGLOB 9

PUSHCONT {
CALL $load_macro$
Expand Down Expand Up @@ -135,6 +139,10 @@ tvm_sender_pubkey:

PUSH s1
SETGLOB 7
PUSH s2
SETGLOB 8
PUSH s3
SETGLOB 9

PUSHCONT {
CALL $load_macro$
Expand Down
4 changes: 2 additions & 2 deletions stdlib/ton-sdk/smart-contract-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ SmartContractInfo get_SmartContractInfo () {
#include "smart-contract-info.inc"

unsigned contract_balance() {
return __builtin_tvm_hiddenstack(4);
return __builtin_tvm_getglobal(9);
}

unsigned message_balance() {
return __builtin_tvm_hiddenstack(3);
return __builtin_tvm_getglobal(8);
}

0 comments on commit 60c4d3c

Please sign in to comment.