Skip to content

Commit e4f705a

Browse files
committed
[TSAR, Anls, Reader] Allow to specify multiple files with external analysis results.
Usage: tsar ... -fanalysis-use=file1,file2 -fanalysis-use=file3
1 parent 7f1970a commit e4f705a

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

include/tsar/Analysis/Reader/Passes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ class ModulePass;
3838
/// Initialize all passes which is necessary to load external analysis results.
3939
void initializeAnalysisReader(PassRegistry &Registry);
4040

41-
/// Create a reader of external analysis results stored in a specified file.
41+
/// Create a reader of external analysis results.
4242
///
43+
/// Files with external results must be specified in GlobalOptions::AnalysisUse
44+
/// option.
4345
/// If `Filename` is empty `GlobalOptions::AnalysisUse` value is used.
44-
FunctionPass * createAnalysisReader(llvm::StringRef Filename = "");
46+
FunctionPass * createAnalysisReader();
4547

4648
/// Initialize a reader of external analysis results.
4749
void initializeAnalysisReaderPass(PassRegistry &Registry);

include/tsar/Support/GlobalOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ struct GlobalOptions {
7373
/// A function is only inlined if the number of memory accesses in the caller
7474
/// does not exceed this value.
7575
unsigned MemoryAccessInlineThreshold = 0;
76-
/// Pass to external analysis results which is used to clarify analysis.
77-
std::string AnalysisUse = "";
76+
/// Passes to external analysis results which is used to clarify analysis.
77+
std::vector<std::string> AnalysisUse;
7878
/// Pass to profile which is used to measure possible optimization gain.
7979
std::string ProfileUse = "";
8080
/// List of object file names.

lib/Analysis/Reader/AnalysisReader.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,15 @@ class AnalysisReader : public FunctionPass, bcl::Uncopyable {
154154
public:
155155
static char ID;
156156

157-
explicit AnalysisReader(StringRef DataFile = "") :
158-
mDataFile(DataFile), FunctionPass(ID) {
157+
explicit AnalysisReader(): FunctionPass(ID) {
159158
initializeAnalysisReaderPass(*PassRegistry::getPassRegistry());
160159
}
161160

162161
bool runOnFunction(Function &F) override;
163162
void getAnalysisUsage(AnalysisUsage &AU) const override;
164163

165164
private:
166-
std::string mDataFile;
165+
bool load(Function &F, unsigned DWLang, StringRef DataFile);
167166
};
168167

169168
/// Extract a list of analyzed functions from external analysis results.
@@ -334,7 +333,7 @@ template<class TraitTag> void updateAntiFlowDep(
334333
DITrait.template set<TraitTag>(new trait::DIDependence(F, DistVector));
335334
LLVM_DEBUG(dbgs() << "[ANALYSIS READER]: set distance to [";
336335
if (Min) dbgs() << *Min; else dbgs() << "?"; dbgs() << ", ";
337-
if (Max) dbgs() << *Max; else dbgs() << "?"; "]\n");
336+
if (Max) dbgs() << *Max; else dbgs() << "?"; dbgs() << "]\n");
338337
}
339338

340339
/// Update description of output dependence in `DITrait` according to
@@ -367,9 +366,7 @@ INITIALIZE_PASS_END(AnalysisReader, "analysis-reader",
367366

368367
char AnalysisReader::ID = 0;
369368

370-
FunctionPass * llvm::createAnalysisReader(StringRef DataFile) {
371-
return new AnalysisReader(DataFile);
372-
}
369+
FunctionPass * llvm::createAnalysisReader() { return new AnalysisReader; }
373370

374371
void AnalysisReader::getAnalysisUsage(AnalysisUsage &AU) const {
375372
AU.addRequired<DIMemoryTraitPoolWrapper>();
@@ -380,16 +377,19 @@ bool AnalysisReader::runOnFunction(Function &F) {
380377
auto DWLang = getLanguage(F);
381378
if (!DWLang)
382379
return false;
383-
if (mDataFile.empty()) {
384-
auto &GO = getAnalysis<GlobalOptionsImmutableWrapper>().getOptions();
385-
if (!GO.AnalysisUse.empty())
386-
mDataFile = GO.AnalysisUse;
387-
else
388-
return false;
389-
}
390-
auto FileOrErr = MemoryBuffer::getFile(mDataFile);
380+
auto &GO{getAnalysis<GlobalOptionsImmutableWrapper>().getOptions()};
381+
for (auto &File : GO.AnalysisUse)
382+
load(F, *DWLang, File);
383+
return false;
384+
}
385+
386+
bool AnalysisReader::load(Function &F, unsigned DWLang, StringRef DataFile) {
387+
LLVM_DEBUG(
388+
dbgs() << "[ANALYSIS READER]: load external analysis results from '"
389+
<< DataFile << "'\n");
390+
auto FileOrErr = MemoryBuffer::getFile(DataFile);
391391
if (auto EC = FileOrErr.getError()) {
392-
F.getContext().diagnose(DiagnosticInfoPGOProfile(mDataFile.data(),
392+
F.getContext().diagnose(DiagnosticInfoPGOProfile(DataFile.data(),
393393
Twine("unable to open file: ") + EC.message()));
394394
return false;
395395
}
@@ -401,9 +401,9 @@ bool AnalysisReader::runOnFunction(Function &F) {
401401
// Build diagnostic in-place of call to diagnose(), because diagnostic
402402
// class uses temporary objects available only at construction time.
403403
F.getContext().diagnose(
404-
DiagnosticInfoPGOProfile(mDataFile.data(), D, DS_Note));
404+
DiagnosticInfoPGOProfile(DataFile.data(), D, DS_Note));
405405
}
406-
F.getContext().diagnose(DiagnosticInfoPGOProfile(mDataFile.data(),
406+
F.getContext().diagnose(DiagnosticInfoPGOProfile(DataFile.data(),
407407
"unable to parse external analysis results"));
408408
return false;
409409
}
@@ -452,7 +452,7 @@ bool AnalysisReader::runOnFunction(Function &F) {
452452
continue;
453453
auto *DIExpr = DIEM->getExpression();
454454
assert(DIVar && DIExpr && "Invalid memory location!");
455-
auto Var{buildVariable(*DWLang, *DIEM)};
455+
auto Var{buildVariable(DWLang, *DIEM)};
456456
if (!Var)
457457
continue;
458458
LLVM_DEBUG(dbgs() << "[ANALYSIS READER]: update traits for a variable "
@@ -506,5 +506,5 @@ bool AnalysisReader::runOnFunction(Function &F) {
506506
DITrait.print(dbgs()); dbgs() << "\n");
507507
}
508508
}
509-
return false;
509+
return true;
510510
}

lib/Core/Tool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ struct Options : private bcl::Uncopyable {
167167
llvm::cl::opt<bool> NoInline;
168168
llvm::cl::opt<bool> LoadSources;
169169
llvm::cl::opt<bool> NoLoadSources;
170-
llvm::cl::opt<std::string> AnalysisUse;
170+
llvm::cl::list<std::string> AnalysisUse;
171171
llvm::cl::opt<std::string> ProfileUse;
172172
llvm::cl::list<std::string> ObjectFilenames;
173173
llvm::cl::opt<unsigned> LoopParallelThreshold;
@@ -314,7 +314,7 @@ Options::Options() :
314314
NoLoadSources("fno-load-sources", cl::cat(AnalysisCategory),
315315
cl::desc("Avoid source-level analysis for an IR-level input")),
316316
AnalysisUse("fanalysis-use", cl::cat(AnalysisCategory),
317-
cl::value_desc("filename"),
317+
cl::value_desc("filenames"), cl::ValueRequired, cl::CommaSeparated,
318318
cl::desc("Use external analysis results to clarify analysis")),
319319
ProfileUse("fprofile-use", cl::cat(AnalysisCategory),
320320
cl::value_desc("filename"),

0 commit comments

Comments
 (0)