Index: llvm/lib/Target/M68k/CMakeLists.txt =================================================================== --- llvm/lib/Target/M68k/CMakeLists.txt +++ llvm/lib/Target/M68k/CMakeLists.txt @@ -1,8 +1,10 @@ -add_llvm_component_group(M68k) +add_llvm_component_group(M68k HAS_JIT) set(LLVM_TARGET_DEFINITIONS M68k.td) +tablegen(LLVM M68kGenRegisterBank.inc -gen-register-bank) tablegen(LLVM M68kGenRegisterInfo.inc -gen-register-info) +tablegen(LLVM M68kGenGlobalISel.inc -gen-global-isel) tablegen(LLVM M68kGenInstrInfo.inc -gen-instr-info) tablegen(LLVM M68kGenSubtargetInfo.inc -gen-subtarget) tablegen(LLVM M68kGenMCCodeBeads.inc -gen-code-beads) @@ -17,6 +19,7 @@ add_llvm_target(M68kCodeGen M68kAsmPrinter.cpp M68kCollapseMOVEMPass.cpp + M68kCallLowering.cpp M68kExpandPseudo.cpp M68kFrameLowering.cpp M68kInstrInfo.cpp @@ -29,11 +32,15 @@ M68kTargetMachine.cpp M68kTargetObjectFile.cpp + DEPENDS + intrinsics_gen + LINK_COMPONENTS Analysis AsmPrinter CodeGen Core + GlobalISel MC SelectionDAG Support Index: llvm/lib/Target/M68k/M68k.h =================================================================== --- llvm/lib/Target/M68k/M68k.h +++ llvm/lib/Target/M68k/M68k.h @@ -16,8 +16,10 @@ #define LLVM_LIB_TARGET_M68K_M68K_H namespace llvm { - +class M68kRegisterBankInfo; +class M68kSubtarget; class FunctionPass; +class InstructionSelector; class M68kTargetMachine; /// This pass converts a legalized DAG into a M68k-specific DAG, ready for @@ -45,6 +47,10 @@ /// so that all possible MOVEs are present. FunctionPass *createM68kConvertMOVToMOVMPass(); +InstructionSelector *createM68kInstructionSelector(const M68kTargetMachine &, + M68kSubtarget &, + M68kRegisterBankInfo &); + } // namespace llvm #endif Index: llvm/lib/Target/M68k/M68kCallLowering.h =================================================================== --- /dev/null +++ llvm/lib/Target/M68k/M68kCallLowering.h @@ -0,0 +1,44 @@ +//===-- M68kCallLowering.h - Call lowering ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file +/// This file describes how to lower LLVM calls to machine code calls. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_M68K_M68KCALLLOWERING_H +#define LLVM_LIB_TARGET_M68K_M68KCALLLOWERING_H + +#include "llvm/CodeGen/CallingConvLower.h" +#include "llvm/CodeGen/GlobalISel/CallLowering.h" +#include "llvm/CodeGen/ValueTypes.h" + +namespace llvm { + +class M68kTargetLowering; + +class M68kCallLowering : public CallLowering { + +public: + M68kCallLowering(const M68kTargetLowering &TLI); + + bool lowerReturn(MachineIRBuilder &MIRBuilder, const Value *Val, + ArrayRef VRegs, FunctionLoweringInfo &FLI, + Register SwiftErrorVReg) const override; + + bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, + ArrayRef> VRegs, + FunctionLoweringInfo &FLI) const override; + + bool lowerCall(MachineIRBuilder &MIRBuilder, + CallLoweringInfo &Info) const override; +}; + +} // end namespace llvm + +#endif // LLVM_LIB_TARGET_M68K_M68KCALLLOWERING_H \ No newline at end of file Index: llvm/lib/Target/M68k/M68kCallLowering.cpp =================================================================== --- /dev/null +++ llvm/lib/Target/M68k/M68kCallLowering.cpp @@ -0,0 +1,52 @@ +//===-- M68kCallLowering.cpp - Call lowering -------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file +/// This file implements the lowering of LLVM calls to machine code calls for +/// GlobalISel. +// +//===----------------------------------------------------------------------===// + +#include "M68kCallLowering.h" +#include "M68kISelLowering.h" +#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" + +using namespace llvm; + +M68kCallLowering::M68kCallLowering(const M68kTargetLowering &TLI) + : CallLowering(&TLI) {} + +bool M68kCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder, + const Value *Val, ArrayRef VRegs, + FunctionLoweringInfo &FLI, + Register SwiftErrorVReg) const { + + MachineInstrBuilder Ret = MIRBuilder.buildInstrNoInsert(M68kISD::RET); + + if (Val != nullptr) { + return false; + } + MIRBuilder.insertInstr(Ret); + return true; +} + +bool M68kCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder, + const Function &F, + ArrayRef> VRegs, + FunctionLoweringInfo &FLI) const { + + if (F.arg_empty()) + return true; + + return false; +} + +bool M68kCallLowering::lowerCall(MachineIRBuilder &MIRBuilder, + CallLoweringInfo &Info) const { + return false; +} \ No newline at end of file Index: llvm/lib/Target/M68k/M68kSubtarget.h =================================================================== --- llvm/lib/Target/M68k/M68kSubtarget.h +++ llvm/lib/Target/M68k/M68kSubtarget.h @@ -17,7 +17,10 @@ #include "M68kFrameLowering.h" #include "M68kISelLowering.h" #include "M68kInstrInfo.h" - +#include "llvm/CodeGen/GlobalISel/CallLowering.h" +#include "llvm/CodeGen/GlobalISel/InstructionSelector.h" +#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" +#include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" #include "llvm/CodeGen/SelectionDAGTargetInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/IR/DataLayout.h" @@ -151,6 +154,18 @@ const InstrItineraryData *getInstrItineraryData() const override { return &InstrItins; } + protected: + // GlobalISel related APIs. + std::unique_ptr CallLoweringInfo; + std::unique_ptr InstSelector; + std::unique_ptr Legalizer; + std::unique_ptr RegBankInfo; + +public: + const CallLowering *getCallLowering() const override; + InstructionSelector *getInstructionSelector() const override; + const LegalizerInfo *getLegalizerInfo() const override; + const RegisterBankInfo *getRegBankInfo() const override; }; } // namespace llvm Index: llvm/lib/Target/M68k/M68kSubtarget.cpp =================================================================== --- llvm/lib/Target/M68k/M68kSubtarget.cpp +++ llvm/lib/Target/M68k/M68kSubtarget.cpp @@ -14,6 +14,7 @@ #include "M68kSubtarget.h" #include "M68k.h" +#include "M68kCallLowering.h" #include "M68kMachineFunction.h" #include "M68kRegisterInfo.h" #include "M68kTargetMachine.h" @@ -50,7 +51,12 @@ : M68kGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TM(TM), TSInfo(), InstrInfo(initializeSubtargetDependencies(CPU, TT, FS, TM)), FrameLowering(*this, this->getStackAlignment()), TLInfo(TM, *this), - TargetTriple(TT) {} + TargetTriple(TT) { + CallLoweringInfo.reset(new M68kCallLowering(*getTargetLowering())); +} +const CallLowering *M68kSubtarget::getCallLowering() const { + return CallLoweringInfo.get(); +} bool M68kSubtarget::isPositionIndependent() const { return TM.isPositionIndependent(); Index: llvm/lib/Target/M68k/M68kTargetMachine.cpp =================================================================== --- llvm/lib/Target/M68k/M68kTargetMachine.cpp +++ llvm/lib/Target/M68k/M68kTargetMachine.cpp @@ -13,14 +13,18 @@ #include "M68kTargetMachine.h" #include "M68k.h" -#include "TargetInfo/M68kTargetInfo.h" - #include "M68kSubtarget.h" #include "M68kTargetObjectFile.h" - +#include "TargetInfo/M68kTargetInfo.h" +#include "llvm/CodeGen/GlobalISel/IRTranslator.h" +#include "llvm/CodeGen/GlobalISel/InstructionSelect.h" +#include "llvm/CodeGen/GlobalISel/Legalizer.h" +#include "llvm/CodeGen/GlobalISel/RegBankSelect.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/LegacyPassManager.h" +#include "llvm/InitializePasses.h" +#include "llvm/PassRegistry.h" #include "llvm/Support/TargetRegistry.h" #include @@ -30,6 +34,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kTarget() { RegisterTargetMachine X(getTheM68kTarget()); + auto *PR = PassRegistry::getPassRegistry(); + initializeGlobalISel(*PR); } namespace { @@ -134,7 +140,7 @@ const M68kSubtarget &getM68kSubtarget() const { return *getM68kTargetMachine().getSubtargetImpl(); } - + bool addIRTranslator() override; bool addInstSelector() override; void addPreSched2() override; void addPreEmitPass() override; @@ -152,6 +158,11 @@ return false; } +bool M68kPassConfig::addIRTranslator() { + addPass(new IRTranslator()); + return false; +} + void M68kPassConfig::addPreSched2() { addPass(createM68kExpandPseudoPass()); } void M68kPassConfig::addPreEmitPass() {