-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[WIP] Introduce a G_PTRTOADDR GIsel node #140300
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
base: users/arichardson/spr/main.wip-introduce-a-g_ptrtoaddr-gisel-node
Are you sure you want to change the base?
[WIP] Introduce a G_PTRTOADDR GIsel node #140300
Conversation
Created using spr 1.3.6-beta.1
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/GlobalISel/GenericMachineInstrs.h llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h llvm/include/llvm/CodeGen/GlobalISel/LegalizerHelper.h llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp llvm/lib/CodeGen/MachineVerifier.cpp View the diff from clang-format here.diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
index 3f465b824..722e3e61e 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
@@ -486,7 +486,7 @@ private:
bool translatePtrToInt(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_PTRTOINT, U, MIRBuilder);
}
- bool translatePtrToAddr(const User &U, MachineIRBuilder &MIRBuilder) {
+ bool translatePtrToAddr(const User &U, MachineIRBuilder &MIRBuilder) {
return translateCast(TargetOpcode::G_PTRTOADDR, U, MIRBuilder);
}
bool translateTrunc(const User &U, MachineIRBuilder &MIRBuilder) {
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 39fc20011..ca1da0138 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -4695,7 +4695,7 @@ LegalizerHelper::lower(MachineInstr &MI, unsigned TypeIdx, LLT LowerHintTy) {
return lowerTRUNC(MI);
case G_PTRTOADDR:
return lowerPTRTOADDR(MI);
- GISEL_VECREDUCE_CASES_NONSEQ
+ GISEL_VECREDUCE_CASES_NONSEQ
return lowerVectorReduction(MI);
case G_VAARG:
return lowerVAArg(MI);
|
@@ -204,6 +207,10 @@ LegacyLegalizerInfo::getAspectAction(const InstrAspect &Aspect) const { | |||
if (Aspect.Type.isScalar() || Aspect.Type.isPointer()) | |||
return findScalarLegalAction(Aspect); | |||
assert(Aspect.Type.isVector()); | |||
if (Aspect.Opcode == TargetOpcode::G_PTRTOADDR) { |
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.
This is really ugly and I don't know if there is a better solution?
auto DstReg = MI.getOperand(0).getReg(); | ||
auto SrcReg = MI.getOperand(1).getReg(); |
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.
auto DstReg = MI.getOperand(0).getReg(); | |
auto SrcReg = MI.getOperand(1).getReg(); | |
Register DstReg = MI.getOperand(0).getReg(); | |
Register SrcReg = MI.getOperand(1).getReg(); |
auto PtrToInt = MIRBuilder.buildPtrToInt(IntPtrTy, SrcReg); | ||
auto Addr = PtrToInt; | ||
if (AddrTy != IntPtrTy) | ||
Addr = MIRBuilder.buildTrunc(AddrTy, PtrToInt.getReg(0)); | ||
MIRBuilder.buildZExtOrTrunc(DstReg, Addr.getReg(0)); |
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.
auto PtrToInt = MIRBuilder.buildPtrToInt(IntPtrTy, SrcReg); | |
auto Addr = PtrToInt; | |
if (AddrTy != IntPtrTy) | |
Addr = MIRBuilder.buildTrunc(AddrTy, PtrToInt.getReg(0)); | |
MIRBuilder.buildZExtOrTrunc(DstReg, Addr.getReg(0)); | |
Register Addr = MIRBuilder.buildPtrToInt(IntPtrTy, SrcReg).getReg(0); | |
if (AddrTy != IntPtrTy) | |
Addr = MIRBuilder.buildTrunc(AddrTy, Addr).getReg(0); | |
MIRBuilder.buildZExtOrTrunc(DstReg, Addr); |
@@ -7407,6 +7412,34 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerTRUNC(MachineInstr &MI) { | |||
return UnableToLegalize; | |||
} | |||
|
|||
LegalizerHelper::LegalizeResult | |||
LegalizerHelper::lowerPTRTOADDR(MachineInstr &MI) { | |||
// Lower G_PTRTOADDR as a truncate to address width of G_PTROINT and then |
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.
// Lower G_PTRTOADDR as a truncate to address width of G_PTROINT and then | |
// Lower G_PTRTOADDR as a truncate to address width of G_PTRTOINT and then |
No description provided.