@@ -29,8 +29,7 @@ static const Function *getCalledFunction(const MachineInstr &MI) {
2929  }
3030  return  nullptr ;
3131}
32- //  TODO: make it static once Operation gets rid of std::variant.
33- std::string llvm::getInstName (const  MachineInstr *MI) {
32+ static  std::string getInstName (const  MachineInstr *MI) {
3433  const  MachineFunction *MF = MI->getParent ()->getParent ();
3534  const  TargetInstrInfo *TII = MF->getSubtarget ().getInstrInfo ();
3635  return  TII->getName (MI->getOpcode ()).str ();
@@ -48,6 +47,24 @@ std::string TemporarySlot::toString() const {
4847  OS << " TMP["   << getInstName (MI) << " , "   << std::to_string (Index) + " ]"  ;
4948  return  std::string (S.str ());
5049}
50+ std::string Operation::toString () const  {
51+   if  (isFunctionCall ()) {
52+     const  MachineOperand *Callee = MI->explicit_uses ().begin ();
53+     return  Callee->getGlobal ()->getName ().str ();
54+   }
55+   if  (isBuiltinCall ())
56+     return  getInstName (MI);
57+ 
58+   assert (isAssignment ());
59+   SmallString<128 > S;
60+   raw_svector_ostream OS (S);
61+   OS << " Assignment("  ;
62+   for  (const  auto  *S : Output)
63+     OS << printReg (cast<VariableSlot>(S)->getReg (), nullptr , 0 , nullptr )
64+        << " , "  ;
65+   OS << " )"  ;
66+   return  std::string (S);
67+ }
5168
5269EVMStackModel::EVMStackModel (MachineFunction &MF, const  LiveIntervals &LIS)
5370    : MF(MF), LIS(LIS) {
@@ -128,22 +145,18 @@ void EVMStackModel::createOperation(MachineInstr &MI,
128145    return ;
129146  case  EVM::FCALL: {
130147    Stack Input;
131-     bool  IsNoReturn = false ;
132148    for  (const  MachineOperand &MO : MI.operands ()) {
133149      if  (MO.isGlobal ()) {
134-         const  auto  *Func = dyn_cast<Function>(MO.getGlobal ());
135-         assert (Func);
136-         IsNoReturn = Func->hasFnAttribute (Attribute::NoReturn);
137-         if  (!IsNoReturn)
150+         const  auto  *Func = cast<Function>(MO.getGlobal ());
151+         if  (!Func->hasFnAttribute (Attribute::NoReturn))
138152          Input.push_back (getFunctionCallReturnLabelSlot (&MI));
139153        break ;
140154      }
141155    }
142156    const  Stack &Tmp = getInstrInput (MI);
143157    Input.insert (Input.end (), Tmp.begin (), Tmp.end ());
144-     size_t  NumArgs = Input.size () - (IsNoReturn ? 0  : 1 );
145-     Ops.emplace_back (Operation{std::move (Input), getInstrOutput (MI),
146-                                FunctionCall{&MI, NumArgs}});
158+     Ops.emplace_back (Operation::FunctionCall, std::move (Input),
159+                      getInstrOutput (MI), &MI);
147160  } break ;
148161  case  EVM::RET:
149162  case  EVM::JUMP:
@@ -165,21 +178,19 @@ void EVMStackModel::createOperation(MachineInstr &MI,
165178      return ;
166179  } break ;
167180  default : {
168-     Ops.emplace_back (
169-         Operation{ getInstrInput (MI),  getInstrOutput (MI), BuiltinCall{ &MI}} );
181+     Ops.emplace_back (Operation::BuiltinCall,  getInstrInput (MI), 
182+                       getInstrOutput (MI), &MI);
170183  } break ;
171184  }
172185
173186  //  Create CFG::Assignment object for the MI.
174187  Stack Input, Output;
175-   SmallVector<VariableSlot *> Variables;
176188  switch  (MI.getOpcode ()) {
177189  case  EVM::CONST_I256: {
178190    const  Register DefReg = MI.getOperand (0 ).getReg ();
179191    const  APInt Imm = MI.getOperand (1 ).getCImm ()->getValue ();
180192    Input.push_back (getLiteralSlot (std::move (Imm)));
181193    Output.push_back (getVariableSlot (DefReg));
182-     Variables.push_back (getVariableSlot (DefReg));
183194  } break ;
184195  case  EVM::DATASIZE:
185196  case  EVM::DATAOFFSET:
@@ -188,15 +199,13 @@ void EVMStackModel::createOperation(MachineInstr &MI,
188199    MCSymbol *Sym = MI.getOperand (1 ).getMCSymbol ();
189200    Input.push_back (getSymbolSlot (Sym, &MI));
190201    Output.push_back (getVariableSlot (DefReg));
191-     Variables.push_back (getVariableSlot (DefReg));
192202  } break ;
193203  case  EVM::COPY_I256: {
194204    //  Copy instruction corresponds to the assignment operator, so
195205    //  we do not need to create intermediate TmpSlots.
196206    Input = getInstrInput (MI);
197207    const  Register DefReg = MI.getOperand (0 ).getReg ();
198208    Output.push_back (getVariableSlot (DefReg));
199-     Variables.push_back (getVariableSlot (DefReg));
200209  } break ;
201210  default : {
202211    unsigned  ArgsNumber = 0 ;
@@ -205,15 +214,14 @@ void EVMStackModel::createOperation(MachineInstr &MI,
205214      const  Register Reg = MO.getReg ();
206215      Input.push_back (getTemporarySlot (&MI, ArgsNumber++));
207216      Output.push_back (getVariableSlot (Reg));
208-       Variables.push_back (getVariableSlot (Reg));
209217    }
210218  } break ;
211219  }
212220  //  We don't need an assignment part of the instructions that do not write
213221  //  results.
214222  if  (!Input.empty () || !Output.empty ())
215-     Ops.emplace_back (Operation{ std::move (Input), std::move (Output),
216-                                Assignment{ std::move (Variables)}} );
223+     Ops.emplace_back (Operation::Assignment,  std::move (Input), std::move (Output),
224+                      &MI );
217225}
218226
219227Stack EVMStackModel::getReturnArguments (const  MachineInstr &MI) const  {
0 commit comments