// If this operand is a constant, emit the code to copy the constant into
// the register here...
//
- if (Constant *C = dyn_cast<Constant>(V))
+ if (Constant *C = dyn_cast<Constant>(V)) {
copyConstantToRegister(C, Reg);
+ } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+ // Move the address of the global into the register
+ BuildMI(BB, X86::MOVir32, 1, Reg).addReg(GV);
+ } else if (Argument *A = dyn_cast<Argument>(V)) {
+ std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
+ } else {
+ assert(0 && "Don't know how to handle a value of this type!");
+ }
return Reg;
}
{
// Push the arguments on the stack in reverse order, as specified by
// the ABI.
- for (unsigned i = CI.getNumOperands (); i >= 1; --i)
+ for (unsigned i = CI.getNumOperands()-1; i >= 1; --i)
{
Value *v = CI.getOperand (i);
- unsigned argReg = getReg (v);
switch (getClass (v->getType ()))
{
case cByte:
case cShort:
+ // Promote V to 32 bits wide, and move the result into EAX,
+ // then push EAX.
promote32 (X86::EAX, v);
BuildMI (BB, X86::PUSHr32, 1).addReg (X86::EAX);
break;
case cInt:
- case cFloat:
- BuildMI (BB, X86::PUSHr32, 1).addReg (argReg);
+ case cFloat: {
+ unsigned Reg = getReg(v);
+ BuildMI (BB, X86::PUSHr32, 1).addReg(Reg);
break;
+ }
default:
- // FIXME
+ // FIXME: long/ulong/double args not handled.
visitInstruction (CI);
break;
}
//the former is that the register allocator could use any register it wants,
//but for now this obviously doesn't matter. :)
-// if target type is bool
-// Emit Compare
-// Emit Set-if-not-zero
+ const Type *targetType = CI.getType ();
+ Value *operand = CI.getOperand (0);
+ unsigned int operandReg = getReg (operand);
+ const Type *sourceType = operand->getType ();
+ unsigned int destReg = getReg (CI);
+
+ // cast to bool:
+ if (targetType == Type::BoolTy) {
+ // Emit Compare
+ BuildMI (BB, X86::CMPri8, 2).addReg (operandReg).addZImm (0);
+ // Emit Set-if-not-zero
+ BuildMI (BB, X86::SETNEr, 1, destReg);
+ return;
+ }
// if size of target type == size of source type
// Emit Mov reg(target) <- reg(source)