Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Unified Diff: src/IceTargetLowering.cpp

Issue 463563006: Subzero: Randomly insert nops. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Fix insertion strategy Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringX8632.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceTargetLowering.cpp
diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp
index 0034de5f7ca3e2340eb15e52f23530dfafc8ca56..057a3eaf8f05f195504087255e868c0bc839f549 100644
--- a/src/IceTargetLowering.cpp
+++ b/src/IceTargetLowering.cpp
@@ -22,8 +22,25 @@
#include "IceTargetLowering.h"
#include "IceTargetLoweringX8632.h"
+#include "llvm/Support/CommandLine.h"
+
namespace Ice {
+namespace {
+
+namespace cl = llvm::cl;
+cl::opt<bool> DoNopInsertion("nop-insertion", cl::desc("Randomly insert NOPs"),
+ cl::init(false));
+
+cl::opt<int> MaxNopsPerInstruction(
+ "max-nops-per-instruction",
+ cl::desc("Max number of nops to insert per instruction"), cl::init(1));
+
+cl::opt<int> NopProbabilityAsPercentage(
+ "nop-insertion-percentage",
+ cl::desc("Nop insertion probability as percentage"), cl::init(10));
+} // end of anonymous namespace
+
void LoweringContext::init(CfgNode *N) {
Node = N;
Begin = getNode()->getInsts().begin();
@@ -90,6 +107,20 @@ void TargetLowering::doAddressOpt() {
Context.advanceNext();
}
+bool TargetLowering::shouldDoNopInsertion() const { return DoNopInsertion; }
+
+void TargetLowering::doNopInsertion() {
+ Inst *I = *Context.getCur();
+ bool ShouldSkip = llvm::isa<InstFakeUse>(I) || llvm::isa<InstFakeDef>(I) ||
+ llvm::isa<InstFakeKill>(I) || I->isRedundantAssign() ||
+ I->isDeleted();
+ if (!ShouldSkip) {
+ for (int I = 0; I < MaxNopsPerInstruction; ++I) {
+ randomlyInsertNop(NopProbabilityAsPercentage / 100.0);
+ }
+ }
+}
+
// Lowers a single instruction according to the information in
// Context, by checking the Context.Cur instruction kind and calling
// the appropriate lowering method. The lowering method should insert
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringX8632.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698