Skip to content

[llvm-opt-report] Show scalable vectorization factors #123367

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 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions llvm/test/tools/llvm-opt-report/Inputs/scalable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stddef.h>

void foo(size_t N, float A[restrict N], float B[N]) {
#pragma clang loop vectorize_width(4, scalable)
for (size_t i = 0; i < N; i++) {
A[i] = B[i] * 42.f;
}
}

12 changes: 12 additions & 0 deletions llvm/test/tools/llvm-opt-report/Inputs/scalable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- !Passed
Pass: loop-vectorize
Name: Vectorized
DebugLoc: { File: './Inputs/scalable.c', Line: 5, Column: 3 }
Function: foo
Args:
- String: 'vectorized loop (vectorization width: '
- VectorizationFactor: vscale x 4
- String: ', interleaved count: '
- InterleaveCount: '2'
- String: ')'
...
12 changes: 12 additions & 0 deletions llvm/test/tools/llvm-opt-report/scalabe.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RUN: llvm-opt-report -r %p %p/Inputs/scalable.yaml | FileCheck -strict-whitespace %s

; CHECK: < {{.*[/\]}}scalable.c
; CHECK-NEXT: 1 | #include <stddef.h>
; CHECK-NEXT: 2 |
; CHECK-NEXT: 3 | void foo(size_t N, float A[restrict N], float B[N]) {
; CHECK-NEXT: 4 | #pragma clang loop vectorize_width(4, scalable)
; CHECK-NEXT: 5 VNx4,2 | for (size_t i = 0; i < N; i++) {
; CHECK-NEXT: 6 | A[i] = B[i] * 42.f;
; CHECK-NEXT: 7 | }
; CHECK-NEXT: 8 | }
; CHECK-NEXT: 9 |
44 changes: 32 additions & 12 deletions llvm/tools/llvm-opt-report/OptReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/TypeSize.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
Expand Down Expand Up @@ -100,7 +101,7 @@ struct OptReportLocationInfo {
OptReportLocationItemInfo Unrolled;
OptReportLocationItemInfo Vectorized;

int VectorizationFactor = 1;
ElementCount VectorizationFactor = ElementCount::getFixed(1);
int InterleaveCount = 1;
int UnrollCount = 1;

Expand All @@ -109,8 +110,9 @@ struct OptReportLocationInfo {
Unrolled |= RHS.Unrolled;
Vectorized |= RHS.Vectorized;

VectorizationFactor =
std::max(VectorizationFactor, RHS.VectorizationFactor);
if (ElementCount::isKnownLT(VectorizationFactor, RHS.VectorizationFactor))
VectorizationFactor = RHS.VectorizationFactor;

InterleaveCount = std::max(InterleaveCount, RHS.InterleaveCount);
UnrollCount = std::max(UnrollCount, RHS.UnrollCount);

Expand All @@ -130,9 +132,11 @@ struct OptReportLocationInfo {
return true;
else if (RHS.Vectorized < Vectorized || Succinct)
return false;
else if (VectorizationFactor < RHS.VectorizationFactor)
else if (ElementCount::isKnownLT(VectorizationFactor,
RHS.VectorizationFactor))
return true;
else if (VectorizationFactor > RHS.VectorizationFactor)
else if (ElementCount::isKnownGT(VectorizationFactor,
RHS.VectorizationFactor))
return false;
else if (InterleaveCount < RHS.InterleaveCount)
return true;
Expand Down Expand Up @@ -197,17 +201,26 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {

bool Transformed = Remark.RemarkType == remarks::Type::Passed;

int VectorizationFactor = 1;
ElementCount VectorizationFactor = ElementCount::getFixed(1);
int InterleaveCount = 1;
int UnrollCount = 1;

for (const remarks::Argument &Arg : Remark.Args) {
if (Arg.Key == "VectorizationFactor")
Arg.Val.getAsInteger(10, VectorizationFactor);
else if (Arg.Key == "InterleaveCount")
if (Arg.Key == "VectorizationFactor") {
int MinValue = 1;
bool IsScalable = false;
if (Arg.Val.starts_with("vscale x ")) {
Arg.Val.drop_front(9).getAsInteger(10, MinValue);
IsScalable = true;
} else {
Arg.Val.getAsInteger(10, MinValue);
}
VectorizationFactor = ElementCount::get(MinValue, IsScalable);
} else if (Arg.Key == "InterleaveCount") {
Arg.Val.getAsInteger(10, InterleaveCount);
else if (Arg.Key == "UnrollCount")
} else if (Arg.Key == "UnrollCount") {
Arg.Val.getAsInteger(10, UnrollCount);
}
}

const std::optional<remarks::RemarkLocation> &Loc = Remark.Loc;
Expand Down Expand Up @@ -292,7 +305,11 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
bool NothingUnrolled = !MaxLI.Unrolled.Transformed;
bool NothingVectorized = !MaxLI.Vectorized.Transformed;

unsigned VFDigits = llvm::utostr(MaxLI.VectorizationFactor).size();
unsigned VFDigits =
llvm::utostr(MaxLI.VectorizationFactor.getKnownMinValue()).size();
if (MaxLI.VectorizationFactor.isScalable())
VFDigits += 2; // For "Nx..."

unsigned ICDigits = llvm::utostr(MaxLI.InterleaveCount).size();
unsigned UCDigits = llvm::utostr(MaxLI.UnrollCount).size();

Expand Down Expand Up @@ -382,7 +399,10 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
raw_string_ostream RS(R);

if (!Succinct) {
RS << LLI.VectorizationFactor << "," << LLI.InterleaveCount;
if (LLI.VectorizationFactor.isScalable())
RS << "Nx";
RS << LLI.VectorizationFactor.getKnownMinValue() << ","
<< LLI.InterleaveCount;
RS << std::string(VFDigits + ICDigits + 1 - R.size(), ' ');
}

Expand Down
Loading