Skip to content

Commit f98ed7f

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:47d9fbc04b91 into amd-gfx:d315d30c5fe7
Local branch amd-gfx d315d30 Merged main:b87110e298df into amd-gfx:265623ac31ed Remote branch main 47d9fbc [LinkerWrapper] Add Freestanding config to the LTO pass
2 parents d315d30 + 47d9fbc commit f98ed7f

File tree

19 files changed

+146
-73
lines changed

19 files changed

+146
-73
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,9 @@ ConstantLValueEmitter::tryEmitAbsolute(llvm::Type *destTy) {
19301930
// FIXME: signedness depends on the original integer type.
19311931
auto intptrTy = CGM.getDataLayout().getIntPtrType(destPtrTy);
19321932
llvm::Constant *C;
1933-
C = llvm::ConstantExpr::getIntegerCast(getOffset(), intptrTy,
1934-
/*isSigned*/ false);
1933+
C = llvm::ConstantFoldIntegerCast(getOffset(), intptrTy, /*isSigned*/ false,
1934+
CGM.getDataLayout());
1935+
assert(C && "Must have folded, as Offset is a ConstantInt");
19351936
C = llvm::ConstantExpr::getIntToPtr(C, destPtrTy);
19361937
return C;
19371938
}

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ std::unique_ptr<lto::LTO> createLTO(
526526

527527
Conf.CPU = Arch.str();
528528
Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
529+
Conf.Freestanding = true;
529530

530531
StringRef OptLevel = Args.getLastArgValue(OPT_opt_level, "O2");
531532
Conf.MAttrs = Features;

lld/COFF/Chunks.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ class NonSectionChunk : public Chunk {
180180
NonSectionChunk(Kind k = OtherKind) : Chunk(k) {}
181181
};
182182

183+
class NonSectionCodeChunk : public NonSectionChunk {
184+
public:
185+
virtual uint32_t getOutputCharacteristics() const override {
186+
return llvm::COFF::IMAGE_SCN_MEM_READ | llvm::COFF::IMAGE_SCN_MEM_EXECUTE;
187+
}
188+
189+
protected:
190+
NonSectionCodeChunk(Kind k = OtherKind) : NonSectionChunk(k) {}
191+
};
192+
183193
// MinGW specific; information about one individual location in the image
184194
// that needs to be fixed up at runtime after loading. This represents
185195
// one individual element in the PseudoRelocTableChunk table.
@@ -508,10 +518,10 @@ static const uint8_t importThunkARM64[] = {
508518
// Windows-specific.
509519
// A chunk for DLL import jump table entry. In a final output, its
510520
// contents will be a JMP instruction to some __imp_ symbol.
511-
class ImportThunkChunk : public NonSectionChunk {
521+
class ImportThunkChunk : public NonSectionCodeChunk {
512522
public:
513523
ImportThunkChunk(COFFLinkerContext &ctx, Defined *s)
514-
: NonSectionChunk(ImportThunkKind), impSymbol(s), ctx(ctx) {}
524+
: NonSectionCodeChunk(ImportThunkKind), impSymbol(s), ctx(ctx) {}
515525
static bool classof(const Chunk *c) { return c->kind() == ImportThunkKind; }
516526

517527
protected:
@@ -560,7 +570,7 @@ class ImportThunkChunkARM64 : public ImportThunkChunk {
560570
MachineTypes getMachine() const override { return ARM64; }
561571
};
562572

563-
class RangeExtensionThunkARM : public NonSectionChunk {
573+
class RangeExtensionThunkARM : public NonSectionCodeChunk {
564574
public:
565575
explicit RangeExtensionThunkARM(COFFLinkerContext &ctx, Defined *t)
566576
: target(t), ctx(ctx) {
@@ -576,7 +586,7 @@ class RangeExtensionThunkARM : public NonSectionChunk {
576586
COFFLinkerContext &ctx;
577587
};
578588

579-
class RangeExtensionThunkARM64 : public NonSectionChunk {
589+
class RangeExtensionThunkARM64 : public NonSectionCodeChunk {
580590
public:
581591
explicit RangeExtensionThunkARM64(COFFLinkerContext &ctx, Defined *t)
582592
: target(t), ctx(ctx) {

lld/COFF/DLL.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static const uint8_t tailMergeARM64[] = {
313313
};
314314

315315
// A chunk for the delay import thunk.
316-
class ThunkChunkX64 : public NonSectionChunk {
316+
class ThunkChunkX64 : public NonSectionCodeChunk {
317317
public:
318318
ThunkChunkX64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {}
319319

@@ -330,7 +330,7 @@ class ThunkChunkX64 : public NonSectionChunk {
330330
Chunk *tailMerge = nullptr;
331331
};
332332

333-
class TailMergeChunkX64 : public NonSectionChunk {
333+
class TailMergeChunkX64 : public NonSectionCodeChunk {
334334
public:
335335
TailMergeChunkX64(Chunk *d, Defined *h) : desc(d), helper(h) {}
336336

@@ -382,7 +382,7 @@ class TailMergeUnwindInfoX64 : public NonSectionChunk {
382382
}
383383
};
384384

385-
class ThunkChunkX86 : public NonSectionChunk {
385+
class ThunkChunkX86 : public NonSectionCodeChunk {
386386
public:
387387
ThunkChunkX86(COFFLinkerContext &ctx, Defined *i, Chunk *tm)
388388
: imp(i), tailMerge(tm), ctx(ctx) {}
@@ -407,7 +407,7 @@ class ThunkChunkX86 : public NonSectionChunk {
407407
const COFFLinkerContext &ctx;
408408
};
409409

410-
class TailMergeChunkX86 : public NonSectionChunk {
410+
class TailMergeChunkX86 : public NonSectionCodeChunk {
411411
public:
412412
TailMergeChunkX86(COFFLinkerContext &ctx, Chunk *d, Defined *h)
413413
: desc(d), helper(h), ctx(ctx) {}
@@ -432,7 +432,7 @@ class TailMergeChunkX86 : public NonSectionChunk {
432432
const COFFLinkerContext &ctx;
433433
};
434434

435-
class ThunkChunkARM : public NonSectionChunk {
435+
class ThunkChunkARM : public NonSectionCodeChunk {
436436
public:
437437
ThunkChunkARM(COFFLinkerContext &ctx, Defined *i, Chunk *tm)
438438
: imp(i), tailMerge(tm), ctx(ctx) {
@@ -459,7 +459,7 @@ class ThunkChunkARM : public NonSectionChunk {
459459
const COFFLinkerContext &ctx;
460460
};
461461

462-
class TailMergeChunkARM : public NonSectionChunk {
462+
class TailMergeChunkARM : public NonSectionCodeChunk {
463463
public:
464464
TailMergeChunkARM(COFFLinkerContext &ctx, Chunk *d, Defined *h)
465465
: desc(d), helper(h), ctx(ctx) {
@@ -486,7 +486,7 @@ class TailMergeChunkARM : public NonSectionChunk {
486486
const COFFLinkerContext &ctx;
487487
};
488488

489-
class ThunkChunkARM64 : public NonSectionChunk {
489+
class ThunkChunkARM64 : public NonSectionCodeChunk {
490490
public:
491491
ThunkChunkARM64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {
492492
setAlignment(4);
@@ -506,7 +506,7 @@ class ThunkChunkARM64 : public NonSectionChunk {
506506
Chunk *tailMerge = nullptr;
507507
};
508508

509-
class TailMergeChunkARM64 : public NonSectionChunk {
509+
class TailMergeChunkARM64 : public NonSectionCodeChunk {
510510
public:
511511
TailMergeChunkARM64(Chunk *d, Defined *h) : desc(d), helper(h) {
512512
setAlignment(4);

lld/test/COFF/export-thunk.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
REQUIRES: x86
2+
3+
RUN: echo -e 'LIBRARY test.dll\nEXPORTS\nimpfunc\n' > %t.imp.def
4+
RUN: llvm-dlltool -m i386:x86-64 -d %t.imp.def -l %t.imp.lib
5+
RUN: lld-link -machine:amd64 -out:%t.dll -dll -noentry -lldmingw %t.imp.lib -export:impfunc -output-def:%t.def
6+
7+
Check that the synthetic import thunk is exported as a function, not data.
8+
9+
RUN: cat %t.def | FileCheck %s
10+
CHECK: EXPORTS
11+
CHECK-NEXT: impfunc @1
12+
13+
RUN: cat %t.def | FileCheck -check-prefix=CHECK-NO-DATA %s
14+
CHECK-NO-DATA-NOT: DATA

lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ void ObjectFileCOFF::ParseSymtab(lldb_private::Symtab &symtab) {
271271
const auto COFFSymRef = m_object->getCOFFSymbol(SymRef);
272272

273273
Expected<StringRef> NameOrErr = SymRef.getName();
274-
if (auto error = NameOrErr.takeError()) {
275-
LLDB_LOG(log, "ObjectFileCOFF: failed to get symbol name: {0}",
276-
llvm::fmt_consume(std::move(error)));
274+
if (!NameOrErr) {
275+
LLDB_LOG_ERROR(log, NameOrErr.takeError(),
276+
"ObjectFileCOFF: failed to get symbol name: {0}");
277277
continue;
278278
}
279279

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,10 @@ void ObjectFilePECOFF::AppendFromCOFFSymbolTable(
791791
for (const auto &sym_ref : m_binary->symbols()) {
792792
const auto coff_sym_ref = m_binary->getCOFFSymbol(sym_ref);
793793
auto name_or_error = sym_ref.getName();
794-
if (auto err = name_or_error.takeError()) {
795-
LLDB_LOG(log,
796-
"ObjectFilePECOFF::AppendFromCOFFSymbolTable - failed to get "
797-
"symbol table entry name: {0}",
798-
llvm::fmt_consume(std::move(err)));
794+
if (!name_or_error) {
795+
LLDB_LOG_ERROR(log, name_or_error.takeError(),
796+
"ObjectFilePECOFF::AppendFromCOFFSymbolTable - failed to "
797+
"get symbol table entry name: {0}");
799798
continue;
800799
}
801800
const llvm::StringRef sym_name = *name_or_error;

llvm/docs/RISCVUsage.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ on support follow.
106106
``Zcb`` Supported
107107
``Zcd`` Supported
108108
``Zcf`` Supported
109-
``Zcmp`` Assembly Support
109+
``Zcmp`` Supported
110110
``Zcmt`` Assembly Support
111111
``Zdinx`` Supported
112112
``Zfa`` Supported
@@ -116,7 +116,7 @@ on support follow.
116116
``Zhinx`` Supported
117117
``Zhinxmin`` Supported
118118
``Zicbom`` Assembly Support
119-
``Zicbop`` Assembly Support
119+
``Zicbop`` Supported
120120
``Zicboz`` Assembly Support
121121
``Zicntr`` (`See Note <#riscv-i2p1-note>`__)
122122
``Zicsr`` (`See Note <#riscv-i2p1-note>`__)

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 479355
19+
#define LLVM_MAIN_REVISION 479369
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,9 +3052,12 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) {
30523052
// Handle casts to pointers by changing them into casts to the appropriate
30533053
// integer type. This promotes constant folding and simplifies this code.
30543054
Constant *Op = CE->getOperand(0);
3055-
Op = ConstantExpr::getIntegerCast(Op, DL.getIntPtrType(CV->getType()),
3056-
false/*ZExt*/);
3057-
return lowerConstant(Op);
3055+
Op = ConstantFoldIntegerCast(Op, DL.getIntPtrType(CV->getType()),
3056+
/*IsSigned*/ false, DL);
3057+
if (Op)
3058+
return lowerConstant(Op);
3059+
3060+
break; // Error
30583061
}
30593062

30603063
case Instruction::PtrToInt: {

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,7 +4773,10 @@ void AArch64InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
47734773
} else if (AArch64::PNRRegClass.hasSubClassEq(RC)) {
47744774
assert((Subtarget.hasSVE2p1() || Subtarget.hasSME2()) &&
47754775
"Unexpected register store without SVE2p1 or SME2");
4776-
SrcReg = (SrcReg - AArch64::PN0) + AArch64::P0;
4776+
if (SrcReg.isVirtual())
4777+
MF.getRegInfo().constrainRegClass(SrcReg, &AArch64::PPRRegClass);
4778+
else
4779+
SrcReg = (SrcReg - AArch64::PN0) + AArch64::P0;
47774780
Opc = AArch64::STR_PXI;
47784781
StackID = TargetStackID::ScalableVector;
47794782
}
@@ -4946,7 +4949,10 @@ void AArch64InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
49464949
assert((Subtarget.hasSVE2p1() || Subtarget.hasSME2()) &&
49474950
"Unexpected register load without SVE2p1 or SME2");
49484951
PNRReg = DestReg;
4949-
DestReg = (DestReg - AArch64::PN0) + AArch64::P0;
4952+
if (DestReg.isVirtual())
4953+
MF.getRegInfo().constrainRegClass(DestReg, &AArch64::PPRRegClass);
4954+
else
4955+
DestReg = (DestReg - AArch64::PN0) + AArch64::P0;
49504956
Opc = AArch64::LDR_PXI;
49514957
StackID = TargetStackID::ScalableVector;
49524958
}

llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "AMDGPU.h"
1616
#include "Utils/AMDGPUBaseInfo.h"
17+
#include "llvm/Analysis/ConstantFolding.h"
1718
#include "llvm/Analysis/ValueTracking.h"
1819
#include "llvm/CodeGen/Passes.h"
1920
#include "llvm/CodeGen/TargetPassConfig.h"
@@ -286,8 +287,8 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
286287
if (HasReqdWorkGroupSize) {
287288
ConstantInt *KnownSize
288289
= mdconst::extract<ConstantInt>(MD->getOperand(I));
289-
UMin->replaceAllUsesWith(ConstantExpr::getIntegerCast(
290-
KnownSize, UMin->getType(), false));
290+
UMin->replaceAllUsesWith(ConstantFoldIntegerCast(
291+
KnownSize, UMin->getType(), false, DL));
291292
} else {
292293
UMin->replaceAllUsesWith(ZextGroupSize);
293294
}
@@ -310,7 +311,7 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
310311

311312
ConstantInt *KnownSize = mdconst::extract<ConstantInt>(MD->getOperand(I));
312313
GroupSize->replaceAllUsesWith(
313-
ConstantExpr::getIntegerCast(KnownSize, GroupSize->getType(), false));
314+
ConstantFoldIntegerCast(KnownSize, GroupSize->getType(), false, DL));
314315
MadeChange = true;
315316
}
316317

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,35 +1980,16 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
19801980
}
19811981

19821982
switch (CE->getOpcode()) {
1983-
default: {
1984-
// If the code isn't optimized, there may be outstanding folding
1985-
// opportunities. Attempt to fold the expression using DataLayout as a
1986-
// last resort before giving up.
1987-
Constant *C = ConstantFoldConstant(CE, getDataLayout());
1988-
if (C != CE)
1989-
return lowerConstantForGV(C, ProcessingGeneric);
1990-
1991-
// Otherwise report the problem to the user.
1992-
std::string S;
1993-
raw_string_ostream OS(S);
1994-
OS << "Unsupported expression in static initializer: ";
1995-
CE->printAsOperand(OS, /*PrintType=*/false,
1996-
!MF ? nullptr : MF->getFunction().getParent());
1997-
report_fatal_error(Twine(OS.str()));
1998-
}
1983+
default:
1984+
break; // Error
19991985

20001986
case Instruction::AddrSpaceCast: {
20011987
// Strip the addrspacecast and pass along the operand
20021988
PointerType *DstTy = cast<PointerType>(CE->getType());
2003-
if (DstTy->getAddressSpace() == 0) {
1989+
if (DstTy->getAddressSpace() == 0)
20041990
return lowerConstantForGV(cast<const Constant>(CE->getOperand(0)), true);
2005-
}
2006-
std::string S;
2007-
raw_string_ostream OS(S);
2008-
OS << "Unsupported expression in static initializer: ";
2009-
CE->printAsOperand(OS, /*PrintType=*/ false,
2010-
!MF ? nullptr : MF->getFunction().getParent());
2011-
report_fatal_error(Twine(OS.str()));
1991+
1992+
break; // Error
20121993
}
20131994

20141995
case Instruction::GetElementPtr: {
@@ -2043,9 +2024,12 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
20432024
// Handle casts to pointers by changing them into casts to the appropriate
20442025
// integer type. This promotes constant folding and simplifies this code.
20452026
Constant *Op = CE->getOperand(0);
2046-
Op = ConstantExpr::getIntegerCast(Op, DL.getIntPtrType(CV->getType()),
2047-
false/*ZExt*/);
2048-
return lowerConstantForGV(Op, ProcessingGeneric);
2027+
Op = ConstantFoldIntegerCast(Op, DL.getIntPtrType(CV->getType()),
2028+
/*IsSigned*/ false, DL);
2029+
if (Op)
2030+
return lowerConstantForGV(Op, ProcessingGeneric);
2031+
2032+
break; // Error
20492033
}
20502034

20512035
case Instruction::PtrToInt: {
@@ -2082,6 +2066,21 @@ NVPTXAsmPrinter::lowerConstantForGV(const Constant *CV, bool ProcessingGeneric)
20822066
}
20832067
}
20842068
}
2069+
2070+
// If the code isn't optimized, there may be outstanding folding
2071+
// opportunities. Attempt to fold the expression using DataLayout as a
2072+
// last resort before giving up.
2073+
Constant *C = ConstantFoldConstant(CE, getDataLayout());
2074+
if (C != CE)
2075+
return lowerConstantForGV(C, ProcessingGeneric);
2076+
2077+
// Otherwise report the problem to the user.
2078+
std::string S;
2079+
raw_string_ostream OS(S);
2080+
OS << "Unsupported expression in static initializer: ";
2081+
CE->printAsOperand(OS, /*PrintType=*/false,
2082+
!MF ? nullptr : MF->getFunction().getParent());
2083+
report_fatal_error(Twine(OS.str()));
20852084
}
20862085

20872086
// Copy of MCExpr::print customized for NVPTX

llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static Type *getReducedType(Value *V, Type *Ty) {
366366
Value *TruncInstCombine::getReducedOperand(Value *V, Type *SclTy) {
367367
Type *Ty = getReducedType(V, SclTy);
368368
if (auto *C = dyn_cast<Constant>(V)) {
369-
C = ConstantExpr::getIntegerCast(C, Ty, false);
369+
C = ConstantExpr::getTrunc(C, Ty);
370370
// If we got a constantexpr back, try to simplify it with DL info.
371371
return ConstantFoldConstant(C, DL, &TLI);
372372
}

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ using namespace PatternMatch;
2929
/// true for, actually insert the code to evaluate the expression.
3030
Value *InstCombinerImpl::EvaluateInDifferentType(Value *V, Type *Ty,
3131
bool isSigned) {
32-
if (Constant *C = dyn_cast<Constant>(V)) {
33-
C = ConstantExpr::getIntegerCast(C, Ty, isSigned /*Sext or ZExt*/);
34-
// If we got a constantexpr back, try to simplify it with DL info.
35-
return ConstantFoldConstant(C, DL, &TLI);
36-
}
32+
if (Constant *C = dyn_cast<Constant>(V))
33+
return ConstantFoldIntegerCast(C, Ty, isSigned, DL);
3734

3835
// Otherwise, it must be an instruction.
3936
Instruction *I = cast<Instruction>(V);
@@ -216,7 +213,7 @@ Instruction *InstCombinerImpl::commonCastTransforms(CastInst &CI) {
216213
/// Constants and extensions/truncates from the destination type are always
217214
/// free to be evaluated in that type. This is a helper for canEvaluate*.
218215
static bool canAlwaysEvaluateInType(Value *V, Type *Ty) {
219-
if (isa<Constant>(V))
216+
if (match(V, m_ImmConstant()))
220217
return true;
221218
Value *X;
222219
if ((match(V, m_ZExtOrSExt(m_Value(X))) || match(V, m_Trunc(m_Value(X)))) &&
@@ -229,7 +226,6 @@ static bool canAlwaysEvaluateInType(Value *V, Type *Ty) {
229226
/// Filter out values that we can not evaluate in the destination type for free.
230227
/// This is a helper for canEvaluate*.
231228
static bool canNotEvaluateInType(Value *V, Type *Ty) {
232-
assert(!isa<Constant>(V) && "Constant should already be handled.");
233229
if (!isa<Instruction>(V))
234230
return true;
235231
// We don't extend or shrink something that has multiple uses -- doing so

0 commit comments

Comments
 (0)