Skip to content

[CodeGen] [ARM] Make RISC-V Init Undef Pass Target Independent and add support for the ARM Architecture. #77770

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

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/CodeGen/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ namespace llvm {
/// This pass reads flow sensitive profile.
extern char &MIRProfileLoaderPassID;

// This pass gives undef values a Pseudo Instruction definition for
// Instructions to ensure early-clobber is followed when using the greedy
// register allocator.
extern char &InitUndefID;

/// FastRegisterAllocation Pass - This pass register allocates as fast as
/// possible. It is best suited for debug code where live ranges are short.
///
Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,15 @@ class TargetInstrInfo : public MCInstrInfo {
llvm_unreachable("unknown number of operands necessary");
}

/// Gets the opcode for the Pseudo Instruction used to initialize
/// the undef value. If no Instruction is available, this will
/// fail compilation.
virtual unsigned getUndefInitOpcode(unsigned RegClassID) const {
(void)RegClassID;

llvm_unreachable("Unexpected register class.");
}

private:
mutable std::unique_ptr<MIRFormatter> Formatter;
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
Expand Down
22 changes: 22 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,28 @@ class TargetRegisterInfo : public MCRegisterInfo {
virtual bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const {
return false;
}

/// Returns the Largest Super Class that is being initialized. There
/// should be a Pseudo Instruction implemented for the super class
/// that is being returned to ensure that Init Undef can apply the
/// initialization correctly.
virtual const TargetRegisterClass *
getLargestSuperClass(const TargetRegisterClass *RC) const {
llvm_unreachable("Unexpected target register class.");
}

/// Returns if the architecture being targeted has the required Pseudo
/// Instructions for initializing the register. By default this returns false,
/// but where it is overriden for an architecture, the behaviour will be
/// different. This can either be a check to ensure the Register Class is
/// present, or to return true as an indication the architecture supports the
/// pass. If using the method that does not check for the Register Class, it
/// is imperative to ensure all required Pseudo Instructions are implemented,
/// otherwise compilation may fail with an `Unexpected register class` error.
virtual bool
doesRegClassHavePseudoInitUndef(const TargetRegisterClass *RC) const {
return false;
}
};

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/TargetSubtargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ class TargetSubtargetInfo : public MCSubtargetInfo {

/// Get the list of MacroFusion predicates.
virtual std::vector<MacroFusionPredTy> getMacroFusions() const { return {}; };

/// supportsInitUndef is used to determine if an architecture supports
/// the Init Undef Pass. By default, it is assumed that it will not support
/// the pass, with architecture specific overrides providing the information
/// where they are implemented.
virtual bool supportsInitUndef() const { return false; }
};

} // end namespace llvm
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ void initializeTLSVariableHoistLegacyPassPass(PassRegistry &);
void initializeTwoAddressInstructionPassPass(PassRegistry&);
void initializeTypeBasedAAWrapperPassPass(PassRegistry&);
void initializeTypePromotionLegacyPass(PassRegistry&);
void initializeInitUndefPass(PassRegistry &);
void initializeUniformityInfoWrapperPassPass(PassRegistry &);
void initializeUnifyLoopExitsLegacyPassPass(PassRegistry &);
void initializeUnpackMachineBundlesPass(PassRegistry&);
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Passes/CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@ void CodeGenPassBuilder<Derived>::addOptimizedRegAlloc(
AddMachinePass &addPass) const {
addPass(DetectDeadLanesPass());

addPass(InitUndefPass());

addPass(ProcessImplicitDefsPass());

// Edge splitting is smarter with machine loop info.
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Passes/MachinePassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ DUMMY_MACHINE_FUNCTION_PASS("fs-profile-loader", MIRProfileLoaderNewPass)
DUMMY_MACHINE_FUNCTION_PASS("funclet-layout", FuncletLayoutPass)
DUMMY_MACHINE_FUNCTION_PASS("gc-empty-basic-blocks", GCEmptyBasicBlocksPass)
DUMMY_MACHINE_FUNCTION_PASS("implicit-null-checks", ImplicitNullChecksPass)
DUMMY_MACHINE_FUNCTION_PASS("init-undef-pass", InitUndefPass)
DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass)
DUMMY_MACHINE_FUNCTION_PASS("irtranslator", IRTranslatorPass)
DUMMY_MACHINE_FUNCTION_PASS("kcfi", MachineKCFIPass)
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ add_llvm_component_library(LLVMCodeGen
IfConversion.cpp
ImplicitNullChecks.cpp
IndirectBrExpandPass.cpp
InitUndef.cpp
InlineSpiller.cpp
InterferenceCache.cpp
InterleavedAccessPass.cpp
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeIfConverterPass(Registry);
initializeImplicitNullChecksPass(Registry);
initializeIndirectBrExpandLegacyPassPass(Registry);
initializeInitUndefPass(Registry);
initializeInterleavedLoadCombinePass(Registry);
initializeInterleavedAccessPass(Registry);
initializeJMCInstrumenterPass(Registry);
Expand Down
Loading