Skip to content

[SYCL][NFCI] Use DeviceConfigFile instead of sycl_aspects metadata #13194

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

Closed
wants to merge 13 commits into from
Closed
5 changes: 3 additions & 2 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// Process properties and annotations
MPM.addPass(CompileTimePropertiesPass());

// Remove SYCL metadata added by the frontend, like sycl_aspects
// Note, this pass should be at the end of the pipeline
// Remove SYCL metadata added by the frontend, like
// sycl_types_that_use_aspects Note, this pass should be at the end of the
// pipeline
MPM.addPass(CleanupSYCLMetadataPass());
}
}
Expand Down
30 changes: 0 additions & 30 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,6 @@ static llvm::MDNode *getAspectsMD(ASTContext &ASTContext,
return llvm::MDNode::get(Ctx, AspectsMD);
}

static llvm::MDNode *getAspectEnumValueMD(ASTContext &ASTContext,
llvm::LLVMContext &Ctx,
const EnumConstantDecl *ECD) {
SmallVector<llvm::Metadata *, 2> AspectEnumValMD;
AspectEnumValMD.push_back(llvm::MDString::get(Ctx, ECD->getName()));
AspectEnumValMD.push_back(
llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(Ctx), ECD->getInitVal().getSExtValue())));
return llvm::MDNode::get(Ctx, AspectEnumValMD);
}

static bool isStackProtectorOn(const LangOptions &LangOpts,
const llvm::Triple &Triple,
clang::LangOptions::StackProtectorMode Mode) {
Expand Down Expand Up @@ -1337,15 +1326,6 @@ void CodeGenModule::Release() {
RD->getAttr<SYCLUsesAspectsAttr>()));
}
}

// Emit metadata for all aspects defined in the aspects enum.
if (AspectsEnumDecl) {
llvm::NamedMDNode *AspectEnumValsMD =
TheModule.getOrInsertNamedMetadata("sycl_aspects");
for (const EnumConstantDecl *ECD : AspectsEnumDecl->enumerators())
AspectEnumValsMD->addOperand(
getAspectEnumValueMD(Context, TheModule.getContext(), ECD));
}
}

// HLSL related end of code gen work items.
Expand Down Expand Up @@ -5720,16 +5700,6 @@ void CodeGenModule::maybeSetTrivialComdat(const Decl &D,
GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
}

void CodeGenModule::setAspectsEnumDecl(const EnumDecl *ED) {
if (AspectsEnumDecl && AspectsEnumDecl != ED) {
// Conflicting definitions of the aspect enum are not allowed.
Error(ED->getLocation(), "redefinition of aspect enum");
getDiags().Report(AspectsEnumDecl->getLocation(),
diag::note_previous_definition);
}
AspectsEnumDecl = ED;
}

void CodeGenModule::generateIntelFPGAAnnotation(
const Decl *D, llvm::SmallString<256> &AnnotStr) {
llvm::raw_svector_ostream Out(AnnotStr);
Expand Down
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ class CodeGenModule : public CodeGenTypeCache {
MetadataTypeMap GeneralizedMetadataIdMap;

llvm::DenseMap<StringRef, const RecordDecl *> TypesWithAspects;
const EnumDecl *AspectsEnumDecl = nullptr;
// Helps squashing blocks of TopLevelStmtDecl into a single llvm::Function
// when used with -fincremental-extensions.
std::pair<std::unique_ptr<CodeGenFunction>, const TopLevelStmtDecl *>
Expand Down Expand Up @@ -1122,8 +1121,6 @@ class CodeGenModule : public CodeGenTypeCache {
TypesWithAspects[TypeName] = RD;
}

void setAspectsEnumDecl(const EnumDecl *ED);

void generateIntelFPGAAnnotation(const Decl *D,
llvm::SmallString<256> &AnnotStr);
void addGlobalIntelFPGAAnnotation(const VarDecl *VD, llvm::GlobalValue *GV);
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/CodeGen/CodeGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) {
if (!ConvertType(ED->getIntegerType())->isIntegerTy(32))
TypeCache.clear();
}
// If this is the SYCL aspect enum it is saved for later processing.
if (const auto *Attr = ED->getAttr<SYCLTypeAttr>())
if (Attr->getType() == SYCLTypeAttr::SYCLType::aspect)
CGM.setAspectsEnumDecl(ED);
// If necessary, provide the full definition of a type only used with a
// declaration so far.
if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
Expand Down
14 changes: 0 additions & 14 deletions clang/test/CodeGenSYCL/aspect_enum.cpp

This file was deleted.

12 changes: 0 additions & 12 deletions clang/test/CodeGenSYCL/multiple_aspect_enum.cpp

This file was deleted.

6 changes: 6 additions & 0 deletions llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ struct TargetInfo {
};
using TargetTable_t = std::map<std::string, TargetInfo>;

// AspectTable maps aspect names to their corresponding enum value
// defined in the SYCL headers
using AspectTable_t = std::map<std::string, int>;

#define GET_TargetTable_IMPL
#define GET_AspectTable_IMPL
#include "llvm/SYCLLowerIR/DeviceConfigFile.inc"
#undef GET_TargetTable_IMPL
#undef GET_AspectTable_IMPL
} // namespace DeviceConfigFile
169 changes: 73 additions & 96 deletions llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,87 @@

