Skip to content

Commit 2fe0875

Browse files
committed
Merge from 'main' to 'sycl-web' (54 commits)
CONFLICT (content): Merge conflict in clang/include/clang/Basic/CodeGenOptions.def
2 parents c1f63b2 + 845cc96 commit 2fe0875

File tree

191 files changed

+10662
-6248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+10662
-6248
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ NVPTX Support
152152
X86 Support
153153
^^^^^^^^^^^
154154

155+
- Disable ``-m[no-]avx10.1`` and switch ``-m[no-]avx10.2`` to alias of 512 bit
156+
options.
157+
- Change ``-mno-avx10.1-512`` to alias of ``-mno-avx10.1-256`` to disable both
158+
256 and 512 bit instructions.
159+
155160
Arm and AArch64 Support
156161
^^^^^^^^^^^^^^^^^^^^^^^
157162

clang/docs/TypeSanitizer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ enough for TypeSanitizer's runtime.
202202

203203
We are actively working on enhancing the tool --- stay tuned. Any help,
204204
issues, pull requests, ideas, is more than welcome. You can find the
205-
`issue tracker here.<https://github.com/llvm/llvm-project/issues?q=is%3Aissue%20state%3Aopen%20TySan%20label%3Acompiler-rt%3Atysan>`
205+
`issue tracker here. <https://github.com/llvm/llvm-project/issues?q=is%3Aissue%20state%3Aopen%20TySan%20label%3Acompiler-rt%3Atysan>`_

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ CODEGENOPT(OptimizeSYCLFramework, 1, 0)
482482
/// operations and no fp64 computation operations (requires Intel GPU backend
483483
/// supporting fp64 partial emulation)
484484
CODEGENOPT(FP64ConvEmu, 1, 0)
485+
486+
/// Enables emitting Import Call sections on supported targets that can be used
487+
/// by the Windows kernel to enable import call optimization.
488+
CODEGENOPT(ImportCallOptimization, 1, 0)
489+
485490
/// FIXME: Make DebugOptions its own top-level .def file.
486491
#include "DebugOptions.def"
487492

clang/include/clang/Basic/Sanitizers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ class SanitizerMaskCutoffs {
162162

163163
void set(SanitizerMask K, double V);
164164
void clear(SanitizerMask K = SanitizerKind::All);
165+
166+
// Returns nullopt if all the values are zero.
167+
// Otherwise, return value contains a vector of all the scaled values.
168+
std::optional<std::vector<unsigned>>
169+
getAllScaled(unsigned ScalingFactor) const;
165170
};
166171

167172
struct SanitizerSet {

clang/include/clang/Driver/Options.td

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6459,15 +6459,13 @@ def mno_avx : Flag<["-"], "mno-avx">, Group<m_x86_Features_Group>;
64596459
def mavx10_1_256 : Flag<["-"], "mavx10.1-256">, Group<m_x86_AVX10_Features_Group>;
64606460
def mno_avx10_1_256 : Flag<["-"], "mno-avx10.1-256">, Group<m_x86_AVX10_Features_Group>;
64616461
def mavx10_1_512 : Flag<["-"], "mavx10.1-512">, Group<m_x86_AVX10_Features_Group>;
6462-
def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, Group<m_x86_AVX10_Features_Group>;
6463-
def mavx10_1 : Flag<["-"], "mavx10.1">, Alias<mavx10_1_256>;
6464-
def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Alias<mno_avx10_1_256>;
6462+
def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, Alias<mno_avx10_1_256>;
6463+
def mavx10_1 : Flag<["-"], "mavx10.1">, Flags<[Unsupported]>;
6464+
def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Flags<[Unsupported]>;
64656465
def mavx10_2_256 : Flag<["-"], "mavx10.2-256">, Group<m_x86_AVX10_Features_Group>;
6466-
def mno_avx10_2_256 : Flag<["-"], "mno-avx10.2-256">, Group<m_x86_AVX10_Features_Group>;
64676466
def mavx10_2_512 : Flag<["-"], "mavx10.2-512">, Group<m_x86_AVX10_Features_Group>;
6468-
def mno_avx10_2_512 : Flag<["-"], "mno-avx10.2-512">, Group<m_x86_AVX10_Features_Group>;
6469-
def mavx10_2 : Flag<["-"], "mavx10.2">, Alias<mavx10_2_256>;
6470-
def mno_avx10_2 : Flag<["-"], "mno-avx10.2">, Alias<mno_avx10_2_256>;
6467+
def mavx10_2 : Flag<["-"], "mavx10.2">, Alias<mavx10_2_512>;
6468+
def mno_avx10_2 : Flag<["-"], "mno-avx10.2">, Group<m_x86_AVX10_Features_Group>;
64716469
def mavx2 : Flag<["-"], "mavx2">, Group<m_x86_Features_Group>;
64726470
def mno_avx2 : Flag<["-"], "mno-avx2">, Group<m_x86_Features_Group>;
64736471
def mavx512f : Flag<["-"], "mavx512f">, Group<m_x86_Features_Group>;
@@ -7985,6 +7983,11 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], "fexperimental-assignme
79857983
def enable_tlsdesc : Flag<["-"], "enable-tlsdesc">,
79867984
MarshallingInfoFlag<CodeGenOpts<"EnableTLSDESC">>;
79877985

