Skip to content

Commit 443c244

Browse files
committed
[GlobalISel] translate freeze to new generic G_FREEZE
Summary: As a follow up to https://reviews.llvm.org/D29014, add translation support for freeze. Introduce a new generic instruction G_FREEZE and translate freeze to it. Reviewers: dsanders, aqjune, arsenm, aditya_nandakumar, t.p.northover, lebedev.ri, paquette, aemerson Reviewed By: aqjune, arsenm Subscribers: fhahn, lebedev.ri, wdng, rovka, hiraditya, jfb, volkan, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77795
1 parent a73a81d commit 443c244

File tree

7 files changed

+63
-4
lines changed

7 files changed

+63
-4
lines changed

llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ class IRTranslator : public MachineFunctionPass {
452452
bool translateAtomicCmpXchg(const User &U, MachineIRBuilder &MIRBuilder);
453453
bool translateAtomicRMW(const User &U, MachineIRBuilder &MIRBuilder);
454454
bool translateFence(const User &U, MachineIRBuilder &MIRBuilder);
455+
bool translateFreeze(const User &U, MachineIRBuilder &MIRBuilder);
455456

456457
// Stubs to keep the compiler happy while we implement the rest of the
457458
// translation.
@@ -482,9 +483,6 @@ class IRTranslator : public MachineFunctionPass {
482483
bool translateUserOp2(const User &U, MachineIRBuilder &MIRBuilder) {
483484
return false;
484485
}
485-
bool translateFreeze(const User &U, MachineIRBuilder &MIRBuilder) {
486-
return false;
487-
}
488486

489487
/// @}
490488

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,11 @@ class MachineIRBuilder {
12701270
/// Build and insert `G_FENCE Ordering, Scope`.
12711271
MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope);
12721272

1273+
/// Build and insert \p Dst = G_FREEZE \p Src
1274+
MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) {
1275+
return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src});
1276+
}
1277+
12731278
/// Build and insert \p Res = G_BLOCK_ADDR \p BA
12741279
///
12751280
/// G_BLOCK_ADDR computes the address of a basic block.

llvm/include/llvm/Support/TargetOpcodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ HANDLE_TARGET_OPCODE(G_INTTOPTR)
279279
/// COPY is the relevant instruction.
280280
HANDLE_TARGET_OPCODE(G_BITCAST)
281281

282+
/// Generic freeze.
283+
HANDLE_TARGET_OPCODE(G_FREEZE)
284+
282285
/// INTRINSIC trunc intrinsic.
283286
HANDLE_TARGET_OPCODE(G_INTRINSIC_TRUNC)
284287

llvm/include/llvm/Target/GenericOpcodes.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ def G_DYN_STACKALLOC : GenericInstruction {
203203
let hasSideEffects = 1;
204204
}
205205

206+
def G_FREEZE : GenericInstruction {
207+
let OutOperandList = (outs type0:$dst);
208+
let InOperandList = (ins type0:$src);
209+
let hasSideEffects = 0;
210+
}
211+
206212
//------------------------------------------------------------------------------
207213
// Binary ops.
208214
//------------------------------------------------------------------------------

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,21 @@ bool IRTranslator::translateFence(const User &U,
21032103
return true;
21042104
}
21052105

2106+
bool IRTranslator::translateFreeze(const User &U,
2107+
MachineIRBuilder &MIRBuilder) {
2108+
const ArrayRef<Register> DstRegs = getOrCreateVRegs(U);
2109+
const ArrayRef<Register> SrcRegs = getOrCreateVRegs(*U.getOperand(0));
2110+
2111+
assert(DstRegs.size() == SrcRegs.size() &&
2112+
"Freeze with different source and destination type?");
2113+
2114+
for (unsigned I = 0; I < DstRegs.size(); ++I) {
2115+
MIRBuilder.buildFreeze(DstRegs[I], SrcRegs[I]);
2116+
}
2117+
2118+
return true;
2119+
}
2120+
21062121
void IRTranslator::finishPendingPhis() {
21072122
#ifndef NDEBUG
21082123
DILocationVerifier Verifier;

llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,4 +2360,32 @@ define i64 @test_readcyclecounter() {
23602360
ret i64 %res
23612361
}
23622362

2363-
!0 = !{ i64 0, i64 2 }
2363+
define i64 @test_freeze(i64 %a) {
2364+
; CHECK-LABEL: name: test_freeze
2365+
; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
2366+
; CHECK-NEXT: [[RES:%[0-9]+]]:_(s64) = G_FREEZE [[COPY]]
2367+
; CHECK-NEXT: $x0 = COPY [[RES]]
2368+
; CHECK-NEXT: RET_ReallyLR implicit $x0
2369+
%res = freeze i64 %a
2370+
ret i64 %res
2371+
}
2372+
2373+
define {i8, i32} @test_freeze_struct({ i8, i32 }* %addr) {
2374+
; CHECK-LABEL: name: test_freeze_struct
2375+
; CHECK: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
2376+
; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s8) = G_LOAD [[COPY]](p0)
2377+
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
2378+
; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C]]
2379+
; CHECK-NEXT: [[LOAD1:%[0-9]+]]:_(s32) = G_LOAD [[PTR_ADD]](p0)
2380+
; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s8) = G_FREEZE [[LOAD]]
2381+
; CHECK-NEXT: [[FREEZE1:%[0-9]+]]:_(s32) = G_FREEZE [[LOAD1]]
2382+
; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[FREEZE]]
2383+
; CHECK-NEXT: $w0 = COPY [[ANYEXT]]
2384+
; CHECK-NEXT: $w1 = COPY [[FREEZE1]]
2385+
; CHECK-NEXT: RET_ReallyLR implicit $w0, implicit $w1
2386+
%load = load { i8, i32 }, { i8, i32 }* %addr
2387+
%res = freeze {i8, i32} %load
2388+
ret {i8, i32} %res
2389+
}
2390+
2391+
!0 = !{ i64 0, i64 2 }

llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@
116116
# DEBUG-NEXT: .. the first uncovered type index: 2, OK
117117
# DEBUG-NEXT: .. the first uncovered imm index: 0, OK
118118
#
119+
# DEBUG-NEXT: G_FREEZE (opcode {{[0-9]+}}): 1 type index, 0 imm indices
120+
# DEBUG-NEXT: .. type index coverage check SKIPPED: no rules defined
121+
# DEBUG-NEXT: .. imm index coverage check SKIPPED: no rules defined
122+
#
119123
# DEBUG-NEXT: G_INTRINSIC_TRUNC (opcode {{[0-9]+}}): 1 type index, 0 imm indices
120124
# DEBUG-NEXT: .. opcode {{[0-9]+}} is aliased to {{[0-9]+}}
121125
# DEBUG-NEXT: .. type index coverage check SKIPPED: user-defined predicate detected

0 commit comments

Comments
 (0)