include "llvm/TableGen/DynamicTable.td"

class Aspect<string name> {
class Aspect<string name, int value> {
string Name = name;
int Value = value;
}

def AspectCpu : Aspect<"cpu">;
def AspectGpu : Aspect<"gpu">;
def AspectAccelerator : Aspect<"accelerator">;
def AspectCustom : Aspect<"custom">;
def AspectFp16 : Aspect<"fp16">;
def AspectFp64 : Aspect<"fp64">;
def AspectImage : Aspect<"image">;
def AspectOnline_compiler : Aspect<"online_compiler">;
def AspectOnline_linker : Aspect<"online_linker">;
def AspectQueue_profiling : Aspect<"queue_profiling">;
def AspectUsm_device_allocations : Aspect<"usm_device_allocations">;
def AspectUsm_host_allocations : Aspect<"usm_host_allocations">;
def AspectUsm_shared_allocations : Aspect<"usm_shared_allocations">;
def AspectUsm_system_allocations : Aspect<"usm_system_allocations">;
def AspectExt_intel_pci_address : Aspect<"ext_intel_pci_address">;
def AspectExt_intel_gpu_eu_count : Aspect<"ext_intel_gpu_eu_count">;
def AspectExt_intel_gpu_eu_simd_width : Aspect<"ext_intel_gpu_eu_simd_width">;
def AspectExt_intel_gpu_slices : Aspect<"ext_intel_gpu_slices">;
def AspectExt_intel_gpu_subslices_per_slice : Aspect<"ext_intel_gpu_subslices_per_slice">;
def AspectExt_intel_gpu_eu_count_per_subslice : Aspect<"ext_intel_gpu_eu_count_per_subslice">;
def AspectExt_intel_max_mem_bandwidth : Aspect<"ext_intel_max_mem_bandwidth">;
def AspectExt_intel_mem_channel : Aspect<"ext_intel_mem_channel">;
def AspectUsm_atomic_host_allocations : Aspect<"usm_atomic_host_allocations">;
def AspectUsm_atomic_shared_allocations : Aspect<"usm_atomic_shared_allocations">;
def AspectAtomic64 : Aspect<"atomic64">;
def AspectExt_intel_device_info_uuid : Aspect<"ext_intel_device_info_uuid">;
def AspectExt_oneapi_srgb : Aspect<"ext_oneapi_srgb">;
def AspectExt_oneapi_native_assert : Aspect<"ext_oneapi_native_assert">;
def AspectHost_debuggable : Aspect<"host_debuggable">;
def AspectExt_intel_gpu_hw_threads_per_eu : Aspect<"ext_intel_gpu_hw_threads_per_eu">;
def AspectExt_oneapi_cuda_async_barrier : Aspect<"ext_oneapi_cuda_async_barrier">;
def AspectExt_oneapi_bfloat16_math_functions : Aspect<"ext_oneapi_bfloat16_math_functions">;
def AspectExt_intel_free_memory : Aspect<"ext_intel_free_memory">;
def AspectExt_intel_device_id : Aspect<"ext_intel_device_id">;
def AspectExt_intel_memory_clock_rate : Aspect<"ext_intel_memory_clock_rate">;
def AspectExt_intel_memory_bus_width : Aspect<"ext_intel_memory_bus_width">;
def AspectEmulated : Aspect<"emulated">;
def AspectExt_intel_legacy_image : Aspect<"ext_intel_legacy_image">;
def AspectExt_oneapi_bindless_images : Aspect<"ext_oneapi_bindless_images">;
def AspectExt_oneapi_bindless_images_shared_usm : Aspect<"ext_oneapi_bindless_images_shared_usm">;
def AspectExt_oneapi_bindless_images_1d_usm : Aspect<"ext_oneapi_bindless_images_1d_usm">;
def AspectExt_oneapi_bindless_images_2d_usm : Aspect<"ext_oneapi_bindless_images_2d_usm">;
def AspectExt_oneapi_interop_memory_import : Aspect<"ext_oneapi_interop_memory_import">;
def AspectExt_oneapi_interop_memory_export : Aspect<"ext_oneapi_interop_memory_export">;
def AspectExt_oneapi_interop_semaphore_import : Aspect<"ext_oneapi_interop_semaphore_import">;
def AspectExt_oneapi_interop_semaphore_export : Aspect<"ext_oneapi_interop_semaphore_export">;
def AspectExt_oneapi_mipmap : Aspect<"ext_oneapi_mipmap">;
def AspectExt_oneapi_mipmap_anisotropy : Aspect<"ext_oneapi_mipmap_anisotropy">;
def AspectExt_oneapi_mipmap_level_reference : Aspect<"ext_oneapi_mipmap_level_reference">;
def AspectExt_intel_esimd : Aspect<"ext_intel_esimd">;
def AspectExt_oneapi_ballot_group : Aspect<"ext_oneapi_ballot_group">;
def AspectExt_oneapi_fixed_size_group : Aspect<"ext_oneapi_fixed_size_group">;
def AspectExt_oneapi_opportunistic_group : Aspect<"ext_oneapi_opportunistic_group">;
def AspectExt_oneapi_tangle_group : Aspect<"ext_oneapi_tangle_group">;
def AspectExt_intel_matrix : Aspect<"ext_intel_matrix">;
def AspectExt_oneapi_is_composite : Aspect<"ext_oneapi_is_composite">;
def AspectExt_oneapi_is_component : Aspect<"ext_oneapi_is_component">;
def AspectExt_oneapi_graph : Aspect<"ext_oneapi_graph">;
def AspectExt_intel_fpga_task_sequence : Aspect<"ext_intel_fpga_task_sequence">;
def AspectExt_oneapi_limited_graph : Aspect<"ext_oneapi_limited_graph">;
def AspectExt_oneapi_private_alloca : Aspect<"ext_oneapi_private_alloca">;
def AspectCpu : Aspect<"cpu", 1>;
def AspectGpu : Aspect<"gpu", 2>;
def AspectAccelerator : Aspect<"accelerator", 3>;
def AspectCustom : Aspect<"custom", 4>;
def AspectFp16 : Aspect<"fp16", 5>;
def AspectFp64 : Aspect<"fp64", 6>;
def AspectImage : Aspect<"image", 9>;
def AspectOnline_compiler : Aspect<"online_compiler", 10>;
def AspectOnline_linker : Aspect<"online_linker", 11>;
def AspectQueue_profiling : Aspect<"queue_profiling", 12>;
def AspectUsm_device_allocations : Aspect<"usm_device_allocations", 13>;
def AspectUsm_host_allocations : Aspect<"usm_host_allocations", 14>;
def AspectUsm_shared_allocations : Aspect<"usm_shared_allocations", 15>;
def AspectUsm_system_allocations : Aspect<"usm_system_allocations", 17>;
def AspectExt_intel_pci_address : Aspect<"ext_intel_pci_address", 18>;
def AspectExt_intel_gpu_eu_count : Aspect<"ext_intel_gpu_eu_count", 19>;
def AspectExt_intel_gpu_eu_simd_width : Aspect<"ext_intel_gpu_eu_simd_width", 20>;
def AspectExt_intel_gpu_slices : Aspect<"ext_intel_gpu_slices", 21>;
def AspectExt_intel_gpu_subslices_per_slice : Aspect<"ext_intel_gpu_subslices_per_slice", 22>;
def AspectExt_intel_gpu_eu_count_per_subslice : Aspect<"ext_intel_gpu_eu_count_per_subslice", 23>;
def AspectExt_intel_max_mem_bandwidth : Aspect<"ext_intel_max_mem_bandwidth", 24>;
def AspectExt_intel_mem_channel : Aspect<"ext_intel_mem_channel", 25>;
def AspectUsm_atomic_host_allocations : Aspect<"usm_atomic_host_allocations", 26>;
def AspectUsm_atomic_shared_allocations : Aspect<"usm_atomic_shared_allocations", 27>;
def AspectAtomic64 : Aspect<"atomic64", 28>;
def AspectExt_intel_device_info_uuid : Aspect<"ext_intel_device_info_uuid", 29>;
def AspectExt_oneapi_srgb : Aspect<"ext_oneapi_srgb", 30>;
def AspectExt_oneapi_native_assert : Aspect<"ext_oneapi_native_assert", 31>;
def AspectHost_debuggable : Aspect<"host_debuggable", 32>;
def AspectExt_intel_gpu_hw_threads_per_eu : Aspect<"ext_intel_gpu_hw_threads_per_eu", 33>;
def AspectExt_oneapi_cuda_async_barrier : Aspect<"ext_oneapi_cuda_async_barrier", 34>;
def AspectExt_oneapi_bfloat16_math_functions : Aspect<"ext_oneapi_bfloat16_math_functions", 35>;
def AspectExt_intel_free_memory : Aspect<"ext_intel_free_memory", 36>;
def AspectExt_intel_device_id : Aspect<"ext_intel_device_id", 37>;
def AspectExt_intel_memory_clock_rate : Aspect<"ext_intel_memory_clock_rate", 38>;
def AspectExt_intel_memory_bus_width : Aspect<"ext_intel_memory_bus_width", 39>;
def AspectEmulated : Aspect<"emulated", 40>;
def AspectExt_intel_legacy_image : Aspect<"ext_intel_legacy_image", 41>;
def AspectExt_oneapi_bindless_images : Aspect<"ext_oneapi_bindless_images", 42>;
def AspectExt_oneapi_bindless_images_shared_usm : Aspect<"ext_oneapi_bindless_images_shared_usm", 43>;
def AspectExt_oneapi_bindless_images_1d_usm : Aspect<"ext_oneapi_bindless_images_1d_usm", 44>;
def AspectExt_oneapi_bindless_images_2d_usm : Aspect<"ext_oneapi_bindless_images_2d_usm", 45>;
def AspectExt_oneapi_interop_memory_import : Aspect<"ext_oneapi_interop_memory_import", 46>;
def AspectExt_oneapi_interop_memory_export : Aspect<"ext_oneapi_interop_memory_export", 47>;
def AspectExt_oneapi_interop_semaphore_import : Aspect<"ext_oneapi_interop_semaphore_import", 48>;
def AspectExt_oneapi_interop_semaphore_export : Aspect<"ext_oneapi_interop_semaphore_export", 49>;
def AspectExt_oneapi_mipmap : Aspect<"ext_oneapi_mipmap", 50>;
def AspectExt_oneapi_mipmap_anisotropy : Aspect<"ext_oneapi_mipmap_anisotropy", 51>;
def AspectExt_oneapi_mipmap_level_reference : Aspect<"ext_oneapi_mipmap_level_reference", 52>;
def AspectExt_intel_esimd : Aspect<"ext_intel_esimd", 53>;
def AspectExt_oneapi_ballot_group : Aspect<"ext_oneapi_ballot_group", 54>;
def AspectExt_oneapi_fixed_size_group : Aspect<"ext_oneapi_fixed_size_group", 55>;
def AspectExt_oneapi_opportunistic_group : Aspect<"ext_oneapi_opportunistic_group", 56>;
def AspectExt_oneapi_tangle_group : Aspect<"ext_oneapi_tangle_group", 57>;
def AspectExt_intel_matrix : Aspect<"ext_intel_matrix", 58>;
def AspectExt_oneapi_is_composite : Aspect<"ext_oneapi_is_composite", 59>;
def AspectExt_oneapi_is_component : Aspect<"ext_oneapi_is_component", 60>;
def AspectExt_oneapi_graph : Aspect<"ext_oneapi_graph", 61>;
def AspectExt_intel_fpga_task_sequence : Aspect<"ext_intel_fpga_task_sequence", 62>;
def AspectExt_oneapi_limited_graph : Aspect<"ext_oneapi_limited_graph", 63>;
def AspectExt_oneapi_private_alloca : Aspect<"ext_oneapi_private_alloca", 64>;
// Deprecated aspects
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics">;
def AspectUsm_system_allocator : Aspect<"usm_system_allocator">;
def AspectUsm_restricted_shared_allocations : Aspect<"usm_restricted_shared_allocations">;
def AspectHost : Aspect<"host">;
def AspectInt64_base_atomics : Aspect<"int64_base_atomics", 7>;
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics", 8>;
def AspectUsm_system_allocator : Aspect<"usm_system_allocator", 17>;
def AspectUsm_restricted_shared_allocations : Aspect<"usm_restricted_shared_allocations", 16>;
def AspectHost : Aspect<"host", 0>;
defvar AllUSMAspects = [AspectUsm_device_allocations, AspectUsm_host_allocations,
AspectUsm_shared_allocations, AspectUsm_system_allocations, AspectUsm_atomic_host_allocations,
AspectUsm_atomic_shared_allocations];

def AspectTable : DynamicTable {
let FilterClass = "Aspect";
let Fields = ["Name", "Value"];
string CppTypeName = "int";
}

def TargetTable : DynamicTable {
let FilterClass = "TargetInfo";
Expand All @@ -105,35 +111,6 @@ class TargetInfo<string targetName, list<Aspect> aspectList, list<int> subGroupS
string aotToolchainOptions = options;
}

// This definition serves the only purpose of testing whether the aspect list defined in here and in SYCL RT match.
def : TargetInfo<"__TestAspectList",
[AspectCpu, AspectGpu, AspectAccelerator, AspectCustom, AspectFp16, AspectFp64, AspectImage, AspectOnline_compiler,
AspectOnline_linker, AspectQueue_profiling, AspectUsm_device_allocations, AspectUsm_host_allocations,
AspectUsm_shared_allocations, AspectUsm_system_allocations, AspectExt_intel_pci_address,
AspectExt_intel_gpu_eu_count, AspectExt_intel_gpu_eu_simd_width, AspectExt_intel_gpu_slices,
AspectExt_intel_gpu_subslices_per_slice, AspectExt_intel_gpu_eu_count_per_subslice,
AspectExt_intel_max_mem_bandwidth, AspectExt_intel_mem_channel, AspectUsm_atomic_host_allocations,
AspectUsm_atomic_shared_allocations, AspectAtomic64, AspectExt_intel_device_info_uuid, AspectExt_oneapi_srgb,
AspectExt_oneapi_native_assert, AspectHost_debuggable, AspectExt_intel_gpu_hw_threads_per_eu,
AspectExt_oneapi_cuda_async_barrier, AspectExt_oneapi_bfloat16_math_functions, AspectExt_intel_free_memory,
AspectExt_intel_device_id, AspectExt_intel_memory_clock_rate, AspectExt_intel_memory_bus_width, AspectEmulated,
AspectExt_intel_legacy_image, AspectExt_oneapi_bindless_images,
AspectExt_oneapi_bindless_images_shared_usm, AspectExt_oneapi_bindless_images_1d_usm, AspectExt_oneapi_bindless_images_2d_usm,
AspectExt_oneapi_interop_memory_import, AspectExt_oneapi_interop_memory_export,
AspectExt_oneapi_interop_semaphore_import, AspectExt_oneapi_interop_semaphore_export,
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd,
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group,
AspectExt_oneapi_tangle_group, AspectExt_intel_matrix, AspectExt_oneapi_is_composite, AspectExt_oneapi_is_component,
AspectExt_oneapi_graph, AspectExt_intel_fpga_task_sequence, AspectExt_oneapi_limited_graph,
AspectExt_oneapi_private_alloca],
[]>;
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
// match.
def : TargetInfo<"__TestDeprecatedAspectList",
[AspectInt64_base_atomics, AspectInt64_extended_atomics, AspectUsm_system_allocator,
AspectUsm_restricted_shared_allocations, AspectHost],
[]>;

def : TargetInfo<"spir64", [], [], "", "", 1>;
def : TargetInfo<"spir64_gen", [], [], "", "", 1>;
def : TargetInfo<"spir64_x86_64", [], [], "", "", 1>;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/SYCLLowerIR/CleanupSYCLMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ PreservedAnalyses CleanupSYCLMetadataPass::run(Module &M,
// Remove SYCL module-level metadata that will never be used again to avoid
// duplication of their operands during llvm-link hence preventing
// increase of the module size
llvm::SmallVector<llvm::StringRef, 2> ModuleMDToRemove = {
"sycl_aspects", "sycl_types_that_use_aspects"};
llvm::SmallVector<llvm::StringRef, 1> ModuleMDToRemove = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect this to grow? Otherwise, we can drop the SmallVector and the loop. Just a nit. Thanks

"sycl_types_that_use_aspects"};
for (const auto &MD : ModuleMDToRemove)
cleanupSYCLCompilerMetadata(M, MD);

Expand Down
Loading