7986+
def import_call_optimization : Flag<["-"], "import-call-optimization">,
7987+
HelpText<"Emit Import Call sections on supported targets that can be used "
7988+
"by the Windows kernel to enable import call optimization">,
7989+
MarshallingInfoFlag<CodeGenOpts<"ImportCallOptimization">>;
7990+
79887991
} // let Visibility = [CC1Option]
79897992

79907993
//===----------------------------------------------------------------------===//

clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using ast_matchers::callee;
1414
using ast_matchers::cxxMemberCallExpr;
1515
using ast_matchers::cxxMethodDecl;
1616
using ast_matchers::cxxOperatorCallExpr;
17+
using ast_matchers::hasCanonicalType;
1718
using ast_matchers::hasName;
1819
using ast_matchers::hasOverloadedOperatorName;
1920
using ast_matchers::ofClass;
@@ -122,27 +123,29 @@ namespace clang::dataflow {
122123
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar() {
123124
return cxxOperatorCallExpr(
124125
hasOverloadedOperatorName("*"),
125-
callee(cxxMethodDecl(parameterCountIs(0), returns(referenceType()),
126+
callee(cxxMethodDecl(parameterCountIs(0),
127+
returns(hasCanonicalType(referenceType())),
126128
ofClass(smartPointerClassWithGetOrValue()))));
127129
}
128130

129131
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow() {
130132
return cxxOperatorCallExpr(
131133
hasOverloadedOperatorName("->"),
132-
callee(cxxMethodDecl(parameterCountIs(0), returns(pointerType()),
134+
callee(cxxMethodDecl(parameterCountIs(0),
135+
returns(hasCanonicalType(pointerType())),
133136
ofClass(smartPointerClassWithGetOrValue()))));
134137
}
135138

136139
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall() {
137-
return cxxMemberCallExpr(callee(
138-
cxxMethodDecl(parameterCountIs(0), returns(referenceType()),
139-
hasName("value"), ofClass(smartPointerClassWithValue()))));
140+
return cxxMemberCallExpr(callee(cxxMethodDecl(
141+
parameterCountIs(0), returns(hasCanonicalType(referenceType())),
142+
hasName("value"), ofClass(smartPointerClassWithValue()))));
140143
}
141144

142145
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall() {
143-
return cxxMemberCallExpr(callee(
144-
cxxMethodDecl(parameterCountIs(0), returns(pointerType()), hasName("get"),
145-
ofClass(smartPointerClassWithGet()))));
146+
return cxxMemberCallExpr(callee(cxxMethodDecl(
147+
parameterCountIs(0), returns(hasCanonicalType(pointerType())),
148+
hasName("get"), ofClass(smartPointerClassWithGet()))));
146149
}
147150

148151
const FunctionDecl *

clang/lib/Basic/Sanitizers.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/Support/MathExtras.h"
1919
#include "llvm/Support/raw_ostream.h"
2020
#include <algorithm>
21+
#include <cmath>
2122
#include <optional>
2223

2324
using namespace clang;
@@ -43,6 +44,27 @@ std::optional<double> SanitizerMaskCutoffs::operator[](unsigned Kind) const {
4344

4445
void SanitizerMaskCutoffs::clear(SanitizerMask K) { set(K, 0); }
4546

47+
std::optional<std::vector<unsigned>>
48+
SanitizerMaskCutoffs::getAllScaled(unsigned ScalingFactor) const {
49+
std::vector<unsigned> ScaledCutoffs;
50+
51+
bool AnyCutoff = false;
52+
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
53+
auto C = (*this)[i];
54+
if (C.has_value()) {
55+
ScaledCutoffs.push_back(lround(std::clamp(*C, 0.0, 1.0) * ScalingFactor));
56+
AnyCutoff = true;
57+
} else {
58+
ScaledCutoffs.push_back(0);
59+
}
60+
}
61+
62+
if (AnyCutoff)
63+
return ScaledCutoffs;
64+
65+
return std::nullopt;
66+
}
67+
4668
// Once LLVM switches to C++17, the constexpr variables can be inline and we
4769
// won't need this.
4870
#define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,23 @@ static void addSanitizers(const Triple &TargetTriple,
837837
PB.registerOptimizerLastEPCallback(SanitizersCallback);
838838
}
839839

840-
if (LowerAllowCheckPass::IsRequested()) {
840+
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
841+
// Opts.cutoffs: unsigned ints with range [0, 1000000]
842+
auto ScaledCutoffs = CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
843+
844+
// TODO: remove IsRequested()
845+
if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) {
841846
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
842-
PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
843-
OptimizationLevel Level,
844-
ThinOrFullLTOPhase Phase) {
845-
LowerAllowCheckPass::Options Opts;
846-
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
847-
});
847+
PB.registerOptimizerEarlyEPCallback(
848+
[ScaledCutoffs](ModulePassManager &MPM, OptimizationLevel Level,
849+
ThinOrFullLTOPhase Phase) {
850+
LowerAllowCheckPass::Options Opts;
851+
// TODO: after removing IsRequested(), make this unconditional
852+
if (ScaledCutoffs.has_value())
853+
Opts.cutoffs = ScaledCutoffs.value();
854+
MPM.addPass(
855+
createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
856+
});
848857
}
849858
}
850859

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,29 +3623,33 @@ void CodeGenFunction::EmitCheck(
36233623
llvm::Value *RecoverableCond = nullptr;
36243624
llvm::Value *TrapCond = nullptr;
36253625
bool NoMerge = false;
3626+
// Expand checks into:
3627+
// (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ...
3628+
// We need separate allow_ubsan_check intrinsics because they have separately
3629+
// specified cutoffs.
3630+
// This expression looks expensive but will be simplified after
3631+
// LowerAllowCheckPass.
36263632
for (auto &[Check, Ord] : Checked) {
3633+
llvm::Value *GuardedCheck = Check;
3634+
if (ClSanitizeGuardChecks ||
3635+
(CGM.getCodeGenOpts().SanitizeSkipHotCutoffs[Ord] > 0)) {
3636+
llvm::Value *Allow = Builder.CreateCall(
3637+
CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
3638+
llvm::ConstantInt::get(CGM.Int8Ty, Ord));
3639+
GuardedCheck = Builder.CreateOr(Check, Builder.CreateNot(Allow));
3640+
}
3641+
36273642
// -fsanitize-trap= overrides -fsanitize-recover=.
36283643
llvm::Value *&Cond = CGM.getCodeGenOpts().SanitizeTrap.has(Ord) ? TrapCond
36293644
: CGM.getCodeGenOpts().SanitizeRecover.has(Ord)
36303645
? RecoverableCond
36313646
: FatalCond;
3632-
Cond = Cond ? Builder.CreateAnd(Cond, Check) : Check;
3647+
Cond = Cond ? Builder.CreateAnd(Cond, GuardedCheck) : GuardedCheck;
36333648

36343649
if (!CGM.getCodeGenOpts().SanitizeMergeHandlers.has(Ord))
36353650
NoMerge = true;
36363651
}
36373652

3638-
if (ClSanitizeGuardChecks) {
3639-
llvm::Value *Allow =
3640-
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
3641-
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandler));
3642-
3643-
for (llvm::Value **Cond : {&FatalCond, &RecoverableCond, &TrapCond}) {
3644-
if (*Cond)
3645-
*Cond = Builder.CreateOr(*Cond, Builder.CreateNot(Allow));
3646-
}
3647-
}
3648-
36493653
if (TrapCond)
36503654
EmitTrapCheck(TrapCond, CheckHandler, NoMerge);
36513655
if (!FatalCond && !RecoverableCond)

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,11 @@ void CodeGenModule::Release() {
13571357
if (LangOpts.EHAsynch)
13581358
getModule().addModuleFlag(llvm::Module::Warning, "eh-asynch", 1);
13591359

1360+
// Emit Import Call section.
1361+
if (CodeGenOpts.ImportCallOptimization)
1362+
getModule().addModuleFlag(llvm::Module::Warning, "import-call-optimization",
1363+
1);
1364+
13601365
// Indicate whether this Module was compiled with -fopenmp
13611366
if (getLangOpts().OpenMP && !getLangOpts().OpenMPSimd)
13621367
getModule().addModuleFlag(llvm::Module::Max, "openmp", LangOpts.OpenMP);

0 commit comments

Comments
 (0)