-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[LoongArch][GlobalISel] Adding initial GlobalISel infrastructure #116005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhaoqi5
wants to merge
3
commits into
llvm:main
Choose a base branch
from
zhaoqi5:initial-gisel-la-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+453
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===-- LoongArchCallLowering.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 "LoongArchCallLowering.h" | ||
#include "LoongArchISelLowering.h" | ||
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" | ||
|
||
using namespace llvm; | ||
|
||
LoongArchCallLowering::LoongArchCallLowering(const LoongArchTargetLowering &TLI) | ||
: CallLowering(&TLI) {} | ||
|
||
bool LoongArchCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder, | ||
const Value *Val, | ||
ArrayRef<Register> VRegs, | ||
FunctionLoweringInfo &FLI) const { | ||
if (Val != nullptr) | ||
return false; | ||
|
||
MIRBuilder.buildInstr(LoongArch::PseudoRET); | ||
return true; | ||
} | ||
|
||
bool LoongArchCallLowering::lowerFormalArguments( | ||
MachineIRBuilder &MIRBuilder, const Function &F, | ||
ArrayRef<ArrayRef<Register>> VRegs, FunctionLoweringInfo &FLI) const { | ||
return F.arg_empty(); | ||
} | ||
|
||
bool LoongArchCallLowering::lowerCall(MachineIRBuilder &MIRBuilder, | ||
CallLoweringInfo &Info) const { | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===-- LoongArchCallLowering.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_LOONGARCH_LOONGARCHCALLLOWERING_H | ||
#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHCALLLOWERING_H | ||
|
||
#include "llvm/CodeGen/CallingConvLower.h" | ||
#include "llvm/CodeGen/GlobalISel/CallLowering.h" | ||
|
||
namespace llvm { | ||
|
||
class LoongArchTargetLowering; | ||
class MachineIRBuilder; | ||
|
||
class LoongArchCallLowering : public CallLowering { | ||
|
||
public: | ||
LoongArchCallLowering(const LoongArchTargetLowering &TLI); | ||
|
||
bool lowerReturn(MachineIRBuilder &MIRBuiler, const Value *Val, | ||
ArrayRef<Register> VRegs, | ||
FunctionLoweringInfo &FLI) const override; | ||
|
||
bool lowerFormalArguments(MachineIRBuilder &MIRBuilder, const Function &F, | ||
ArrayRef<ArrayRef<Register>> VRegs, | ||
FunctionLoweringInfo &FLI) const override; | ||
|
||
bool lowerCall(MachineIRBuilder &MIRBuilder, | ||
CallLoweringInfo &Info) const override; | ||
}; | ||
|
||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHCALLLOWERING_H |
102 changes: 102 additions & 0 deletions
102
llvm/lib/Target/LoongArch/GISel/LoongArchInstructionSelector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//===-- LoongArchInstructionSelector.cpp -------------------------*- 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 targeting of the InstructionSelector class for | ||
/// LoongArch. | ||
/// \todo This should be generated by TableGen. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LoongArchRegisterBankInfo.h" | ||
#include "LoongArchSubtarget.h" | ||
#include "LoongArchTargetMachine.h" | ||
#include "llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h" | ||
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h" | ||
#include "llvm/IR/IntrinsicsLoongArch.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
#define DEBUG_TYPE "loongarch-isel" | ||
|
||
using namespace llvm; | ||
|
||
#define GET_GLOBALISEL_PREDICATE_BITSET | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATE_BITSET | ||
|
||
namespace { | ||
|
||
class LoongArchInstructionSelector : public InstructionSelector { | ||
public: | ||
LoongArchInstructionSelector(const LoongArchTargetMachine &TM, | ||
const LoongArchSubtarget &STI, | ||
const LoongArchRegisterBankInfo &RBI); | ||
|
||
bool select(MachineInstr &MI) override; | ||
|
||
static const char *getName() { return DEBUG_TYPE; } | ||
|
||
private: | ||
// tblgen-erated 'select' implementation, used as the initial selector for | ||
// the patterns that don't require complex C++. | ||
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const; | ||
|
||
const LoongArchSubtarget &STI; | ||
const LoongArchInstrInfo &TII; | ||
const LoongArchRegisterInfo &TRI; | ||
const LoongArchRegisterBankInfo &RBI; | ||
const LoongArchTargetMachine &TM; | ||
|
||
#define GET_GLOBALISEL_PREDICATES_DECL | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATES_DECL | ||
|
||
#define GET_GLOBALISEL_TEMPORARIES_DECL | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_TEMPORARIES_DECL | ||
}; | ||
|
||
} // end anonymous namespace | ||
|
||
#define GET_GLOBALISEL_IMPL | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_IMPL | ||
|
||
LoongArchInstructionSelector::LoongArchInstructionSelector( | ||
const LoongArchTargetMachine &TM, const LoongArchSubtarget &STI, | ||
const LoongArchRegisterBankInfo &RBI) | ||
: STI(STI), TII(*STI.getInstrInfo()), TRI(*STI.getRegisterInfo()), RBI(RBI), | ||
TM(TM), | ||
|
||
#define GET_GLOBALISEL_PREDICATES_INIT | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_PREDICATES_INIT | ||
#define GET_GLOBALISEL_TEMPORARIES_INIT | ||
#include "LoongArchGenGlobalISel.inc" | ||
#undef GET_GLOBALISEL_TEMPORARIES_INIT | ||
{ | ||
} | ||
|
||
bool LoongArchInstructionSelector::select(MachineInstr &MI) { | ||
if (!isPreISelGenericOpcode(MI.getOpcode())) { | ||
// Certain non-generic instructions also need some special handling. | ||
return true; | ||
} | ||
|
||
if (selectImpl(MI, *CoverageInfo)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
namespace llvm { | ||
InstructionSelector * | ||
createLoongArchInstructionSelector(const LoongArchTargetMachine &TM, | ||
const LoongArchSubtarget &Subtarget, | ||
const LoongArchRegisterBankInfo &RBI) { | ||
return new LoongArchInstructionSelector(TM, Subtarget, RBI); | ||
} | ||
} // end namespace llvm |
24 changes: 24 additions & 0 deletions
24
llvm/lib/Target/LoongArch/GISel/LoongArchLegalizerInfo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- LoongArchLegalizerInfo.cpp ------------------------------*- 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 targeting of the Machinelegalizer class for | ||
/// LoongArch. | ||
/// \todo This should be generated by TableGen. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LoongArchLegalizerInfo.h" | ||
#include "llvm/CodeGen/TargetOpcodes.h" | ||
#include "llvm/CodeGen/ValueTypes.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/Type.h" | ||
|
||
using namespace llvm; | ||
|
||
LoongArchLegalizerInfo::LoongArchLegalizerInfo(const LoongArchSubtarget &ST) { | ||
getLegacyLegalizerInfo().computeTables(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===-- LoongArchLegalizerInfo.h --------------------------------*- 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 declares the targeting of the Machinelegalizer class for | ||
/// LoongArch. | ||
/// \todo This should be generated by TableGen. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINELEGALIZER_H | ||
#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINELEGALIZER_H | ||
|
||
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" | ||
|
||
namespace llvm { | ||
|
||
class LoongArchSubtarget; | ||
|
||
class LoongArchLegalizerInfo : public LegalizerInfo { | ||
public: | ||
LoongArchLegalizerInfo(const LoongArchSubtarget &ST); | ||
}; | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHMACHINELEGALIZER_H |
27 changes: 27 additions & 0 deletions
27
llvm/lib/Target/LoongArch/GISel/LoongArchRegisterBankInfo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//===-- LoongArchRegisterBankInfo.cpp ---------------------------*- 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 targeting of the RegisterBankInfo class for | ||
/// LoongArch. | ||
/// \todo This should be generated by TableGen. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LoongArchRegisterBankInfo.h" | ||
#include "MCTargetDesc/LoongArchMCTargetDesc.h" | ||
#include "llvm/CodeGen/MachineRegisterInfo.h" | ||
#include "llvm/CodeGen/RegisterBank.h" | ||
#include "llvm/CodeGen/RegisterBankInfo.h" | ||
#include "llvm/CodeGen/TargetRegisterInfo.h" | ||
|
||
#define GET_TARGET_REGBANK_IMPL | ||
#include "LoongArchGenRegisterBank.inc" | ||
|
||
using namespace llvm; | ||
|
||
LoongArchRegisterBankInfo::LoongArchRegisterBankInfo(unsigned HwMode) | ||
: LoongArchGenRegisterBankInfo(HwMode) {} |
39 changes: 39 additions & 0 deletions
39
llvm/lib/Target/LoongArch/GISel/LoongArchRegisterBankInfo.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- LoongArchRegisterBankInfo.h -----------------------------*- 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 declares the targeting of the RegisterBankInfo class for | ||
/// LoongArch. | ||
/// \todo This should be generated by TableGen. | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHREGISTERBANKINFO_H | ||
#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHREGISTERBANKINFO_H | ||
|
||
#include "llvm/CodeGen/RegisterBankInfo.h" | ||
|
||
#define GET_REGBANK_DECLARATIONS | ||
#include "LoongArchGenRegisterBank.inc" | ||
|
||
namespace llvm { | ||
|
||
class TargetRegisterInfo; | ||
|
||
class LoongArchGenRegisterBankInfo : public RegisterBankInfo { | ||
protected: | ||
#define GET_TARGET_REGBANK_CLASS | ||
#include "LoongArchGenRegisterBank.inc" | ||
}; | ||
|
||
/// This class provides the information for the target register banks. | ||
class LoongArchRegisterBankInfo final : public LoongArchGenRegisterBankInfo { | ||
public: | ||
LoongArchRegisterBankInfo(unsigned HwMode); | ||
}; | ||
} // end namespace llvm | ||
|
||
#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHREGISTERBANKINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//=- LoongArchRegisterBanks.td - Describe the LoongArch Banks -*- tablegen -*-=// | ||
// | ||
// 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 | ||
// | ||
//===-----------------------------------------------------------------------===// | ||
// | ||
// | ||
//===-----------------------------------------------------------------------===// | ||
|
||
/// General Purpose Registers: R. | ||
def GPRBRegBank : RegisterBank<"GPRB", [GPR]>; | ||
|
||
/// Floating Point Registers: F. | ||
def FPRBRegBank : RegisterBank<"FPRB", [FPR64]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the return false case you've created an instruction and never inserted it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have put the instruction creation right before to the insert. Thanks.