-
Notifications
You must be signed in to change notification settings - Fork 15k
[SandboxVec][NFC] Add LLVM_DEBUG dumps #129335
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
Conversation
This patch updates/adds LLVM_DEBUG dumps. It moves the DEBUG_TYPE into SandboxVectorizer/Debug.h such that it can be shared across all components of the vectorizer.
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: vporpo (vporpo) ChangesThis patch updates/adds LLVM_DEBUG dumps. Full diff: https://github.com/llvm/llvm-project/pull/129335.diff 6 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h
new file mode 100644
index 0000000000000..85b25c0249e7d
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h
@@ -0,0 +1,21 @@
+//===- Debug.h --------------------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines the DEBUG_TYPE macro for LLVM_DEBUG which is shared across the
+// vectorizer components.
+//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEBUG_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEBUG_H
+
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "sandbox-vectorizer"
+#define DEBUG_PREFIX "SBVec: "
+
+#endif // LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_DEBUG_H
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Legality.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Legality.cpp
index 74634372156aa..a80ae2aefff0a 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Legality.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Legality.cpp
@@ -17,8 +17,6 @@
namespace llvm::sandboxir {
-#define DEBUG_TYPE "SBVec:Legality"
-
#ifndef NDEBUG
void ShuffleMask::dump() const {
print(dbgs());
@@ -191,13 +189,6 @@ LegalityAnalysis::notVectorizableBasedOnOpcodesAndTypes(
return std::nullopt;
}
-#ifndef NDEBUG
-static void dumpBndl(ArrayRef<Value *> Bndl) {
- for (auto *V : Bndl)
- dbgs() << *V << "\n";
-}
-#endif // NDEBUG
-
CollectDescr
LegalityAnalysis::getHowToCollectValues(ArrayRef<Value *> Bndl) const {
SmallVector<CollectDescr::ExtractElementDescr, 4> Vec;
@@ -220,11 +211,8 @@ LegalityAnalysis::getHowToCollectValues(ArrayRef<Value *> Bndl) const {
const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl,
bool SkipScheduling) {
// If Bndl contains values other than instructions, we need to Pack.
- if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); })) {
- LLVM_DEBUG(dbgs() << "Not vectorizing: Not Instructions:\n";
- dumpBndl(Bndl););
+ if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); }))
return createLegalityResult<Pack>(ResultReason::NotInstructions);
- }
// Pack if not in the same BB.
auto *BB = cast<Instruction>(Bndl[0])->getParent();
if (any_of(drop_begin(Bndl),
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
index fe4f73e50687d..9a65f6cec42fb 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp
@@ -14,6 +14,7 @@
#include "llvm/SandboxIR/Module.h"
#include "llvm/SandboxIR/Region.h"
#include "llvm/SandboxIR/Utils.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h"
namespace llvm {
@@ -169,7 +170,9 @@ Value *BottomUpVec::createVectorInstr(ArrayRef<Value *> Bndl,
// TODO: Propagate debug info.
};
- return CreateVectorInstr(Bndl, Operands);
+ auto *NewI = CreateVectorInstr(Bndl, Operands);
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "New instr: " << *NewI << "\n");
+ return NewI;
}
void BottomUpVec::tryEraseDeadInstrs() {
@@ -182,9 +185,11 @@ void BottomUpVec::tryEraseDeadInstrs() {
[](Instruction *I1, Instruction *I2) { return I1->comesBefore(I2); });
for (const auto &Pair : SortedDeadInstrCandidates) {
for (Instruction *I : reverse(Pair.second)) {
- if (I->hasNUses(0))
+ if (I->hasNUses(0)) {
// Erase the dead instructions bottom-to-top.
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Erase dead: " << *I << "\n");
I->eraseFromParent();
+ }
}
}
DeadInstrCandidates.clear();
@@ -277,8 +282,11 @@ Action *BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl,
ArrayRef<Value *> UserBndl, unsigned Depth) {
bool StopForDebug =
DebugBndlCnt++ >= StopBundle && StopBundle != StopBundleDisabled;
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
+ VecUtils::dump(Bndl));
const auto &LegalityRes = StopForDebug ? Legality->getForcedPackForDebugging()
: Legality->canVectorize(Bndl);
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
auto ActionPtr =
std::make_unique<Action>(&LegalityRes, Bndl, UserBndl, Depth);
SmallVector<Action *> Operands;
@@ -479,6 +487,8 @@ bool BottomUpVec::tryVectorize(ArrayRef<Value *> Bndl) {
Actions.clear();
DebugBndlCnt = 0;
vectorizeRec(Bndl, {}, /*Depth=*/0);
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "BottomUpVec: Vectorization Actions:\n";
+ Actions.dump());
emitVectors();
tryEraseDeadInstrs();
return Change;
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
index 874390ba2daae..ec929fb3c71e4 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.cpp
@@ -9,6 +9,7 @@
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionAcceptOrRevert.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InstructionCost.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h"
namespace llvm {
@@ -20,15 +21,22 @@ namespace sandboxir {
bool TransactionAcceptOrRevert::runOnRegion(Region &Rgn, const Analyses &A) {
const auto &SB = Rgn.getScoreboard();
+ auto CostBefore = SB.getBeforeCost();
+ auto CostAfter = SB.getAfterCost();
InstructionCost CostAfterMinusBefore = SB.getAfterCost() - SB.getBeforeCost();
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Cost gain: " << CostAfterMinusBefore
+ << " (before/after/threshold: " << CostBefore << "/"
+ << CostAfter << "/" << CostThreshold << ")\n");
// TODO: Print costs / write to remarks.
auto &Tracker = Rgn.getContext().getTracker();
if (CostAfterMinusBefore < -CostThreshold) {
bool HasChanges = !Tracker.empty();
Tracker.accept();
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Accept ***\n");
return HasChanges;
}
// Revert the IR.
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Transaction Revert ***\n");
Rgn.getContext().getTracker().revert();
return false;
}
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.cpp
index 8d39d971273b4..e34d0fd817d0a 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.cpp
@@ -9,10 +9,12 @@
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/TransactionSave.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InstructionCost.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h"
namespace llvm::sandboxir {
bool TransactionSave::runOnRegion(Region &Rgn, const Analyses &A) {
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "*** Save Transaction ***\n");
Rgn.getContext().save();
return false;
}
diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
index bffb9f187e882..20186426a5259 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -11,14 +11,12 @@
#include "llvm/IR/Module.h"
#include "llvm/SandboxIR/Constant.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/Debug.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizerPassBuilder.h"
#include <regex>
using namespace llvm;
-#define SV_NAME "sandbox-vectorizer"
-#define DEBUG_TYPE SV_NAME
-
static cl::opt<bool>
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
cl::desc("Prints the pass pipeline and returns."));
@@ -119,13 +117,16 @@ bool SandboxVectorizerPass::runImpl(Function &LLVMF) {
// If the target claims to have no vector registers early return.
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
- LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n");
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX
+ << "Target has no vector registers, return.\n");
return false;
}
- LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << LLVMF.getName() << ".\n");
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Analyzing " << LLVMF.getName()
+ << ".\n");
// Early return if the attribute NoImplicitFloat is used.
if (LLVMF.hasFnAttribute(Attribute::NoImplicitFloat)) {
- LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
+ LLVM_DEBUG(dbgs() << DEBUG_PREFIX
+ << "NoImplicitFloat attribute, return.\n");
return false;
}
|
@@ -220,11 +211,8 @@ LegalityAnalysis::getHowToCollectValues(ArrayRef<Value *> Bndl) const { | |||
const LegalityResult &LegalityAnalysis::canVectorize(ArrayRef<Value *> Bndl, | |||
bool SkipScheduling) { | |||
// If Bndl contains values other than instructions, we need to Pack. | |||
if (any_of(Bndl, [](auto *V) { return !isa<Instruction>(V); })) { | |||
LLVM_DEBUG(dbgs() << "Not vectorizing: Not Instructions:\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed because I am now dumping all legality outcomes at the call site of of canVectorize()
here: BottomUpVec.cpp:289.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/14223 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/13774 Here is the relevant piece of the build log for the reference
|
This patch updates/adds LLVM_DEBUG dumps.
It moves the DEBUG_TYPE into SandboxVectorizer/Debug.h such that it can be shared across all components of the vectorizer.