Changeset View
Changeset View
Standalone View
Standalone View
lib/Transforms/Scalar/LoopDistribute.cpp
Show All 28 Lines | |||||
#include "llvm/Analysis/LoopAccessAnalysis.h" | #include "llvm/Analysis/LoopAccessAnalysis.h" | ||||
#include "llvm/Analysis/LoopInfo.h" | #include "llvm/Analysis/LoopInfo.h" | ||||
#include "llvm/IR/Dominators.h" | #include "llvm/IR/Dominators.h" | ||||
#include "llvm/Pass.h" | #include "llvm/Pass.h" | ||||
#include "llvm/Support/CommandLine.h" | #include "llvm/Support/CommandLine.h" | ||||
#include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h" | #include "llvm/Transforms/Utils/BasicBlockUtils.h" | ||||
#include "llvm/Transforms/Utils/Cloning.h" | #include "llvm/Transforms/Utils/Cloning.h" | ||||
#include "llvm/Transforms/Utils/LoopUtils.h" | |||||
#include "llvm/Transforms/Utils/LoopVersioning.h" | #include "llvm/Transforms/Utils/LoopVersioning.h" | ||||
#include <list> | #include <list> | ||||
#define LDIST_NAME "loop-distribute" | #define LDIST_NAME "loop-distribute" | ||||
#define DEBUG_TYPE LDIST_NAME | #define DEBUG_TYPE LDIST_NAME | ||||
using namespace llvm; | using namespace llvm; | ||||
static cl::opt<bool> | static cl::opt<bool> | ||||
LDistVerify("loop-distribute-verify", cl::Hidden, | LDistVerify("loop-distribute-verify", cl::Hidden, | ||||
cl::desc("Turn on DominatorTree and LoopInfo verification " | cl::desc("Turn on DominatorTree and LoopInfo verification " | ||||
"after Loop Distribution"), | "after Loop Distribution"), | ||||
cl::init(false)); | cl::init(false)); | ||||
static cl::opt<bool> DistributeNonIfConvertible( | static cl::opt<bool> DistributeNonIfConvertible( | ||||
"loop-distribute-non-if-convertible", cl::Hidden, | "loop-distribute-non-if-convertible", cl::Hidden, | ||||
cl::desc("Whether to distribute into a loop that may not be " | cl::desc("Whether to distribute into a loop that may not be " | ||||
"if-convertible by the loop vectorizer"), | "if-convertible by the loop vectorizer"), | ||||
cl::init(false)); | cl::init(false)); | ||||
STATISTIC(NumLoopsDistributed, "Number of loops distributed"); | STATISTIC(NumLoopsDistributed, "Number of loops distributed"); | ||||
/// \brief Returns the instructions that use values defined in the loop. | |||||
SmallVector<Instruction *, 8> llvm::findDefsUsedOutsideOfLoop(Loop *L) { | |||||
SmallVector<Instruction *, 8> UsedOutside; | |||||
for (auto *Block : L->getBlocks()) | |||||
// FIXME: I believe that this could use copy_if if the Inst reference could | |||||
// be adapted into a pointer. | |||||
for (auto &Inst : *Block) { | |||||
auto Users = Inst.users(); | |||||
if (std::any_of(Users.begin(), Users.end(), [&](User *U) { | |||||
auto *Use = cast<Instruction>(U); | |||||
return !L->contains(Use->getParent()); | |||||
})) | |||||
UsedOutside.push_back(&Inst); | |||||
} | |||||
return UsedOutside; | |||||
} | |||||
anemet: You also need to move this to LoopUtils.cpp. | |||||
namespace { | namespace { | ||||
/// \brief Maintains the set of instructions of the loop for a partition before | /// \brief Maintains the set of instructions of the loop for a partition before | ||||
/// cloning. After cloning, it hosts the new loop. | /// cloning. After cloning, it hosts the new loop. | ||||
class InstPartition { | class InstPartition { | ||||
typedef SmallPtrSet<Instruction *, 8> InstructionSet; | typedef SmallPtrSet<Instruction *, 8> InstructionSet; | ||||
public: | public: | ||||
InstPartition(Instruction *I, Loop *L, bool DepCycle = false) | InstPartition(Instruction *I, Loop *L, bool DepCycle = false) | ||||
▲ Show 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | for (auto &Dep : InterestingDependences) | ||||
DEBUG(Dep.print(dbgs(), 2, Instructions)); | DEBUG(Dep.print(dbgs(), 2, Instructions)); | ||||
} | } | ||||
} | } | ||||
private: | private: | ||||
AccessesType Accesses; | AccessesType Accesses; | ||||
}; | }; | ||||
/// \brief Returns the instructions that use values defined in the loop. | |||||
static SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L) { | |||||
SmallVector<Instruction *, 8> UsedOutside; | |||||
for (auto *Block : L->getBlocks()) | |||||
// FIXME: I believe that this could use copy_if if the Inst reference could | |||||
// be adapted into a pointer. | |||||
for (auto &Inst : *Block) { | |||||
auto Users = Inst.users(); | |||||
if (std::any_of(Users.begin(), Users.end(), [&](User *U) { | |||||
auto *Use = cast<Instruction>(U); | |||||
return !L->contains(Use->getParent()); | |||||
})) | |||||
UsedOutside.push_back(&Inst); | |||||
} | |||||
return UsedOutside; | |||||
} | |||||
/// \brief The pass class. | /// \brief The pass class. | ||||
class LoopDistribute : public FunctionPass { | class LoopDistribute : public FunctionPass { | ||||
public: | public: | ||||
LoopDistribute() : FunctionPass(ID) { | LoopDistribute() : FunctionPass(ID) { | ||||
initializeLoopDistributePass(*PassRegistry::getPassRegistry()); | initializeLoopDistributePass(*PassRegistry::getPassRegistry()); | ||||
} | } | ||||
bool runOnFunction(Function &F) override { | bool runOnFunction(Function &F) override { | ||||
▲ Show 20 Lines • Show All 244 Lines • Show Last 20 Lines |
You also need to move this to LoopUtils.cpp.