Convert StringMap to using StringRef for its APIs.
[oota-llvm.git] / lib / Analysis / ScalarEvolutionExpander.cpp
index 20d6e20601f28465c33150206e4c44a5a8f161a1..6d55ffc4216a253b74dc04b7b6631f3a81027131 100644 (file)
@@ -55,7 +55,7 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, const Type *Ty) {
 
   // FIXME: keep track of the cast instruction.
   if (Constant *C = dyn_cast<Constant>(V))
-    return getContext()->getConstantExprCast(Op, C, Ty);
+    return getContext().getConstantExprCast(Op, C, Ty);
   
   if (Argument *A = dyn_cast<Argument>(V)) {
     // Check to see if there is already a cast!
@@ -126,7 +126,7 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
   // Fold a binop with constant operands.
   if (Constant *CLHS = dyn_cast<Constant>(LHS))
     if (Constant *CRHS = dyn_cast<Constant>(RHS))
-      return getContext()->getConstantExpr(Opcode, CLHS, CRHS);
+      return getContext().getConstantExpr(Opcode, CLHS, CRHS);
 
   // Do a quick scan to see if we have this binop nearby.  If so, reuse it.
   unsigned ScanLimit = 6;
@@ -167,7 +167,7 @@ static bool FactorOutConstant(const SCEV *&S,
   // For a Constant, check for a multiple of the given factor.
   if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) {
     ConstantInt *CI =
-      SE.getContext()->getConstantInt(C->getValue()->getValue().sdiv(Factor));
+      SE.getContext().getConstantInt(C->getValue()->getValue().sdiv(Factor));
     // If the quotient is zero and the remainder is non-zero, reject
     // the value at this scale. It will be considered for subsequent
     // smaller scales.
@@ -215,13 +215,11 @@ static bool FactorOutConstant(const SCEV *&S,
 
 /// expandAddToGEP - Expand a SCEVAddExpr with a pointer type into a GEP
 /// instead of using ptrtoint+arithmetic+inttoptr. This helps
-/// BasicAliasAnalysis analyze the result. However, it suffers from the
-/// underlying bug described in PR2831. Addition in LLVM currently always
-/// has two's complement wrapping guaranteed. However, the semantics for
-/// getelementptr overflow are ambiguous. In the common case though, this
-/// expansion gets used when a GEP in the original code has been converted
-/// into integer arithmetic, in which case the resulting code will be no
-/// more undefined than it was originally.
+/// BasicAliasAnalysis analyze the result.
+///
+/// Design note: This depends on ScalarEvolution not recognizing inttoptr
+/// and ptrtoint operators, as they may introduce pointer arithmetic
+/// which may not be safely converted into getelementptr.
 ///
 /// Design note: It might seem desirable for this function to be more
 /// loop-aware. If some of the indices are loop-invariant while others
@@ -287,7 +285,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
     Ops = NewOps;
     AnyNonZeroIndices |= !ScaledOps.empty();
     Value *Scaled = ScaledOps.empty() ?
-                    getContext()->getNullValue(Ty) :
+                    getContext().getNullValue(Ty) :
                     expandCodeFor(SE.getAddExpr(ScaledOps), Ty);
     GepIndices.push_back(Scaled);
 
@@ -301,7 +299,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
             if (FullOffset < SL.getSizeInBytes()) {
               unsigned ElIdx = SL.getElementContainingOffset(FullOffset);
               GepIndices.push_back(
-                            getContext()->getConstantInt(Type::Int32Ty, ElIdx));
+                            getContext().getConstantInt(Type::Int32Ty, ElIdx));
               ElTy = STy->getTypeAtIndex(ElIdx);
               Ops[0] =
                 SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx));
@@ -330,7 +328,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
     // Fold a GEP with constant operands.
     if (Constant *CLHS = dyn_cast<Constant>(V))
       if (Constant *CRHS = dyn_cast<Constant>(Idx))
-        return getContext()->getConstantExprGetElementPtr(CLHS, &CRHS, 1);
+        return getContext().getConstantExprGetElementPtr(CLHS, &CRHS, 1);
 
     // Do a quick scan to see if we have this GEP nearby.  If so, reuse it.
     unsigned ScanLimit = 6;
@@ -402,7 +400,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) {
 
   // -1 * ...  --->  0 - ...
   if (FirstOp == 1)
-    V = InsertBinop(Instruction::Sub, getContext()->getNullValue(Ty), V);
+    V = InsertBinop(Instruction::Sub, getContext().getNullValue(Ty), V);
   return V;
 }
 
@@ -414,7 +412,7 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) {
     const APInt &RHS = SC->getValue()->getValue();
     if (RHS.isPowerOf2())
       return InsertBinop(Instruction::LShr, LHS,
-                         getContext()->getConstantInt(Ty, RHS.logBase2()));
+                         getContext().getConstantInt(Ty, RHS.logBase2()));
   }
 
   Value *RHS = expandCodeFor(S->getRHS(), Ty);
@@ -524,7 +522,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
     BasicBlock *Preheader = L->getLoopPreheader();
     PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
     InsertedValues.insert(PN);
-    PN->addIncoming(getContext()->getNullValue(Ty), Preheader);
+    PN->addIncoming(getContext().getNullValue(Ty), Preheader);
 
     pred_iterator HPI = pred_begin(Header);
     assert(HPI != pred_end(Header) && "Loop with zero preds???");
@@ -534,7 +532,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
 
     // Insert a unit add instruction right before the terminator corresponding
     // to the back-edge.
-    Constant *One = getContext()->getConstantInt(Ty, 1);
+    Constant *One = getContext().getConstantInt(Ty, 1);
     Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
                                                  (*HPI)->getTerminator());
     InsertedValues.insert(Add);