Skip to content

Commit a26b77e

Browse files
authored
Merge branch 'main' into hliao/main/fix-cir-dependency
2 parents 5423538 + 8560da2 commit a26b77e

Some content is hidden

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

58 files changed

+6835
-519
lines changed

llvm/include/llvm/IR/FMF.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ class FastMathFlags {
2323

2424
unsigned Flags = 0;
2525

26-
FastMathFlags(unsigned F) {
27-
// If all 7 bits are set, turn this into -1. If the number of bits grows,
28-
// this must be updated. This is intended to provide some forward binary
29-
// compatibility insurance for the meaning of 'fast' in case bits are added.
30-
if (F == 0x7F) Flags = ~0U;
31-
else Flags = F;
32-
}
26+
FastMathFlags(unsigned F) : Flags(F) {}
3327

3428
public:
3529
// This is how the bits are used in Value::SubclassOptionalData so they
@@ -43,9 +37,12 @@ class FastMathFlags {
4337
NoSignedZeros = (1 << 3),
4438
AllowReciprocal = (1 << 4),
4539
AllowContract = (1 << 5),
46-
ApproxFunc = (1 << 6)
40+
ApproxFunc = (1 << 6),
41+
FlagEnd = (1 << 7)
4742
};
4843

44+
constexpr static unsigned AllFlagsMask = FlagEnd - 1;
45+
4946
FastMathFlags() = default;
5047

5148
static FastMathFlags getFast() {
@@ -56,10 +53,10 @@ class FastMathFlags {
5653

5754
bool any() const { return Flags != 0; }
5855
bool none() const { return Flags == 0; }
59-
bool all() const { return Flags == ~0U; }
56+
bool all() const { return Flags == AllFlagsMask; }
6057

6158
void clear() { Flags = 0; }
62-
void set() { Flags = ~0U; }
59+
void set() { Flags = AllFlagsMask; }
6360

6461
/// Flag queries
6562
bool allowReassoc() const { return 0 != (Flags & AllowReassoc); }

llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerCommon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ void getAddressSanitizerParams(const Triple &TargetTriple, int LongSize,
5858
bool IsKasan, uint64_t *ShadowBase,
5959
int *MappingScale, bool *OrShadowOffset);
6060

61+
/// Remove memory attributes that are incompatible with the instrumentation
62+
/// added by AddressSanitizer and HWAddressSanitizer.
63+
/// \p ReadsArgMem - indicates whether function arguments may be read by
64+
/// instrumentation and require removing `writeonly` attributes.
65+
void removeASanIncompatibleFnAttributes(Function &F, bool ReadsArgMem);
66+
6167
} // namespace llvm
6268

6369
#endif

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MCTargetDesc/MipsFixupKinds.h"
10+
#include "MCTargetDesc/MipsMCExpr.h"
1011
#include "MCTargetDesc/MipsMCTargetDesc.h"
1112
#include "llvm/ADT/STLExtras.h"
1213
#include "llvm/BinaryFormat/ELF.h"
@@ -161,6 +162,22 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
161162
if (Kind >= FirstLiteralRelocationKind)
162163
return Kind - FirstLiteralRelocationKind;
163164

165+
switch (Target.getRefKind()) {
166+
case MipsMCExpr::MEK_DTPREL:
167+
case MipsMCExpr::MEK_DTPREL_HI:
168+
case MipsMCExpr::MEK_DTPREL_LO:
169+
case MipsMCExpr::MEK_TLSLDM:
170+
case MipsMCExpr::MEK_TLSGD:
171+
case MipsMCExpr::MEK_GOTTPREL:
172+
case MipsMCExpr::MEK_TPREL_HI:
173+
case MipsMCExpr::MEK_TPREL_LO:
174+
if (auto *S = Target.getSymA())
175+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
176+
break;
177+
default:
178+
break;
179+
}
180+
164181
switch (Kind) {
165182
case FK_NONE:
166183
return ELF::R_MIPS_NONE;

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -219,73 +219,6 @@ void MipsMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
219219
Streamer.visitUsedExpr(*getSubExpr());
220220
}
221221

222-
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
223-
switch (Expr->getKind()) {
224-
case MCExpr::Target:
225-
fixELFSymbolsInTLSFixupsImpl(cast<MipsMCExpr>(Expr)->getSubExpr(), Asm);
226-
break;
227-
case MCExpr::Constant:
228-
break;
229-
case MCExpr::Binary: {
230-
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
231-
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
232-
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
233-
break;
234-
}
235-
case MCExpr::SymbolRef: {
236-
// We're known to be under a TLS fixup, so any symbol should be
237-
// modified. There should be only one.
238-
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
239-
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
240-
break;
241-
}
242-
case MCExpr::Unary:
243-
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
244-
break;
245-
}
246-
}
247-
248-
void MipsMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
249-
switch (getKind()) {
250-
case MEK_None:
251-
case MEK_Special:
252-
llvm_unreachable("MEK_None and MEK_Special are invalid");
253-
break;
254-
case MEK_CALL_HI16:
255-
case MEK_CALL_LO16:
256-
case MEK_GOT:
257-
case MEK_GOT_CALL:
258-
case MEK_GOT_DISP:
259-
case MEK_GOT_HI16:
260-
case MEK_GOT_LO16:
261-
case MEK_GOT_OFST:
262-
case MEK_GOT_PAGE:
263-
case MEK_GPREL:
264-
case MEK_HI:
265-
case MEK_HIGHER:
266-
case MEK_HIGHEST:
267-
case MEK_LO:
268-
case MEK_NEG:
269-
case MEK_PCREL_HI16:
270-
case MEK_PCREL_LO16:
271-
// If we do have nested target-specific expressions, they will be in
272-
// a consecutive chain.
273-
if (const MipsMCExpr *E = dyn_cast<const MipsMCExpr>(getSubExpr()))
274-
E->fixELFSymbolsInTLSFixups(Asm);
275-
break;
276-
case MEK_DTPREL:
277-
case MEK_DTPREL_HI:
278-
case MEK_DTPREL_LO:
279-
case MEK_TLSLDM:
280-
case MEK_TLSGD:
281-
case MEK_GOTTPREL:
282-
case MEK_TPREL_HI:
283-
case MEK_TPREL_LO:
284-
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
285-
break;
286-
}
287-
}
288-
289222
bool MipsMCExpr::isGpOff(MipsExprKind &Kind) const {
290223
if (getKind() == MEK_HI || getKind() == MEK_LO) {
291224
if (const MipsMCExpr *S1 = dyn_cast<const MipsMCExpr>(getSubExpr())) {

llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class MipsMCExpr : public MCTargetExpr {
7474
return getSubExpr()->findAssociatedFragment();
7575
}
7676

77-
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
78-
7977
static bool classof(const MCExpr *E) {
8078
return E->getKind() == MCExpr::Target;
8179
}

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,17 @@ std::optional<int64_t> PPCMCExpr::evaluateAsInt64(int64_t Value) const {
7373

7474
bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
7575
const MCFixup *Fixup) const {
76+
if (!Asm)
77+
return false;
7678
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
7779
return false;
7880

81+
// The signedness of the result is dependent on the instruction operand. E.g.
82+
// in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
83+
// parse time (!Asm), disable the folding.
7984
std::optional<int64_t> MaybeInt = evaluateAsInt64(Res.getConstant());
8085
if (Res.isAbsolute() && MaybeInt) {
81-
int64_t Result = *MaybeInt;
82-
bool IsHalf16 = Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16;
83-
bool IsHalf16DS =
84-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16ds;
85-
bool IsHalf16DQ =
86-
Fixup && Fixup->getTargetKind() == PPC::fixup_ppc_half16dq;
87-
bool IsHalf = IsHalf16 || IsHalf16DS || IsHalf16DQ;
88-
89-
if (!IsHalf && Result >= 0x8000)
90-
return false;
91-
if ((IsHalf16DS && (Result & 0x3)) || (IsHalf16DQ && (Result & 0xf)))
92-
return false;
93-
94-
Res = MCValue::get(Result);
86+
Res = MCValue::get(*MaybeInt);
9587
} else {
9688
Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
9789
getKind());

llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ unsigned RISCVELFObjectWriter::getRelocType(MCContext &Ctx,
5555
unsigned Kind = Fixup.getTargetKind();
5656
if (Kind >= FirstLiteralRelocationKind)
5757
return Kind - FirstLiteralRelocationKind;
58+
59+
switch (Target.getRefKind()) {
60+
case RISCVMCExpr::VK_RISCV_TPREL_HI:
61+
case RISCVMCExpr::VK_RISCV_TLS_GOT_HI:
62+
case RISCVMCExpr::VK_RISCV_TLS_GD_HI:
63+
case RISCVMCExpr::VK_RISCV_TLSDESC_HI:
64+
if (auto *S = Target.getSymA())
65+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
66+
break;
67+
}
68+
5869
if (IsPCRel) {
5970
switch (Kind) {
6071
default:

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ const MCFixup *RISCVMCExpr::getPCRelHiFixup(const MCFragment **DFOut) const {
9191
bool RISCVMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
9292
const MCAssembler *Asm,
9393
const MCFixup *Fixup) const {
94-
// Explicitly drop the layout and assembler to prevent any symbolic folding in
95-
// the expression handling. This is required to preserve symbolic difference
96-
// expressions to emit the paired relocations.
97-
if (!getSubExpr()->evaluateAsRelocatable(Res, nullptr, nullptr))
94+
if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup))
9895
return false;
9996

10097
Res =
@@ -169,49 +166,6 @@ StringRef RISCVMCExpr::getVariantKindName(VariantKind Kind) {
169166
llvm_unreachable("Invalid ELF symbol kind");
170167
}
171168

172-
static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
173-
switch (Expr->getKind()) {
174-
case MCExpr::Target:
175-
llvm_unreachable("Can't handle nested target expression");
176-
break;
177-
case MCExpr::Constant:
178-
break;
179-
180-
case MCExpr::Binary: {
181-
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
182-
fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
183-
fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
184-
break;
185-
}
186-
187-
case MCExpr::SymbolRef: {
188-
// We're known to be under a TLS fixup, so any symbol should be
189-
// modified. There should be only one.
190-
const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
191-
cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
192-
break;
193-
}
194-
195-
case MCExpr::Unary:
196-
fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
197-
break;
198-
}
199-
}
200-
201-
void RISCVMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
202-
switch (getKind()) {
203-
default:
204-
return;
205-
case VK_RISCV_TPREL_HI:
206-
case VK_RISCV_TLS_GOT_HI:
207-
case VK_RISCV_TLS_GD_HI:
208-
case VK_RISCV_TLSDESC_HI:
209-
break;
210-
}
211-
212-
fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
213-
}
214-
215169
bool RISCVMCExpr::evaluateAsConstant(int64_t &Res) const {
216170
MCValue Value;
217171
if (Kind != VK_RISCV_LO && Kind != VK_RISCV_HI)

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ class RISCVMCExpr : public MCTargetExpr {
7676
return getSubExpr()->findAssociatedFragment();
7777
}
7878

79-
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
80-
8179
bool evaluateAsConstant(int64_t &Res) const;
8280

8381
static bool classof(const MCExpr *E) {

llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
4646
if (Kind >= FirstLiteralRelocationKind)
4747
return Kind - FirstLiteralRelocationKind;
4848

49+
switch (Target.getRefKind()) {
50+
case SparcMCExpr::VK_Sparc_TLS_GD_HI22:
51+
case SparcMCExpr::VK_Sparc_TLS_GD_LO10:
52+
case SparcMCExpr::VK_Sparc_TLS_GD_ADD:
53+
case SparcMCExpr::VK_Sparc_TLS_LDM_HI22:
54+
case SparcMCExpr::VK_Sparc_TLS_LDM_LO10:
55+
case SparcMCExpr::VK_Sparc_TLS_LDM_ADD:
56+
case SparcMCExpr::VK_Sparc_TLS_LDO_HIX22:
57+
case SparcMCExpr::VK_Sparc_TLS_LDO_LOX10:
58+
case SparcMCExpr::VK_Sparc_TLS_LDO_ADD:
59+
case SparcMCExpr::VK_Sparc_TLS_IE_HI22:
60+
case SparcMCExpr::VK_Sparc_TLS_IE_LO10:
61+
case SparcMCExpr::VK_Sparc_TLS_IE_LD:
62+
case SparcMCExpr::VK_Sparc_TLS_IE_LDX:
63+
case SparcMCExpr::VK_Sparc_TLS_IE_ADD:
64+
case SparcMCExpr::VK_Sparc_TLS_LE_HIX22:
65+
case SparcMCExpr::VK_Sparc_TLS_LE_LOX10:
66+
if (auto *S = Target.getSymA())
67+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
68+
break;
69+
default:
70+
break;
71+
}
72+
4973
if (const SparcMCExpr *SExpr = dyn_cast<SparcMCExpr>(Fixup.getValue())) {
5074
if (SExpr->getKind() == SparcMCExpr::VK_Sparc_R_DISP32)
5175
return ELF::R_SPARC_DISP32;

0 commit comments

Comments
 (0)