fix function calls
This commit is contained in:
parent
1927db30f9
commit
6e5ef10cc0
@ -25,6 +25,7 @@ add_llvm_target(FootCodeGen
|
||||
FootAsmPrinter.cpp
|
||||
FootISelDAGToDAG.cpp
|
||||
FootRemovePseudoInstructions.cpp
|
||||
FootMachineFunctionInfo.cpp
|
||||
|
||||
LINK_COMPONENTS
|
||||
FootDesc
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "FootFrameLowering.h"
|
||||
|
||||
#include "FootMachineFunctionInfo.h"
|
||||
#include "MCTargetDesc/FootMCTargetDesc.h"
|
||||
|
||||
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||
@ -17,7 +18,12 @@ void FootFrameLowering::emitPrologue(MachineFunction &MF,
|
||||
MachineFrameInfo &MFI = MF.getFrameInfo();
|
||||
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
||||
|
||||
int FrameIndex = MFI.CreateFixedObject(4, -4, true);
|
||||
int FI = MF.getInfo<FootMachineFunctionInfo>()->getReturnAddressFrameIndex();
|
||||
|
||||
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::BWOR_I_D_M_A))
|
||||
.addFrameIndex(FI)
|
||||
.addReg(Foot::RRA)
|
||||
.addImm(0);
|
||||
|
||||
unsigned NumBytes = MFI.getStackSize();
|
||||
|
||||
@ -36,11 +42,6 @@ void FootFrameLowering::emitPrologue(MachineFunction &MF,
|
||||
.addImm(NumBytes);
|
||||
}
|
||||
}
|
||||
|
||||
BuildMI(MBB, MBB.begin(), DebugLoc(), TII->get(Foot::BWOR_I_D_M_A))
|
||||
.addFrameIndex(FrameIndex)
|
||||
.addReg(Foot::RRA)
|
||||
.addImm(0);
|
||||
}
|
||||
|
||||
void FootFrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
@ -50,27 +51,32 @@ void FootFrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
|
||||
unsigned NumBytes = MFI.getStackSize();
|
||||
|
||||
int FI = MF.getInfo<FootMachineFunctionInfo>()->getReturnAddressFrameIndex();
|
||||
BuildMI(MBB, MBB.getFirstTerminator(), DebugLoc(), TII->get(Foot::BWOR_D_I_M_A))
|
||||
.addReg(Foot::RRA)
|
||||
.addFrameIndex(FI)
|
||||
.addImm(0);
|
||||
|
||||
if (NumBytes > 0) {
|
||||
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
||||
if (NumBytes < (1 << 5)) {
|
||||
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_M_A), Foot::RSP)
|
||||
BuildMI(MBB, MBB.getFirstTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_M_A), Foot::RSP)
|
||||
.addReg(Foot::RSP)
|
||||
.addImm(NumBytes);
|
||||
}
|
||||
else {
|
||||
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_D_A), Foot::RSP)
|
||||
BuildMI(MBB, MBB.getFirstTerminator(), DebugLoc(), TII->get(Foot::ADDI_D_D_D_A), Foot::RSP)
|
||||
.addReg(Foot::RSP)
|
||||
.addReg(Foot::R27);
|
||||
BuildMI(MBB, MBB.getFirstInstrTerminator(), DebugLoc(), TII->get(Foot::CNST_D_A), Foot::R27)
|
||||
BuildMI(MBB, MBB.getFirstTerminator(), DebugLoc(), TII->get(Foot::CNST_D_A), Foot::R27)
|
||||
.addImm(NumBytes);
|
||||
}
|
||||
}
|
||||
|
||||
const auto& I = MBB.getFirstTerminator();
|
||||
BuildMI(MBB, I, I->getDebugLoc(), TII->get(Foot::BWOR_D_I_M_A))
|
||||
BuildMI(MBB, MBB.getFirstTerminator(), I->getDebugLoc(), TII->get(Foot::COPY_D_D_A))
|
||||
.addReg(Foot::RPC)
|
||||
.addFrameIndex(0)
|
||||
.addImm(0);
|
||||
.addReg(Foot::RRA);
|
||||
|
||||
MBB.erase(I);
|
||||
}
|
||||
@ -109,3 +115,14 @@ StackOffset FootFrameLowering::getFrameIndexReference(const MachineFunction &MF,
|
||||
|
||||
return StackOffset::getFixed(Offset);
|
||||
}
|
||||
|
||||
void FootFrameLowering::determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
|
||||
RegScavenger *RS) const {
|
||||
TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
|
||||
|
||||
MachineFrameInfo &MFI = MF.getFrameInfo();
|
||||
|
||||
int RetAddrFI = MFI.CreateStackObject(4, Align(4), false);
|
||||
|
||||
MF.getInfo<FootMachineFunctionInfo>()->setReturnAddressFrameIndex(RetAddrFI);
|
||||
}
|
||||
|
||||
@ -24,6 +24,9 @@ public:
|
||||
|
||||
StackOffset getFrameIndexReference(const MachineFunction &MF, int FrameIndex,
|
||||
Register &FrameReg) const override;
|
||||
|
||||
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
|
||||
RegScavenger *RS) const override;
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
@ -47,7 +47,6 @@ private:
|
||||
void SelectBrG(SDNode *N, SDLoc &Loc);
|
||||
void SelectBrNE(SDNode *N, SDLoc &Loc);
|
||||
void SelectCmpChain(SDNode *N, SDLoc &Loc);
|
||||
void SelectCmp(SDNode *N, SDLoc &Loc);
|
||||
void SelectSelectCC(SDNode *N, SDLoc &Loc);
|
||||
|
||||
void Select(SDNode *N) override;
|
||||
@ -804,18 +803,20 @@ void FootDAGToDAGISel::SelectCmpChain(SDNode *N, SDLoc &Loc) {
|
||||
SDValue LHS = N->getOperand(1);
|
||||
SDValue RHS = N->getOperand(2);
|
||||
|
||||
int LHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
int RHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
|
||||
if (ConstantSDNode *CN = DoesConstantFitImm(LHS.getNode())) {
|
||||
LHS = CurDAG->getTargetConstant(CN->getSExtValue(), Loc, MVT::i32);
|
||||
LHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
// since LHS and RHS are swapped, set RHS mode
|
||||
RHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
}
|
||||
|
||||
int RHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
int LHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
|
||||
if (ConstantSDNode *CN = DoesConstantFitImm(RHS.getNode())) {
|
||||
RHS = CurDAG->getTargetConstant(CN->getSExtValue(), Loc, MVT::i32);
|
||||
RHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
// since LHS and RHS are swapped, set LHS mode
|
||||
LHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
}
|
||||
|
||||
unsigned Opc = Foot::CMPR_D_D_A;
|
||||
@ -838,44 +839,6 @@ void FootDAGToDAGISel::SelectCmpChain(SDNode *N, SDLoc &Loc) {
|
||||
ReplaceNode(N, NewNode);
|
||||
}
|
||||
|
||||
void FootDAGToDAGISel::SelectCmp(SDNode *N, SDLoc &Loc) {
|
||||
SDValue LHS = N->getOperand(0);
|
||||
SDValue RHS = N->getOperand(1);
|
||||
|
||||
int LHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
|
||||
if (ConstantSDNode *CN = DoesConstantFitImm(LHS.getNode())) {
|
||||
LHS = CurDAG->getTargetConstant(CN->getSExtValue(), Loc, MVT::i32);
|
||||
LHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
}
|
||||
|
||||
int RHS_AddrMode = FOOT_ADDRMODE_D;
|
||||
|
||||
if (ConstantSDNode *CN = DoesConstantFitImm(RHS.getNode())) {
|
||||
RHS = CurDAG->getTargetConstant(CN->getSExtValue(), Loc, MVT::i32);
|
||||
RHS_AddrMode = FOOT_ADDRMODE_M;
|
||||
}
|
||||
|
||||
unsigned Opc = Foot::CMPR_D_D_A;
|
||||
|
||||
switch (LHS_AddrMode + FOOT_ADDRMODE_COUNT * RHS_AddrMode) {
|
||||
case FOOT_ADDRMODE_D + FOOT_ADDRMODE_COUNT * FOOT_ADDRMODE_M:
|
||||
Opc = Foot::CMPR_D_M_A;
|
||||
break;
|
||||
case FOOT_ADDRMODE_M + FOOT_ADDRMODE_COUNT * FOOT_ADDRMODE_D:
|
||||
Opc = Foot::CMPR_M_D_A;
|
||||
break;
|
||||
case FOOT_ADDRMODE_M + FOOT_ADDRMODE_COUNT * FOOT_ADDRMODE_M:
|
||||
Opc = Foot::CMPR_M_M_A;
|
||||
break;
|
||||
}
|
||||
|
||||
// swap LHS and RHS, as dst is 'b' operand, so it should be first
|
||||
SDNode *NewNode = CurDAG->getMachineNode(Opc, Loc, MVT::Other, {RHS, LHS});
|
||||
|
||||
ReplaceNode(N, NewNode);
|
||||
}
|
||||
|
||||
void FootDAGToDAGISel::SelectBr(SDNode *N, SDLoc &Loc) {
|
||||
SDValue PC = CurDAG->getRegister(Foot::RPC, MVT::i32);
|
||||
SDValue Chain = N->getOperand(0);
|
||||
@ -1106,9 +1069,6 @@ void FootDAGToDAGISel::Select(SDNode *N) {
|
||||
case FootISD::CMP_CHAIN:
|
||||
SelectCmpChain(N, DL);
|
||||
break;
|
||||
case FootISD::CMP:
|
||||
SelectCmp(N, DL);
|
||||
break;
|
||||
case FootISD::BR_L:
|
||||
SelectBrL(N, DL);
|
||||
break;
|
||||
|
||||
@ -42,8 +42,6 @@ const char *FootTargetLowering::getTargetNodeName(unsigned Opcode) const {
|
||||
break;
|
||||
case FootISD::CALL:
|
||||
return "FootISD::CALL";
|
||||
case FootISD::CMP:
|
||||
return "FootISD::CMP";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ namespace FootISD {
|
||||
enum NodeType : unsigned {
|
||||
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
||||
CALL,
|
||||
CMP,
|
||||
CMP_CHAIN,
|
||||
BR_L,
|
||||
BR_LE,
|
||||
|
||||
8
llvm/lib/Target/Foot/FootMachineFunctionInfo.cpp
Normal file
8
llvm/lib/Target/Foot/FootMachineFunctionInfo.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "FootMachineFunctionInfo.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
MachineFunctionInfo *FootMachineFunctionInfo::clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
|
||||
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) const {
|
||||
return new FootMachineFunctionInfo(*this);
|
||||
}
|
||||
24
llvm/lib/Target/Foot/FootMachineFunctionInfo.h
Normal file
24
llvm/lib/Target/Foot/FootMachineFunctionInfo.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef LLVM_LIB_TARGET_FOOT_FOOTMACHINEFUNCTIONINFO_H
|
||||
#define LLVM_LIB_TARGET_FOOT_FOOTMACHINEFUNCTIONINFO_H
|
||||
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class FootMachineFunctionInfo : public MachineFunctionInfo {
|
||||
int RetAddrFI = -1;
|
||||
|
||||
public:
|
||||
FootMachineFunctionInfo() = default;
|
||||
|
||||
int getReturnAddressFrameIndex() const { return RetAddrFI; }
|
||||
void setReturnAddressFrameIndex(int RetAddrFI) { this->RetAddrFI = RetAddrFI; }
|
||||
|
||||
MachineFunctionInfo *
|
||||
clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
|
||||
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) const override;
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_LIB_TARGET_FOOT_FOOTMACHINEFUNCTIONINFO_H
|
||||
@ -1,5 +1,6 @@
|
||||
#include "Foot.h"
|
||||
#include "FootTargetMachine.h"
|
||||
#include "FootMachineFunctionInfo.h"
|
||||
#include "FootTargetObjectFile.h"
|
||||
#include "TargetInfo/FootTargetInfo.h"
|
||||
#include "llvm/CodeGen/GlobalISel/IRTranslator.h"
|
||||
@ -54,6 +55,12 @@ const FootSubtarget *FootTargetMachine::getSubtargetImpl(const Function &F) cons
|
||||
return SubtargetSingleton.get();
|
||||
}
|
||||
|
||||
MachineFunctionInfo *
|
||||
FootTargetMachine::createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
|
||||
const TargetSubtargetInfo *STI) const {
|
||||
return new FootMachineFunctionInfo();
|
||||
}
|
||||
|
||||
FootPassConfig::FootPassConfig(TargetMachine &TM, PassManagerBase &PM) :
|
||||
TargetPassConfig(TM, PM) {}
|
||||
|
||||
|
||||
@ -23,6 +23,10 @@ public:
|
||||
TargetLoweringObjectFile *getObjFileLowering() const override;
|
||||
|
||||
const FootSubtarget *getSubtargetImpl(const Function &) const override;
|
||||
|
||||
MachineFunctionInfo *
|
||||
createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
|
||||
const TargetSubtargetInfo *STI) const override;
|
||||
};
|
||||
|
||||
class FootPassConfig : public TargetPassConfig {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user