Index: EntryExitInstrumenter.cpp
===================================================================
--- EntryExitInstrumenter.cpp
+++ EntryExitInstrumenter.cpp
@@ -16,10 +16,18 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Cloning.h" //Synopsys
#include "llvm/Transforms/Scalar.h"
using namespace llvm;
-static void insertCall(Function &CurFn, StringRef Func,
+// 9001412848
+static cl::opt ArcInstrumentInline("arc-instrument-inline",
+ cl::Hidden, cl::ZeroOrMore, cl::init(true));
+//
+
+
+static CallInst* //Synopsys (changed from void)
+ insertCall(Function &CurFn, StringRef Func,
Instruction *InsertionPt, DebugLoc DL) {
Module &M = *InsertionPt->getParent()->getParent()->getParent();
LLVMContext &C = InsertionPt->getParent()->getContext();
@@ -35,7 +43,7 @@
Constant *Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
CallInst *Call = CallInst::Create(Fn, "", InsertionPt);
Call->setDebugLoc(DL);
- return;
+ return Call; //Synopsys
}
if (Func == "__cyg_profile_func_enter" || Func == "__cyg_profile_func_exit") {
@@ -56,15 +64,25 @@
CallInst *Call =
CallInst::Create(Fn, ArrayRef(Args), "", InsertionPt);
Call->setDebugLoc(DL);
- return;
+ return Call; //Synopsys
}
// We only know how to call a fixed set of instrumentation functions, because
// they all expect different arguments, etc.
report_fatal_error(Twine("Unknown instrumentation function: '") + Func + "'");
+ return nullptr; //Synopsys
}
-static bool runOnFunction(Function &F, bool PostInlining) {
+//
+static bool tryToInline(Function &F, CallInst *CI, AAResults *CalleeAAR) {
+ if (!ArcInstrumentInline)
+ return false;
+ InlineFunctionInfo IFI;
+ return InlineFunction(CI, IFI, CalleeAAR);
+}
+//
+
+static bool runOnFunction(Function &F, bool PostInlining, AAResults *AA) { //Synopsys added AA
StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
: "instrument-function-entry";
@@ -74,8 +92,19 @@
StringRef EntryFunc = F.getFnAttribute(EntryAttr).getValueAsString();
StringRef ExitFunc = F.getFnAttribute(ExitAttr).getValueAsString();
+ // Don't instrument the instrumentation funciton to
+ // recursively call itself!
+ const StringRef &Fn = F.getName();
+ if (Fn == EntryFunc)
+ return false;
+ if (Fn == ExitFunc)
+ return false;
+ //
+
bool Changed = false;
+ std::list callsToInline; //Synopsys
+
// If the attribute is specified, insert instrumentation and then "consume"
// the attribute so that it's not inserted again if the pass should happen to
// run later for some reason.
@@ -85,7 +114,9 @@
if (auto SP = F.getSubprogram())
DL = DebugLoc::get(SP->getScopeLine(), 0, SP);
+ auto *CI = //Synopsys
insertCall(F, EntryFunc, &*F.begin()->getFirstInsertionPt(), DL);
+ if (CI) callsToInline.push_back(CI); //Synopsys
Changed = true;
F.removeAttribute(AttributeList::FunctionIndex, EntryAttr);
}
@@ -100,13 +131,24 @@
DL = DebugLoc::get(0, 0, SP);
if (isa(T)) {
+ auto *CI = //Synopsys
insertCall(F, ExitFunc, T, DL);
+ if (CI) callsToInline.push_back(CI); //Synopsys
Changed = true;
}
}
F.removeAttribute(AttributeList::FunctionIndex, ExitAttr);
}
+ //
+ if (PostInlining && AA) {
+ for (auto *CI : callsToInline) {
+ if (tryToInline(F,CI, AA))
+ Changed = true;
+ }
+ }
+ //
+
return Changed;
}
@@ -118,8 +160,13 @@
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addPreserved();
+ AU.addRequired(); //Synopsys
+ AU.addPreserved(); //Synopsys
}
- bool runOnFunction(Function &F) override { return ::runOnFunction(F, false); }
+ bool runOnFunction(Function &F) override {
+ auto *AA = &getAnalysis().getAAResults(); //Synopsys
+ return ::runOnFunction(F, false, AA); //Synopsys added AA
+ }
};
char EntryExitInstrumenter::ID = 0;
@@ -131,8 +178,13 @@
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addPreserved();
+ AU.addRequired(); //Synopsys
+ AU.addPreserved(); //Synopsys
}
- bool runOnFunction(Function &F) override { return ::runOnFunction(F, true); }
+ bool runOnFunction(Function &F) override {
+ auto *AA = &getAnalysis().getAAResults(); //Synopsys
+ return ::runOnFunction(F, true, AA); //Synopsys added AA
+ }
};
char PostInlineEntryExitInstrumenter::ID = 0;
}
@@ -156,7 +208,7 @@
PreservedAnalyses
llvm::EntryExitInstrumenterPass::run(Function &F, FunctionAnalysisManager &AM) {
- runOnFunction(F, PostInlining);
+ runOnFunction(F, PostInlining, nullptr); //Synopsys added nullptr param
PreservedAnalyses PA;
PA.preserveSet();
return PA;