-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InferAddressSpaces] Add InferAddressSpaces pass to pipeline for SPIR (…
…#7418) Clang generates 'addrspacecast' instructions to align address spaces between alloca/global variables/kernel parameters and flat address space pointers (i.e. addrspace(4)). For the SPIR/SPIR-V target, addrspace(4) is the generic address space and these addrspacecast instructions can be safely removed from the code when named address space can be deduced. To perform this removing, the InferAddressSpaces pass has been added to the clang optimization pipeline for SPIR and SPIR-V targets. This pass should be run after the other optimization passes (both function and module) and, it is very important, after inlining to let the pass "understand" from which address space as many as possible variables came and eliminate as many as possible addrspacecast instructions. The elimination of redundant addrspacecast instruction decreases the size of the generated SPIR-V module and therefore makes less pressure on the backend/JIT compilers.
- Loading branch information
Showing
3 changed files
with
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===---- SPIR.h - Declare SPIR and SPIR-V target interfaces ----*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
namespace clang { | ||
namespace targets { | ||
|
||
// Used by both the SPIR and SPIR-V targets. Code of the generic address space | ||
// for the target | ||
constexpr unsigned SPIR_GENERIC_AS = 4u; | ||
|
||
} // namespace targets | ||
} // namespace clang |
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,21 @@ | ||
// RUN: %clang_cc1 -O1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64 -emit-llvm %s -o - | FileCheck %s | ||
|
||
// Test that address spaces are deduced correctly by compiler optimizations. | ||
|
||
#include "sycl.hpp" | ||
|
||
using namespace sycl; | ||
|
||
void foo(const float *usm_in, float* usm_out) { | ||
queue Q; | ||
Q.submit([&](handler &cgh) { | ||
cgh.single_task<class test>([=](){ | ||
*usm_out = *usm_in; | ||
}); | ||
}); | ||
} | ||
|
||
// No addrspacecast before loading and storing values | ||
// CHECK-NOT: addrspacecast | ||
// CHECK: %0 = load float, ptr addrspace(1) | ||
// CHECK: store float %0, ptr addrspace(1) |