Skip to content

Commit 4efa1a1

Browse files
committed
[CodeGen] Port two-address-instructions to new pass manager
1 parent 34bfed6 commit 4efa1a1

20 files changed

+170
-73
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- llvm/CodeGen/TwoAddressInstructionPass.h -----------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CODEGEN_TWOADDRESSINSTRUCTIONPASS_H
10+
#define LLVM_CODEGEN_TWOADDRESSINSTRUCTIONPASS_H
11+
12+
#include "llvm/CodeGen/MachinePassManager.h"
13+
14+
namespace llvm {
15+
16+
class TwoAddressInstructionPass
17+
: public PassInfoMixin<TwoAddressInstructionPass> {
18+
public:
19+
PreservedAnalyses run(MachineFunction &MF,
20+
MachineFunctionAnalysisManager &MFAM);
21+
MachineFunctionProperties getSetProperties() {
22+
return MachineFunctionProperties().set(
23+
MachineFunctionProperties::Property::TiedOpsRewritten);
24+
}
25+
};
26+
27+
} // namespace llvm
28+
29+
#endif // LLVM_CODEGEN_TWOADDRESSINSTRUCTIONPASS_H

llvm/include/llvm/InitializePasses.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void initializeTargetLibraryInfoWrapperPassPass(PassRegistry&);
298298
void initializeTargetPassConfigPass(PassRegistry&);
299299
void initializeTargetTransformInfoWrapperPassPass(PassRegistry&);
300300
void initializeTLSVariableHoistLegacyPassPass(PassRegistry &);
301-
void initializeTwoAddressInstructionPassPass(PassRegistry&);
301+
void initializeTwoAddressInstructionLegacyPassPass(PassRegistry &);
302302
void initializeTypeBasedAAWrapperPassPass(PassRegistry&);
303303
void initializeTypePromotionLegacyPass(PassRegistry&);
304304
void initializeInitUndefPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "llvm/CodeGen/SjLjEHPrepare.h"
5353
#include "llvm/CodeGen/StackProtector.h"
5454
#include "llvm/CodeGen/TargetPassConfig.h"
55+
#include "llvm/CodeGen/TwoAddressInstructionPass.h"
5556
#include "llvm/CodeGen/UnreachableBlockElim.h"
5657
#include "llvm/CodeGen/WasmEHPrepare.h"
5758
#include "llvm/CodeGen/WinEHPrepare.h"

llvm/include/llvm/Passes/MachinePassRegistry.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ MACHINE_FUNCTION_PASS("print<slot-indexes>", SlotIndexesPrinterPass(dbgs()))
148148
MACHINE_FUNCTION_PASS("require-all-machine-function-properties",
149149
RequireAllMachineFunctionPropertiesPass())
150150
MACHINE_FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
151+
MACHINE_FUNCTION_PASS("two-address-instruction", TwoAddressInstructionPass())
151152
MACHINE_FUNCTION_PASS("verify", MachineVerifierPass())
152153
#undef MACHINE_FUNCTION_PASS
153154

@@ -258,7 +259,6 @@ DUMMY_MACHINE_FUNCTION_PASS("stack-frame-layout", StackFrameLayoutAnalysisPass)
258259
DUMMY_MACHINE_FUNCTION_PASS("stack-slot-coloring", StackSlotColoringPass)
259260
DUMMY_MACHINE_FUNCTION_PASS("stackmap-liveness", StackMapLivenessPass)
260261
DUMMY_MACHINE_FUNCTION_PASS("tailduplication", TailDuplicatePass)
261-
DUMMY_MACHINE_FUNCTION_PASS("twoaddressinstruction", TwoAddressInstructionPass)
262262
DUMMY_MACHINE_FUNCTION_PASS("unpack-mi-bundles", UnpackMachineBundlesPass)
263263
DUMMY_MACHINE_FUNCTION_PASS("virtregrewriter", VirtRegRewriterPass)
264264
DUMMY_MACHINE_FUNCTION_PASS("xray-instrumentation", XRayInstrumentationPass)

llvm/lib/CodeGen/CodeGen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
132132
initializeStripDebugMachineModulePass(Registry);
133133
initializeTailDuplicatePass(Registry);
134134
initializeTargetPassConfigPass(Registry);
135-
initializeTwoAddressInstructionPassPass(Registry);
135+
initializeTwoAddressInstructionLegacyPassPass(Registry);
136136
initializeTypePromotionLegacyPass(Registry);
137137
initializeUnpackMachineBundlesPass(Registry);
138138
initializeUnreachableBlockElimLegacyPassPass(Registry);

llvm/lib/CodeGen/TwoAddressInstructionPass.cpp

+120-70
Large diffs are not rendered by default.

llvm/lib/Passes/PassBuilder.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "llvm/CodeGen/SlotIndexes.h"
115115
#include "llvm/CodeGen/StackProtector.h"
116116
#include "llvm/CodeGen/TargetPassConfig.h"
117+
#include "llvm/CodeGen/TwoAddressInstructionPass.h"
117118
#include "llvm/CodeGen/TypePromotion.h"
118119
#include "llvm/CodeGen/WasmEHPrepare.h"
119120
#include "llvm/CodeGen/WinEHPrepare.h"

