mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	InstSelectSimple.cpp: Give promote32 a comment. Add initial
implementation of getReg() for arguments. MachineCodeEmitter.cpp: Fix using EBP with index, scale and no displacement (whew!) due to Chris. Printer.cpp: Fix printing out index and scale in memory references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4998 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -114,9 +114,10 @@ namespace {
 | 
			
		||||
      abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void promote32(unsigned targetReg, Value *V);
 | 
			
		||||
    /// promote32 - Make a value 32-bits wide, and put it somewhere.
 | 
			
		||||
    void promote32 (const unsigned targetReg, Value *v);
 | 
			
		||||
    
 | 
			
		||||
    // emitGEPOperation - Common code shared between visitGetElemenPtrInst and
 | 
			
		||||
    // emitGEPOperation - Common code shared between visitGetElementPtrInst and
 | 
			
		||||
    // constant expression GEP support.
 | 
			
		||||
    //
 | 
			
		||||
    void emitGEPOperation(Value *Src, User::op_iterator IdxBegin,
 | 
			
		||||
@@ -156,7 +157,25 @@ namespace {
 | 
			
		||||
        // 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";
 | 
			
		||||
	// Find the position of the argument in the argument list.
 | 
			
		||||
	const Function *f = F->getFunction ();
 | 
			
		||||
	int counter = 0, argPosition = -1;
 | 
			
		||||
	for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
 | 
			
		||||
	     ai != ae; ++ai) {
 | 
			
		||||
	  ++counter;
 | 
			
		||||
	  if (&(*ai) == A) {
 | 
			
		||||
	    argPosition = counter;
 | 
			
		||||
	  }
 | 
			
		||||
	}
 | 
			
		||||
	assert (argPosition != -1
 | 
			
		||||
		&& "Argument not found in current function's argument list");
 | 
			
		||||
	// Load it out of the stack frame at EBP + 4*argPosition.
 | 
			
		||||
	// (First, load Reg with argPosition, then load Reg with DWORD
 | 
			
		||||
	// PTR [EBP + 4*Reg].)
 | 
			
		||||
	BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
 | 
			
		||||
	BuildMI (BB, X86::MOVmr32, 4,
 | 
			
		||||
		 Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
 | 
			
		||||
        // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return Reg;
 | 
			
		||||
 
 | 
			
		||||
@@ -157,17 +157,19 @@ void Emitter::emitMemModRMByte(const MachineInstr &MI,
 | 
			
		||||
    assert(IndexReg.getReg() != X86::ESP && "Cannot use ESP as index reg!");
 | 
			
		||||
 | 
			
		||||
    bool ForceDisp32 = false;
 | 
			
		||||
    bool ForceDisp8  = false;
 | 
			
		||||
    if (BaseReg.getReg() == 0) {
 | 
			
		||||
      // If there is no base register, we emit the special case SIB byte with
 | 
			
		||||
      // MOD=0, BASE=5, to JUST get the index, scale, and displacement.
 | 
			
		||||
      MCE.emitByte(ModRMByte(0, RegOpcodeField, 4));
 | 
			
		||||
      ForceDisp32 = true;
 | 
			
		||||
    } else if (Disp.getImmedValue() == 0) {
 | 
			
		||||
    } else if (Disp.getImmedValue() == 0 && BaseReg.getReg() != X86::EBP) {
 | 
			
		||||
      // Emit no displacement ModR/M byte
 | 
			
		||||
      MCE.emitByte(ModRMByte(0, RegOpcodeField, 4));
 | 
			
		||||
    } else if (isDisp8(Disp.getImmedValue())) {
 | 
			
		||||
      // Emit the disp8 encoding...
 | 
			
		||||
      MCE.emitByte(ModRMByte(1, RegOpcodeField, 4));
 | 
			
		||||
      ForceDisp8 = true;           // Make sure to force 8 bit disp if Base=EBP
 | 
			
		||||
    } else {
 | 
			
		||||
      // Emit the normal disp32 encoding...
 | 
			
		||||
      MCE.emitByte(ModRMByte(2, RegOpcodeField, 4));
 | 
			
		||||
@@ -189,7 +191,7 @@ void Emitter::emitMemModRMByte(const MachineInstr &MI,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Do we need to output a displacement?
 | 
			
		||||
    if (Disp.getImmedValue() != 0 || ForceDisp32) {
 | 
			
		||||
    if (Disp.getImmedValue() != 0 || ForceDisp32 || ForceDisp8) {
 | 
			
		||||
      if (!ForceDisp32 && isDisp8(Disp.getImmedValue()))
 | 
			
		||||
        emitConstant(Disp.getImmedValue(), 1);
 | 
			
		||||
      else
 | 
			
		||||
 
 | 
			
		||||
@@ -148,8 +148,8 @@ static void printMemReference(std::ostream &O, const MachineInstr *MI,
 | 
			
		||||
 | 
			
		||||
  if (IndexReg.getReg()) {
 | 
			
		||||
    if (NeedPlus) O << " + ";
 | 
			
		||||
    if (IndexReg.getImmedValue() != 1)
 | 
			
		||||
      O << IndexReg.getImmedValue() << "*";
 | 
			
		||||
    if (Scale.getImmedValue() != 1)
 | 
			
		||||
      O << Scale.getImmedValue() << "*";
 | 
			
		||||
    printOp(O, IndexReg, RI);
 | 
			
		||||
    NeedPlus = true;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -148,8 +148,8 @@ static void printMemReference(std::ostream &O, const MachineInstr *MI,
 | 
			
		||||
 | 
			
		||||
  if (IndexReg.getReg()) {
 | 
			
		||||
    if (NeedPlus) O << " + ";
 | 
			
		||||
    if (IndexReg.getImmedValue() != 1)
 | 
			
		||||
      O << IndexReg.getImmedValue() << "*";
 | 
			
		||||
    if (Scale.getImmedValue() != 1)
 | 
			
		||||
      O << Scale.getImmedValue() << "*";
 | 
			
		||||
    printOp(O, IndexReg, RI);
 | 
			
		||||
    NeedPlus = true;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -157,17 +157,19 @@ void Emitter::emitMemModRMByte(const MachineInstr &MI,
 | 
			
		||||
    assert(IndexReg.getReg() != X86::ESP && "Cannot use ESP as index reg!");
 | 
			
		||||
 | 
			
		||||
    bool ForceDisp32 = false;
 | 
			
		||||
    bool ForceDisp8  = false;
 | 
			
		||||
    if (BaseReg.getReg() == 0) {
 | 
			
		||||
      // If there is no base register, we emit the special case SIB byte with
 | 
			
		||||
      // MOD=0, BASE=5, to JUST get the index, scale, and displacement.
 | 
			
		||||
      MCE.emitByte(ModRMByte(0, RegOpcodeField, 4));
 | 
			
		||||
      ForceDisp32 = true;
 | 
			
		||||
    } else if (Disp.getImmedValue() == 0) {
 | 
			
		||||
    } else if (Disp.getImmedValue() == 0 && BaseReg.getReg() != X86::EBP) {
 | 
			
		||||
      // Emit no displacement ModR/M byte
 | 
			
		||||
      MCE.emitByte(ModRMByte(0, RegOpcodeField, 4));
 | 
			
		||||
    } else if (isDisp8(Disp.getImmedValue())) {
 | 
			
		||||
      // Emit the disp8 encoding...
 | 
			
		||||
      MCE.emitByte(ModRMByte(1, RegOpcodeField, 4));
 | 
			
		||||
      ForceDisp8 = true;           // Make sure to force 8 bit disp if Base=EBP
 | 
			
		||||
    } else {
 | 
			
		||||
      // Emit the normal disp32 encoding...
 | 
			
		||||
      MCE.emitByte(ModRMByte(2, RegOpcodeField, 4));
 | 
			
		||||
@@ -189,7 +191,7 @@ void Emitter::emitMemModRMByte(const MachineInstr &MI,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Do we need to output a displacement?
 | 
			
		||||
    if (Disp.getImmedValue() != 0 || ForceDisp32) {
 | 
			
		||||
    if (Disp.getImmedValue() != 0 || ForceDisp32 || ForceDisp8) {
 | 
			
		||||
      if (!ForceDisp32 && isDisp8(Disp.getImmedValue()))
 | 
			
		||||
        emitConstant(Disp.getImmedValue(), 1);
 | 
			
		||||
      else
 | 
			
		||||
 
 | 
			
		||||
@@ -114,9 +114,10 @@ namespace {
 | 
			
		||||
      abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void promote32(unsigned targetReg, Value *V);
 | 
			
		||||
    /// promote32 - Make a value 32-bits wide, and put it somewhere.
 | 
			
		||||
    void promote32 (const unsigned targetReg, Value *v);
 | 
			
		||||
    
 | 
			
		||||
    // emitGEPOperation - Common code shared between visitGetElemenPtrInst and
 | 
			
		||||
    // emitGEPOperation - Common code shared between visitGetElementPtrInst and
 | 
			
		||||
    // constant expression GEP support.
 | 
			
		||||
    //
 | 
			
		||||
    void emitGEPOperation(Value *Src, User::op_iterator IdxBegin,
 | 
			
		||||
@@ -156,7 +157,25 @@ namespace {
 | 
			
		||||
        // 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";
 | 
			
		||||
	// Find the position of the argument in the argument list.
 | 
			
		||||
	const Function *f = F->getFunction ();
 | 
			
		||||
	int counter = 0, argPosition = -1;
 | 
			
		||||
	for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
 | 
			
		||||
	     ai != ae; ++ai) {
 | 
			
		||||
	  ++counter;
 | 
			
		||||
	  if (&(*ai) == A) {
 | 
			
		||||
	    argPosition = counter;
 | 
			
		||||
	  }
 | 
			
		||||
	}
 | 
			
		||||
	assert (argPosition != -1
 | 
			
		||||
		&& "Argument not found in current function's argument list");
 | 
			
		||||
	// Load it out of the stack frame at EBP + 4*argPosition.
 | 
			
		||||
	// (First, load Reg with argPosition, then load Reg with DWORD
 | 
			
		||||
	// PTR [EBP + 4*Reg].)
 | 
			
		||||
	BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
 | 
			
		||||
	BuildMI (BB, X86::MOVmr32, 4,
 | 
			
		||||
		 Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
 | 
			
		||||
        // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      return Reg;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user