43 Commits

Author SHA1 Message Date
Craig Topper
5442aa1853
[RDF] Rename RegisterId field in RegisterRef Reg->Id. NFC (#168154)
Not all RegisterId values are registers, so Id is a more appropriate
name.

Use asMCReg() in some places that assumed it was a register.
2025-11-14 18:33:50 -08:00
Craig Topper
7108b12f6b
[RDF] RegisterRef/RegisterId improvements. NFC (#168030)
RegisterId can represent a physical register, a MCRegUnit, or
an index into a side structure that stores register masks. These 3
types were encoded by using the physical reg, stack slot, and
virtual register encoding partitions from the Register class.
This encoding scheme alias wasn't well contained so
Register::index2StackSlot and Register::stackSlotIndex appeared
in multiple places.

This patch gives RegisterRef its own encoding defines and separates
it from Register.

I've removed the generic idx() method in favor of getAsMCReg(),
getAsMCRegUnit(), and getMaskIdx() for some degree of type safety.

Some places used the RegisterId field of RegisterRef directly as a
register. Those have been updated to use getAsMCReg.
    
Some special cases for RegisterId 0 have been removed as it can
be treated like a MCRegister by existing code.
    
I think I want to rename the Reg field of RegisterRef to Id, but
I'll do that in another patch.
    
Additionally, callers of the RegisterRef constructor need to be
audited for implicit conversions from Register/MCRegister
to unsigned.
2025-11-14 10:30:25 -08:00
Kazu Hirata
d4427f308e
[llvm] Use range constructors of *Set (NFC) (#133549) 2025-03-28 19:55:18 -07:00
Kazu Hirata
599005686a
[llvm] Use *Set::insert_range (NFC) (#132325)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range.  This patch replaces:

  Dest.insert(Src.begin(), Src.end());

with:

  Dest.insert_range(Src);

This patch does not touch custom begin like succ_begin for now.
2025-03-20 22:24:06 -07:00
Yashas Andaluri
a361de6d13
[RDF] Create phi nodes for clobbering defs (#123694)
When a def in a block A reaches another block B that is in A's iterated
dominance frontier, a phi node is added to B for the def register.

A clobbering def can be created at a call instruction, for a register
clobbered by a call.
However, phi nodes are not created for a register, when one of the
reaching defs of the register is a clobbering def.

This patch adds phi nodes for registers that have a clobbering reaching
def. These additional phis help in checking reaching defs for an
instruction in RDF based copy propagation and addressing mode
optimizations.
2025-02-07 08:28:29 -06:00
Yashas Andaluri
b28eebf926
[RDF] Fix cover check when linking refs to defs (#113888)
During RDF graph construction, linkRefUp method links a register ref to
its upward reaching defs until all RegUnits of the ref have been covered
by defs.
However, when a sub-register def covers some, but not all, of the
RegUnits of a previous super-register def, a super-register ref is not
linked to the super-register def.
This can result in certain super register defs being dead code
eliminated.

This patch fixes the cover check for a register ref. A def must be
skipped only when all RegUnits of that def have already been covered by
a previously seen def.
2024-11-19 12:38:36 -06:00
Kazu Hirata
735ab61ac8
[CodeGen] Remove unused includes (NFC) (#115996)
Identified with misc-include-cleaner.
2024-11-12 23:15:06 -08:00
Craig Topper
c503758ab6 [CodeGen] Use std::pair<MCRegister, Register> to match return from MRI.liveins(). NFC
MachineRegisterInfo::liveins returns std::pair<MCRegister, Register>.
Don't convert to std::pair<unsigned, unsigned>.
2024-08-25 15:28:08 -07:00
Youngsuk Kim
9d4575c910 [llvm] Make lambda take const reference to prevent unneeded copy (NFC)
Closes #89198
2024-05-02 15:34:03 -05:00
Jay Foad
abea3b2799
[RDF] Skip over NoRegister. NFCI. (#80672)
This just avoids useless work of adding NoRegister to BaseSet, for
consistency with other places that iterate over all physical registers.
2024-02-05 14:15:55 +00:00
Kazu Hirata
15179aa433 [llvm] Use llvm::is_contained (NFC) 2024-01-12 18:39:48 -08:00
Krzysztof Parzyszek
39ab9da920 [RDF] Create build config
- Add option to ignore reserved registers
- Add possibility to track selected registers or register classes only

Tracking is done based on register units, so the set of registers to track
is translated into a set of register units.
2023-06-14 15:34:24 -07:00
Krzysztof Parzyszek
3eeebfe83b [RDF] Minor refactoring for clarity, NFC 2023-06-14 09:12:08 -07:00
Krzysztof Parzyszek
198d647fad [RDF] Remove unused variant of getNextShadow, NFC 2023-06-14 09:12:08 -07:00
Krzysztof Parzyszek
ffa2bbc7f4 [RDF] Print something useful for NodeId == 0 instead of crashing 2023-06-14 06:17:33 -07:00
Krzysztof Parzyszek
edfcc3a5d5 [RDF] Remove unused parameter AllRefs from buildPhis 2023-06-14 06:17:32 -07:00
Krzysztof Parzyszek
375d798067 [RDF] Define short type names: NodeAddr<XyzNode*> -> Xyz, NFC
Remove all instances of 'using namespace rdf' from files in CodeGen,
all implementation code is explicitly enclosed in 'namespace rdf'.
2023-06-12 17:07:05 -07:00
Krzysztof Parzyszek
2af7036d7b [RDF] Allow RegisterRef to contain register unit
Recommit with the fix for incorrect `constexpr` with `hash` from a later
commit, and a fix for "std::swap(std::less<RegisterRef>...)" issue with
MSVC's `std::map`.
2023-06-12 13:51:31 -07:00
Nico Weber
7b31d3dada Revert "[RDF] Allow RegisterRef to contain register unit" and follow-ups
This reverts commit 859b05b02d3fd9ab6b77f2bed8df6902fe704806.

Also reverts these follow-ups:

Revert "[RDF] Remove `constexpr` from `hash"
This reverts commit 621507ce20ad8eef2986be2712631165e53b7d91.

Revert "[RDF] Do not use trailing return type after all, NFC"
This reverts commit 46e19e3a2c45e7fb5f501bdb983a7151c158304f.

Revert "[RDF] Stop looking when reached code node in getNextRef with NextOnly"
This reverts commit a049ce9d1bd5a7c1c4fcccc6a801b72b00ea8e0f.

Revert "[RDF] Use trailing return type syntax, NFC"
This reverts commit d3b34b7f3a7cbfc96aea897419f167b5ee19e61a.

Revert "[RDF] Define short type names: NodeAddr<XyzNode*> -> Xyz, NFC"
This reverts commit f8ed60b56d1948422dda924fcf450560591e8a19.
2023-06-12 11:35:28 -04:00
Krzysztof Parzyszek
46e19e3a2c [RDF] Do not use trailing return type after all, NFC
This sort of reverts commit d3b34b7f3a7cbfc96aea897419f167b5ee19e61a,
the issue with `Use` will be addressed by using fully-qualified name.
2023-06-09 15:36:48 -07:00
Krzysztof Parzyszek
d3b34b7f3a [RDF] Use trailing return type syntax, NFC
The name rdf::Use conflicts with llvm::Use when both namespaces are
used via `using namespace`. Specifically this happened in the declaration
of DataFlowGraph::newUse (in RDFGraph.cpp):
```
using namespace rdf;

Use newUse(...);  <-- Lookup conflict for "Use"
```
Since the TRT lookup starts in a different namespace than that of the
leading type, this serves as a workaround. In general the rdf namespace
will not likely be introduced via `using namespace`, so this shouldn't
be a problem elsewhere.
2023-06-09 11:46:27 -07:00
Krzysztof Parzyszek
f8ed60b56d [RDF] Define short type names: NodeAddr<XyzNode*> -> Xyz, NFC 2023-06-09 11:46:27 -07:00
Krzysztof Parzyszek
859b05b02d [RDF] Allow RegisterRef to contain register unit 2023-06-09 06:19:03 -07:00
Krzysztof Parzyszek
f10f7b0dca [RDF] Add RegisterAggr::refs to return iterator range, NFC 2023-06-08 11:07:57 -07:00
Krzysztof Parzyszek
c6ddd04d73 [RDF] Create individual phi for each indivisible register
This isn't quite using register units, but it's getting close. The phi
generation is driven by register units, but each phi still contains a
reference to a register, potentially with a mask that amounts to a unit.
In cases of explicit register aliasing this may still create phis with
references that are aliased, whereas separate phis would ideally contain
disjoint references (this is all within a single basic block).

Previously phis used maximal registers, now they use minimal. This is a
step towards both, using register units directly, and a simpler liveness
calculation algorithm. The idea is that a phi cannot reach a reference
to anything smaller than the phi itself represents. Before there could
be a phi for R1_R0, now there will be two for this case (assuming R0 and
R1 have one unit each).
2023-06-08 11:07:57 -07:00
Krzysztof Parzyszek
fc3ad148cd [RDF] Use RegisterAggr instead of RegisterSet in few places
This shouldn't change any functionality.
2023-06-08 11:07:57 -07:00
Krzysztof Parzyszek
7fc73104e8 [RDF] Clang-format the sources, NFC 2023-06-08 11:07:56 -07:00
Jay Foad
5022fc2ad3 [CodeGen] Make use of MachineInstr::all_defs and all_uses. NFCI.
Differential Revision: https://reviews.llvm.org/D151424
2023-06-01 19:17:34 +01:00
Jay Foad
073401e59c [MC] Define and use MCInstrDesc implicit_uses and implicit_defs. NFC.
The new methods return a range for easier iteration. Use them everywhere
instead of getImplicitUses, getNumImplicitUses, getImplicitDefs and
getNumImplicitDefs. A future patch will remove the old methods.

In some use cases the new methods are less efficient because they always
have to scan the whole uses/defs array to count its length, but that
will be fixed in a future patch by storing the number of implicit
uses/defs explicitly in MCInstrDesc. At that point there will be no need
to 0-terminate the arrays.

Differential Revision: https://reviews.llvm.org/D142215
2023-01-23 14:44:58 +00:00
Craig Topper
e72ca520bb [CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFC
Use isPhysical/isVirtual methods.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D141715
2023-01-13 14:38:08 -08:00
Krzysztof Parzyszek
0f5385b70e Recommit [RDF] Remove explicit template arguments from Print
The build breakages should be addressed by d4abdd2e3d:
  [CMake] Check CMAKE_CXX_STANDARD and error if it's to old

Thanks to Tobias and Roy for addressing these issues.
2022-08-08 07:28:45 -07:00
Aaron Ballman
32fd0b7fd5 Revert "[RDF] Remove explicit template arguments from Print"
This reverts commit ede96de751224487aea122af8bfb4e82bc54840b.

This breaks the build on Windows with Visual Studio:
https://lab.llvm.org/buildbot/#/builders/123/builds/12134
2022-08-07 08:24:01 -04:00
Krzysztof Parzyszek
2bc390bdd6 [RDF] Use default TargetOperandInfo if not given in constructor
All current in-tree users use the default implementation.
2022-08-06 14:32:52 -05:00
Krzysztof Parzyszek
ede96de751 [RDF] Remove explicit template arguments from Print
CTAD takes care of it.
2022-08-06 13:29:15 -05:00
Kazu Hirata
9e6d1f4b5d [CodeGen] Qualify auto variables in for loops (NFC) 2022-07-17 01:33:28 -07:00
Kazu Hirata
34ff78c5cf [CodeGen] Remove restrictRef (NFC)
The last use was removed on Apr 14, 2017 in commit
4fe9d6c640e81457db1350766bf6dfef118bcacd.
2022-06-13 23:08:48 -07:00
serge-sans-paille
989f1c72e0 Cleanup codegen includes
This is a (fixed) recommit of https://reviews.llvm.org/D121169

after:  1061034926
before: 1063332844

Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup
Differential Revision: https://reviews.llvm.org/D121681
2022-03-16 08:43:00 +01:00
Nico Weber
a278250b0f Revert "Cleanup codegen includes"
This reverts commit 7f230feeeac8a67b335f52bd2e900a05c6098f20.
Breaks CodeGenCUDA/link-device-bitcode.cu in check-clang,
and many LLVM tests, see comments on https://reviews.llvm.org/D121169
2022-03-10 07:59:22 -05:00
serge-sans-paille
7f230feeea Cleanup codegen includes
after:  1061034926
before: 1063332844

Differential Revision: https://reviews.llvm.org/D121169
2022-03-10 10:00:30 +01:00
Kazu Hirata
bb6447a78c [llvm] Use llvm::reverse (NFC) 2021-12-12 16:13:49 -08:00
Kazu Hirata
61efa3d93f [CodeGen] Use range-based for loops (NFC) 2021-02-17 23:58:46 -08:00
Krzysztof Parzyszek
4b25f67299 [RDF] Really remove remaining uses of PhysicalRegisterInfo::normalize 2020-08-04 18:23:38 -05:00
Scott Constable
080dd10f7d Move RDF from Hexagon to Codegen
RDF is designed to be target agnostic. Therefore it would be useful to have it available for other targets, such as X86.

Based on a previous patch by Krzysztof Parzyszek

Differential Revision: https://reviews.llvm.org/D75932
2020-03-17 12:43:14 -07:00