Add X86FastISel support for static allocas, and refences
to static allocas. As part of this change, refactor the
address mode code for laods and stores.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56066 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 912dc32..8a70b06 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -37,14 +37,14 @@
     return 0;
   if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
     if (CI->getValue().getActiveBits() > 64)
-      return TargetMaterializeConstant(CI,
-                                       MBB->getParent()->getConstantPool());
+      return TargetMaterializeConstant(CI);
     // Don't cache constant materializations.  To do so would require
     // tracking what uses they dominate.
     Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
   } else if (isa<GlobalValue>(V)) {
-    return TargetMaterializeConstant(dyn_cast<Constant>(V),
-                                     MBB->getParent()->getConstantPool());
+    return TargetMaterializeConstant(cast<Constant>(V));
+  } else if (isa<AllocaInst>(V)) {
+    return TargetMaterializeAlloca(cast<AllocaInst>(V));
   } else if (isa<ConstantPointerNull>(V)) {
     Reg = FastEmit_i(VT, VT, ISD::Constant, 0);
   } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
@@ -58,19 +58,16 @@
       uint32_t IntBitWidth = IntVT.getSizeInBits();
       if (Flt.convertToInteger(x, IntBitWidth, /*isSigned=*/true,
                                APFloat::rmTowardZero) != APFloat::opOK)
-        return TargetMaterializeConstant(CF,    
-                                         MBB->getParent()->getConstantPool());
+        return TargetMaterializeConstant(CF);
       APInt IntVal(IntBitWidth, 2, x);
 
       unsigned IntegerReg = FastEmit_i(IntVT.getSimpleVT(), IntVT.getSimpleVT(),
                                        ISD::Constant, IntVal.getZExtValue());
       if (IntegerReg == 0)
-        return TargetMaterializeConstant(CF,
-                                         MBB->getParent()->getConstantPool());
+        return TargetMaterializeConstant(CF);
       Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
       if (Reg == 0)
-        return TargetMaterializeConstant(CF,
-                                         MBB->getParent()->getConstantPool());;
+        return TargetMaterializeConstant(CF);
     }
   } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
     if (!SelectOperator(CE, CE->getOpcode())) return 0;
@@ -83,8 +80,7 @@
   }
   
   if (!Reg && isa<Constant>(V))
-    return TargetMaterializeConstant(cast<Constant>(V),
-                                     MBB->getParent()->getConstantPool());
+    return TargetMaterializeConstant(cast<Constant>(V));
   
   LocalValueMap[V] = Reg;
   return Reg;
@@ -416,6 +412,14 @@
   case Instruction::PHI:
     // PHI nodes are already emitted.
     return true;
+
+  case Instruction::Alloca:
+    // FunctionLowering has the static-sized case covered.
+    if (StaticAllocaMap.count(cast<AllocaInst>(I)))
+      return true;
+
+    // Dynamic-sized alloca is not handled yet.
+    return false;
     
   case Instruction::BitCast:
     return SelectBitCast(I);
@@ -453,12 +457,16 @@
 
 FastISel::FastISel(MachineFunction &mf,
                    DenseMap<const Value *, unsigned> &vm,
-                   DenseMap<const BasicBlock *, MachineBasicBlock *> &bm)
+                   DenseMap<const BasicBlock *, MachineBasicBlock *> &bm,
+                   DenseMap<const AllocaInst *, int> &am)
   : MBB(0),
     ValueMap(vm),
     MBBMap(bm),
+    StaticAllocaMap(am),
     MF(mf),
     MRI(MF.getRegInfo()),
+    MFI(*MF.getFrameInfo()),
+    MCP(*MF.getConstantPool()),
     TM(MF.getTarget()),
     TD(*TM.getTargetData()),
     TII(*TM.getInstrInfo()),
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index f47abb3..c9376a1 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -737,7 +737,8 @@
     // FastISel doesn't support EH landing pads, which require special handling.
     if (EnableFastISel && !BB->isLandingPad()) {
       if (FastISel *F = TLI.createFastISel(*FuncInfo->MF, FuncInfo->ValueMap,
-                                           FuncInfo->MBBMap)) {
+                                           FuncInfo->MBBMap,
+                                           FuncInfo->StaticAllocaMap)) {
         // Emit code for any incoming arguments. This must happen before
         // beginning FastISel on the entry block.
         if (LLVMBB == &Fn.getEntryBlock()) {