-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR] Add support for byteswap intrinsic (#523)
This PR adds support for the following intrinsic functions: - `__builtin_bswap{16, 32, 64}` - `_byteswap_{ushort, ulong, uint64}` This PR adds a new `cir.bswap` operation to represent such an intrinsic call. CIRGen and LLVMIR lowering for the new operation is included in this PR.
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
using u16 = unsigned short; | ||
using u32 = unsigned int; | ||
using u64 = unsigned long long; | ||
|
||
u16 bswap_u16(u16 x) { | ||
return __builtin_bswap16(x); | ||
} | ||
|
||
// CHECK: cir.func @_Z9bswap_u16t | ||
// CHECK: %{{.+}} = cir.bswap(%{{.+}} : !u16i) : !u16i | ||
// CHECK: } | ||
|
||
u32 bswap_u32(u32 x) { | ||
return __builtin_bswap32(x); | ||
} | ||
|
||
// CHECK: cir.func @_Z9bswap_u32j | ||
// CHECK: %{{.+}} = cir.bswap(%{{.+}} : !u32i) : !u32i | ||
// CHECK: } | ||
|
||
u64 bswap_u64(u64 x) { | ||
return __builtin_bswap64(x); | ||
} | ||
|
||
// CHECK: cir.func @_Z9bswap_u64y | ||
// CHECK: %{{.+}} = cir.bswap(%{{.+}} : !u64i) : !u64i | ||
// CHECK: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR | ||
// RUN: cir-translate %s -cir-to-llvmir | FileCheck %s -check-prefix=LLVM | ||
|
||
!u32i = !cir.int<u, 32> | ||
|
||
cir.func @test(%arg0: !u32i) -> !u32i { | ||
%0 = cir.bswap(%arg0 : !u32i) : !u32i | ||
cir.return %0 : !u32i | ||
} | ||
|
||
// MLIR: llvm.func @test(%arg0: i32) -> i32 | ||
// MLIR-NEXT: %0 = llvm.call_intrinsic "llvm.bswap.i32"(%arg0) : (i32) -> i32 | ||
// MLIR-NEXT: llvm.return %0 : i32 | ||
// MLIR-NEXT: } | ||
|
||
// LLVM: define i32 @test(i32 %0) | ||
// LLVM-NEXT: %2 = call i32 @llvm.bswap.i32(i32 %0) | ||
// LLVM-NEXT: ret i32 %2 | ||
// LLVM-NEXT: } |