-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It also prints a loop bound if it can be determined via LLVM's ScalarEvolution class. Specifically it's equal to the `ConstantMaxBackedgeTakenCount` (). Partially addressed #760
- Loading branch information
Shaobo
committed
Nov 16, 2021
1 parent
28932f3
commit ba12ba0
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// This file is distributed under the MIT License. See LICENSE for details. | ||
// | ||
#ifndef LOOPINFO_H | ||
#define LOOPINFO_H | ||
|
||
#include "llvm/Pass.h" | ||
|
||
namespace smack { | ||
|
||
class LoopInfo : public llvm::FunctionPass { | ||
public: | ||
static char ID; // Pass identification, replacement for typeid | ||
LoopInfo() : llvm::FunctionPass(ID) {} | ||
virtual llvm::StringRef getPassName() const override; | ||
virtual bool runOnFunction(llvm::Function &F) override; | ||
virtual void getAnalysisUsage(llvm::AnalysisUsage &) const override; | ||
}; | ||
} // namespace smack | ||
|
||
#endif // LOOPINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// This file is distributed under the MIT License. See LICENSE for details. | ||
// | ||
|
||
#define DEBUG_TYPE "smack-loop-info" | ||
#include "smack/LoopInfo.h" | ||
#include "smack/Debug.h" | ||
#include "smack/SmackWarnings.h" | ||
#include "llvm/Analysis/LoopInfo.h" | ||
#include "llvm/Analysis/ScalarEvolution.h" | ||
#include "llvm/Analysis/ScalarEvolutionExpressions.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
namespace smack { | ||
|
||
using namespace llvm; | ||
|
||
void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { | ||
AU.setPreservesAll(); | ||
AU.addRequired<LoopInfoWrapperPass>(); | ||
AU.addRequired<ScalarEvolutionWrapperPass>(); | ||
} | ||
|
||
bool LoopInfo::runOnFunction(Function &F) { | ||
auto &loopInfo = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); | ||
auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); | ||
for (auto LI = loopInfo.begin(), LIEnd = loopInfo.end(); LI != LIEnd; ++LI) { | ||
auto L = *LI; | ||
auto lr = L->getLocRange(); | ||
auto sl = lr.getStart(); | ||
auto el = lr.getEnd(); | ||
std::string description; | ||
raw_string_ostream o(description); | ||
o << "found loop from line " << sl.getLine() << " to line " << el.getLine() | ||
<< " in function " << F.getName() << " with "; | ||
// TODO: figure out why induction variable won't work | ||
// auto bs = L->getInductionVariable(SE); | ||
if (auto C = | ||
dyn_cast<SCEVConstant>(SE.getConstantMaxBackedgeTakenCount(L))) { | ||
auto CI = C->getValue()->getValue().getZExtValue(); | ||
o << "known loop bound " << CI; | ||
} else | ||
o << " unknown loop bound"; | ||
SmackWarnings::warnLoop(o.str()); | ||
} | ||
return false; | ||
} | ||
|
||
char LoopInfo::ID = 0; | ||
|
||
StringRef LoopInfo::getPassName() const { | ||
return "Get Loop Information for the purpose of sound analysis"; | ||
} | ||
} // namespace smack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters