Skip to content

Commit 49a8c50

Browse files
authored
Merge branch 'main' into fabrice/missing-llvm-abi-annotations
2 parents 18627f7 + 6125f26 commit 49a8c50

File tree

265 files changed

+4027
-1397
lines changed

Some content is hidden

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

265 files changed

+4027
-1397
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
applyTo: lldb/**/*
3+
---
4+
5+
When reviewing code, focus on:
6+
7+
## Language, Libraries & Standards
8+
9+
- Target C++17 and avoid vendor-specific extensions.
10+
- For Python scripts, follow PEP 8.
11+
- Prefer standard library or LLVM support libraries instead of reinventing data structures.
12+
13+
## Comments & Documentation
14+
15+
- Each source file should include the standard LLVM file header.
16+
- Header files must have proper header guards.
17+
- Non-trivial classes and public methods should have Doxygen documentation.
18+
- Use `//` or `///` comments normally; avoid block comments unless necessary.
19+
- Non-trivial code should have comments explaining what it does and why. Avoid comments that explain how it does it at a micro level.
20+
21+
## Language & Compiler Issues
22+
23+
- Write portable code; wrap non-portable code in interfaces.
24+
- Do not use RTTI or exceptions.
25+
- Prefer C++-style casts over C-style casts.
26+
- Do not use static constructors.
27+
- Use `class` or `struct` consistently; `struct` only for all-public data.
28+
- When then same class is declared or defined multiple times, make sure it's consistently done using either `class` or `struct`.
29+
30+
## Headers & Library Layering
31+
32+
- Include order: module header → local/private headers → project headers → system headers.
33+
- Headers must compile standalone (include all dependencies).
34+
- Maintain proper library layering; avoid circular dependencies.
35+
- Include minimally; use forward declarations where possible.
36+
- Keep internal headers private to modules.
37+
- Use full namespace qualifiers for out-of-line definitions.
38+
39+
## Control Flow & Structure
40+
41+
- Prefer early exits over deep nesting.
42+
- Do not use `else` after `return`, `continue`, `break`, or `goto`.
43+
- Encapsulate loops that compute predicates into helper functions.
44+
45+
## Naming
46+
47+
- LLDB's code style differs from LLVM's coding style.
48+
- Variables are `snake_case`.
49+
- Functions and methods are `UpperCamelCase`.
50+
- Static, global and member variables have `s_`, `g_` and `m_` prefixes respectively.
51+
52+
## General Guidelines
53+
54+
- Use `assert` liberally; prefer `llvm_unreachable` for unreachable states.
55+
- Do not use `using namespace std;` in headers.
56+
- Provide a virtual method anchor for classes defined in headers.
57+
- Do not use default labels in fully covered switches over enumerations.
58+
- Use range-based for loops wherever possible.
59+
- Capture `end()` outside loops if not using range-based iteration.
60+
- Including `<iostream>` is forbidded. Use LLVM’s `raw_ostream` instead.
61+
- Don’t use `inline` when defining a function in a class definition.
62+
63+
## Microscopic Details
64+
65+
- Preserve existing style in modified code.
66+
- Prefer pre-increment (`++i`) when value is unused.
67+
- Use `private`, `protected`, or `public` keyword as appropriate to restrict class member visibility.
68+
- Omit braces for single-statement `if`, `else`, `while`, `for` unless needed.
69+
70+
## Review Style
71+
72+
- Be specific and actionable in feedback.
73+
- Explain the "why" behind recommendations.
74+
- Link back to the LLVM Coding Standards: https://llvm.org/docs/CodingStandards.html.
75+
- Ask clarifying questions when code intent is unclear.
76+
77+
Ignore formatting and assume that's handled by external tools like `clang-format` and `black`.
78+
Remember that these standards are **guidelines**.
79+
Always prioritize consistency with the style that is already being used by the surrounding code.

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,16 @@ class BinaryContext {
932932
std::pair<const MCSymbol *, uint64_t>
933933
handleAddressRef(uint64_t Address, BinaryFunction &BF, bool IsPCRel);
934934

935+
/// When \p Address inside function \p BF is a target of a control transfer
936+
/// instruction (branch) from another function, return a corresponding symbol
937+
/// that should be used by the branch. For example, main or secondary entry
938+
/// point.
939+
///
940+
/// If \p Address is an invalid destination, such as a constant island, return
941+
/// nullptr and mark \p BF as ignored, since we cannot properly handle a
942+
/// branch to a constant island.
943+
MCSymbol *handleExternalBranchTarget(uint64_t Address, BinaryFunction &BF);
944+
935945
/// Analyze memory contents at the given \p Address and return the type of
936946
/// memory contents (such as a possible jump table).
937947
MemoryContentsType analyzeMemoryAt(uint64_t Address, BinaryFunction &BF);

bolt/lib/Core/BinaryContext.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,23 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
518518
return std::make_pair(TargetSymbol, 0);
519519
}
520520

521+
MCSymbol *BinaryContext::handleExternalBranchTarget(uint64_t Address,
522+
BinaryFunction &BF) {
523+
if (BF.isInConstantIsland(Address)) {
524+
BF.setIgnored();
525+
this->outs() << "BOLT-WARNING: ignoring entry point at address 0x"
526+
<< Twine::utohexstr(Address)
527+
<< " in constant island of function " << BF << '\n';
528+
return nullptr;
529+
}
530+
531+
const uint64_t Offset = Address - BF.getAddress();
532+
assert(Offset < BF.getSize() &&
533+
"Address should be inside the referenced function");
534+
535+
return Offset ? BF.addEntryPointAtOffset(Offset) : BF.getSymbol();
536+
}
537+
521538
MemoryContentsType BinaryContext::analyzeMemoryAt(uint64_t Address,
522539
BinaryFunction &BF) {
523540
if (!isX86())
@@ -1399,17 +1416,10 @@ void BinaryContext::processInterproceduralReferences() {
13991416
<< Function.getPrintName() << " and "
14001417
<< TargetFunction->getPrintName() << '\n';
14011418
}
1402-
if (uint64_t Offset = Address - TargetFunction->getAddress()) {
1403-
if (!TargetFunction->isInConstantIsland(Address)) {
1404-
TargetFunction->addEntryPointAtOffset(Offset);
1405-
} else {
1406-
TargetFunction->setIgnored();
1407-
this->outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
1408-
<< Twine::utohexstr(Address)
1409-
<< " in constant island of function " << *TargetFunction
1410-
<< '\n';
1411-
}
1412-
}
1419+
1420+
// Create an extra entry point if needed. Can also render the target
1421+
// function ignored if the reference is invalid.
1422+
handleExternalBranchTarget(Address, *TargetFunction);
14131423

14141424
continue;
14151425
}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,21 +1697,12 @@ bool BinaryFunction::scanExternalRefs() {
16971697
if (!TargetFunction || ignoreFunctionRef(*TargetFunction))
16981698
continue;
16991699

1700-
const uint64_t FunctionOffset =
1701-
TargetAddress - TargetFunction->getAddress();
1702-
if (!TargetFunction->isInConstantIsland(TargetAddress)) {
1703-
BranchTargetSymbol =
1704-
FunctionOffset
1705-
? TargetFunction->addEntryPointAtOffset(FunctionOffset)
1706-
: TargetFunction->getSymbol();
1707-
} else {
1708-
TargetFunction->setIgnored();
1709-
BC.outs() << "BOLT-WARNING: Ignoring entry point at address 0x"
1710-
<< Twine::utohexstr(Address)
1711-
<< " in constant island of function " << *TargetFunction
1712-
<< '\n';
1700+
// Get a reference symbol for the function when address is a valid code
1701+
// reference.
1702+
BranchTargetSymbol =
1703+
BC.handleExternalBranchTarget(TargetAddress, *TargetFunction);
1704+
if (!BranchTargetSymbol)
17131705
continue;
1714-
}
17151706
}
17161707

17171708
// Can't find more references. Not creating relocations since we are not

bolt/test/AArch64/constant-island-entry.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## Skip caller to check the identical warning is triggered from ScanExternalRefs().
1111
# RUN: llvm-bolt %t.exe -o %t.bolt -skip-funcs=caller 2>&1 | FileCheck %s
1212

13-
# CHECK: BOLT-WARNING: Ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
13+
# CHECK: BOLT-WARNING: ignoring entry point at address 0x{{[0-9a-f]+}} in constant island of function func
1414

