summaryrefslogtreecommitdiff
path: root/src/jit/loopcloning.h
diff options
context:
space:
mode:
authorMichelle McDaniel <adiaaida@gmail.com>2016-08-09 13:15:05 -0700
committerMichelle McDaniel <adiaaida@gmail.com>2016-08-11 09:53:41 -0700
commit36a2b906c008cd3693a9ab5aef7b4402addd6c74 (patch)
tree27333c6f26304490169825ae1c17484534246dc6 /src/jit/loopcloning.h
parentab7d6a8df73d3d89210a778338feaa9fedf4146a (diff)
downloadcoreclr-36a2b906c008cd3693a9ab5aef7b4402addd6c74.tar.gz
coreclr-36a2b906c008cd3693a9ab5aef7b4402addd6c74.tar.bz2
coreclr-36a2b906c008cd3693a9ab5aef7b4402addd6c74.zip
Reformat jit sources with clang-tidy and format
This change is the result of running clang-tidy and clang-format on jit sources.
Diffstat (limited to 'src/jit/loopcloning.h')
-rw-r--r--src/jit/loopcloning.h277
1 files changed, 150 insertions, 127 deletions
diff --git a/src/jit/loopcloning.h b/src/jit/loopcloning.h
index faa6a0a1c2..40793afcf1 100644
--- a/src/jit/loopcloning.h
+++ b/src/jit/loopcloning.h
@@ -24,7 +24,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
i) The array index is stored in the "context" variable with
additional block, tree, stmt info.
- Once the optimization candidates are identified, we derive cloning conditions
- For ex: to clone a simple "for (i=0; i<n; ++i) { a[i] }" loop, we need the
+ For ex: to clone a simple "for (i=0; i<n; ++i) { a[i] }" loop, we need the
following conditions:
(a != null) && ((n >= 0) & (n <= a.length) & (stride > 0))
a) Note the short circuit AND for (a != null). These are called block
@@ -55,7 +55,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GenTree and added to the loop cloning choice block.
Preconditions
- - Loop detection should have completed and the loop table should be
+ - Loop detection should have completed and the loop table should be
populated with the loop dscs.
- The loops that will be considered are the ones with the LPFLG_ITER
marked on them.
@@ -80,7 +80,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bitwise AND operations.
- Perform short circuit AND for (array != null) side effect check
before hoisting (limit <= a.length) check.
- For ex: to clone a simple "for (i=0; i<n; ++i) { a[i] }" loop, we need the
+ For ex: to clone a simple "for (i=0; i<n; ++i) { a[i] }" loop, we need the
following conditions:
(a != null) && ((n >= 0) & (n <= a.length) & (stride > 0))
@@ -99,19 +99,15 @@ class Compiler;
*/
struct ArrIndex
{
- unsigned arrLcl; // The array base local num
- ExpandArrayStack<unsigned> indLcls; // The indices local nums
- ExpandArrayStack<GenTree*> bndsChks; // The bounds checks nodes along each dimension.
- unsigned rank; // Rank of the array
- BasicBlock* useBlock; // Block where the [] occurs
-
- ArrIndex(IAllocator* alloc)
- : arrLcl(BAD_VAR_NUM)
- , indLcls(alloc)
- , bndsChks(alloc)
- , rank(0)
- , useBlock(nullptr)
- {}
+ unsigned arrLcl; // The array base local num
+ ExpandArrayStack<unsigned> indLcls; // The indices local nums
+ ExpandArrayStack<GenTree*> bndsChks; // The bounds checks nodes along each dimension.
+ unsigned rank; // Rank of the array
+ BasicBlock* useBlock; // Block where the [] occurs
+
+ ArrIndex(IAllocator* alloc) : arrLcl(BAD_VAR_NUM), indLcls(alloc), bndsChks(alloc), rank(0), useBlock(nullptr)
+ {
+ }
#ifdef DEBUG
void Print(unsigned dim = -1)
@@ -125,16 +121,15 @@ struct ArrIndex
#endif
};
-
// Forward declarations
#define LC_OPT(en) struct en##OptInfo;
#include "loopcloningopts.h"
/**
*
- * LcOptInfo represents the optimization information for loop cloning,
+ * LcOptInfo represents the optimization information for loop cloning,
* other classes are supposed to derive from this base class.
- *
+ *
* Example usage:
* LcMdArrayOptInfo is multi-dimensional array optimization for which the
* loop can be cloned.
@@ -154,19 +149,22 @@ struct LcOptInfo
#include "loopcloningopts.h"
};
- void* optInfo;
+ void* optInfo;
OptType optType;
- LcOptInfo(void* optInfo, OptType optType)
- : optInfo(optInfo)
- , optType(optType) {}
+ LcOptInfo(void* optInfo, OptType optType) : optInfo(optInfo), optType(optType)
+ {
+ }
- OptType GetOptType() { return optType; }
+ OptType GetOptType()
+ {
+ return optType;
+ }
#undef LC_OPT
-#define LC_OPT(en) \
- en##OptInfo* As##en##OptInfo() \
- { \
- assert(optType == en); \
- return reinterpret_cast<en##OptInfo*>(this); \
+#define LC_OPT(en) \
+ en##OptInfo* As##en##OptInfo() \
+ { \
+ assert(optType == en); \
+ return reinterpret_cast<en##OptInfo*>(this); \
}
#include "loopcloningopts.h"
};
@@ -177,23 +175,22 @@ struct LcOptInfo
*/
struct LcMdArrayOptInfo : public LcOptInfo
{
- GenTreeArrElem* arrElem; // "arrElem" node of an MD array.
- unsigned dim; // "dim" represents upto what level of the rank this optimization applies to.
- // For example, a[i,j,k] could be the MD array "arrElem" but if "dim" is 2,
- // then this node is treated as though it were a[i,j]
- ArrIndex* index; // "index" cached computation in the form of an ArrIndex representation.
+ GenTreeArrElem* arrElem; // "arrElem" node of an MD array.
+ unsigned dim; // "dim" represents upto what level of the rank this optimization applies to.
+ // For example, a[i,j,k] could be the MD array "arrElem" but if "dim" is 2,
+ // then this node is treated as though it were a[i,j]
+ ArrIndex* index; // "index" cached computation in the form of an ArrIndex representation.
LcMdArrayOptInfo(GenTreeArrElem* arrElem, unsigned dim)
- : LcOptInfo(this, LcMdArray)
- , arrElem(arrElem)
- , dim(dim)
- , index(nullptr) {}
+ : LcOptInfo(this, LcMdArray), arrElem(arrElem), dim(dim), index(nullptr)
+ {
+ }
ArrIndex* GetArrIndexForDim(IAllocator* alloc)
{
if (index == nullptr)
{
- index = new (alloc) ArrIndex(alloc);
+ index = new (alloc) ArrIndex(alloc);
index->rank = arrElem->gtArrRank;
for (unsigned i = 0; i < dim; ++i)
{
@@ -211,17 +208,16 @@ struct LcMdArrayOptInfo : public LcOptInfo
*/
struct LcJaggedArrayOptInfo : public LcOptInfo
{
- unsigned dim; // "dim" represents upto what level of the rank this optimization applies to.
- // For example, a[i][j][k] could be the jagged array but if "dim" is 2,
- // then this node is treated as though it were a[i][j]
- ArrIndex arrIndex; // ArrIndex representation of the array.
- GenTreePtr stmt; // "stmt" where the optimization opportunity occurs.
+ unsigned dim; // "dim" represents upto what level of the rank this optimization applies to.
+ // For example, a[i][j][k] could be the jagged array but if "dim" is 2,
+ // then this node is treated as though it were a[i][j]
+ ArrIndex arrIndex; // ArrIndex representation of the array.
+ GenTreePtr stmt; // "stmt" where the optimization opportunity occurs.
LcJaggedArrayOptInfo(ArrIndex& arrIndex, unsigned dim, GenTreePtr stmt)
- : LcOptInfo(this, LcJaggedArray)
- , dim(dim)
- , arrIndex(arrIndex)
- , stmt(stmt) {}
+ : LcOptInfo(this, LcJaggedArray), dim(dim), arrIndex(arrIndex), stmt(stmt)
+ {
+ }
};
/**
@@ -244,8 +240,8 @@ struct LC_Array
ArrLen,
};
- ArrType type; // The type of the array on which to invoke length operator.
- ArrIndex* arrIndex; // ArrIndex representation of this array.
+ ArrType type; // The type of the array on which to invoke length operator.
+ ArrIndex* arrIndex; // ArrIndex representation of this array.
OperType oper;
@@ -260,13 +256,20 @@ struct LC_Array
}
#endif
- int dim; // "dim" = which index to invoke arrLen on, if -1 invoke on the whole array
- // Example 1: a[0][1][2] and dim = 2 implies a[0][1].length
- // Example 2: a[0][1][2] and dim = -1 implies a[0][1][2].length
- LC_Array() : type(Invalid), dim(-1) {}
- LC_Array(ArrType type, ArrIndex* arrIndex, int dim, OperType oper) : type(type), arrIndex(arrIndex), oper(oper), dim(dim) {}
+ int dim; // "dim" = which index to invoke arrLen on, if -1 invoke on the whole array
+ // Example 1: a[0][1][2] and dim = 2 implies a[0][1].length
+ // Example 2: a[0][1][2] and dim = -1 implies a[0][1][2].length
+ LC_Array() : type(Invalid), dim(-1)
+ {
+ }
+ LC_Array(ArrType type, ArrIndex* arrIndex, int dim, OperType oper)
+ : type(type), arrIndex(arrIndex), oper(oper), dim(dim)
+ {
+ }
- LC_Array(ArrType type, ArrIndex* arrIndex, OperType oper) : type(type), arrIndex(arrIndex), oper(oper), dim(-1) {}
+ LC_Array(ArrType type, ArrIndex* arrIndex, OperType oper) : type(type), arrIndex(arrIndex), oper(oper), dim(-1)
+ {
+ }
// Equality operator
bool operator==(const LC_Array& that) const
@@ -274,9 +277,7 @@ struct LC_Array
assert(type != Invalid && that.type != Invalid);
// Types match and the array base matches.
- if (type != that.type ||
- arrIndex->arrLcl != that.arrIndex->arrLcl ||
- oper != that.oper)
+ if (type != that.type || arrIndex->arrLcl != that.arrIndex->arrLcl || oper != that.oper)
{
return false;
}
@@ -303,7 +304,7 @@ struct LC_Array
// The max dim on which length is invoked.
int GetDimRank() const
{
- return (dim < 0) ? (int) arrIndex->rank : dim;
+ return (dim < 0) ? (int)arrIndex->rank : dim;
}
// Get a tree representation for this symbolic a.length
@@ -312,7 +313,8 @@ struct LC_Array
/**
*
- * Symbolic representation of either a constant like 1, 2 or a variable V02, V03 etc. or an "LC_Array" or the null constant.
+ * Symbolic representation of either a constant like 1, 2 or a variable V02, V03 etc. or an "LC_Array" or the null
+ * constant.
*/
struct LC_Ident
{
@@ -325,25 +327,25 @@ struct LC_Ident
Null,
};
- INT64 constant; // The constant value if this node is of type "Const", or the lcl num if "Var"
- LC_Array arrLen; // The LC_Array if the type is "ArrLen"
- IdentType type; // The type of this object
+ INT64 constant; // The constant value if this node is of type "Const", or the lcl num if "Var"
+ LC_Array arrLen; // The LC_Array if the type is "ArrLen"
+ IdentType type; // The type of this object
// Equality operator
bool operator==(const LC_Ident& that) const
{
switch (type)
{
- case Const:
- case Var:
- return (type == that.type) && constant == that.constant;
- case ArrLen:
- return (type == that.type) && (arrLen == that.arrLen);
- case Null:
- return (type == that.type);
- default:
- assert(!"Unknown LC_Ident type");
- unreached();
+ case Const:
+ case Var:
+ return (type == that.type) && constant == that.constant;
+ case ArrLen:
+ return (type == that.type) && (arrLen == that.arrLen);
+ case Null:
+ return (type == that.type);
+ default:
+ assert(!"Unknown LC_Ident type");
+ unreached();
}
}
@@ -352,29 +354,37 @@ struct LC_Ident
{
switch (type)
{
- case Const:
- printf("%I64d", constant);
- break;
- case Var:
- printf("V%02d", constant);
- break;
- case ArrLen:
- arrLen.Print();
- break;
- case Null:
- printf("null");
- break;
- default:
- assert(false);
- break;
+ case Const:
+ printf("%I64d", constant);
+ break;
+ case Var:
+ printf("V%02d", constant);
+ break;
+ case ArrLen:
+ arrLen.Print();
+ break;
+ case Null:
+ printf("null");
+ break;
+ default:
+ assert(false);
+ break;
}
}
#endif
- LC_Ident() : type(Invalid) {}
- LC_Ident(INT64 constant, IdentType type) : constant(constant), type(type) {}
- explicit LC_Ident(IdentType type) : type(type) {}
- explicit LC_Ident(const LC_Array& arrLen) : arrLen(arrLen), type(ArrLen) {}
+ LC_Ident() : type(Invalid)
+ {
+ }
+ LC_Ident(INT64 constant, IdentType type) : constant(constant), type(type)
+ {
+ }
+ explicit LC_Ident(IdentType type) : type(type)
+ {
+ }
+ explicit LC_Ident(const LC_Array& arrLen) : arrLen(arrLen), type(ArrLen)
+ {
+ }
// Convert this symbolic representation into a tree node.
GenTreePtr ToGenTree(Compiler* comp);
@@ -394,7 +404,7 @@ struct LC_Expr
};
LC_Ident ident;
- INT64 constant;
+ INT64 constant;
ExprType type;
// Equality operator
@@ -434,9 +444,15 @@ struct LC_Expr
}
#endif
- LC_Expr() : type(Invalid) {}
- explicit LC_Expr(const LC_Ident& ident) : ident(ident), type(Ident) {}
- LC_Expr(const LC_Ident& ident, INT64 constant) : ident(ident), constant(constant), type(IdentPlusConst) {}
+ LC_Expr() : type(Invalid)
+ {
+ }
+ explicit LC_Expr(const LC_Ident& ident) : ident(ident), type(Ident)
+ {
+ }
+ LC_Expr(const LC_Ident& ident, INT64 constant) : ident(ident), constant(constant), type(IdentPlusConst)
+ {
+ }
// Convert LC_Expr into a tree node.
GenTreePtr ToGenTree(Compiler* comp);
@@ -449,8 +465,8 @@ struct LC_Expr
*/
struct LC_Condition
{
- LC_Expr op1;
- LC_Expr op2;
+ LC_Expr op1;
+ LC_Expr op2;
genTreeOps oper;
#ifdef DEBUG
@@ -470,8 +486,12 @@ struct LC_Condition
// Check if two conditions can be combined to yield one condition.
bool Combines(const LC_Condition& cond, LC_Condition* newCond);
- LC_Condition() {}
- LC_Condition(genTreeOps oper, const LC_Expr& op1, const LC_Expr& op2) : op1(op1), op2(op2), oper(oper) {}
+ LC_Condition()
+ {
+ }
+ LC_Condition(genTreeOps oper, const LC_Expr& op1, const LC_Expr& op2) : op1(op1), op2(op2), oper(oper)
+ {
+ }
// Convert this conditional operation into a GenTree.
GenTreePtr ToGenTree(Compiler* comp);
@@ -496,16 +516,14 @@ struct LC_Condition
*/
struct LC_Deref
{
- const LC_Array array;
+ const LC_Array array;
ExpandArrayStack<LC_Deref*>* children;
unsigned level;
- LC_Deref(const LC_Array& array, unsigned level)
- : array(array)
- , children(nullptr)
- , level(level)
- { }
+ LC_Deref(const LC_Array& array, unsigned level) : array(array), children(nullptr), level(level)
+ {
+ }
LC_Deref* Find(unsigned lcl);
@@ -525,11 +543,14 @@ struct LC_Deref
{
for (unsigned i = 0; i < children->Size(); ++i)
{
- if (i > 0) { printf(","); }
+ if (i > 0)
+ {
+ printf(",");
+ }
printf("\n");
#ifdef _MSC_VER
(*children)[i]->Print(indent + 1);
-#else // _MSC_VER
+#else // _MSC_VER
(*((ExpandArray<LC_Deref*>*)children))[i]->Print(indent + 1);
#endif // _MSC_VER
}
@@ -552,28 +573,31 @@ struct LC_Deref
* LC_Ident : Constant | Var | LC_Array
* LC_Array : .
* genTreeOps : GT_GE | GT_LE | GT_GT | GT_LT
- *
+ *
*/
struct LoopCloneContext
{
- IAllocator* alloc; // The allocator
- ExpandArrayStack<LcOptInfo*>** optInfo; // The array of optimization opportunities found in each loop. (loop x optimization-opportunities)
- ExpandArrayStack<LC_Condition>** conditions; // The array of conditions that influence which path to take for each loop. (loop x cloning-conditions)
- ExpandArrayStack<LC_Array>** derefs; // The array of dereference conditions found in each loop. (loop x deref-conditions)
- ExpandArrayStack<ExpandArrayStack<LC_Condition>*>** blockConditions; // The array of block levels of conditions for each loop. (loop x level x conditions)
-
- LoopCloneContext(unsigned loopCount, IAllocator* alloc)
- : alloc(alloc)
- {
- optInfo = new (alloc) ExpandArrayStack<LcOptInfo*>*[loopCount];
- conditions = new (alloc) ExpandArrayStack<LC_Condition>*[loopCount];
- derefs = new (alloc) ExpandArrayStack<LC_Array>*[loopCount];
+ IAllocator* alloc; // The allocator
+ ExpandArrayStack<LcOptInfo*>** optInfo; // The array of optimization opportunities found in each loop. (loop x
+ // optimization-opportunities)
+ ExpandArrayStack<LC_Condition>** conditions; // The array of conditions that influence which path to take for each
+ // loop. (loop x cloning-conditions)
+ ExpandArrayStack<LC_Array>** derefs; // The array of dereference conditions found in each loop. (loop x
+ // deref-conditions)
+ ExpandArrayStack<ExpandArrayStack<LC_Condition>*>** blockConditions; // The array of block levels of conditions for
+ // each loop. (loop x level x conditions)
+
+ LoopCloneContext(unsigned loopCount, IAllocator* alloc) : alloc(alloc)
+ {
+ optInfo = new (alloc) ExpandArrayStack<LcOptInfo*>*[loopCount];
+ conditions = new (alloc) ExpandArrayStack<LC_Condition>*[loopCount];
+ derefs = new (alloc) ExpandArrayStack<LC_Array>*[loopCount];
blockConditions = new (alloc) ExpandArrayStack<ExpandArrayStack<LC_Condition>*>*[loopCount];
for (unsigned i = 0; i < loopCount; ++i)
{
- optInfo[i] = nullptr;
- conditions[i] = nullptr;
- derefs[i] = nullptr;
+ optInfo[i] = nullptr;
+ conditions[i] = nullptr;
+ derefs[i] = nullptr;
blockConditions[i] = nullptr;
}
}
@@ -634,11 +658,10 @@ private:
public:
// Optimize conditions to remove redundant conditions.
void OptimizeConditions(unsigned loopNum DEBUGARG(bool verbose));
-
+
void OptimizeBlockConditions(unsigned loopNum DEBUGARG(bool verbose));
#ifdef DEBUG
void PrintConditions(unsigned loopNum);
#endif
};
-