Skip to content

Commit f9acaca

Browse files
committed
CodeGen: Refactor renameDisconnectedComponents() as a pass
Refactor LiveIntervals::renameDisconnectedComponents() to be a pass. Also change the name to "RenameIndependentSubregs": - renameDisconnectedComponents() worked on a MachineFunction at a time so it is a natural candidate for a machine function pass. - The algorithm is testable with a .mir test now. - This also fixes a problem where the lazy renaming as part of the MachineScheduler introduced IMPLICIT_DEF instructions after the number of a nodes in a region were counted leading to a mismatch. Differential Revision: http://reviews.llvm.org/D20507 llvm-svn: 271345
1 parent cbb1d06 commit f9acaca

13 files changed

+496
-369
lines changed

llvm/include/llvm/CodeGen/LiveInterval.h

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -864,77 +864,5 @@ namespace llvm {
864864
void Distribute(LiveInterval &LI, LiveInterval *LIV[],
865865
MachineRegisterInfo &MRI);
866866
};
867-
868-
/// Helper class that can divide MachineOperands of a virtual register into
869-
/// equivalence classes of connected components.
870-
/// MachineOperands belong to the same equivalence class when they are part of
871-
/// the same SubRange segment or adjacent segments (adjacent in control
872-
/// flow); Different subranges affected by the same MachineOperand belong to
873-
/// the same equivalence class.
874-
///
875-
/// Example:
876-
/// vreg0:sub0 = ...
877-
/// vreg0:sub1 = ...
878-
/// vreg0:sub2 = ...
879-
/// ...
880-
/// xxx = op vreg0:sub1
881-
/// vreg0:sub1 = ...
882-
/// store vreg0:sub0_sub1
883-
///
884-
/// The example contains 3 different equivalence classes:
885-
/// - One for the (dead) vreg0:sub2 definition
886-
/// - One containing the first vreg0:sub1 definition and its use,
887-
/// but not the second definition!
888-
/// - The remaining class contains all other operands involving vreg0.
889-
///
890-
/// We provide a utility function here to rename disjunct classes to different
891-
/// virtual registers.
892-
class ConnectedSubRegClasses {
893-
LiveIntervals &LIS;
894-
MachineRegisterInfo &MRI;
895-
const TargetInstrInfo &TII;
896-
897-
public:
898-
ConnectedSubRegClasses(LiveIntervals &LIS, MachineRegisterInfo &MRI,
899-
const TargetInstrInfo &TII)
900-
: LIS(LIS), MRI(MRI), TII(TII) {}
901-
902-
/// Split unrelated subregister components and rename them to new vregs.
903-
void renameComponents(LiveInterval &LI) const;
904-
905-
private:
906-
struct SubRangeInfo {
907-
ConnectedVNInfoEqClasses ConEQ;
908-
LiveInterval::SubRange *SR;
909-
unsigned Index;
910-
911-
SubRangeInfo(LiveIntervals &LIS, LiveInterval::SubRange &SR,
912-
unsigned Index)
913-
: ConEQ(LIS), SR(&SR), Index(Index) {}
914-
};
915-
916-
/// \brief Build a vector of SubRange infos and a union find set of
917-
/// equivalence classes.
918-
/// Returns true if more than 1 equivalence class was found.
919-
bool findComponents(IntEqClasses &Classes,
920-
SmallVectorImpl<SubRangeInfo> &SubRangeInfos,
921-
LiveInterval &LI) const;
922-
923-
/// \brief Distribute the LiveInterval segments into the new LiveIntervals
924-
/// belonging to their class.
925-
void distribute(const IntEqClasses &Classes,
926-
const SmallVectorImpl<SubRangeInfo> &SubRangeInfos,
927-
const SmallVectorImpl<LiveInterval*> &Intervals) const;
928-
929-
/// \brief Constructs main liverange and add missing undef+dead flags.
930-
void computeMainRangesFixFlags(const IntEqClasses &Classes,
931-
const SmallVectorImpl<SubRangeInfo> &SubRangeInfos,
932-
const SmallVectorImpl<LiveInterval*> &Intervals) const;
933-
934-
/// Rewrite Machine Operands to use the new vreg belonging to their class.
935-
void rewriteOperands(const IntEqClasses &Classes,
936-
const SmallVectorImpl<SubRangeInfo> &SubRangeInfos,
937-
const SmallVectorImpl<LiveInterval*> &Intervals) const;
938-
};
939867
}
940868
#endif

llvm/include/llvm/CodeGen/LiveIntervalAnalysis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,6 @@ extern cl::opt<bool> UseSegmentSetForPhysRegs;
405405
void splitSeparateComponents(LiveInterval &LI,
406406
SmallVectorImpl<LiveInterval*> &SplitLIs);
407407

408-
/// Assure dead subregister definitions have their own vreg assigned.
409-
/// This calls ConnectedSubRegClasses::splitSeparateSubRegComponent()
410-
/// on each virtual register.
411-
void renameDisconnectedComponents();
412-
413408
/// For live interval \p LI with correct SubRanges construct matching
414409
/// information for the main live range. Expects the main live range to not
415410
/// have any segments or value numbers.

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ namespace llvm {
356356
/// This pass splits the stack into a safe stack and an unsafe stack to
357357
/// protect against stack-based overflow vulnerabilities.
358358
FunctionPass *createSafeStackPass(const TargetMachine *TM = nullptr);
359+
360+
/// This pass detects subregister lanes in a virtual register that are used
361+
/// independently of other lanes and splits them into separate virtual
362+
/// registers.
363+
extern char &RenameIndependentSubregsID;
359364
} // End llvm namespace
360365

361366
/// Target machine pass initializer for passes with dependencies. Use with

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void initializeRegionOnlyPrinterPass(PassRegistry&);
266266
void initializeRegionOnlyViewerPass(PassRegistry&);
267267
void initializeRegionPrinterPass(PassRegistry&);
268268
void initializeRegionViewerPass(PassRegistry&);
269+
void initializeRenameIndependentSubregsPass(PassRegistry&);
269270
void initializeReversePostOrderFunctionAttrsPass(PassRegistry&);
270271
void initializeRewriteStatepointsForGCPass(PassRegistry&);
271272
void initializeSafeStackPass(PassRegistry&);

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ add_llvm_library(LLVMCodeGen
100100
RegisterCoalescer.cpp
101101
RegisterPressure.cpp
102102
RegisterScavenging.cpp
103+
RenameIndependentSubregs.cpp
103104
SafeStack.cpp
104105
ScheduleDAG.cpp
105106
ScheduleDAGInstrs.cpp

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
6868
initializePreISelIntrinsicLoweringPass(Registry);
6969
initializeProcessImplicitDefsPass(Registry);
7070
initializeRegisterCoalescerPass(Registry);
71+
initializeRenameIndependentSubregsPass(Registry);
7172
initializeShrinkWrapPass(Registry);
7273
initializeSlotIndexesPass(Registry);
7374
initializeStackColoringPass(Registry);

0 commit comments

Comments
 (0)