diff options
Diffstat (limited to 'lib/CodeGen')
| -rw-r--r-- | lib/CodeGen/BackendUtil.cpp | 15 | ||||
| -rw-r--r-- | lib/CodeGen/CGCall.cpp | 83 | ||||
| -rw-r--r-- | lib/CodeGen/CGCall.h | 1 | ||||
| -rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 39 | ||||
| -rw-r--r-- | lib/CodeGen/CGDecl.cpp | 8 | ||||
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 38 | ||||
| -rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 6 | ||||
| -rw-r--r-- | lib/CodeGen/CGObjC.cpp | 18 | ||||
| -rw-r--r-- | lib/CodeGen/CGStmt.cpp | 2 | ||||
| -rw-r--r-- | lib/CodeGen/CGVTables.cpp | 7 | ||||
| -rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 13 | ||||
| -rw-r--r-- | lib/CodeGen/CodeGenModule.h | 7 | ||||
| -rw-r--r-- | lib/CodeGen/CodeGenTypeCache.h | 6 | ||||
| -rw-r--r-- | lib/CodeGen/ModuleBuilder.cpp | 2 | 
14 files changed, 117 insertions, 128 deletions
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 855d6795b9d6..20059d922f90 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -83,9 +83,6 @@ class EmitAssemblyHelper {      return TargetIRAnalysis();    } -  /// Set LLVM command line options passed through -backend-option. -  void setCommandLineOpts(); -    void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM);    /// Generates the TargetMachine. @@ -372,7 +369,9 @@ static void initTargetOptions(llvm::TargetOptions &Options,    // Set FP fusion mode.    switch (LangOpts.getDefaultFPContractMode()) {    case LangOptions::FPC_Off: -    Options.AllowFPOpFusion = llvm::FPOpFusion::Strict; +    // Preserve any contraction performed by the front-end.  (Strict performs +    // splitting of the muladd instrinsic in the backend.) +    Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;      break;    case LangOptions::FPC_On:      Options.AllowFPOpFusion = llvm::FPOpFusion::Standard; @@ -604,7 +603,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,    PMBuilder.populateModulePassManager(MPM);  } -void EmitAssemblyHelper::setCommandLineOpts() { +static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {    SmallVector<const char *, 16> BackendArgs;    BackendArgs.push_back("clang"); // Fake program name.    if (!CodeGenOpts.DebugPass.empty()) { @@ -677,7 +676,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,                                        std::unique_ptr<raw_pwrite_stream> OS) {    TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr); -  setCommandLineOpts(); +  setCommandLineOpts(CodeGenOpts);    bool UsesCodeGen = (Action != Backend_EmitNothing &&                        Action != Backend_EmitBC && @@ -806,7 +805,7 @@ static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {  void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(      BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {    TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr); -  setCommandLineOpts(); +  setCommandLineOpts(CodeGenOpts);    // The new pass manager always makes a target machine available to passes    // during construction. @@ -944,6 +943,8 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,        ModuleToDefinedGVSummaries;    CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries); +  setCommandLineOpts(CGOpts); +    // We can simply import the values mentioned in the combined index, since    // we should only invoke this using the individual indexes written out    // via a WriteIndexesThinBackend. diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 8af32055fc4c..26235257b19d 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1586,9 +1586,10 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {      case ABIArgInfo::Indirect: {        assert(NumIRArgs == 1); -      // indirect arguments are always on the stack, which is addr space #0. +      // indirect arguments are always on the stack, which is alloca addr space.        llvm::Type *LTy = ConvertTypeForMem(it->type); -      ArgTypes[FirstIRArg] = LTy->getPointerTo(); +      ArgTypes[FirstIRArg] = LTy->getPointerTo( +          CGM.getDataLayout().getAllocaAddrSpace());        break;      } @@ -1761,7 +1762,7 @@ void CodeGenModule::AddDefaultFnAttrs(llvm::Function &F) {  void CodeGenModule::ConstructAttributeList(      StringRef Name, const CGFunctionInfo &FI, CGCalleeInfo CalleeInfo, -    AttributeListType &PAL, unsigned &CallingConv, bool AttrOnCallSite) { +    llvm::AttributeList &AttrList, unsigned &CallingConv, bool AttrOnCallSite) {    llvm::AttrBuilder FuncAttrs;    llvm::AttrBuilder RetAttrs; @@ -1930,13 +1931,8 @@ void CodeGenModule::ConstructAttributeList(        RetAttrs.addAttribute(llvm::Attribute::NonNull);    } -  // Attach return attributes. -  if (RetAttrs.hasAttributes()) { -    PAL.push_back(llvm::AttributeList::get( -        getLLVMContext(), llvm::AttributeList::ReturnIndex, RetAttrs)); -  } -    bool hasUsedSRet = false; +  SmallVector<llvm::AttributeSet, 4> ArgAttrs(IRFunctionArgs.totalIRArgs());    // Attach attributes to sret.    if (IRFunctionArgs.hasSRetArg()) { @@ -1945,16 +1941,16 @@ void CodeGenModule::ConstructAttributeList(      hasUsedSRet = true;      if (RetAI.getInReg())        SRETAttrs.addAttribute(llvm::Attribute::InReg); -    PAL.push_back(llvm::AttributeList::get( -        getLLVMContext(), IRFunctionArgs.getSRetArgNo() + 1, SRETAttrs)); +    ArgAttrs[IRFunctionArgs.getSRetArgNo()] = +        llvm::AttributeSet::get(getLLVMContext(), SRETAttrs);    }    // Attach attributes to inalloca argument.    if (IRFunctionArgs.hasInallocaArg()) {      llvm::AttrBuilder Attrs;      Attrs.addAttribute(llvm::Attribute::InAlloca); -    PAL.push_back(llvm::AttributeList::get( -        getLLVMContext(), IRFunctionArgs.getInallocaArgNo() + 1, Attrs)); +    ArgAttrs[IRFunctionArgs.getInallocaArgNo()] = +        llvm::AttributeSet::get(getLLVMContext(), Attrs);    }    unsigned ArgNo = 0; @@ -1967,10 +1963,12 @@ void CodeGenModule::ConstructAttributeList(      // Add attribute for padding argument, if necessary.      if (IRFunctionArgs.hasPaddingArg(ArgNo)) { -      if (AI.getPaddingInReg()) -        PAL.push_back(llvm::AttributeList::get( -            getLLVMContext(), IRFunctionArgs.getPaddingArgNo(ArgNo) + 1, -            llvm::Attribute::InReg)); +      if (AI.getPaddingInReg()) { +        ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] = +            llvm::AttributeSet::get( +                getLLVMContext(), +                llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg)); +      }      }      // 'restrict' -> 'noalias' is done in EmitFunctionProlog when we @@ -2085,15 +2083,15 @@ void CodeGenModule::ConstructAttributeList(        unsigned FirstIRArg, NumIRArgs;        std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);        for (unsigned i = 0; i < NumIRArgs; i++) -        PAL.push_back(llvm::AttributeList::get(getLLVMContext(), -                                               FirstIRArg + i + 1, Attrs)); +        ArgAttrs[FirstIRArg + i] = +            llvm::AttributeSet::get(getLLVMContext(), Attrs);      }    }    assert(ArgNo == FI.arg_size()); -  if (FuncAttrs.hasAttributes()) -    PAL.push_back(llvm::AttributeList::get( -        getLLVMContext(), llvm::AttributeList::FunctionIndex, FuncAttrs)); +  AttrList = llvm::AttributeList::get( +      getLLVMContext(), llvm::AttributeSet::get(getLLVMContext(), FuncAttrs), +      llvm::AttributeSet::get(getLLVMContext(), RetAttrs), ArgAttrs);  }  /// An argument came in as a promoted argument; demote it back to its @@ -2204,8 +2202,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,    if (IRFunctionArgs.hasSRetArg()) {      auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);      AI->setName("agg.result"); -    AI->addAttr(llvm::AttributeList::get(getLLVMContext(), AI->getArgNo() + 1, -                                         llvm::Attribute::NoAlias)); +    AI->addAttr(llvm::Attribute::NoAlias);    }    // Track if we received the parameter as a pointer (indirect, byval, or @@ -2296,9 +2293,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,          if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {            if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(),                               PVD->getFunctionScopeIndex())) -            AI->addAttr(llvm::AttributeList::get(getLLVMContext(), -                                                 AI->getArgNo() + 1, -                                                 llvm::Attribute::NonNull)); +            AI->addAttr(llvm::Attribute::NonNull);            QualType OTy = PVD->getOriginalType();            if (const auto *ArrTy = @@ -2315,12 +2310,9 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,                  llvm::AttrBuilder Attrs;                  Attrs.addDereferenceableAttr(                    getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize); -                AI->addAttr(llvm::AttributeList::get( -                    getLLVMContext(), AI->getArgNo() + 1, Attrs)); +                AI->addAttrs(Attrs);                } else if (getContext().getTargetAddressSpace(ETy) == 0) { -                AI->addAttr(llvm::AttributeList::get(getLLVMContext(), -                                                     AI->getArgNo() + 1, -                                                     llvm::Attribute::NonNull)); +                AI->addAttr(llvm::Attribute::NonNull);                }              }            } else if (const auto *ArrTy = @@ -2330,34 +2322,26 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,              // we know that it must be nonnull.              if (ArrTy->getSizeModifier() == VariableArrayType::Static &&                  !getContext().getTargetAddressSpace(ArrTy->getElementType())) -              AI->addAttr(llvm::AttributeList::get(getLLVMContext(), -                                                   AI->getArgNo() + 1, -                                                   llvm::Attribute::NonNull)); +              AI->addAttr(llvm::Attribute::NonNull);            }            const auto *AVAttr = PVD->getAttr<AlignValueAttr>();            if (!AVAttr)              if (const auto *TOTy = dyn_cast<TypedefType>(OTy))                AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>(); -          if (AVAttr) {          +          if (AVAttr) {              llvm::Value *AlignmentValue =                EmitScalarExpr(AVAttr->getAlignment());              llvm::ConstantInt *AlignmentCI =                cast<llvm::ConstantInt>(AlignmentValue); -            unsigned Alignment = -              std::min((unsigned) AlignmentCI->getZExtValue(), -                       +llvm::Value::MaximumAlignment); - -            llvm::AttrBuilder Attrs; -            Attrs.addAlignmentAttr(Alignment); -            AI->addAttr(llvm::AttributeList::get(getLLVMContext(), -                                                 AI->getArgNo() + 1, Attrs)); +            unsigned Alignment = std::min((unsigned)AlignmentCI->getZExtValue(), +                                          +llvm::Value::MaximumAlignment); +            AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment));            }          }          if (Arg->getType().isRestrictQualified()) -          AI->addAttr(llvm::AttributeList::get( -              getLLVMContext(), AI->getArgNo() + 1, llvm::Attribute::NoAlias)); +          AI->addAttr(llvm::Attribute::NoAlias);          // LLVM expects swifterror parameters to be used in very restricted          // ways.  Copy the value into a less-restricted temporary. @@ -4113,13 +4097,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,    // Compute the calling convention and attributes.    unsigned CallingConv; -  CodeGen::AttributeListType AttributeList; +  llvm::AttributeList Attrs;    CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo, -                             Callee.getAbstractInfo(), -                             AttributeList, CallingConv, +                             Callee.getAbstractInfo(), Attrs, CallingConv,                               /*AttrOnCallSite=*/true); -  llvm::AttributeList Attrs = -      llvm::AttributeList::get(getLLVMContext(), AttributeList);    // Apply some call-site-specific attributes.    // TODO: work this into building the attribute set. diff --git a/lib/CodeGen/CGCall.h b/lib/CodeGen/CGCall.h index 97221e20c195..7e10407fc31c 100644 --- a/lib/CodeGen/CGCall.h +++ b/lib/CodeGen/CGCall.h @@ -39,7 +39,6 @@ namespace clang {    class VarDecl;  namespace CodeGen { -typedef SmallVector<llvm::AttributeList, 8> AttributeListType;  /// Abstract information about a function or function prototype.  class CGCalleeInfo { diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 818b51543d30..2f6a2b95fb61 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -3466,17 +3466,17 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, llvm::Value *Storage,    // functions there won't be an implicit param at arg1 and    // otherwise it is 'self' or 'this'.    if (isa<ImplicitParamDecl>(VD) && ArgNo && *ArgNo == 1) -    Flags |= llvm::DINode::FlagObjectPointer; -  if (auto *Arg = dyn_cast<llvm::Argument>(Storage)) -    if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() && -        !VD->getType()->isPointerType()) -      Expr.push_back(llvm::dwarf::DW_OP_deref); +  Flags |= llvm::DINode::FlagObjectPointer; +  // Note: Older versions of clang used to emit byval references with an extra +  // DW_OP_deref, because they referenced the IR arg directly instead of +  // referencing an alloca. Newer versions of LLVM don't treat allocas +  // differently from other function arguments when used in a dbg.declare.    auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back()); -    StringRef Name = VD->getName();    if (!Name.empty()) {      if (VD->hasAttr<BlocksAttr>()) { +      // Here, we need an offset *into* the alloca.        CharUnits offset = CharUnits::fromQuantity(32);        Expr.push_back(llvm::dwarf::DW_OP_plus);        // offset of __forwarding field @@ -3488,22 +3488,7 @@ void CGDebugInfo::EmitDeclare(const VarDecl *VD, llvm::Value *Storage,        // offset of x field        offset = CGM.getContext().toCharUnitsFromBits(XOffset);        Expr.push_back(offset.getQuantity()); - -      // Create the descriptor for the variable. -      auto *D = ArgNo -                    ? DBuilder.createParameterVariable(Scope, VD->getName(), -                                                       *ArgNo, Unit, Line, Ty) -                    : DBuilder.createAutoVariable(Scope, VD->getName(), Unit, -                                                  Line, Ty, Align); - -      // Insert an llvm.dbg.declare into the current block. -      DBuilder.insertDeclare( -          Storage, D, DBuilder.createExpression(Expr), -          llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt), -          Builder.GetInsertBlock()); -      return; -    } else if (isa<VariableArrayType>(VD->getType())) -      Expr.push_back(llvm::dwarf::DW_OP_deref); +    }    } else if (const auto *RT = dyn_cast<RecordType>(VD->getType())) {      // If VD is an anonymous union then Storage represents value for      // all union fields. @@ -3606,8 +3591,7 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(            ->getElementOffset(blockInfo.getCapture(VD).getIndex()));    SmallVector<int64_t, 9> addr; -  if (isa<llvm::AllocaInst>(Storage)) -    addr.push_back(llvm::dwarf::DW_OP_deref); +  addr.push_back(llvm::dwarf::DW_OP_deref);    addr.push_back(llvm::dwarf::DW_OP_plus);    addr.push_back(offset.getQuantity());    if (isByRef) { @@ -3633,12 +3617,11 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(    // Insert an llvm.dbg.declare into the current block.    auto DL =        llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt); +  auto *Expr = DBuilder.createExpression(addr);    if (InsertPoint) -    DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL, -                           InsertPoint); +    DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);    else -    DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL, -                           Builder.GetInsertBlock()); +    DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());  }  void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI, diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 0f959043a22e..10a0b46d9028 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -924,7 +924,7 @@ llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,      return nullptr;    llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size); -  Addr = Builder.CreateBitCast(Addr, Int8PtrTy); +  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);    llvm::CallInst *C =        Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});    C->setDoesNotThrow(); @@ -932,7 +932,7 @@ llvm::Value *CodeGenFunction::EmitLifetimeStart(uint64_t Size,  }  void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) { -  Addr = Builder.CreateBitCast(Addr, Int8PtrTy); +  Addr = Builder.CreateBitCast(Addr, AllocaInt8PtrTy);    llvm::CallInst *C =        Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});    C->setDoesNotThrow(); @@ -1728,7 +1728,7 @@ llvm::Constant *CodeGenModule::getLLVMLifetimeStartFn() {    if (LifetimeStartFn)      return LifetimeStartFn;    LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(), -    llvm::Intrinsic::lifetime_start, Int8PtrTy); +    llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy);    return LifetimeStartFn;  } @@ -1737,7 +1737,7 @@ llvm::Constant *CodeGenModule::getLLVMLifetimeEndFn() {    if (LifetimeEndFn)      return LifetimeEndFn;    LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(), -    llvm::Intrinsic::lifetime_end, Int8PtrTy); +    llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy);    return LifetimeEndFn;  } diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 265ef27a46b0..719147a58e08 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -533,6 +533,15 @@ bool CodeGenFunction::sanitizePerformTypeCheck() const {           SanOpts.has(SanitizerKind::Vptr);  } +/// Check if a runtime null check for \p Ptr can be omitted. +static bool canOmitPointerNullCheck(llvm::Value *Ptr) { +  // Note: do not perform any constant-folding in this function. That is best +  // left to the IR builder. + +  // Pointers to alloca'd memory are non-null. +  return isa<llvm::AllocaInst>(Ptr->stripPointerCastsNoFollowAliases()); +} +  void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,                                      llvm::Value *Ptr, QualType Ty,                                      CharUnits Alignment, @@ -554,19 +563,28 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,    bool AllowNullPointers = TCK == TCK_DowncastPointer || TCK == TCK_Upcast ||                             TCK == TCK_UpcastToVirtualBase;    if ((SanOpts.has(SanitizerKind::Null) || AllowNullPointers) && -      !SkippedChecks.has(SanitizerKind::Null)) { +      !SkippedChecks.has(SanitizerKind::Null) && +      !canOmitPointerNullCheck(Ptr)) {      // The glvalue must not be an empty glvalue.      llvm::Value *IsNonNull = Builder.CreateIsNotNull(Ptr); -    if (AllowNullPointers) { -      // When performing pointer casts, it's OK if the value is null. -      // Skip the remaining checks in that case. -      Done = createBasicBlock("null"); -      llvm::BasicBlock *Rest = createBasicBlock("not.null"); -      Builder.CreateCondBr(IsNonNull, Rest, Done); -      EmitBlock(Rest); -    } else { -      Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null)); +    // The IR builder can constant-fold the null check if the pointer points to +    // a constant. +    bool PtrIsNonNull = +        IsNonNull == llvm::ConstantInt::getTrue(getLLVMContext()); + +    // Skip the null check if the pointer is known to be non-null. +    if (!PtrIsNonNull) { +      if (AllowNullPointers) { +        // When performing pointer casts, it's OK if the value is null. +        // Skip the remaining checks in that case. +        Done = createBasicBlock("null"); +        llvm::BasicBlock *Rest = createBasicBlock("not.null"); +        Builder.CreateCondBr(IsNonNull, Rest, Done); +        EmitBlock(Rest); +      } else { +        Checks.push_back(std::make_pair(IsNonNull, SanitizerKind::Null)); +      }      }    } diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 3db15c646f43..53c184130709 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -201,7 +201,7 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,        unsigned NewFieldWidth = FieldSize - BitsInPreviousByte;        if (CGM.getDataLayout().isBigEndian()) { -        Tmp = Tmp.lshr(NewFieldWidth); +        Tmp.lshrInPlace(NewFieldWidth);          Tmp = Tmp.trunc(BitsInPreviousByte);          // We want the remaining high bits. @@ -210,7 +210,7 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,          Tmp = Tmp.trunc(BitsInPreviousByte);          // We want the remaining low bits. -        FieldValue = FieldValue.lshr(BitsInPreviousByte); +        FieldValue.lshrInPlace(BitsInPreviousByte);          FieldValue = FieldValue.trunc(NewFieldWidth);        }      } @@ -273,7 +273,7 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,        // We want the low bits.        Tmp = FieldValue.trunc(CharWidth); -      FieldValue = FieldValue.lshr(CharWidth); +      FieldValue.lshrInPlace(CharWidth);      }      Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp)); diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 3a09a15dbc15..76e7df861f74 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -126,10 +126,12 @@ llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,      QualType IdTy(CGM.getContext().getObjCIdType());      llvm::Constant *Constant =          CGM.CreateRuntimeVariable(ConvertType(IdTy), ConstantName); -    Address Addr(Constant, Context.getTypeAlignInChars(IdTy)); -    LValue LV = MakeAddrLValue(Addr, IdTy); -    return Builder.CreateBitCast(EmitLoadOfScalar(LV, E->getLocStart()), -                                 ConvertType(E->getType())); +    LValue LV = MakeNaturalAlignAddrLValue(Constant, IdTy); +    llvm::Value *Ptr = EmitLoadOfScalar(LV, E->getLocStart()); +    cast<llvm::LoadInst>(Ptr)->setMetadata( +        CGM.getModule().getMDKindID("invariant.load"), +        llvm::MDNode::get(getLLVMContext(), None)); +    return Builder.CreateBitCast(Ptr, ConvertType(E->getType()));    }    // Compute the type of the array we're initializing. @@ -1848,12 +1850,8 @@ static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,        F->addFnAttr(llvm::Attribute::NonLazyBind);      } -    if (IsForwarding(Name)) { -      llvm::AttrBuilder B; -      B.addAttribute(llvm::Attribute::Returned); - -      F->arg_begin()->addAttr(llvm::AttributeList::get(F->getContext(), 1, B)); -    } +    if (IsForwarding(Name)) +      F->arg_begin()->addAttr(llvm::Attribute::Returned);    }    return RTF; diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 0ebfd99363c1..683f366ebe45 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -1166,7 +1166,7 @@ void CodeGenFunction::EmitCaseStmtRange(const CaseStmt &S) {        if (Rem)          Rem--;        SwitchInsn->addCase(Builder.getInt(LHS), CaseDest); -      LHS++; +      ++LHS;      }      return;    } diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 7b0c8bf7d6e9..1869c0e809df 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -379,12 +379,9 @@ void CodeGenFunction::EmitMustTailThunk(const CXXMethodDecl *MD,    // Apply the standard set of call attributes.    unsigned CallingConv; -  CodeGen::AttributeListType AttributeList; -  CGM.ConstructAttributeList(CalleePtr->getName(), -                             *CurFnInfo, MD, AttributeList, +  llvm::AttributeList Attrs; +  CGM.ConstructAttributeList(CalleePtr->getName(), *CurFnInfo, MD, Attrs,                               CallingConv, /*AttrOnCallSite=*/true); -  llvm::AttributeList Attrs = -      llvm::AttributeList::get(getLLVMContext(), AttributeList);    Call->setAttributes(Attrs);    Call->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv)); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index d48bff9c30a3..19203973ff1b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -111,6 +111,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO,      C.getTargetInfo().getMaxPointerWidth());    Int8PtrTy = Int8Ty->getPointerTo(0);    Int8PtrPtrTy = Int8PtrTy->getPointerTo(0); +  AllocaInt8PtrTy = Int8Ty->getPointerTo( +      M.getDataLayout().getAllocaAddrSpace());    RuntimeCC = getTargetCodeGenInfo().getABIInfo().getRuntimeCC();    BuiltinCC = getTargetCodeGenInfo().getABIInfo().getBuiltinCC(); @@ -839,10 +841,9 @@ void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D,                                                const CGFunctionInfo &Info,                                                llvm::Function *F) {    unsigned CallingConv; -  AttributeListType AttributeList; -  ConstructAttributeList(F->getName(), Info, D, AttributeList, CallingConv, -                         false); -  F->setAttributes(llvm::AttributeList::get(getLLVMContext(), AttributeList)); +  llvm::AttributeList PAL; +  ConstructAttributeList(F->getName(), Info, D, PAL, CallingConv, false); +  F->setAttributes(PAL);    F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));  } @@ -3793,6 +3794,10 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {      AddDeferredUnusedCoverageMapping(D);      break; +  case Decl::CXXDeductionGuide: +    // Function-like, but does not result in code emission. +    break; +    case Decl::Var:    case Decl::Decomposition:      // Skip variable templates diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index d0b2dd717c8c..c4985ba41db1 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -1020,11 +1020,12 @@ public:    /// \param CalleeInfo - The callee information these attributes are being    /// constructed for. If valid, the attributes applied to this decl may    /// contribute to the function attributes and calling convention. -  /// \param PAL [out] - On return, the attribute list to use. +  /// \param Attrs [out] - On return, the attribute list to use.    /// \param CallingConv [out] - On return, the LLVM calling convention to use.    void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, -                              CGCalleeInfo CalleeInfo, AttributeListType &PAL, -                              unsigned &CallingConv, bool AttrOnCallSite); +                              CGCalleeInfo CalleeInfo, +                              llvm::AttributeList &Attrs, unsigned &CallingConv, +                              bool AttrOnCallSite);    /// Adds attributes to F according to our CodeGenOptions and LangOptions, as    /// though we had emitted it ourselves.  We remove any attributes on F that diff --git a/lib/CodeGen/CodeGenTypeCache.h b/lib/CodeGen/CodeGenTypeCache.h index 47e26bcaa1b6..8ce9860cc638 100644 --- a/lib/CodeGen/CodeGenTypeCache.h +++ b/lib/CodeGen/CodeGenTypeCache.h @@ -60,6 +60,12 @@ struct CodeGenTypeCache {      llvm::PointerType *Int8PtrPtrTy;    }; +  /// void* in alloca address space +  union { +    llvm::PointerType *AllocaVoidPtrTy; +    llvm::PointerType *AllocaInt8PtrTy; +  }; +    /// The size and alignment of the builtin C type 'int'.  This comes    /// up enough in various ABI lowering tasks to be worth pre-computing.    union { diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp index 89090c8b6a1b..fc642850d60a 100644 --- a/lib/CodeGen/ModuleBuilder.cpp +++ b/lib/CodeGen/ModuleBuilder.cpp @@ -197,7 +197,7 @@ namespace {        // Provide some coverage mapping even for methods that aren't emitted.        // Don't do this for templated classes though, as they may not be        // instantiable. -      if (!MD->getParent()->getDescribedClassTemplate()) +      if (!MD->getParent()->isDependentContext())          Builder->AddDeferredUnusedCoverageMapping(MD);      }  | 
