[llvm] 3ccba24 - [RISCV][GISEL] Legalize G_VASTART using custom legalization (#73063)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 09:05:51 PST 2023
Author: Michael Maitland
Date: 2023-11-30T12:05:45-05:00
New Revision: 3ccba24c99ac234e7df78241964a91b2db6a8e50
URL: https://github.com/llvm/llvm-project/commit/3ccba24c99ac234e7df78241964a91b2db6a8e50
DIFF: https://github.com/llvm/llvm-project/commit/3ccba24c99ac234e7df78241964a91b2db6a8e50.diff
LOG: [RISCV][GISEL] Legalize G_VASTART using custom legalization (#73063)
The legalization was modeled after SelectionDAG.
Added:
Modified:
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
index 4673dfdd160d999..9564ed9c41874a7 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "RISCVLegalizerInfo.h"
+#include "RISCVMachineFunctionInfo.h"
#include "RISCVSubtarget.h"
#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
@@ -300,6 +301,8 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
getActionDefinitionsBuilder({G_FCEIL, G_FFLOOR})
.libcallFor({s32, s64});
+ getActionDefinitionsBuilder(G_VASTART).customFor({p0});
+
getLegacyLegalizerInfo().computeTables();
}
@@ -327,6 +330,25 @@ bool RISCVLegalizerInfo::legalizeShlAshrLshr(
return true;
}
+bool RISCVLegalizerInfo::legalizeVAStart(MachineInstr &MI,
+ MachineIRBuilder &MIRBuilder,
+ GISelChangeObserver &Observer) const {
+ // Stores the address of the VarArgsFrameIndex slot into the memory location
+ assert(MI.getOpcode() == TargetOpcode::G_VASTART);
+ MachineFunction *MF = MI.getParent()->getParent();
+ RISCVMachineFunctionInfo *FuncInfo = MF->getInfo<RISCVMachineFunctionInfo>();
+ int FI = FuncInfo->getVarArgsFrameIndex();
+ LLT AddrTy = MIRBuilder.getMRI()->getType(MI.getOperand(0).getReg());
+ auto FINAddr = MIRBuilder.buildFrameIndex(AddrTy, FI);
+ assert(MI.hasOneMemOperand());
+ MachineInstr *LoweredMI = MIRBuilder.buildStore(
+ MI.getOperand(0).getReg(), FINAddr, *MI.memoperands()[0]);
+ Observer.createdInstr(*LoweredMI);
+ Observer.erasingInstr(MI);
+ MI.eraseFromParent();
+ return true;
+}
+
bool RISCVLegalizerInfo::legalizeCustom(LegalizerHelper &Helper,
MachineInstr &MI) const {
MachineIRBuilder &MIRBuilder = Helper.MIRBuilder;
@@ -367,6 +389,8 @@ bool RISCVLegalizerInfo::legalizeCustom(LegalizerHelper &Helper,
MI.eraseFromParent();
return true;
}
+ case TargetOpcode::G_VASTART:
+ return legalizeVAStart(MI, MIRBuilder, Observer);
}
llvm_unreachable("expected switch to return");
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h
index 6a5f49cd98d1842..c0e6088ac5c193b 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h
+++ b/llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.h
@@ -35,6 +35,9 @@ class RISCVLegalizerInfo : public LegalizerInfo {
private:
bool legalizeShlAshrLshr(MachineInstr &MI, MachineIRBuilder &MIRBuilder,
GISelChangeObserver &Observer) const;
+
+ bool legalizeVAStart(MachineInstr &MI, MachineIRBuilder &MIRBuilder,
+ GISelChangeObserver &Observer) const;
};
} // end namespace llvm
#endif
More information about the llvm-commits
mailing list