diff options
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp')
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 74 | 
1 files changed, 66 insertions, 8 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 3aabdaeaa094a..5e0feccb6b4c6 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -38,6 +38,7 @@  #include "llvm/CodeGen/MachineInstr.h"  #include "llvm/CodeGen/MachineInstrBuilder.h"  #include "llvm/CodeGen/MachineMemOperand.h" +#include "llvm/CodeGen/MachineModuleInfo.h"  #include "llvm/CodeGen/MachineOperand.h"  #include "llvm/CodeGen/MachinePassRegistry.h"  #include "llvm/CodeGen/MachineRegisterInfo.h" @@ -299,7 +300,7 @@ SelectionDAGISel::SelectionDAGISel(TargetMachine &tm,    FuncInfo(new FunctionLoweringInfo()),    CurDAG(new SelectionDAG(tm, OL)),    SDB(new SelectionDAGBuilder(*CurDAG, *FuncInfo, OL)), -  GFI(), +  AA(), GFI(),    OptLevel(OL),    DAGSize(0) {      initializeGCModuleInfoPass(*PassRegistry::getPassRegistry()); @@ -317,7 +318,8 @@ SelectionDAGISel::~SelectionDAGISel() {  }  void SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) const { -  AU.addRequired<AAResultsWrapperPass>(); +  if (OptLevel != CodeGenOpt::None) +    AU.addRequired<AAResultsWrapperPass>();    AU.addRequired<GCModuleInfo>();    AU.addRequired<StackProtector>();    AU.addPreserved<StackProtector>(); @@ -394,7 +396,6 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {    TII = MF->getSubtarget().getInstrInfo();    TLI = MF->getSubtarget().getTargetLowering();    RegInfo = &MF->getRegInfo(); -  AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();    LibInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();    GFI = Fn.hasGC() ? &getAnalysis<GCModuleInfo>().getFunctionInfo(Fn) : nullptr;    ORE = make_unique<OptimizationRemarkEmitter>(&Fn); @@ -406,12 +407,22 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {    CurDAG->init(*MF, *ORE);    FuncInfo->set(Fn, *MF, CurDAG); +  // Now get the optional analyzes if we want to. +  // This is based on the possibly changed OptLevel (after optnone is taken +  // into account).  That's unfortunate but OK because it just means we won't +  // ask for passes that have been required anyway. +    if (UseMBPI && OptLevel != CodeGenOpt::None)      FuncInfo->BPI = &getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();    else      FuncInfo->BPI = nullptr; -  SDB->init(GFI, *AA, LibInfo); +  if (OptLevel != CodeGenOpt::None) +    AA = &getAnalysis<AAResultsWrapperPass>().getAAResults(); +  else +    AA = nullptr; + +  SDB->init(GFI, AA, LibInfo);    MF->setHasInlineAsm(false); @@ -715,7 +726,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {    {      NamedRegionTimer T("combine1", "DAG Combining 1", GroupName,                         GroupDescription, TimePassesIsEnabled); -    CurDAG->Combine(BeforeLegalizeTypes, *AA, OptLevel); +    CurDAG->Combine(BeforeLegalizeTypes, AA, OptLevel);    }    DEBUG(dbgs() << "Optimized lowered selection DAG: BB#" << BlockNumber @@ -747,7 +758,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {      {        NamedRegionTimer T("combine_lt", "DAG Combining after legalize types",                           GroupName, GroupDescription, TimePassesIsEnabled); -      CurDAG->Combine(AfterLegalizeTypes, *AA, OptLevel); +      CurDAG->Combine(AfterLegalizeTypes, AA, OptLevel);      }      DEBUG(dbgs() << "Optimized type-legalized selection DAG: BB#" << BlockNumber @@ -781,7 +792,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {      {        NamedRegionTimer T("combine_lv", "DAG Combining after legalize vectors",                           GroupName, GroupDescription, TimePassesIsEnabled); -      CurDAG->Combine(AfterLegalizeVectorOps, *AA, OptLevel); +      CurDAG->Combine(AfterLegalizeVectorOps, AA, OptLevel);      }      DEBUG(dbgs() << "Optimized vector-legalized selection DAG: BB#" @@ -807,7 +818,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {    {      NamedRegionTimer T("combine2", "DAG Combining 2", GroupName,                         GroupDescription, TimePassesIsEnabled); -    CurDAG->Combine(AfterLegalizeDAG, *AA, OptLevel); +    CurDAG->Combine(AfterLegalizeDAG, AA, OptLevel);    }    DEBUG(dbgs() << "Optimized legalized selection DAG: BB#" << BlockNumber @@ -1145,6 +1156,51 @@ static void createSwiftErrorEntriesInEntryBlock(FunctionLoweringInfo *FuncInfo,    }  } +/// Collect llvm.dbg.declare information. This is done after argument lowering +/// in case the declarations refer to arguments. +static void processDbgDeclares(FunctionLoweringInfo *FuncInfo) { +  MachineFunction *MF = FuncInfo->MF; +  const DataLayout &DL = MF->getDataLayout(); +  for (const BasicBlock &BB : *FuncInfo->Fn) { +    for (const Instruction &I : BB) { +      const DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(&I); +      if (!DI) +        continue; + +      assert(DI->getVariable() && "Missing variable"); +      assert(DI->getDebugLoc() && "Missing location"); +      const Value *Address = DI->getAddress(); +      if (!Address) +        continue; + +      // Look through casts and constant offset GEPs. These mostly come from +      // inalloca. +      APInt Offset(DL.getPointerSizeInBits(0), 0); +      Address = Address->stripAndAccumulateInBoundsConstantOffsets(DL, Offset); + +      // Check if the variable is a static alloca or a byval or inalloca +      // argument passed in memory. If it is not, then we will ignore this +      // intrinsic and handle this during isel like dbg.value. +      int FI = INT_MAX; +      if (const auto *AI = dyn_cast<AllocaInst>(Address)) { +        auto SI = FuncInfo->StaticAllocaMap.find(AI); +        if (SI != FuncInfo->StaticAllocaMap.end()) +          FI = SI->second; +      } else if (const auto *Arg = dyn_cast<Argument>(Address)) +        FI = FuncInfo->getArgumentFrameIndex(Arg); + +      if (FI == INT_MAX) +        continue; + +      DIExpression *Expr = DI->getExpression(); +      if (Offset.getBoolValue()) +        Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, +                                     Offset.getZExtValue()); +      MF->setVariableDbgInfo(DI->getVariable(), Expr, FI, DI->getDebugLoc()); +    } +  } +} +  /// Propagate swifterror values through the machine function CFG.  static void propagateSwiftErrorVRegs(FunctionLoweringInfo *FuncInfo) {    auto *TLI = FuncInfo->TLI; @@ -1317,6 +1373,8 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) {    }    createSwiftErrorEntriesInEntryBlock(FuncInfo, FastIS, TLI, TII, SDB); +  processDbgDeclares(FuncInfo); +    // Iterate over all basic blocks in the function.    for (const BasicBlock *LLVMBB : RPOT) {      if (OptLevel != CodeGenOpt::None) {  | 