1515
.globl func
1616
.type func, %function

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ LANGOPT(OpenCLGenericAddressSpace, 1, 0, NotCompatible, "OpenCL generic keyword"
216216
LANGOPT(OpenCLPipes , 1, 0, NotCompatible, "OpenCL pipes language constructs and built-ins")
217217
LANGOPT(NativeHalfType , 1, 0, NotCompatible, "Native half type support")
218218
LANGOPT(NativeHalfArgsAndReturns, 1, 0, NotCompatible, "Native half args and returns")
219+
LANGOPT(NativeInt16Type , 1, 1, NotCompatible, "Native int 16 type support")
219220
LANGOPT(CUDA , 1, 0, NotCompatible, "CUDA")
220221
LANGOPT(HIP , 1, 0, NotCompatible, "HIP")
221222
LANGOPT(OpenMP , 32, 0, NotCompatible, "OpenMP support and version of OpenMP (31, 40 or 45)")

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8626,6 +8626,11 @@ def fobjc_subscripting_legacy_runtime : Flag<["-"], "fobjc-subscripting-legacy-r
86268626
def vtordisp_mode_EQ : Joined<["-"], "vtordisp-mode=">,
86278627
HelpText<"Control vtordisp placement on win32 targets">,
86288628
MarshallingInfoInt<LangOpts<"VtorDispMode">, "1">;
8629+
def fnative_int16_type : Flag<["-"], "fnative-int16-type">,
8630+
HelpText<"Use 16 bit integer types">,
8631+
// This option is implied unless we are in HLSL lang mode
8632+
ImpliedByAnyOf<[!strconcat("!", hlsl.KeyPath)]>,
8633+
MarshallingInfoFlag<LangOpts<"NativeInt16Type">>;
86298634
def fnative_half_type: Flag<["-"], "fnative-half-type">,
86308635
HelpText<"Use the native half type for __fp16 instead of promoting to float">,
86318636
MarshallingInfoFlag<LangOpts<"NativeHalfType">>,
@@ -9518,7 +9523,7 @@ def emit_pristine_llvm : DXCFlag<"emit-pristine-llvm">,
95189523
HelpText<"Emit pristine LLVM IR from the frontend by not running any LLVM passes at all."
95199524
"Same as -S + -emit-llvm + -disable-llvm-passes.">;
95209525
def fcgl : DXCFlag<"fcgl">, Alias<emit_pristine_llvm>;
9521-
def enable_16bit_types : DXCFlag<"enable-16bit-types">, Alias<fnative_half_type>,
9526+
def enable_16bit_types : DXCFlag<"enable-16bit-types">,
95229527
HelpText<"Enable 16-bit types and disable min precision types."
95239528
"Available in HLSL 2018 and shader model 6.2.">;
95249529
def fdx_rootsignature_version :

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,6 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
771771
case X86::BI_WriteBarrier:
772772
case X86::BI_AddressOfReturnAddress:
773773
case X86::BI__stosb:
774-
case X86::BI__builtin_ia32_t2rpntlvwz0_internal:
775-
case X86::BI__builtin_ia32_t2rpntlvwz0rs_internal:
776-
case X86::BI__builtin_ia32_t2rpntlvwz0t1_internal:
777-
case X86::BI__builtin_ia32_t2rpntlvwz0rst1_internal:
778-
case X86::BI__builtin_ia32_t2rpntlvwz1_internal:
779-
case X86::BI__builtin_ia32_t2rpntlvwz1rs_internal:
780-
case X86::BI__builtin_ia32_t2rpntlvwz1t1_internal:
781-
case X86::BI__builtin_ia32_t2rpntlvwz1rst1_internal:
782774
case X86::BI__ud2:
783775
case X86::BI__int2c:
784776
case X86::BI__readfsbyte:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,6 +3708,7 @@ static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs,
37083708
options::OPT_emit_obj,
37093709
options::OPT_disable_llvm_passes,
37103710
options::OPT_fnative_half_type,
3711+
options::OPT_fnative_int16_type,
37113712
options::OPT_hlsl_entrypoint,
37123713
options::OPT_fdx_rootsignature_define,
37133714
options::OPT_fdx_rootsignature_version,

clang/lib/Driver/ToolChains/HLSL.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,15 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
498498
continue;
499499
}
500500

501+
if (A->getOption().getID() == options::OPT_enable_16bit_types) {
502+
// Translate -enable-16bit-types into -fnative-half-type and
503+
// -fnative-int16-type
504+
DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_fnative_half_type));
505+
DAL->AddFlagArg(nullptr, Opts.getOption(options::OPT_fnative_int16_type));
506+
A->claim();
507+
continue;
508+
}
509+
501510
DAL->append(A);
502511
}
503512

0 commit comments

Comments
 (0)