631 Commits
Author SHA1 Message Date
Matt ArsenaultandClaude Opus 5.5 e7ffa953f8 CodeGen: Remove TargetOptions::ExceptionModel (#232977)
The exception model now comes only from the "exception-model" module
flag. Remove the TargetOptions field and its copy into MCAsmInfo, so
MCAsmInfo only knows the target's default model.

The WebAssembly model checks move from the TargetMachine constructor
into the Emscripten EH/SjLj lowering pass. Clang relied on the backend
to reject non-wasm models for wasm targets, so it now rejects them itself.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 10:49:33 -07:00
Mian Miftah 862eeabddb [CodeGen] Clear call site info when resetting a MachineFunction (#229331)
MachineFunction::clear() deletes the instructions but keeps the call
site info and called globals that refer to them. After
ResetMachineFunction, which GlobalISel uses to fall back to
SelectionDAG, the entries point to deleted instructions, and printing
the MIR hangs. Clear both maps with the rest of the function, as is done
for the variable debug info that GlobalISel records.

No GlobalISel target records call site info yet, so the test resets a
MIR function marked failedISel.
2026-10-20 23:36:39 -07:00
Teresa Johnson be7aacdc8c Reapply "[ProfileSummaryInfo] Honor the hot function attribute in hotness queries" (#233530)
This reapplies commit 21740d6b79 (reverted
in
627b8cf3d4) with test updates for 5fda7711c6 (#233298), which landed
shortly beforehand and updated the IR verifier to reject functions that
carry both the `hot` and `cold` attributes. Remove the `hot`+`cold` test
cases in `hot-attribute.ll` and `ProfileSummaryInfoTest.cpp`, and update
the comment in `ProfileSummaryInfo.cpp` accordingly.

Original commit message:

LangRef documents the `hot` function attribute as taking precedence over
profile information and acting as a manual alternative to PGO hotness
data when training inputs lack coverage for hot functions. However,
ProfileSummaryInfo only checked `Attribute::Cold` (in
isFunctionEntryCold) and never consulted `Attribute::Hot`. As a result,
functions marked `hot` that had zero entry counts in PGO profiles (for
example, newly introduced functions not executed during profile
collection) were still treated as cold by PSI queries, causing passes
such as TailCallElim and PGOForceFunctionAttrs to apply cold-function
heuristics.

Check `Attribute::Hot` in `isFunctionEntryHot`,
`isFunctionHotInCallGraph`, `isFunctionColdInCallGraph`, and
`isFunctionEntryCold` before checking `hasProfileSummary()`. This
ensures
the attribute is honored both with and without profile data.

Assisted-by: Gemini
2026-10-19 13:28:23 -07:00
Teresa Johnson 627b8cf3d4 Revert "[ProfileSummaryInfo] Honor the hot function attribute in hotness queries" (#233334)
Reverts llvm/llvm-project#232085

Looks like https://github.com/llvm/llvm-project/pull/233298 broke one of
the tests. I'll fix it tomorrow and resubmit then.
2026-10-18 21:03:41 -07:00
Teresa Johnson 21740d6b79 [ProfileSummaryInfo] Honor the hot function attribute in hotness queries (#232085)
LangRef documents the `hot` function attribute as taking precedence over
profile information and acting as a manual alternative to PGO hotness
data when training inputs lack coverage for hot functions. However,
ProfileSummaryInfo only checked `Attribute::Cold` (in
isFunctionEntryCold) and never consulted `Attribute::Hot`. As a result,
functions marked `hot` that had zero entry counts in PGO profiles (for
example, newly introduced functions not executed during profile
collection) were still treated as cold by PSI queries, causing passes
such as TailCallElim and PGOForceFunctionAttrs to apply cold-function
heuristics.

Check `Attribute::Hot` in `isFunctionEntryHot`,
`isFunctionHotInCallGraph`, `isFunctionColdInCallGraph`, and
`isFunctionEntryCold` before checking `hasProfileSummary()` or
`Attribute::Cold`. This matches the precedence in CodeGenPrepare and
ensures the attribute is honored both with and without profile data.

Assisted-by: Gemini
2026-10-18 20:40:23 -07:00
Matt ArsenaultandClaude Opus 8dbe455a1f MC: Make usesWindowsCFI a pure object-format predicate (#231087)
Whether unwind information is encoded with SEH opcodes (.seh_*, .pdata
and .xdata) is a property of the object format. Whether a function uses
that encoding depends on the exception model, but usesWindowsCFI()
conflated the two. Make it report only the format, and add
MachineFunction::usesWindowsUnwindInfo() for the combined question and
needsWinCFI() for the common case that also requires an unwind table
entry.

This moves the exception model check to the point of use, in preparation
for removing ExceptionModel from TargetOptions. The assembler now
accepts
.seh_* directives whenever the object format supports them (i.e., MC
only tools will no longer have a notion of ExceptionModel).

Co-authored-by: Claude Opus <noreply@anthropic.com>
2026-10-12 19:06:44 +02:00
Ömer Sinan Ağacan cd9c8d090c [Alignment] Add a static function to construct an Align from power-of-2 values (#230920)
Many call sites of the `Align` constructor uses it as `Align(1ULL << n)`, and
the constructors takes the `Log2` of the value. Add a new static function to
allow `Align::fromLog2(n)` and update old call sites. This avoids the
unnecessary `Log2(1ULL << n)` computations when constructing `Align`s.
2026-10-11 15:20:10 +02:00
Matt ArsenaultandClaude (Claude-Opus-4.8) 229aa7df42 CodeGen: Move frame-pointer queries out of TargetOptions (#221416)
These used to depend on a TargetOptions field, which was removed
at some point. These are now only depend on MachineFunction,
so move the attribute check there.

Co-authored-by: Claude (Claude-Opus-4.8)
2026-09-05 14:31:25 +02:00
Craig Topper 3b5d3d2c1c [MachineFunction] Print type when printing constant pool value. (#220485)
Previously we printed something like `cp#2: splat (i8 -8), align=64`
which doesn't give any indication of total size.

This would have made debugging
https://github.com/llvm/llvm-project/pull/220448 easier.
2026-09-02 08:00:28 -07:00
Matt Arsenault 1a315dc409 CodeGen: Use getVRegDef in salvageCopySSAImpl (#219518) 2026-08-28 17:11:25 +00:00
Yonah GoldbergandFiigii f180ce951b [SDAG][NVPTX] Cache control metadata support and lowering (#204067)
This is the follow up for commit
https://github.com/llvm/llvm-project/commit/0fc5d0ab0cea3afe32592f24af17b5d7e02c9dfe,
which added IR support for cache hint metadata, as described in
https://discourse.llvm.org/t/rfc-composable-and-extensible-memory-cache-control-hints-in-llvm-ir/89443.

See previous https://github.com/llvm/llvm-project/pull/175901 that I
closed in favor of this one.

This PR adds support in SelectionDAG and lowering in NVPTX.

Supported cache hints:

L1 eviction: L1::evict_first, L1::evict_last, L1::evict_unchanged,
L1::no_allocate (requires SM 70+)
L2 eviction: L2::evict_first, L2::evict_last (requires SM 70+)
L2 prefetch: L2::64B, L2::128B (SM 75+), L2::256B (SM 80+)
L2::cache_hint with 64-bit cache policy descriptor (SM 80+, PTX 7.4+)

L1 eviction: L1::evict_first, L1::evict_last, L1::evict_unchanged,
L1::no_allocate (requires SM 70+ and PTX 7.4+)
L2 eviction: L2::evict_first, L2::evict_last (requires SM 100+, PTX
8.8+, and a 256-bit .v8.b32 or .v4.b64 memory operation)
L2 prefetch: L2::64B, L2::128B (requires SM 75+ and PTX 7.4+), L2::256B
(requires SM 80+ and PTX 7.4+)
L2 cache policy: L2::cache_hint with a 64-bit cache policy descriptor
(requires SM 80+ and PTX 7.4+)

I know this is a fairly large PR, but I needed to plug the support all
the way through the backend. I supposed I could add machinery in
SelectionDAG as an initial PR, but I'm not sure if that makes sense. I
implemented lowering on load + store + memcpy. I supposed memcpy can go
in a follow-up, but it doesn't really reduce the size that much.

TODO:
- implement support in global ISEL
- Implement lowering in NVPTX for atomics + other intrinsics
(llvm.masked.load/store)
- Better handling of cache hint metadata in legalization. Today we will
often drop the metadata. If we legalize a wide vector load into a bunch
of smaller loads, for example, we should preserve the metadata.
- Preserve L2 eviction metadata for suitably aligned, 32-byte-multiple
memcpy operations

Design decisions:
- I encoded the metadata in the MachineMemOperand. I hope it's ok to
increase the size. I think this is the best place because similar
information (atomic info, range metadata, etc...) is all stored there.
- When the metadata node values (strings which are target dependent) are
not valid for NVPTX, I call `ctx.emitError` to emit a diagnostic. I
think this is best because we wouldn't want front-ends to accidentally
emit incorrect metadata and for it to silently be dropped.

Co-authored-by: Fiigii <feipeng.compiler@gmail.com>

Assisted by AI
2026-08-06 15:55:49 -07:00
Prabhu Rajasekaran acd3fcfdd6 [clang] Emit call graph type metadata for internal linkage symbols (#210194) 2026-07-18 08:59:20 -07:00
Prabhu Rajasekaran c311656883 [clang][llvm]Uncorrelate CFI and Callgraph related type metadata annotations (#204266)
When -fexperimental-call-graph-section flag is set, it adds type
metadata to all the functions whose addresses are taken and does not
have local linkage. When this flag is set along with CFI, the type
metadata is added to all the vtable functions including destructors.
This changes which functions are to be treated as CFI functions and
includes such vtable entries to become part of the CFI check jumptables.

To disambiguate intentions of CFI and callgraph mechanisms, this patch
renames metadata set by callgraph mechanism to !callgraph
(MD_callgraph). This prevents inflating the list of CFI functions when
callgraph section is enabled along with CFI.
2026-06-30 18:47:04 -07:00
Aiden Grossman 37a71b650a [IR] Remove ProfileCount Abstraction
This only exists to differentiate between real and synthetic profiles.
Remove the abstraction now that we plan to fully remove synthetic
profiles.

Reviewers: mtrofin, david-xl

Reviewed By: mtrofin

Pull Request: https://github.com/llvm/llvm-project/pull/204770
2026-06-23 20:26:14 +00:00
Aiden Grossman 7e6d7003d8 [PSI] Return raw entry count values
Now that synthetic entry counts are being removed, stop using the
ProfileCount wrapper around entrycounts given it only exists to
distinguish between synthetic and real profile counts.

Reviewers: teresajohnson, david-xl, mtrofin

Pull Request: https://github.com/llvm/llvm-project/pull/204769
2026-06-23 20:23:40 +00:00
Quentin Colombet 422af7cca6 [MIR] Save internal VirtRegMap state in MIR (#197361)
Adds two optional fields to the per-vreg YAML record so MIR tests can
express VirtRegMap state that previously had no representation:

  registers:
    - { id: 1, class: vgpr_32, split-from: '%0', assigned-phys: '$vgpr5' }

Testing passes that consume sibling-register information (e.g.
InlineSpiller) requires constructing a VirtRegMap with split
relationships from a MIR test, which implies triggering live-range
splitting at minimum and make reproducers unnecessarily complicated.

So this change introduces a mechanism to serialize/deserialize the state
of the VirtRegMap pass.

Mechanism:
- For serialization:
  - MIRPrinter emits the new fields only when the VirtRegMap is available.
- For deserialization:
  - MIRParser stashes parsed entries in the MachineRegisterInfo object
  - VirtRegMap::init() drains the stash via assignVirt2Phys and
    setIsSplitFromReg, then clears it.

Validation at parse time:
  - 'assigned-phys' must be a physical register.
  - 'split-from' must reference a different vreg than 'id'.
  - 'split-from' physregs / named-vreg references already rejected
    by parseStandaloneVirtualRegister.

I'm not super happy about stashing the VRM info in the MRI, but that's
a small price to pay.
2026-06-12 17:42:21 +02:00
Scott Linder 5a7e4a0cf7 [AMDGPU][MC] Replace shifted registers in CFI instructions (#183147)
Change-Id: I0d99e9fe43ec3b6fecac20531119956dca2e4e5c
2026-05-27 17:26:40 -04:00
Heejin Ahn 6cad48ae72 [WebAssembly] Remove WasmEHFuncInfo (NFC) (#194972)
This removes `WasmEHFuncInfo` class.

This class was created to maintain the information of, "If an exception
is not caught by EHPad A, what is its next unwind destination?". Turns
out this information is already in the CFG.

After #130374, we use the common `findUnwindDestination`:
https://github.com/llvm/llvm-project/blob/113479d119a997e4c4c3eae63e087588c9662121/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp#L2107-L2164

Note that in case of `catchswitch`, we follow its unwind destination
chain and add all of them to the invoke BB's successors until it meets a
`cleanuppad`, which always catches an exception. And the order of the
successor is the order of the unwind destination chain. So an invoke
BB's successor list would be like: [normal destination, unwind EHPad 1,
unwind EHPad 2, unwind EHPad 3, ...] where EHPad 2 is the next unwind
destination if EHPad 1 does not catch an exception and so on. So if we
want to know what the current EHPad's next unwind destination is, we can
examine the EHPad's predecessor (invoke BB)'s successor list, and find
the next successor of EHPad. If there is no further next unwind
destination, the list should end with that EHPad.

How we do this is in the added lambda functions in CFGStackify, which
replaces `WasmEHFuncInfo`'s `hasUnwindDest`/`getUnwindDest`.

This depends on the order of successors of a CFG, which someone can
argue may be not guaranteed, in case someone messes up the successor
order in later passes. But I think in practice this should be fine. Also
maintaining `WasmEHFuncInfo` has more risks, because if other passes
change EH-related CFGs, they have to make sure `WasmEHFuncInfo` stays
synced. I haven't personally found (so far) those passes and haven't had
to any adjustments to other passes, but it was always an inherent risk
when you maintain a separate data structure.

I wasn't able to completely delete `WasmEHFuncInfo.h` because it
contains the `Tag` enum. I renamed it to `WasmEHInfo.h`, because we
dont' have `WasmEHFuncInfo` class anymore.
2026-04-29 16:51:30 -07:00
Cullen Rhodes f2efeabe31 [CodeGen] Parse frame-pointer attribute once when creating MachineFunction (#191974)
TargetOptions::DisableFramePointerElim is hot and showing up in
compile-time profiles via AArch64FrameLowering::hasFPImpl on
aarch64-O0-g builds. Repeatedly looking up the function attribute is
expensive. Parsing it once at MachineFunction initialisation and storing
as FramePointerKind on MachineFrameInfo is a -0.21% geomean improvement
on CTMark stage1-aarch64-O0-g. Also helps debug builds on other targets.

https://llvm-compile-time-tracker.com/compare.php?from=215f35eb8f1c313ac135ad47db1cc0b99b3ae694&to=51f6617517177bea1cc49baeab3acaf62d5e9df9&stat=instructions%3Au
2026-04-20 09:48:21 +01:00
Stefan Mada 8d734fdae5 Added better datalayout incompatible error message (#191862)
The existing datalayout incompatible error assert does not help with
debugging, as it does not print the datalayouts in question.

This change makes this failure give more useful information.
2026-04-14 14:47:31 -07:00
Alexis Engelke 9a2f23e1a4 [CodeGen] Use separate MBB number for analyses (#187086)
Block numbers are updated too frequently, which makes it difficult to
keep analyses up to date. Therefore, introduce a second number per basic
block that is used for analyses and is renumbered less often. This frees
analyses from providing somewhat efficient facilities for dealing with
changed block numbers, making it simpler to implement in e.g. LoopInfo
or CycleInfo.

(Currently, "less often" means not at all, but we might want to renumber
after certain passes if the numbering gets too sparse and no analyses
are preserved anyway.)

When we introduced a more general use of block numbers some time ago,
using the existing numbers seemed to be a somewhat obvious choice, but I
now think that this was a bad decision, as it conflates a number that is
used for ordering with a number that should be more stable.

MachineBasicBlock isn't particularly size-optimized and there's a fair
amount of padding where we can add another number.

There should be no performance impact,
2026-03-18 07:35:36 +01:00
Fangrui Song c889454f1d [MC] Rename PrivateGlobalPrefix to InternalSymbolPrefix. NFC (#185164)
The "private global" terminology, likely came from
llvm/lib/IR/Mangler.cpp, is misleading: "private" is the opposite of
"global", and these prefixed symbols are not global in the object file
format sense (e.g. ELF has STB_GLOBAL while these symbols are always
STB_LOCAL). The term "internal symbol" better describes their purpose:
symbols for internal use by compilers and assemblers, not meant to be
visible externally.

This rename is a step toward adopting the "internal symbol prefix"
terminology agreed with GNU as
(https://sourceware.org/pipermail/binutils/2026-March/148448.html).
2026-03-10 01:03:27 -07:00
Carlos Alberto Enciso bc9d5b01d3 [clang][DebugInfo] Add virtuality call-site target information in DWARF. (#182510)
Given the test case:

  struct CBase {
    virtual void foo();
  };

  void bar(CBase *Base) {
    Base->foo();
  }

and using '-emit-call-site-info' with llc, the following DWARF
is produced for the indirect call 'Base->foo()':

1$: DW_TAG_structure_type "CBase"
      ...
2$:   DW_TAG_subprogram "foo"
        ...

3$: DW_TAG_subprogram "bar"
      ...
4$:   DW_TAG_call_site
        ...

We add DW_AT_LLVM_virtual_call_origin to existing call-site
information, linking indirect calls to the function-declaration
they correspond to.

4$:   DW_TAG_call_site
        ...
        DW_AT_LLVM_virtual_call_origin (2$ "_ZN5CBase3fooEv")

The new attribute DW_AT_LLVM_virtual_call_origin helps to
address the ambiguity to any consumer due to the usage of
DW_AT_call_origin.

The functionality is available to all supported debuggers and
it is generated only for DWARF version 5 or greater.
2026-02-25 05:35:07 +00:00
Peter Collingbourne ebe9c6eabd CodeGen: Introduce MachineFunction::getPreferredAlignment().
MachineFunction can now be queried for the preferred alignment which
comes from the function attributes (optsize, minsize, prefalign) and
TargetLowering.

Part of this RFC:
https://discourse.llvm.org/t/rfc-enhancing-function-alignment-attributes/88019

Reviewers: vitalybuka, nikic, efriedma-quic, MaskRay

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/158368
2026-02-20 11:16:45 -08:00
Paul Kirth ec8b9ca47d Revert "[clang][DebugInfo] Add virtuality call-site target informatio… (#182343)
…n in DWARF. (#167666)"

This reverts commit 418ba6e8ae.

The commit caused an ICE due to hitting unreachable in
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:1307

Fixes #182337
2026-02-19 12:19:11 -08:00
Carlos Alberto Enciso 418ba6e8ae [clang][DebugInfo] Add virtuality call-site target information in DWARF. (#167666)
Given the test case:

  struct CBase {
    virtual void foo();
  };

  void bar(CBase *Base) {
    Base->foo();
  }

and using '-emit-call-site-info' with llc, the following DWARF
is produced for the indirect call 'Base->foo()':

1$: DW_TAG_structure_type "CBase"
      ...
2$:   DW_TAG_subprogram "foo"
        ...

3$: DW_TAG_subprogram "bar"
      ...
4$:   DW_TAG_call_site
        ...

We add DW_AT_LLVM_virtual_call_origin to existing call-site
information, linking indirect calls to the function-declaration
they correspond to.

4$:   DW_TAG_call_site
        ...
        DW_AT_LLVM_virtual_call_origin (2$ "_ZN5CBase3fooEv")

The new attribute DW_AT_LLVM_virtual_call_origin helps to
address the ambiguity to any consumer due to the usage of
DW_AT_call_origin.

The functionality is available to all supported debuggers.
2026-02-19 14:48:59 +00:00
Jay Foad 7ea33e6848 [CodeGen] Remove unused first operand of SUBREG_TO_REG (#179690)
The first input operand of SUBREG_TO_REG was an immediate that most
targets set to 0. In practice it had no effect on codegen. Remove it.
2026-02-04 17:35:21 +00:00
Seraphimt 112a6126ef Fixes non-functional changes found static analyzer (#171197)
As per @arsenm 's instructions, I've separated the non-functional
changes from https://github.com/llvm/llvm-project/pull/169958.
Afterwards I'll tackle the functional ones one by one. I hope I did
everything right this time.

Full descriptions in the article:
https://pvs-studio.com/en/blog/posts/cpp/1318/
3. Array overrun is possible.
The PVS-Studio warning: V557 Array overrun is possible. The value of
'regIdx' index could reach 31. VEAsmParser.cpp 696
10. Excessive check.
The PVS-Studio warning: V547 Expression 'IsLeaf' is always false.
PPCInstrInfo.cpp 419
11. Doubling the same check.
The PVS-Studio warning: V581 The conditional expressions of the 'if'
statements situated alongside each other are identical. Check lines:
5820, 5823. PPCInstrInfo.cpp 5823
15. Excessive check.
The PVS-Studio warning: V547 Expression 'i != e' is always true.
MachineFunction.cpp 1444
17. Excessive assignment.
The PVS-Studio warning: V1048 The 'FirstOp' variable was assigned the
same value. MachineInstr.cpp 1995
18. Excessive check.
The PVS-Studio warning: V547 Expression 'AllSame' is always true.
SimplifyCFG.cpp 1914
19. Excessive check.
The PVS-Studio warning: V547 Expression 'AbbrevDecl' is always true.
LVDWARFReader.cpp 398
2025-12-12 20:03:02 +01:00
Peter Collingbourne 6227eb90da Add IR and codegen support for deactivation symbols.
Deactivation symbols are a mechanism for allowing object files to disable
specific instructions in other object files at link time. The initial use
case is for pointer field protection.

For more information, see the RFC:
https://discourse.llvm.org/t/rfc-deactivation-symbols/85556

Reviewers: ojhunt, nikic, fmayer, arsenm, ahmedbougacha

Reviewed By: fmayer

Pull Request: https://github.com/llvm/llvm-project/pull/133536
2025-11-26 12:37:09 -08:00
Rahul Joshi 2a4f5b2751 [NFC][LLVM][CodeGen] Namespace related cleanups (#162999) 2025-10-13 07:54:50 -07:00
Peter Collingbourne 97716d2e31 Revert "CodeGen: Respect function align attribute if less than preferred alignment."
This reverts commit 9878ef3abd.

Needs more discussion of the semantics of the align attribute. See:
https://discourse.llvm.org/t/rfc-enhancing-function-alignment-attributes/88019
2025-08-22 13:17:53 -07:00
Matt Arsenault db126d8004 CodeGen: Make MachineFunction's subtarget member a reference (#153352) 2025-08-13 16:22:32 +09:00
Prabhu Rajasekaran 9e0dc4f737 [MachineFunction] Move CallSiteInfo constructor out of header (#151520) 2025-07-31 07:34:46 -07:00
Prabhu Rajasekaran c46336b396 Reapply "[llvm] Add CalleeTypeIds field to CallSiteInfo" (#150335) (#150990)
This reverts commit 05e08cdb3e.
Adding the missing -mtriple flags in MIR/X86 test files which caused
these tests to fail which was the reason for reverting the patch.
2025-07-28 13:34:26 -07:00
Ellis Hoag 819f020b28 Use F.hasOptSize() instead of checking optsize directly (#147348) 2025-07-28 08:38:52 -07:00
Haowei 05e08cdb3e Revert "[llvm] Add CalleeTypeIds field to CallSiteInfo" (#150335)
Reverts llvm/llvm-project#87574, which breaks LLVM ::
CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir tests
on linux-arm64 builders.
2025-07-23 15:45:43 -07:00
Prabhu Rajasekaran 7baf4bdd16 [llvm] Add CalleeTypeIds field to CallSiteInfo
Introducing `EnableCallGraphSection` target option to add
CalleeTypeIds field in CallSiteInfo. Read the callee type ids
in and out by the MIR parser/printer.

Reviewers: ilovepi

Reviewed By: ilovepi

Pull Request: https://github.com/llvm/llvm-project/pull/87574
2025-07-23 10:11:20 -07:00
Peter Collingbourne 9878ef3abd CodeGen: Respect function align attribute if less than preferred alignment.
Reviewers: arsenm, efriedma-quic

Reviewed By: arsenm

Pull Request: https://github.com/llvm/llvm-project/pull/149444
2025-07-18 13:33:46 -07:00
Alexis Engelke 2a8c65e983 [CodeGen][NFC] Fix quadratic c-t for large jump tables
Deleting a basic block removes all references from jump tables, which
is O(n). When freeing a MachineFunction, all basic blocks are deleted
before the jump tables, causing O(n^2) runtime. Fix this by deallocating
the jump table first.

Test case generator:

    import sys

    n = int(sys.argv[1])
    print("define void @f(i64 %c, ptr %p) {")
    print("  switch i64 %c, label %d [")
    for i in range(n):
        print(f"    i64 {i}, label %h{i}")
    print(f"  ]")
    for i in range(n):
        print(f'h{i}:')
        print(f'  store i64 {i*i}, ptr %p')
        print(f'  ret void')
    print('d:')
    print('  ret void')
    print('}')

Improvement at 5000 entries:

    Benchmark 1: ./llc.pre -filetype=obj -O0 <switch5k.bc
      Time (mean ± σ):      49.7 ms ±   1.0 ms
      Range (min … max):    48.0 ms …  52.1 ms    57 runs

    Benchmark 2: ./llc.post -filetype=obj -O0 <switch5k.bc
      Time (mean ± σ):      39.4 ms ±   0.8 ms
      Range (min … max):    37.1 ms …  41.1 ms    72 runs

    Summary
      ./llc.post -filetype=obj -O0 <switch5k.bc ran
        1.26 ± 0.04 times faster than ./llc.pre -filetype=obj -O0 <switch5k.bc

Improvement at 20000 entries:

    Benchmark 1: ./llc.pre -filetype=obj -O0 <switch20k.bc
      Time (mean ± σ):     281.7 ms ±   1.0 ms
      Range (min … max):   280.2 ms … 283.0 ms    10 runs

    Benchmark 2: ./llc.post -filetype=obj -O0 <switch20k.bc
      Time (mean ± σ):     123.9 ms ±   1.5 ms
      Range (min … max):   121.4 ms … 129.2 ms    23 runs

    Summary
      ./llc.post -filetype=obj -O0 <switch20k.bc ran
        2.27 ± 0.03 times faster than ./llc.pre -filetype=obj -O0 <switch20k.bc

Pull Request: https://github.com/llvm/llvm-project/pull/144108
2025-06-18 18:56:30 +02:00
Rahul Joshi 1fdf02ad5a [LLVM][CodeGen] Add convenience accessors for MachineFunctionProperties (#140002)
Add per-property has<Prop>/set<Prop>/reset<Prop> functions to
MachineFunctionProperties.
2025-05-22 08:07:52 -07:00
Kazu Hirata 1256ca04c2 [CodeGen] Call DenseMap::erase directly (NFC) (#135898) 2025-04-16 00:36:36 -07:00
Matt Arsenault db40592de6 MachineFunction: Remove null check on TargetRegisterInfo (#128480)
Targets are required to define this, it is not optional. Make the method
pure virtual to enforce this
2025-02-24 18:21:20 +07:00
Abhishek Kaushik 7b348f9bfd [MIR][NFC] Use std::move to avoid copying (#125930) 2025-02-09 13:51:34 +05:30
Shubham Sandeep Rastogi 44c9e46fce [InstrRef] Fix mismatch between LiveDebugValues and salvageCopySSA (#124233)
The LiveDebugValues pass and the instruction selector (which calls
salvageCopySSA) need to be consistent on what they consider a copy
instruction. With https://github.com/llvm/llvm-project/pull/75184, the
definition of what a copy instruction is was narrowed for AArch64 to
exclude a w->x ORR and treat it as a zero-extend rather than a copy

However, to make sure LiveDebugValues still treats a w->x ORR as a copy,
the new function, isCopyLikeInstr was created. We need to make sure that
salvageCopySSA also calls that function.

This patch addresses this mismatch.
2025-01-27 09:26:22 -08:00
Jeremy MorseandStephen Tozer 6292a808b3 [NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites (#123737)
As part of the "RemoveDIs" project, BasicBlock::iterator now carries a
debug-info bit that's needed when getFirstNonPHI and similar feed into
instruction insertion positions. Call-sites where that's necessary were
updated a year ago; but to ensure some type safety however, we'd like to
have all calls to getFirstNonPHI use the iterator-returning version.

This patch changes a bunch of call-sites calling getFirstNonPHI to use
getFirstNonPHIIt, which returns an iterator. All these call sites are
where it's obviously safe to fetch the iterator then dereference it. A
follow-up patch will contain less-obviously-safe changes.

We'll eventually deprecate and remove the instruction-pointer
getFirstNonPHI, but not before adding concise documentation of what
considerations are needed (very few).

---------

Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
2025-01-24 13:27:56 +00:00
Mingming LiuandEllis Hoag de209fa11b [CodeGen] Introduce Static Data Splitter pass (#122183)
https://discourse.llvm.org/t/rfc-profile-guided-static-data-partitioning/83744
proposes to partition static data sections.

This patch introduces a codegen pass. This patch produces jump table
hotness in the in-memory states (machine jump table info and entries).
Target-lowering and asm-printer consume the states and produce `.hot`
section suffix. The follow up PR
https://github.com/llvm/llvm-project/pull/122215 implements such
changes.

---------

Co-authored-by: Ellis Hoag <ellis.sparky.hoag@gmail.com>
2025-01-22 21:06:46 -08:00
Daniel Paoliello 19032bfe87 [aarch64][win] Update Called Globals info when updating Call Site info (#122762)
Fixes the "use after poison" issue introduced by #121516 (see
<https://github.com/llvm/llvm-project/pull/121516#issuecomment-2585912395>).

The root cause of this issue is that #121516 introduced "Called Global"
information for call instructions modeling how "Call Site" info is
stored in the machine function, HOWEVER it didn't copy the
copy/move/erase operations for call site information.

The fix is to rename and update the existing copy/move/erase functions
so they also take care of Called Global info.
2025-01-13 14:00:31 -08:00
Matt Arsenault 61f99a1c75 RegAlloc: Do not fatal error if there are no registers in the alloc order (#119640)
Try to use DiagnosticInfo if every register in the class is reserved
by forcing assignment to a reserved register. Also reduces the number
of redundant errors emitted, particularly with fast.

This is still broken in the case of undef uses. There are additional
complications in greedy and fast, so leave it for a separate fix.
2024-12-16 10:52:49 +09:00
Matin Raayai bb3f5e1fed Overhaul the TargetMachine and LLVMTargetMachine Classes (#111234)
Following discussions in #110443, and the following earlier discussions
in https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html,
https://reviews.llvm.org/D38482, https://reviews.llvm.org/D38489, this
PR attempts to overhaul the `TargetMachine` and `LLVMTargetMachine`
interface classes. More specifically:
1. Makes `TargetMachine` the only class implemented under
`TargetMachine.h` in the `Target` library.
2. `TargetMachine` contains target-specific interface functions that
relate to IR/CodeGen/MC constructs, whereas before (at least on paper)
it was supposed to have only IR/MC constructs. Any Target that doesn't
want to use the independent code generator simply does not implement
them, and returns either `false` or `nullptr`.
3. Renames `LLVMTargetMachine` to `CodeGenCommonTMImpl`. This renaming
aims to make the purpose of `LLVMTargetMachine` clearer. Its interface
was moved under the CodeGen library, to further emphasis its usage in
Targets that use CodeGen directly.
4. Makes `TargetMachine` the only interface used across LLVM and its
projects. With these changes, `CodeGenCommonTMImpl` is simply a set of
shared function implementations of `TargetMachine`, and CodeGen users
don't need to static cast to `LLVMTargetMachine` every time they need a
CodeGen-specific feature of the `TargetMachine`.
5. More importantly, does not change any requirements regarding library
linking.

cc @arsenm @aeubanks
2024-11-14 13:30:05 -08:00
Kazu Hirata 735ab61ac8 [CodeGen] Remove unused includes (NFC) (#115996)
Identified with misc-include-cleaner.
2024-11-12 23:15:06 -08:00