Skip to content
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

Update llvm-public #18

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
e81819e
G_CONCAT_VECTOR legalization & selection for generic IR (JIRA AIECC-…
ValentijnvdBeek Apr 24, 2024
f334a82
Add support to G_UNMERGE for unpacking into scalar elements and split…
ValentijnvdBeek Apr 24, 2024
e22d945
[AIE2] Fix control reg IR dependencies for VPACK and VST.PACK.
SagarMaheshwari99 Apr 15, 2024
13b59b9
[TableGen] Support modelInaccessibleMemThroughRegs property for Table…
SagarMaheshwari99 Apr 26, 2024
c4bf2f8
[AIE2] Model ctrl reg IR dependencies for VSRS, VUPS, VST.SRS and VLD…
SagarMaheshwari99 Apr 26, 2024
e206259
[AIE2] Model ctrl reg IR dependencies for VCONV.bf16.fp32 and VST.CON…
SagarMaheshwari99 Apr 16, 2024
ffff9eb
[AIE2] Model ctrl reg IR dependencies for VFLOOR.
SagarMaheshwari99 Apr 15, 2024
e2cccaf
[AIE2] Model ctrl reg IR dependencies for VADD.f, VSUB.f, VNEGADD/SUB.f.
SagarMaheshwari99 Apr 16, 2024
87bf9d5
[AIE2] Model ctrl reg IR dependencies for VCLR, VNEG.f, VMUL.f and VN…
SagarMaheshwari99 Apr 17, 2024
6b61d72
[AIE2] Model ctrl reg IR dependencies for VMAC.f, VMSC.f, VADDMAC.f &…
SagarMaheshwari99 Apr 17, 2024
e4ab1bd
[AIE2] Model ctrl reg IR dependencies for VMUL.f, VNEGMUL.f, VMAC.f, …
SagarMaheshwari99 Apr 17, 2024
83090a1
Update DeadMachineInstructionElim
abhinay-anubola Apr 22, 2024
2db7b15
Update AIEPostSelectOptimize by splitting into two passes
abhinay-anubola Apr 22, 2024
5488ceb
[AIE2] G_BUILD_VECTOR legalization from generic IR for native vectors
ValentijnvdBeek Apr 4, 2024
38a1447
[AIE2] Implement selection for the new G_AIE_VECTOR_ELT_LEFT
ValentijnvdBeek Apr 3, 2024
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
4 changes: 2 additions & 2 deletions clang/include/clang/Basic/BuiltinsAIE.def
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ BUILTIN(__builtin_aiev2_get_ctrl_reg, "UiUi", "nc")
BUILTIN(__builtin_aiev2_get_coreid, "i", "nc")

// Pack-Unpack
BUILTIN(__builtin_aiev2_pack_I8_I16, "V32cV32sii", "nc")
BUILTIN(__builtin_aiev2_pack_I4_I8, "V32cV32sii", "nc")
BUILTIN(__builtin_aiev2_pack_I8_I16, "V32cV32si", "nc")
BUILTIN(__builtin_aiev2_pack_I4_I8, "V32cV32si", "nc")
BUILTIN(__builtin_aiev2_unpack_I16_I8, "V32sV32ci", "nc")
BUILTIN(__builtin_aiev2_unpack_I8_I4, "V32sV32ci", "nc")

Expand Down
24 changes: 8 additions & 16 deletions clang/lib/Headers/aiev2_ldst.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,35 @@
#define __AIEV2_PACK_UNPACK_H__

INTRINSIC(v32int8) pack(v32int16 v, int sign) {
return __builtin_aiev2_pack_I8_I16(v, sign,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I8_I16(v, sign);
}

INTRINSIC(v32uint8) pack(v32uint16 v, int sign) {
return __builtin_aiev2_pack_I8_I16(v, sign,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I8_I16(v, sign);
}

INTRINSIC(v64int4) pack(v64int8 v, int sign) {
return __builtin_aiev2_pack_I4_I8(v, sign,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I4_I8(v, sign);
}

INTRINSIC(v64uint4) pack(v64uint8 v, int sign) {
return __builtin_aiev2_pack_I4_I8(v, sign,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I4_I8(v, sign);
}

INTRINSIC(v32int8) pack(v32int16 v) {
return __builtin_aiev2_pack_I8_I16(v, __SIGN_SIGNED,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I8_I16(v, __SIGN_SIGNED);
}

INTRINSIC(v32uint8) pack(v32uint16 v) {
return __builtin_aiev2_pack_I8_I16(v, __SIGN_UNSIGNED,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I8_I16(v, __SIGN_UNSIGNED);
}

INTRINSIC(v64int4) pack(v64int8 v) {
return __builtin_aiev2_pack_I4_I8(v, __SIGN_SIGNED,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I4_I8(v, __SIGN_SIGNED);
}

INTRINSIC(v64uint4) pack(v64uint8 v) {
return __builtin_aiev2_pack_I4_I8(v, __SIGN_UNSIGNED,
__builtin_aiev2_get_ctrl_reg(crSat));
return __builtin_aiev2_pack_I4_I8(v, __SIGN_UNSIGNED);
}

INTRINSIC(v32int16) unpack(v32int8 v, bool sign) {
Expand Down
135 changes: 54 additions & 81 deletions clang/test/CodeGen/aie/aie2/aie2-ldst.cpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions llvm/include/llvm/CodeGen/MachineRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Modifications (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its
// affiliates
//
//===----------------------------------------------------------------------===//
//
// This file defines the MachineRegisterInfo class.
Expand Down Expand Up @@ -976,6 +979,15 @@ class MachineRegisterInfo {
!isReserved(PhysReg);
}

/// Returns true if redundant assignments to \p PhysReg can be simplified.
/// This is queried by DeadMachineInstructionElim.
/// This essentially means that all assignments of \p PhysReg are visible and
/// non volatile.
bool canSimplifyPhysReg(MCRegister PhysReg) const {
return !isReserved(PhysReg) ||
getTargetRegisterInfo()->isSimplifiableReservedReg(PhysReg);
}

//===--------------------------------------------------------------------===//
// LiveIn Management
//===--------------------------------------------------------------------===//
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ class TargetRegisterInfo : public MCRegisterInfo {
return {};
}

/// Whether redundant assignments to reserved registers can be simplified by
/// e.g. DeadMachineInstructionElim
/// See \p MachineRegisterInfo::canSimplifyPhysReg().
virtual bool isSimplifiableReservedReg(MCRegister PhysReg) const {
return false;
}

/// Returns false if we can't guarantee that Physreg, specified as an IR asm
/// clobber constraint, will be preserved across the statement.
virtual bool isAsmClobberable(const MachineFunction &MF,
Expand Down
81 changes: 49 additions & 32 deletions llvm/include/llvm/IR/IntrinsicsAIE2.td
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ class AIEV2I1024I1024ADDMACConf

class AIEV2I1024I1024MULConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v64bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I1024I1024MACConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v64bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I1024I1024ADDMACConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v64bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I512I1024MULConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I512I1024MACConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I512I1024ADDMACConfBF16
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_i128_ty, llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2I512I512MULConf
: Intrinsic<[llvm_v16i64_ty], [llvm_v64i8_ty, llvm_v16i32_ty, llvm_i32_ty],
Expand All @@ -93,24 +93,29 @@ class AIEV2I512I512AddMaconf

class AIE2bf16MULConf
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_i32_ty],
[IntrNoMem]>;
class AIE2bf16MACConf
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIE2bf16MACConf
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
class AIE2bf16AddMACConf
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIE2bf16AddMACConf
: Intrinsic<[llvm_v8i64_ty], [llvm_v32bf16_ty, llvm_v32bf16_ty, llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;

[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2AddSubAcc : DefaultAttrsIntrinsic<[llvm_v16i64_ty], [llvm_v16i64_ty, llvm_v16i64_ty, llvm_i32_ty],
[IntrNoMem]>;

class AIEV2AddSubAccFloat : DefaultAttrsIntrinsic<[llvm_v8i64_ty], [llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrNoMem]>;
class AIEV2AddSubAccFloat : DefaultAttrsIntrinsic<[llvm_v8i64_ty],
[llvm_v8i64_ty, llvm_v8i64_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2NEGCONF : DefaultAttrsIntrinsic<[llvm_v16i64_ty], [llvm_v16i64_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2NEGFPCONF : DefaultAttrsIntrinsic<[llvm_v8i64_ty], [llvm_v8i64_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2NEGFPCONF : DefaultAttrsIntrinsic<[llvm_v8i64_ty],
[llvm_v8i64_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2V16AccFloatToV16Bf : Intrinsic<[llvm_v16bf16_ty], [llvm_v8i64_ty], [IntrNoMem]>;
class AIEV2V16AccFloatToV16Bf : Intrinsic<[llvm_v16bf16_ty],
[llvm_v8i64_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2V16BfToV16AccFloat : Intrinsic<[llvm_v8i64_ty], [llvm_v16bf16_ty], [IntrNoMem]>;

class AIEV2UNDV4Int32
Expand Down Expand Up @@ -314,30 +319,42 @@ class AIEV2Concat_1024_512_acc
//srs
class AIEV2I256V16Acc32I
: Intrinsic<[llvm_v16i16_ty], [llvm_v8i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2I256V16Acc64I
: Intrinsic<[llvm_v16i16_ty], [llvm_v16i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2I256V32Acc32I
: Intrinsic<[llvm_v32i8_ty], [llvm_v16i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2I256V8Acc64I
: Intrinsic<[llvm_v8i32_ty], [llvm_v8i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2I512V16Acc64I
: Intrinsic<[llvm_v16i32_ty], [llvm_v16i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2I512V32Acc32I
: Intrinsic<[llvm_v32i16_ty], [llvm_v16i64_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

// VUPS
class AIEV2Acc32V16I256I : Intrinsic<[llvm_v8i64_ty], [llvm_v16i16_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc32V32I256I : Intrinsic<[llvm_v16i64_ty], [llvm_v32i8_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc32V32I512I : Intrinsic<[llvm_v16i64_ty], [llvm_v32i16_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc64V16I256I : Intrinsic<[llvm_v16i64_ty], [llvm_v16i16_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc64V16I512I : Intrinsic<[llvm_v16i64_ty], [llvm_v16i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc64V8I256I : Intrinsic<[llvm_v8i64_ty], [llvm_v8i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2Acc32V16I256I : Intrinsic<[llvm_v8i64_ty],
[llvm_v16i16_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2Acc32V32I256I : Intrinsic<[llvm_v16i64_ty],
[llvm_v32i8_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2Acc32V32I512I : Intrinsic<[llvm_v16i64_ty],
[llvm_v32i16_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2Acc64V16I256I : Intrinsic<[llvm_v16i64_ty],
[llvm_v16i16_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2Acc64V16I512I : Intrinsic<[llvm_v16i64_ty],
[llvm_v16i32_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2Acc64V8I256I : Intrinsic<[llvm_v8i64_ty],
[llvm_v8i32_ty, llvm_i32_ty, llvm_i32_ty],
[IntrReadMem, IntrInaccessibleMemOnly]>;

class AIEV2V64I8V2I32V64I8I32 : DefaultAttrsIntrinsic<[llvm_v64i8_ty, llvm_v2i32_ty], [llvm_v64i8_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2V32I16I32V32I16I32 : DefaultAttrsIntrinsic<[llvm_v32i16_ty, llvm_i32_ty], [llvm_v32i16_ty, llvm_i32_ty], [IntrNoMem]>;
Expand Down Expand Up @@ -427,7 +444,7 @@ class AIEV2BF16ToInt : Intrinsic<[llvm_i32_ty],
[IntrNoMem]>;
class AIEV2V16BF16ToV16I : Intrinsic<[llvm_v16i32_ty],
[llvm_v16bf16_ty, llvm_i32_ty],
[IntrNoMem]>;
[IntrReadMem, IntrInaccessibleMemOnly]>;

// Streams
class AIEV2V16I32I32I32 : DefaultAttrsIntrinsic<[llvm_v16i32_ty], [llvm_i32_ty], [IntrInaccessibleMemOnly]>;
Expand Down Expand Up @@ -469,16 +486,16 @@ class AIEV2CLB : Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;
class AIEV2DIVS : Intrinsic<[llvm_i32_ty, llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;

// Pack-Unpack
class AIEV2PackI4I8 : Intrinsic<[llvm_v32i8_ty], [llvm_v32i16_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2PackI8I16 : Intrinsic<[llvm_v32i8_ty], [llvm_v32i16_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2PackI4I8 : Intrinsic<[llvm_v32i8_ty], [llvm_v32i16_ty, llvm_i32_ty], [IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2PackI8I16 : Intrinsic<[llvm_v32i8_ty], [llvm_v32i16_ty, llvm_i32_ty], [IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2UnPackI8I4 : Intrinsic<[llvm_v32i16_ty], [llvm_v32i8_ty, llvm_i32_ty], [IntrNoMem]>;
class AIEV2UnPackI16I8 : Intrinsic<[llvm_v32i16_ty], [llvm_v32i8_ty, llvm_i32_ty], [IntrNoMem]>;

// Scheduling barrier
class AIEV2SchedBarrier : Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrConvergent, IntrWillReturn]>;

// clear accumulator
class AIEV2CLR16F : Intrinsic<[llvm_v8i64_ty], [], [IntrNoMem]>;
class AIEV2CLR16F : Intrinsic<[llvm_v8i64_ty], [], [IntrReadMem, IntrInaccessibleMemOnly]>;
class AIEV2VCLRACC1024 : Intrinsic<[llvm_v16i64_ty], [], [IntrNoMem]>;

// Extract Sub-Vector
Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ class Instruction : InstructionEncoding {
// Added complexity passed onto matching pattern.
int AddedComplexity = 0;

// Passed onto matching pattern and helps in skipping checks
// where mayLoad/mayStore is inferred in the instruction but doesn't
// mirror in the pattern.
bit ModelsInaccessibleMemThroughRegs = false;

// Indicates if this is a pre-isel opcode that should be
// legalized/regbankselected/selected.
bit isPreISelOpcode = false;
Expand Down
7 changes: 6 additions & 1 deletion llvm/include/llvm/Target/TargetSelectionDAG.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Modifications (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
//
//===----------------------------------------------------------------------===//
//
// This file defines the target-independent interfaces used by SelectionDAG
Expand Down Expand Up @@ -1935,9 +1937,11 @@ def atomic_store_64 :
// their GPRs).
//

class Pattern<dag patternToMatch, list<dag> resultInstrs> {
class Pattern<dag patternToMatch, list<dag> resultInstrs,
bit modelsInaccessibleMemThroughRegs = false> {
dag PatternToMatch = patternToMatch;
list<dag> ResultInstrs = resultInstrs;
bit ModelsInaccessibleMemThroughRegs = modelsInaccessibleMemThroughRegs;
list<Predicate> Predicates = []; // See class Instruction in Target.td.
int AddedComplexity = 0; // See class Instruction in Target.td.
}
Expand All @@ -1946,6 +1950,7 @@ class Pattern<dag patternToMatch, list<dag> resultInstrs> {
// not needing a full list.
class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;

class PatInaccessibleMem<dag pattern, dag result>: Pattern<pattern, [result], true>;
//===----------------------------------------------------------------------===//
// Complex pattern definitions.
//
Expand Down
39 changes: 35 additions & 4 deletions llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Modifications (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its
// affiliates
//
//===----------------------------------------------------------------------===//
//
// This is an extremely simple MachineInstr-level dead-code-elimination pass.
Expand Down Expand Up @@ -34,11 +37,15 @@ namespace {
const MachineRegisterInfo *MRI = nullptr;
const TargetInstrInfo *TII = nullptr;
LiveRegUnits LivePhysRegs;
bool KeepLifetimeInstructions;

public:
static char ID; // Pass identification, replacement for typeid
DeadMachineInstructionElim() : MachineFunctionPass(ID) {
initializeDeadMachineInstructionElimPass(*PassRegistry::getPassRegistry());
DeadMachineInstructionElim(bool LifetimeInstructions = false)
: MachineFunctionPass(ID),
KeepLifetimeInstructions(LifetimeInstructions) {
initializeDeadMachineInstructionElimPass(
*PassRegistry::getPassRegistry());
}

void getAnalysisUsage(AnalysisUsage &AU) const override {
Expand Down Expand Up @@ -69,6 +76,15 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
if (MI->getOpcode() == TargetOpcode::LOCAL_ESCAPE)
return false;

// Don't delete marks of start and end of lifetime of a stack, as they give
// information about lifetime of stack for next passes.
if (KeepLifetimeInstructions) {
if (MI->getOpcode() == TargetOpcode::LIFETIME_START ||
MI->getOpcode() == TargetOpcode::LIFETIME_END) {
return false;
}
}

// Don't delete instructions with side effects.
bool SawStore = false;
if (!MI->isSafeToMove(nullptr, SawStore) && !MI->isPHI())
Expand All @@ -78,8 +94,8 @@ bool DeadMachineInstructionElim::isDead(const MachineInstr *MI) const {
for (const MachineOperand &MO : MI->all_defs()) {
Register Reg = MO.getReg();
if (Reg.isPhysical()) {
// Don't delete live physreg defs, or any reserved register defs.
if (!LivePhysRegs.available(Reg) || MRI->isReserved(Reg))
// Don't delete live physreg defs, or any non-simplifiable physreg defs.
if (!LivePhysRegs.available(Reg) || !MRI->canSimplifyPhysReg(Reg))
return false;
} else {
if (MO.isDead()) {
Expand Down Expand Up @@ -127,6 +143,14 @@ bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
for (MachineBasicBlock *MBB : post_order(&MF)) {
LivePhysRegs.addLiveOuts(*MBB);

// Reserved registers are considered always live, so consider them as
// live-outs for MBB. Inside MBB, dead assignments can still be detected.
for (MCPhysReg PhysReg : MRI->getReservedRegs().set_bits()) {
if (MRI->canSimplifyPhysReg(PhysReg)) {
LivePhysRegs.addReg(PhysReg);
}
}

// Now scan the instructions and delete dead ones, tracking physreg
// liveness as we go.
for (MachineInstr &MI : make_early_inc_range(reverse(*MBB))) {
Expand All @@ -149,3 +173,10 @@ bool DeadMachineInstructionElim::eliminateDeadMI(MachineFunction &MF) {
LivePhysRegs.clear();
return AnyChanges;
}

namespace llvm {
MachineFunctionPass *
createDeadMachineInstructionElim(bool KeepLifetimeInstructions = false) {
return new DeadMachineInstructionElim(KeepLifetimeInstructions);
}
} // end namespace llvm
Loading
Loading