Skip to content

[NFC][SYCL] Minor stylistic changes in SYCLPropagateAspectsUsage.cpp #7049

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

Merged
merged 5 commits into from
Oct 17, 2022
Merged
Changes from all commits
Commits
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
34 changes: 15 additions & 19 deletions llvm/lib/SYCLLowerIR/SYCLPropagateAspectsUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "llvm/SYCLLowerIR/SYCLPropagateAspectsUsage.h"

#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
Expand Down Expand Up @@ -58,20 +59,18 @@ TypeToAspectsMapTy getTypesThatUseAspectsFromMetadata(const Module &M) {
return Result;

LLVMContext &C = M.getContext();
for (const auto OperandIt : Node->operands()) {
const MDNode &N = *OperandIt;
assert(N.getNumOperands() > 1 && "intel_types_that_use_aspect metadata "
"shouldn't contain empty metadata nodes");
for (const MDNode *N : Node->operands()) {
assert(N->getNumOperands() > 1 && "intel_types_that_use_aspect metadata "
"shouldn't contain empty metadata nodes");

const auto *TypeName = cast<MDString>(N.getOperand(0));
const auto *TypeName = cast<MDString>(N->getOperand(0));
const Type *T = StructType::getTypeByName(C, TypeName->getString());
assert(T &&
"invalid type referenced by intel_types_that_use_aspect metadata");

AspectsSetTy &Aspects = Result[T];
for (size_t I = 1; I != N.getNumOperands(); ++I) {
const auto *CAM = cast<ConstantAsMetadata>(N.getOperand(I));
const Constant *C = CAM->getValue();
for (const MDOperand &Op : drop_begin(N->operands())) {
const Constant *C = cast<ConstantAsMetadata>(Op)->getValue();
Aspects.insert(cast<ConstantInt>(C)->getSExtValue());
}
}
Expand All @@ -89,16 +88,15 @@ AspectValueToNameMapTy getAspectsFromMetadata(const Module &M) {
if (!Node)
return Result;

for (const auto OperandIt : Node->operands()) {
const MDNode &N = *OperandIt;
assert(N.getNumOperands() == 2 &&
for (const MDNode *N : Node->operands()) {
assert(N->getNumOperands() == 2 &&
"Each operand of sycl_aspects must be a pair.");

// The aspect's name is the first operand.
const auto *AspectName = cast<MDString>(N.getOperand(0));
const auto *AspectName = cast<MDString>(N->getOperand(0));

// The aspect's integral value is the second operand.
const auto *AspectCAM = cast<ConstantAsMetadata>(N.getOperand(1));
const auto *AspectCAM = cast<ConstantAsMetadata>(N->getOperand(1));
const Constant *AspectC = AspectCAM->getValue();

Result[AspectName->getString()] =
Expand All @@ -119,6 +117,7 @@ void propagateAspectsThroughTypes(const TypesEdgesTy &Edges, const Type *Start,
const AspectsSetTy &AspectsToPropagate = Aspects[Start];
SmallSetVector<const Type *, 16> TypesToPropagate;
TypesToPropagate.insert(Start);
// The TypesToPropagate is being updated inside the loop, so no range-for.
for (size_t I = 0; I < TypesToPropagate.size(); ++I) {
const Type *T = TypesToPropagate[I];
Aspects[T].insert(AspectsToPropagate.begin(), AspectsToPropagate.end());
Expand Down Expand Up @@ -240,12 +239,10 @@ using FunctionToAspectsMapTy = DenseMap<Function *, AspectsSetTy>;
using CallGraphTy = DenseMap<Function *, SmallPtrSet<Function *, 8>>;

void createUsedAspectsMetadataForFunctions(FunctionToAspectsMapTy &Map) {
for (auto &It : Map) {
AspectsSetTy &Aspects = It.second;
for (auto &[F, Aspects] : Map) {
if (Aspects.empty())
continue;

Function *F = It.first;
LLVMContext &C = F->getContext();

SmallVector<Metadata *, 16> AspectsMetadata;
Expand Down Expand Up @@ -312,9 +309,8 @@ void processFunction(Function &F, FunctionToAspectsMapTy &FunctionToAspects,
if (F.hasMetadata("sycl_used_aspects")) {
const MDNode *MD = F.getMetadata("sycl_used_aspects");
AspectsSetTy Aspects;
for (size_t I = 0, E = MD->getNumOperands(); I < E; ++I) {
Constant *C =
cast<ConstantAsMetadata>(MD->getOperand(I).get())->getValue();
for (const MDOperand &Op : MD->operands()) {
Constant *C = cast<ConstantAsMetadata>(Op.get())->getValue();
Aspects.insert(cast<ConstantInt>(C)->getSExtValue());
}
FunctionToAspects[&F].insert(Aspects.begin(), Aspects.end());
Expand Down