llvm/test/CodeGen/AArch64/statepoint-twoaddr.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=aarch64-unknown-linux -run-pass=twoaddressinstruction -verify-machineinstrs %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=aarch64-unknown-linux --passes=two-address-instruction %s -o - | FileCheck %s
34
# REQUIRES: aarch64-registered-target
45

56
# Verify that the register class is correctly constrained after the twoaddress replacement

llvm/test/CodeGen/AMDGPU/GlobalISel/twoaddr-extract-dyn-v7f64.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -early-live-intervals -run-pass=liveintervals -run-pass=twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -passes='require<live-intervals>,two-address-instruction' -o - %s | FileCheck %s
34

45
---
56
name: dyn_extract_v7f64_v_v

llvm/test/CodeGen/AMDGPU/early-lis-two-address-partial-def.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
22
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -run-pass=liveintervals -run-pass=twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck --check-prefix=GFX90A %s
3+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a --passes='require<live-intervals>,two-address-instruction' -o - %s | FileCheck --check-prefix=GFX90A %s
34

45
---
56
name: aligned_partial_vgpr_64

llvm/test/CodeGen/AMDGPU/gfx10-twoaddr-fma.mir

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX10 %s
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck --check-prefixes=GFX10 %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GFX10 %s
4+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -o - -early-live-intervals | FileCheck --check-prefixes=GFX10 %s
35

46
# GFX10-LABEL: name: test_fmamk_reg_imm_f16
57
# GFX10: %2:vgpr_32 = IMPLICIT_DEF

llvm/test/CodeGen/AMDGPU/gfx11-twoaddr-fma.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX11 %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GFX11 %s
34

45
---
56
name: test_fmamk_reg_imm_f16

llvm/test/CodeGen/AMDGPU/twoaddr-fma-f64.mir

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck -check-prefix=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
4+
# RUN: llc -mtriple=amdgcn -mcpu=gfx90a %s --passes=two-address-instruction -o - -early-live-intervals | FileCheck -check-prefix=GCN %s
35

46
# GCN-LABEL: name: test_fmamk_reg_imm_f64
57
# GCN: V_FMA_F64_e64 0, killed %0, 0, %2, 0, killed %1, 0, 0, implicit $mode, implicit $exec

llvm/test/CodeGen/AMDGPU/twoaddr-fma.mir

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck --check-prefixes=GCN %s
33
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck --check-prefixes=GCN %s
44
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck --check-prefixes=GCN %s
5+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1010 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GCN %s
6+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -o - | FileCheck --check-prefixes=GCN %s
57

68
# GCN-LABEL: name: test_fmamk_reg_imm_f32
79
# GCN: %2:vgpr_32 = IMPLICIT_DEF

llvm/test/CodeGen/AMDGPU/twoaddr-mad.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck -check-prefix=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx900 %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
34

45
# GCN-LABEL: name: test_madmk_reg_imm_f32
56
# GCN: V_MADMK_F32 killed %0.sub0, 1078523331, killed %1, implicit $mode, implicit $exec

llvm/test/CodeGen/AMDGPU/twoaddr-wmma.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - | FileCheck -check-prefix=GCN %s
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s -run-pass twoaddressinstruction -verify-machineinstrs -o - -early-live-intervals | FileCheck -check-prefix=GCN %s
3+
# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 %s --passes=two-address-instruction -o - | FileCheck -check-prefix=GCN %s
34

45
# GCN-LABEL: name: test_v_wmma_f32_16x16x16_f16_twoaddr_w32
56
# GCN: early-clobber %2:vreg_256 = V_WMMA_F32_16X16X16_F16_threeaddr_w32 8, killed %1, 8, killed %1, 8, %0, 0, 0, implicit $exec

llvm/test/CodeGen/Hexagon/two-addr-tied-subregs.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -march hexagon -run-pass livevars -run-pass twoaddressinstruction -verify-machineinstrs -o - %s | FileCheck %s
2+
# RUN: llc -march hexagon --passes='require<live-vars>,two-address-instruction' -o - %s | FileCheck %s
23

34

45
###############################################################################

llvm/test/CodeGen/X86/distancemap.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc %s -o - -mtriple=x86_64-unknown-linux -run-pass=twoaddressinstruction -verify-machineinstrs | FileCheck %s
3+
# RUN: llc %s -o - -mtriple=x86_64-unknown-linux --passes=two-address-instruction | FileCheck %s
34

45
# In TwoAddressInstructionPass, new instructions should be added to DistanceMap.
56
# In this case, function convertInstTo3Addr is called on the first ADD

llvm/test/CodeGen/X86/statepoint-vreg-twoaddr.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: llc -x mir -run-pass=twoaddressinstruction < %s | FileCheck %s
2+
# RUN: llc -x mir --passes=two-address-instruction < %s | FileCheck %s
23

34
# This test checks that TwoAddressInstruction pass does not create redundate COPY
45
# instruction for STATEPOINT tied operands.

llvm/test/CodeGen/X86/twoaddr-mul2.mir

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
# RUN: llc -mtriple=x86_64-unknown -mcpu=haswell -run-pass=twoaddressinstruction -verify-machineinstrs %s -o - | FileCheck %s
3+
# RUN: llc -mtriple=x86_64-unknown -mcpu=haswell --passes=two-address-instruction -verify-machineinstrs %s -o - | FileCheck %s
34

45
# Check that we don't have any uses of [[COPY]] after it is killed.
56
---

0 commit comments

Comments
 (0)