1. Aug 07, 2022
    • Fangrui Song's avatar
      [ADT] Fix signature of StringSet::insert · bf5550b6
      Fangrui Song authored
      to match StringMap and unordered_set.
      bf5550b6
    • Shilei Tian's avatar
      [Clang][OpenMP] Fix the issue that `llvm.lifetime.end` is emitted too early... · e21202da
      Shilei Tian authored
      [Clang][OpenMP] Fix the issue that `llvm.lifetime.end` is emitted too early for variables captured in linear clause
      
      Currently if an OpenMP program uses `linear` clause, and is compiled with
      optimization, `llvm.lifetime.end` for variables listed in `linear` clause are
      emitted too early such that there could still be uses after that. Let's take the
      following code as example:
      ```
      // loop.c
      int j;
      int *u;
      
      void loop(int n) {
        int i;
        for (i = 0; i < n; ++i) {
          ++j;
          u = &j;
        }
      }
      ```
      We compile using the command:
      ```
      clang -cc1 -fopenmp-simd -O3 -x c -triple x86_64-apple-darwin10 -emit-llvm loop.c -o loop.ll
      ```
      The following IR (simplified) will be generated:
      ```
      @j = local_unnamed_addr global i32 0, align 4
      @u = local_unnamed_addr global ptr null, align 8
      
      define void @loop(i32 noundef %n) local_unnamed_addr {
      entry:
        %j = alloca i32, align 4
        %cmp = icmp sgt i32 %n, 0
        br i1 %cmp, label %simd.if.then, label %simd.if.end
      
      simd.if.then:                                     ; preds = %entry
        call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %j)
        store ptr %j, ptr @u, align 8
        call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
        %0 = load i32, ptr %j, align 4
        store i32 %0, ptr @j, align 4
        br label %simd.if.end
      
      simd.if.end:                                      ; preds = %simd.if.then, %entry
        ret void
      }
      ```
      The most important part is:
      ```
        call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
        %0 = load i32, ptr %j, align 4
        store i32 %0, ptr @j, align 4
      ```
      `%j` is still loaded after `@llvm.lifetime.end.p0(i64 4, ptr nonnull %j)`. This
      could cause the backend incorrectly optimizes the code and further generates
      incorrect code. The root cause is, when we emit a construct that could have
      `linear` clause, it usually has the following pattern:
      ```
      EmitOMPLinearClauseInit(S)
      {
        OMPPrivateScope LoopScope(*this);
        ...
        EmitOMPLinearClause(S, LoopScope);
        ...
        (void)LoopScope.Privatize();
        ...
      }
      EmitOMPLinearClauseFinal(S, [](CodeGenFunction &) { return nullptr; });
      ```
      Variables that need to be privatized are added into `LoopScope`, which also
      serves as a RAII object. When `LoopScope` is destructed and if optimization is
      enabled, a `@llvm.lifetime.end` is also emitted for each privatized variable.
      However, the writing back to original variables in `linear` clause happens after
      the scope in `EmitOMPLinearClauseFinal`, causing the issue we see above.
      
      A quick "fix" seems to be, moving `EmitOMPLinearClauseFinal` inside the scope.
      However, it doesn't work. That's because the local variable map has been updated
      by `LoopScope` such that a variable declaration is mapped to the privatized
      variable, instead of the actual one. In that way, the following code will be
      generated:
      ```
        %0 = load i32, ptr %j, align 4
        store i32 %0, ptr %j, align 4
        call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
      ```
      Well, now the life time is correct, but apparently the writing back is broken.
      
      In this patch, a new function `OMPPrivateScope::restoreMap` is added and called
      before calling `EmitOMPLinearClauseFinal`. This can make sure that
      `EmitOMPLinearClauseFinal` can find the orignal varaibls to write back.
      
      Fixes #56913.
      
      Reviewed By: ABataev
      
      Differential Revision: https://reviews.llvm.org/D131272
      e21202da
    • Tom Stellard's avatar
      lld/cmake: Drop use of llvm-config for LLVM install discovery · 91f3f0bf
      Tom Stellard authored
      This has been deprecated since D116492 earlier in 2022.
      
      That seems recent, but with the recent cut of LLVM 15 that is still two releases (14 and 15). Meanwhile Clang has deprecated `llvm-config` for a lot longer, and since it is likely that LLD users are also Clang users, this serves as an extra "heads up" that `llvm-config` is on its way out.
      
      Remove it in favor of using CMake's find_package() function.
      
      Reviewed By: MaskRay, mgorny
      
      Differential Revision: https://reviews.llvm.org/D131144
      91f3f0bf
    • Tom Stellard's avatar
      clang/cmake: Drop use of llvm-config for LLVM install discovery · d2b158e2
      Tom Stellard authored
      This has been deprecated for a while, since D51714 in 2018.
      
      Remove it in favor of using CMake's find_package() function.
      
      Reviewed By: phosek, mgorny
      
      Differential Revision: https://reviews.llvm.org/D128777
      d2b158e2
    • Benjamin Kramer's avatar
      [bazel] Switch to C++17 · 2d2ad02f
      Benjamin Kramer authored
      LLVM switched to C++17 in b1356504
      2d2ad02f
    • Aarush Bhat's avatar
      clang: fix typo availbility · a6cb8419
      Aarush Bhat authored
      - Fixes [[ https://github.com/llvm/llvm-project/issues/56787 | #56787 ]].
      
      I am fixing the spelling of availability.
      
      I am unsure if this change will have any side effects. If someone can
      help on how to check if it has any side effects, I can test those out as
      well.
      
      Reviewed By: inclyc
      
      Differential Revision: https://reviews.llvm.org/D131277
      a6cb8419
    • Krzysztof Parzyszek's avatar
      [RDF] Use default TargetOperandInfo if not given in constructor · 2bc390bd
      Krzysztof Parzyszek authored
      All current in-tree users use the default implementation.
      2bc390bd
    • Thorsten Schütt's avatar
      0c925861
    • Krzysztof Parzyszek's avatar
      [RDF] Remove explicit template arguments from Print · ede96de7
      Krzysztof Parzyszek authored
      CTAD takes care of it.
      ede96de7
    • Kazu Hirata's avatar
      Use value instead of getValue (NFC) · c8e6ebd7
      Kazu Hirata authored
      c8e6ebd7
    • Kazu Hirata's avatar
      9750648c
  2. Aug 06, 2022