Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/dyn-aa/LogProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
namespace dyn_aa {
struct LogProcessor {
LogProcessor(): CurrentRecordID(0) {}

void processLog(bool Reversed = false);
bool processLog(const std::string &LogFileName, bool Reversed = false);
unsigned getCurrentRecordID() const { return CurrentRecordID; }
std::string getCurrentFileName() const {return CurrentFileName; }

// initialize is called before processing each log file, and finalize is
// called after processing each log file.
virtual void initialize() {}
virtual void finalize() {}
virtual bool finalize() { return false; }
// beforeRecord is called before processing each log record, and afterRecord
// is called after processing each log record. Therefore, a typical callback
// flow is:
Expand Down Expand Up @@ -45,11 +46,11 @@ struct LogProcessor {
virtual void processBasicBlock(const BasicBlockRecord &) {}

private:
void processLog(const std::string &LogFileName, bool Reversed);
static bool ReadData(void *P, int Length, bool Reversed, FILE *LogFile);
static off_t GetFileSize(FILE *LogFile);

unsigned CurrentRecordID;
std::string CurrentFileName;
};
}

Expand Down
3 changes: 2 additions & 1 deletion include/dyn-aa/MissingAliasesClassifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct MissingAliasesClassifier: public ModulePass, public LogProcessor {
bool isRootCause(Value *V1, Value *V2);

// Interfaces of LogProcessor.
void initialize();
void processTopLevel(const TopLevelRecord &Record);
void processStore(const StoreRecord &Record);
void processCall(const CallRecord &Record);
Expand All @@ -46,7 +47,7 @@ struct MissingAliasesClassifier: public ModulePass, public LogProcessor {
// Argument list
list<Value *> ArgMem;
// CallSite list
list<Value *> CallMem;
Value *CallMem;
// Keys are PointerAddress, values are list of <LoadInst, PointeeAddress>
DenseMap<void *, list<pair<Value *, void *> > > LoadMem;
// Keys are PointeeAddress, values are SelectInst or PHINode list
Expand Down
53 changes: 53 additions & 0 deletions include/dyn-aa/Reducer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// vim: sw=2

#ifndef __DYN_AA_REDUCER_H
#define __DYN_AA_REDUCER_H

#include <string>

#include "llvm/IntrinsicInst.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/CFG.h"

#include "rcs/typedefs.h"
#include "rcs/IDAssigner.h"

#include "dyn-aa/LogProcessor.h"
#include "dyn-aa/Utils.h"

typedef void (*ReductionFunction)(Module &);

using namespace llvm;
using namespace std;
using namespace rcs;

namespace dyn_aa {
struct Reducer: public ModulePass {
static char ID;

Reducer(): ModulePass(ID) {
ReductionFunctions.push_back(Reducer::reduceUnexecuted);
ReductionFunctions.push_back(Reducer::reduceUnrelatedFunctions);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是说现在要不把unrelated functions都去掉,要不都不去掉么?有没有中间态?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是吧,,需要中间态吗

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是啊,粒度可以做细一点。而且related function应该也可以删吧

On Tue, Mar 5, 2013 at 5:17 PM, jl3937 notifications@github.com wrote:

In include/dyn-aa/Reducer.h:

+#include "dyn-aa/LogProcessor.h"
+#include "dyn-aa/Utils.h"
+
+typedef void (*ReductionFunction)(Module &);
+
+using namespace llvm;
+using namespace std;
+using namespace rcs;
+
+namespace dyn_aa {
+struct Reducer: public ModulePass {

  • static char ID;
  • Reducer(): ModulePass(ID) {
  • ReductionFunctions.push_back(Reducer::reduceUnexecuted);
  • ReductionFunctions.push_back(Reducer::reduceUnrelatedFunctions);

是吧,,需要中间态吗


Reply to this email directly or view it on GitHubhttps://github.com//pull/8/files#r3252387
.

Jingyue Wu
Department of Computer Science
Columbia University
New York, NY 10027
http://www.cs.columbia.edu/~jingyue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但一般都删了也还是verified啊,就不需要做细了吧。删related function就是下一步的事了

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那也行。明天开会你给我看一下现在的结果

On Tue, Mar 5, 2013 at 5:29 PM, jl3937 notifications@github.com wrote:

In include/dyn-aa/Reducer.h:

+#include "dyn-aa/LogProcessor.h"
+#include "dyn-aa/Utils.h"
+
+typedef void (*ReductionFunction)(Module &);
+
+using namespace llvm;
+using namespace std;
+using namespace rcs;
+
+namespace dyn_aa {
+struct Reducer: public ModulePass {

  • static char ID;
  • Reducer(): ModulePass(ID) {
  • ReductionFunctions.push_back(Reducer::reduceUnexecuted);
  • ReductionFunctions.push_back(Reducer::reduceUnrelatedFunctions);

但一般都删了也还是verified啊,就不需要做细了吧。删related function就是下一步的事了


Reply to this email directly or view it on GitHubhttps://github.com//pull/8/files#r3252585
.

Jingyue Wu
Department of Computer Science
Columbia University
New York, NY 10027
http://www.cs.columbia.edu/~jingyue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦,那定了4点?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ºÃ

On Tue, Mar 5, 2013 at 6:44 PM, jl3937 notifications@github.com wrote:

In include/dyn-aa/Reducer.h:

+#include "dyn-aa/LogProcessor.h"
+#include "dyn-aa/Utils.h"
+
+typedef void (*ReductionFunction)(Module &);
+
+using namespace llvm;
+using namespace std;
+using namespace rcs;
+
+namespace dyn_aa {
+struct Reducer: public ModulePass {

  • static char ID;
  • Reducer(): ModulePass(ID) {
  • ReductionFunctions.push_back(Reducer::reduceUnexecuted);
  • ReductionFunctions.push_back(Reducer::reduceUnrelatedFunctions);

Ŷ£¬ÄǶ¨ÁË4µã£¿

¡ª
Reply to this email directly or view it on GitHubhttps://github.com//pull/8/files#r3253654
.

Jingyue Wu
Department of Computer Science
Columbia University
New York, NY 10027
http://www.cs.columbia.edu/~jingyue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

乱码。。。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hao

On Tue, Mar 5, 2013 at 6:47 PM, jl3937 notifications@github.com wrote:

In include/dyn-aa/Reducer.h:

+#include "dyn-aa/LogProcessor.h"
+#include "dyn-aa/Utils.h"
+
+typedef void (*ReductionFunction)(Module &);
+
+using namespace llvm;
+using namespace std;
+using namespace rcs;
+
+namespace dyn_aa {
+struct Reducer: public ModulePass {

  • static char ID;
  • Reducer(): ModulePass(ID) {
  • ReductionFunctions.push_back(Reducer::reduceUnexecuted);
  • ReductionFunctions.push_back(Reducer::reduceUnrelatedFunctions);

乱码。。。


Reply to this email directly or view it on GitHubhttps://github.com//pull/8/files#r3253695
.

Jingyue Wu
Department of Computer Science
Columbia University
New York, NY 10027
http://www.cs.columbia.edu/~jingyue

ReductionFunctions.push_back(Reducer::reduceGlobalVariables);
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual bool runOnModule(Module &M);

bool setReductionOptions(const vector<bool> &RO);

private:
static void reduceUnexecuted(Module &M);
static void reduceUnrelatedFunctions(Module &M);
static void reduceGlobalVariables(Module &M);
static void reduceInstructions(Module &M);
// indicate whether the ith reduction function is executed
vector<bool> ReductionOptions;
vector<ReductionFunction> ReductionFunctions;
};
}

#endif
38 changes: 38 additions & 0 deletions include/dyn-aa/ReductionVerifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// vim: sw=2

#ifndef __DYN_AA_REDUCTION_VERIFIER_H
#define __DYN_AA_REDUCTION_VERIFIER_H

#include <cstdio>

#include "llvm/IntrinsicInst.h"
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/CallSite.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"

#include "dyn-aa/BaselineAliasAnalysis.h"
#include "dyn-aa/Utils.h"

using namespace std;
using namespace llvm;
using namespace dyn_aa;

namespace dyn_aa {
struct ReductionVerifier: public ModulePass {
static char ID;

ReductionVerifier(): ModulePass(ID) { }
virtual bool runOnModule(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;

bool getVerified() { return Verified; }
private:
bool Verified;
};
}

#endif
16 changes: 14 additions & 2 deletions include/dyn-aa/TraceSlicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ struct PointerTrace{
struct TraceSlicer: public ModulePass, public LogProcessor {
static char ID;

TraceSlicer(): ModulePass(ID) {}
TraceSlicer(): ModulePass(ID),
CurrentFunction(NULL),
Merged(false),
PushCallInst(false) {}
virtual bool runOnModule(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual void print(raw_ostream &O, const Module *M) const;

// Interfaces of LogProcessor.
void processMemAlloc(const MemAllocRecord &Record);
void processTopLevel(const TopLevelRecord &Record);
void processEnter(const EnterRecord &Record);
void processStore(const StoreRecord &Record);
void processCall(const CallRecord &Record);
void processReturn(const ReturnRecord &Record);
void processBasicBlock(const BasicBlockRecord &Record);
static bool isCalledFunction(Function *F, CallSite CS);
static Value *getOperandIfConstant(Value *V);
Value *getLatestCommonAncestor();

Expand All @@ -68,9 +71,18 @@ struct TraceSlicer: public ModulePass, public LogProcessor {
pair<unsigned, Value *> TraceRecord,
int PointerLabel) const;
pair<bool, bool> dependsOn(LogRecordInfo &R1, LogRecordInfo &R2);
// for inst, arg, gv: alias, slice; for bb: related; for func: executed
void addMetaData(Value *V, string Kind, Module *M);

PointerTrace Trace[2];
unsigned CurrentRecordID;
Function *CurrentFunction;
bool Merged;
bool PushCallInst;

// for reduction tagging
DenseSet<Function *> RelatedFunctions;
DenseSet<BasicBlock *> ExecutedBasicBlocks;
};
}

Expand Down
48 changes: 26 additions & 22 deletions lib/Analyses/MissingAliasesClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ bool MissingAliasesClassifier::isRootCause(Value *V1, Value *V2) {
return true;
}

void MissingAliasesClassifier::initialize() {
ArgMem.clear();
CallMem = NULL;
LoadMem.clear();
SelectPHIMem.clear();
}

void MissingAliasesClassifier::processTopLevel(const TopLevelRecord &Record) {
IDAssigner &IDA = getAnalysis<IDAssigner>();
Value *V = IDA.getValue(Record.PointerValueID);
Expand Down Expand Up @@ -199,7 +206,7 @@ void MissingAliasesClassifier::processTopLevel(const TopLevelRecord &Record) {
if (isa<LoadInst>(V)) {
LoadMem[Record.LoadedFrom].push_back(make_pair(V, Record.PointeeAddress));
} else if (CS) {
CallMem.push_back(V);
CallMem = V;
} else if (isa<Argument>(V)) {
ArgMem.push_back(V);
} else if (isa<SelectInst>(V) || isa<PHINode>(V)) {
Expand Down Expand Up @@ -228,25 +235,26 @@ void MissingAliasesClassifier::processCall(const CallRecord &Record) {
CallSite CS(V);
assert(CS);

Function *CalledFunction = CS.getCalledFunction();
if (CalledFunction && CalledFunction->isDeclaration()) {
// containing function is called by external function
ArgMem.clear();
}

// extract from ArgMem
for (list<Value *>::iterator I = ArgMem.begin(), E = ArgMem.end(); I != E;) {
for (list<Value *>::iterator I = ArgMem.begin(); I != ArgMem.end(); ++I) {
Argument *A = dyn_cast<Argument>(*I);
if (TraceSlicer::isCalledFunction(A->getParent(), CS)) {
PrevInst[A].insert(
TraceSlicer::getOperandIfConstant(CS.getArgument(A->getArgNo())));
I = ArgMem.erase(I);
} else
++I;
PrevInst[A].insert(
TraceSlicer::getOperandIfConstant(CS.getArgument(A->getArgNo())));
}
ArgMem.clear();

// extract from CallMem, for external function
if (CS.getType()->isPointerTy()) {
for (list<Value *>::iterator I = CallMem.begin(), E = CallMem.end();
I != E;) {
if (V == *I) {
I = CallMem.erase(I);
} else
++I;
if (CallMem) {
CallSite CS(CallMem);
assert(CallMem == V);
CallMem = NULL;
}
}
}
Expand All @@ -261,14 +269,10 @@ void MissingAliasesClassifier::processReturn(const ReturnRecord &Record) {
Value *ReturnValue = RI->getReturnValue();
if (ReturnValue && ReturnValue->getType()->isPointerTy()) {
// extract from CallMem
for (list<Value *>::iterator I = CallMem.begin(), E = CallMem.end();
I != E;) {
CallSite CS(*I);
if (TraceSlicer::isCalledFunction(RI->getParent()->getParent(), CS)) {
PrevInst[*I].insert(ReturnValue);
I = CallMem.erase(I);
} else
++I;
if (CallMem) {
CallSite CS(CallMem);
PrevInst[CallMem].insert(ReturnValue);
CallMem = NULL;
}
}
}
Expand Down
33 changes: 13 additions & 20 deletions lib/Analyses/ReductionVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,17 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"

#include "dyn-aa/BaselineAliasAnalysis.h"
#include "dyn-aa/Utils.h"
#include "dyn-aa/Reducer.h"
#include "dyn-aa/ReductionVerifier.h"

using namespace std;
using namespace llvm;
using namespace dyn_aa;

namespace dyn_aa {
struct ReductionVerifier: public ModulePass {
static char ID;

ReductionVerifier(): ModulePass(ID) { }
virtual bool runOnModule(Module &M);
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
};
}

static RegisterPass<ReductionVerifier> X("verify-reducer",
"Verify whether reducer keeps "
static RegisterPass<ReductionVerifier> X("verify-reduction",
"Verify whether reduction keeps "
"the bug",
false, // Is CFG Only?
true); // Is Analysis?
Expand All @@ -45,30 +38,30 @@ bool ReductionVerifier::runOnModule(Module &M) {
assert(ValueNum < 2);
DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I);
if (DDI) {
V[ValueNum++] = DDI->getAddress();
V[ValueNum] = DDI->getAddress();
} else {
V[ValueNum++] = I;
V[ValueNum] = I;
}
ValueNum++;
}
}
}
}
assert(ValueNum == 2);

AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
errs().changeColor(raw_ostream::RED);
Verified = AA.alias(V[0], V[1]) == AliasAnalysis::NoAlias;

errs() << "Reduction Verifier: ";
if (AA.alias(V[0], V[1]) == AliasAnalysis::NoAlias) {
errs() << "Pass\n";
if (Verified) {
errs() << "Verified\n";
} else {
errs() << "Fail\n";
errs() << "Not verified\n";
}
errs().resetColor();

return false;
}

void ReductionVerifier::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<AliasAnalysis>();
}
Loading