mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Support intrinsic calls (although no particular intrinsics are supported yet).
Support indirect calls. Support returning a float value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14223 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -554,6 +554,16 @@ void V8ISel::visitStoreInst(StoreInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void V8ISel::visitCallInst(CallInst &I) {
|
void V8ISel::visitCallInst(CallInst &I) {
|
||||||
|
MachineInstr *TheCall;
|
||||||
|
// Is it an intrinsic function call?
|
||||||
|
if (Function *F = I.getCalledFunction()) {
|
||||||
|
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
|
||||||
|
visitIntrinsicCall(ID, I); // Special intrinsics are not handled here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal with args
|
||||||
assert (I.getNumOperands () < 8
|
assert (I.getNumOperands () < 8
|
||||||
&& "Can't handle pushing excess call args on the stack yet");
|
&& "Can't handle pushing excess call args on the stack yet");
|
||||||
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
||||||
@@ -566,19 +576,27 @@ void V8ISel::visitCallInst(CallInst &I) {
|
|||||||
.addReg (ArgReg);
|
.addReg (ArgReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (I.getCalledFunction() && "don't know what to do with NULL function!");
|
// Emit call instruction
|
||||||
BuildMI (BB, V8::CALL, 1).addGlobalAddress(I.getCalledFunction (), true);
|
if (Function *F = I.getCalledFunction ()) {
|
||||||
|
BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true);
|
||||||
|
} else { // Emit an indirect call...
|
||||||
|
unsigned Reg = getReg (I.getCalledValue ());
|
||||||
|
BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal w/ return value: schlep it over into the destination register
|
||||||
if (I.getType () == Type::VoidTy)
|
if (I.getType () == Type::VoidTy)
|
||||||
return;
|
return;
|
||||||
unsigned DestReg = getReg (I);
|
unsigned DestReg = getReg (I);
|
||||||
// Deal w/ return value
|
|
||||||
switch (getClass (I.getType ())) {
|
switch (getClass (I.getType ())) {
|
||||||
case cByte:
|
case cByte:
|
||||||
case cShort:
|
case cShort:
|
||||||
case cInt:
|
case cInt:
|
||||||
// Schlep it over into the destination register
|
|
||||||
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
||||||
break;
|
break;
|
||||||
|
case cFloat:
|
||||||
|
BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Return type of call instruction not handled: " << I;
|
std::cerr << "Return type of call instruction not handled: " << I;
|
||||||
abort ();
|
abort ();
|
||||||
|
@@ -554,6 +554,16 @@ void V8ISel::visitStoreInst(StoreInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void V8ISel::visitCallInst(CallInst &I) {
|
void V8ISel::visitCallInst(CallInst &I) {
|
||||||
|
MachineInstr *TheCall;
|
||||||
|
// Is it an intrinsic function call?
|
||||||
|
if (Function *F = I.getCalledFunction()) {
|
||||||
|
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
|
||||||
|
visitIntrinsicCall(ID, I); // Special intrinsics are not handled here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal with args
|
||||||
assert (I.getNumOperands () < 8
|
assert (I.getNumOperands () < 8
|
||||||
&& "Can't handle pushing excess call args on the stack yet");
|
&& "Can't handle pushing excess call args on the stack yet");
|
||||||
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
||||||
@@ -566,19 +576,27 @@ void V8ISel::visitCallInst(CallInst &I) {
|
|||||||
.addReg (ArgReg);
|
.addReg (ArgReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (I.getCalledFunction() && "don't know what to do with NULL function!");
|
// Emit call instruction
|
||||||
BuildMI (BB, V8::CALL, 1).addGlobalAddress(I.getCalledFunction (), true);
|
if (Function *F = I.getCalledFunction ()) {
|
||||||
|
BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true);
|
||||||
|
} else { // Emit an indirect call...
|
||||||
|
unsigned Reg = getReg (I.getCalledValue ());
|
||||||
|
BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal w/ return value: schlep it over into the destination register
|
||||||
if (I.getType () == Type::VoidTy)
|
if (I.getType () == Type::VoidTy)
|
||||||
return;
|
return;
|
||||||
unsigned DestReg = getReg (I);
|
unsigned DestReg = getReg (I);
|
||||||
// Deal w/ return value
|
|
||||||
switch (getClass (I.getType ())) {
|
switch (getClass (I.getType ())) {
|
||||||
case cByte:
|
case cByte:
|
||||||
case cShort:
|
case cShort:
|
||||||
case cInt:
|
case cInt:
|
||||||
// Schlep it over into the destination register
|
|
||||||
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
||||||
break;
|
break;
|
||||||
|
case cFloat:
|
||||||
|
BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Return type of call instruction not handled: " << I;
|
std::cerr << "Return type of call instruction not handled: " << I;
|
||||||
abort ();
|
abort ();
|
||||||
|
@@ -554,6 +554,16 @@ void V8ISel::visitStoreInst(StoreInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void V8ISel::visitCallInst(CallInst &I) {
|
void V8ISel::visitCallInst(CallInst &I) {
|
||||||
|
MachineInstr *TheCall;
|
||||||
|
// Is it an intrinsic function call?
|
||||||
|
if (Function *F = I.getCalledFunction()) {
|
||||||
|
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
|
||||||
|
visitIntrinsicCall(ID, I); // Special intrinsics are not handled here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal with args
|
||||||
assert (I.getNumOperands () < 8
|
assert (I.getNumOperands () < 8
|
||||||
&& "Can't handle pushing excess call args on the stack yet");
|
&& "Can't handle pushing excess call args on the stack yet");
|
||||||
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
||||||
@@ -566,19 +576,27 @@ void V8ISel::visitCallInst(CallInst &I) {
|
|||||||
.addReg (ArgReg);
|
.addReg (ArgReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (I.getCalledFunction() && "don't know what to do with NULL function!");
|
// Emit call instruction
|
||||||
BuildMI (BB, V8::CALL, 1).addGlobalAddress(I.getCalledFunction (), true);
|
if (Function *F = I.getCalledFunction ()) {
|
||||||
|
BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true);
|
||||||
|
} else { // Emit an indirect call...
|
||||||
|
unsigned Reg = getReg (I.getCalledValue ());
|
||||||
|
BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal w/ return value: schlep it over into the destination register
|
||||||
if (I.getType () == Type::VoidTy)
|
if (I.getType () == Type::VoidTy)
|
||||||
return;
|
return;
|
||||||
unsigned DestReg = getReg (I);
|
unsigned DestReg = getReg (I);
|
||||||
// Deal w/ return value
|
|
||||||
switch (getClass (I.getType ())) {
|
switch (getClass (I.getType ())) {
|
||||||
case cByte:
|
case cByte:
|
||||||
case cShort:
|
case cShort:
|
||||||
case cInt:
|
case cInt:
|
||||||
// Schlep it over into the destination register
|
|
||||||
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
||||||
break;
|
break;
|
||||||
|
case cFloat:
|
||||||
|
BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Return type of call instruction not handled: " << I;
|
std::cerr << "Return type of call instruction not handled: " << I;
|
||||||
abort ();
|
abort ();
|
||||||
|
@@ -554,6 +554,16 @@ void V8ISel::visitStoreInst(StoreInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void V8ISel::visitCallInst(CallInst &I) {
|
void V8ISel::visitCallInst(CallInst &I) {
|
||||||
|
MachineInstr *TheCall;
|
||||||
|
// Is it an intrinsic function call?
|
||||||
|
if (Function *F = I.getCalledFunction()) {
|
||||||
|
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
|
||||||
|
visitIntrinsicCall(ID, I); // Special intrinsics are not handled here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal with args
|
||||||
assert (I.getNumOperands () < 8
|
assert (I.getNumOperands () < 8
|
||||||
&& "Can't handle pushing excess call args on the stack yet");
|
&& "Can't handle pushing excess call args on the stack yet");
|
||||||
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
||||||
@@ -566,19 +576,27 @@ void V8ISel::visitCallInst(CallInst &I) {
|
|||||||
.addReg (ArgReg);
|
.addReg (ArgReg);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (I.getCalledFunction() && "don't know what to do with NULL function!");
|
// Emit call instruction
|
||||||
BuildMI (BB, V8::CALL, 1).addGlobalAddress(I.getCalledFunction (), true);
|
if (Function *F = I.getCalledFunction ()) {
|
||||||
|
BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true);
|
||||||
|
} else { // Emit an indirect call...
|
||||||
|
unsigned Reg = getReg (I.getCalledValue ());
|
||||||
|
BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deal w/ return value: schlep it over into the destination register
|
||||||
if (I.getType () == Type::VoidTy)
|
if (I.getType () == Type::VoidTy)
|
||||||
return;
|
return;
|
||||||
unsigned DestReg = getReg (I);
|
unsigned DestReg = getReg (I);
|
||||||
// Deal w/ return value
|
|
||||||
switch (getClass (I.getType ())) {
|
switch (getClass (I.getType ())) {
|
||||||
case cByte:
|
case cByte:
|
||||||
case cShort:
|
case cShort:
|
||||||
case cInt:
|
case cInt:
|
||||||
// Schlep it over into the destination register
|
|
||||||
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
||||||
break;
|
break;
|
||||||
|
case cFloat:
|
||||||
|
BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Return type of call instruction not handled: " << I;
|
std::cerr << "Return type of call instruction not handled: " << I;
|
||||||
abort ();
|
abort ();
|
||||||
|
Reference in New Issue
Block a user