|
From: <mic...@us...> - 2007-08-06 15:25:10
|
Revision: 158
http://pearcolator.svn.sourceforge.net/pearcolator/?rev=158&view=rev
Author: michael_baer
Date: 2007-08-06 08:25:12 -0700 (Mon, 06 Aug 2007)
Log Message:
-----------
- Made optimizations by profiling optional
Modified Paths:
--------------
src/org/binarytranslator/DBT_Options.java
src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java
src/org/binarytranslator/generic/decoder/CodeTranslator.java
Modified: src/org/binarytranslator/DBT_Options.java
===================================================================
--- src/org/binarytranslator/DBT_Options.java 2007-08-06 15:23:44 UTC (rev 157)
+++ src/org/binarytranslator/DBT_Options.java 2007-08-06 15:25:12 UTC (rev 158)
@@ -93,6 +93,9 @@
/** Just a temporary variable for testing. It describes, when the staged emulation controller switches from interpretation to translation. */
public static int minTraceValue = 20;
+ /** Just a temporary variable for testing. It describes, if the translated program shall be optimized using profiling information.. */
+ public static boolean optimizeTranslationByProfiling = false;
+
/** Print debug information during the translation of instructions. */
public static boolean debugTranslation = true;
@@ -198,8 +201,9 @@
saveProfileToFile = value;
} else if (key.equalsIgnoreCase("minTraceValue")) {
minTraceValue = Integer.parseInt(value);
+ } else if (key.equalsIgnoreCase("optimizeTranslation")) {
+ optimizeTranslationByProfiling = Boolean.parseBoolean(value);
}
-
else {
throw new Error("Unknown DBT option: " + key);
}
Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java
===================================================================
--- src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-08-06 15:23:44 UTC (rev 157)
+++ src/org/binarytranslator/arch/arm/decoder/ARM_Translator.java 2007-08-06 15:25:12 UTC (rev 158)
@@ -756,23 +756,31 @@
arm2ir.getCurrentBlock().insertOut(condBlock);
//Query the branch profile to get the probability that this instruction is going to get executed
- float skipProbability = ps.branchInfo.getBranchProbability(pc, pc + (inThumb() ? 2 : 4));
OPT_BranchProfileOperand profileOperand;
- if (skipProbability == -1 || skipProbability == 0.5f) {
- profileOperand = new OPT_BranchProfileOperand();
+ if (DBT_Options.optimizeTranslationByProfiling) {
+ float skipProbability = ps.branchInfo.getBranchProbability(pc, pc + (inThumb() ? 2 : 4));
+
+ if (skipProbability == -1 || skipProbability == 0.5f) {
+ profileOperand = new OPT_BranchProfileOperand();
+ }
+ else if (skipProbability > 0.8f) {
+ profileOperand = OPT_BranchProfileOperand.always();
+ condBlock.setInfrequent();
+ }
+ else if (skipProbability > 0.5f) {
+ profileOperand = OPT_BranchProfileOperand.likely();
+ condBlock.setInfrequent();
+ }
+ else if (skipProbability < 0.2f) {
+ profileOperand = OPT_BranchProfileOperand.never();
+ }
+ else {
+ profileOperand = OPT_BranchProfileOperand.unlikely();
+ }
}
- else if (skipProbability > 0.8f) {
- profileOperand = OPT_BranchProfileOperand.always();
- }
- else if (skipProbability > 0.5f) {
- profileOperand = OPT_BranchProfileOperand.likely();
- }
- else if (skipProbability < 0.2f) {
- profileOperand = OPT_BranchProfileOperand.never();
- }
else {
- profileOperand = OPT_BranchProfileOperand.unlikely();
+ profileOperand = new OPT_BranchProfileOperand();
}
switch (condition) {
@@ -2208,8 +2216,22 @@
//rotation = (address & 0x3) * 8
arm2ir.appendInstruction(Binary.create(INT_AND, rotation, address.copy(), new OPT_IntConstantOperand(0x3)));
+
+ OPT_BasicBlock remainderBlock = arm2ir.createBlockAfterCurrent();
+ OPT_BasicBlock rotationBlock = arm2ir.createBlockAfterCurrent();
+
+ //do we actually have to perform the rotation?
+ arm2ir.appendInstruction(IfCmp.create(INT_IFCMP, arm2ir.getTempValidation(0), rotation.copy(), new OPT_IntConstantOperand(0), OPT_ConditionOperand.NOT_EQUAL(), rotationBlock.makeJumpTarget(), OPT_BranchProfileOperand.never()));
+ arm2ir.appendInstruction(Goto.create(GOTO, remainderBlock.makeJumpTarget()));
+
+ //in case we are performing the rotation...
+ arm2ir.setCurrentBlock(rotationBlock);
+ rotationBlock.setInfrequent();
arm2ir.appendInstruction(Binary.create(INT_SHL, rotation.copyRO(), rotation.copy(), new OPT_IntConstantOperand(3)));
arm2ir.appendRotateRight(value.copyRO(), value.copy(), rotation.copy());
+
+ //continue with the remainder of the instruction
+ arm2ir.setCurrentBlock(remainderBlock);
//allow further usage of the memory address
address = adrCopy;
@@ -2284,6 +2306,7 @@
arm2ir.appendBranch(arm2ir.getRegister(i.Rd), lazy, BranchType.INDIRECT_BRANCH);
}
}
+
public Condition getCondition() {
return i.condition;
Modified: src/org/binarytranslator/generic/decoder/CodeTranslator.java
===================================================================
--- src/org/binarytranslator/generic/decoder/CodeTranslator.java 2007-08-06 15:23:44 UTC (rev 157)
+++ src/org/binarytranslator/generic/decoder/CodeTranslator.java 2007-08-06 15:25:12 UTC (rev 158)
@@ -158,7 +158,7 @@
/**
* This variable is being set by a call to {@link #printTraceAfterCompletion()} and notifies
* the system that the current trace shall be printed, after it has been completed. */
- private boolean requestPrintTrace;
+ private boolean printTraceAfterCompletionRequested;
/** Map to locate HIR basic blocks to re-use translation within a trace */
protected final HashMap<Laziness.Key, OPT_BasicBlock> blockMap;
@@ -248,7 +248,7 @@
* debug purposes.
*/
protected void printTraceAfterCompletion() {
- requestPrintTrace = true;
+ printTraceAfterCompletionRequested = true;
}
/** This is the main loop, which generates the HIR. */
@@ -263,7 +263,10 @@
while (unresolvedDirectBranches.size() > 0 || unresolvedDynamicBranches.size() > 0) {
// Resolve all open direct branches first
- resolveAllDirectBranches();
+ do {
+ resolveAllDirectBranches();
+ }
+ while (unresolvedDirectBranches.size() > 0);
// Resolve unresolved dynamic jumps
resolveAllDynamicBranches();
@@ -276,14 +279,24 @@
eliminateRegisterFills(getUnusedRegisters());
}
- if (requestPrintTrace) {
- requestPrintTrace = false;
+ if (printTraceAfterCompletionRequested) {
+ printTraceAfterCompletionRequested = false;
printNextBlocks(preFillBlock, 50);
}
-
- // TODO: maximizeBasicBlocks()
}
+ /*
+ protected final void maximizeBasicBlocks(OPT_IR ir) {
+ for (OPT_BasicBlock currBB = ir.cfg.firstInCodeOrder(); currBB != null;) {
+ if (currBB.mergeFallThrough(ir)) {
+ // don't advance currBB; it may have a new trivial fallthrough to
+ // swallow
+ } else {
+ currBB = currBB.nextBasicBlockInCodeOrder();
+ }
+ }
+ }*/
+
/**
* Translate a sequence of instructions upto an instruction that doesn't know
* its immediate/default successor. The currentBlock should be an empty basic
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|