Skip to content

Commit

Permalink
[SandboxVec][Interval] Add print() and dump()
Browse files Browse the repository at this point in the history
  • Loading branch information
vporpo committed Oct 8, 2024
1 parent c6d6da4 commit 56d2c62
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DGNode {

#ifndef NDEBUG
virtual void print(raw_ostream &OS, bool PrintDeps = true) const;
friend raw_ostream &operator<<(DGNode &N, raw_ostream &OS) {
friend raw_ostream &operator<<(raw_ostream &OS, DGNode &N) {
N.print(OS);
return OS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
//
// This is currently used for Instruction intervals.
// It provides an API for some basic operations on the interval, including some
// simple set operations, like union, interseciton and others.
// simple set operations, like union, intersection and others.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_INSTRINTERVAL_H
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_INSTRINTERVAL_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/raw_ostream.h"
#include <iterator>

namespace llvm::sandboxir {
Expand Down Expand Up @@ -197,6 +198,27 @@ template <typename T> class Interval {
auto *NewTo = To->comesBefore(Other.To) ? Other.To : To;
return {NewFrom, NewTo};
}

#ifndef NDEBUG
void print(raw_ostream &OS) const {
auto *Top = top();
auto *Bot = bottom();
OS << "Top: ";
if (Top != nullptr)
OS << *Top;
else
OS << "nullptr";
OS << "\n";

OS << "Bot: ";
if (Bot != nullptr)
OS << *Bot;
else
OS << "nullptr";
OS << "\n";
}
LLVM_DUMP_METHOD void dump() const;
#endif
};

} // namespace llvm::sandboxir
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Vectorize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_llvm_component_library(LLVMVectorize
LoopVectorizationLegality.cpp
LoopVectorize.cpp
SandboxVectorizer/DependencyGraph.cpp
SandboxVectorizer/Interval.cpp
SandboxVectorizer/Passes/BottomUpVec.cpp
SandboxVectorizer/SandboxVectorizer.cpp
SandboxVectorizer/SeedCollector.cpp
Expand Down
22 changes: 22 additions & 0 deletions llvm/lib/Transforms/Vectorize/SandboxVectorizer/Interval.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- Interval.cpp -------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "llvm/Transforms/Vectorize/SandboxVectorizer/Interval.h"
#include "llvm/SandboxIR/Instruction.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h"

namespace llvm::sandboxir {

template class Interval<Instruction>;
template class Interval<MemDGNode>;

#ifndef NDEBUG
template <typename T> void Interval<T>::dump() const { print(dbgs()); }
#endif
} // namespace llvm::sandboxir

0 comments on commit 56d2c62

Please sign in to comment.