Skip to content

Commit 3b329ab

Browse files
committed
Merge branch 'upstream' into x86-insert-shuffle-combine
2 parents bb8491b + 445c43d commit 3b329ab

File tree

22 files changed

+511
-271
lines changed

22 files changed

+511
-271
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,6 +5167,12 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
51675167
}
51685168

51695169
template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
5170+
auto visitChildStmt = [&](const Stmt *S) -> bool {
5171+
LocalScope<Emitter> SScope(this);
5172+
if (!visitStmt(S))
5173+
return false;
5174+
return SScope.destroyLocals();
5175+
};
51705176
if (auto *CondInit = IS->getInit())
51715177
if (!visitStmt(CondInit))
51725178
return false;
@@ -5175,7 +5181,22 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
51755181
if (!visitDeclStmt(CondDecl))
51765182
return false;
51775183

5178-
// Compile condition.
5184+
// Save ourselves compiling some code and the jumps, etc. if the condition is
5185+
// stataically known to be either true or false. We could look at more cases
5186+
// here, but I think all the ones that actually happen are using a
5187+
// ConstantExpr.
5188+
if (const auto *CE = dyn_cast_if_present<ConstantExpr>(IS->getCond());
5189+
CE && CE->hasAPValueResult() &&
5190+
CE->getResultAPValueKind() == APValue::ValueKind::Int) {
5191+
APSInt Value = CE->getResultAsAPSInt();
5192+
if (Value.getBoolValue())
5193+
return visitChildStmt(IS->getThen());
5194+
else if (const Stmt *Else = IS->getElse())
5195+
return visitChildStmt(Else);
5196+
return true;
5197+
}
5198+
5199+
// Otherwise, compile the condition.
51795200
if (IS->isNonNegatedConsteval()) {
51805201
if (!this->emitIsConstantContext(IS))
51815202
return false;
@@ -5194,35 +5215,20 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
51945215
LabelTy LabelEnd = this->getLabel();
51955216
if (!this->jumpFalse(LabelElse))
51965217
return false;
5197-
{
5198-
LocalScope<Emitter> ThenScope(this);
5199-
if (!visitStmt(IS->getThen()))
5200-
return false;
5201-
if (!ThenScope.destroyLocals())
5202-
return false;
5203-
}
5218+
if (!visitChildStmt(IS->getThen()))
5219+
return false;
52045220
if (!this->jump(LabelEnd))
52055221
return false;
52065222
this->emitLabel(LabelElse);
5207-
{
5208-
LocalScope<Emitter> ElseScope(this);
5209-
if (!visitStmt(Else))
5210-
return false;
5211-
if (!ElseScope.destroyLocals())
5212-
return false;
5213-
}
5223+
if (!visitChildStmt(Else))
5224+
return false;
52145225
this->emitLabel(LabelEnd);
52155226
} else {
52165227
LabelTy LabelEnd = this->getLabel();
52175228
if (!this->jumpFalse(LabelEnd))
52185229
return false;
5219-
{
5220-
LocalScope<Emitter> ThenScope(this);
5221-
if (!visitStmt(IS->getThen()))
5222-
return false;
5223-
if (!ThenScope.destroyLocals())
5224-
return false;
5225-
}
5230+
if (!visitChildStmt(IS->getThen()))
5231+
return false;
52265232
this->emitLabel(LabelEnd);
52275233
}
52285234

clang/lib/AST/TypePrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,9 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
20932093
case attr::ArmMveStrictPolymorphism:
20942094
OS << "__clang_arm_mve_strict_polymorphism";
20952095
break;
2096+
case attr::ExtVectorType:
2097+
OS << "ext_vector_type";
2098+
break;
20962099
}
20972100
OS << "))";
20982101
}

clang/test/Driver/hip-partial-link.hip

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@
6262
// STATIC: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID2:[0-9a-f]+]]
6363
// STATIC: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID1]]
6464
// STATIC: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID2]]
65-
// STATIC: "{{.*}}/clang-offload-bundler" {{.*}}-unbundle
66-
// STATIC: "{{.*}}/lld" -flavor gnu -m elf64_amdgpu
67-
// STATIC: "{{.*}}/clang-offload-bundler"
68-
// STATIC: "{{.*}}/clang{{.*}}" -target x86_64-unknown-linux-gnu
69-
// STATIC: "{{.*}}/llvm-ar"
65+
// STATIC: "{{.*[/\\]}}clang-offload-bundler" {{.*}}-unbundle
66+
// STATIC: "{{.*[/\\]}}lld" -flavor gnu -m elf64_amdgpu
67+
// STATIC: "{{.*[/\\]}}clang-offload-bundler"
68+
// STATIC: "{{.*[/\\]}}clang{{.*}}" -target x86_64-unknown-linux-gnu
69+
// STATIC: "{{.*[/\\]}}llvm-ar"
7070

7171
// RUN: %clang -v --target=x86_64-unknown-linux-gnu --no-offload-new-driver \
7272
// RUN: --hip-link -no-hip-rt -fgpu-rdc --offload-arch=gfx906 \

clang/test/Driver/linker-wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ __attribute__((visibility("protected"), used)) int x;
119119

120120
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a
121121
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
122-
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input=/dev/null -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
122+
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input={{/dev/null|NUL}} -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
123123

124124
// RUN: clang-offload-packager -o %t.out \
125125
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
@@ -210,7 +210,7 @@ __attribute__((visibility("protected"), used)) int x;
210210
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP
211211

212212
// RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa
213-
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a -input=/dev/null -input={{.*}} -output={{.*}}
213+
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}}
214214
// RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r
215215
// RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading
216216

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,11 @@ Expected<StringRef> writeOffloadFile(const OffloadFile &File) {
603603

604604
StringRef Prefix =
605605
sys::path::stem(Binary.getMemoryBufferRef().getBufferIdentifier());
606-
607-
auto TempFileOrErr = createOutputFile(
608-
Prefix + "-" + Binary.getTriple() + "-" + Binary.getArch(), "o");
606+
SmallString<128> Filename;
607+
(Prefix + "-" + Binary.getTriple() + "-" + Binary.getArch())
608+
.toVector(Filename);
609+
llvm::replace(Filename, ':', '-');
610+
auto TempFileOrErr = createOutputFile(Filename, "o");
609611
if (!TempFileOrErr)
610612
return TempFileOrErr.takeError();
611613

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,6 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
5151
v, fir::GlobalOp::getTargetAttrName(globalOpName));
5252
}
5353

54-
static mlir::Value
55-
getOriginalDef(mlir::Value v,
56-
fir::AliasAnalysis::Source::Attributes &attributes,
57-
bool &isCapturedInInternalProcedure, bool &approximateSource) {
58-
mlir::Operation *defOp;
59-
bool breakFromLoop = false;
60-
while (!breakFromLoop && (defOp = v.getDefiningOp())) {
61-
mlir::Type ty = defOp->getResultTypes()[0];
62-
llvm::TypeSwitch<Operation *>(defOp)
63-
.Case<fir::ConvertOp>([&](fir::ConvertOp op) { v = op.getValue(); })
64-
.Case<fir::DeclareOp, hlfir::DeclareOp>([&](auto op) {
65-
v = op.getMemref();
66-
auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
67-
attributes |= getAttrsFromVariable(varIf);
68-
isCapturedInInternalProcedure |=
69-
varIf.isCapturedInInternalProcedure();
70-
})
71-
.Case<fir::CoordinateOp>([&](auto op) {
72-
if (fir::AliasAnalysis::isPointerReference(ty))
73-
attributes.set(fir::AliasAnalysis::Attribute::Pointer);
74-
v = op->getOperand(0);
75-
approximateSource = true;
76-
})
77-
.Case<hlfir::DesignateOp>([&](hlfir::DesignateOp op) {
78-
auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
79-
attributes |= getAttrsFromVariable(varIf);
80-
v = op.getMemref();
81-
approximateSource = true;
82-
})
83-
.Default([&](auto op) { breakFromLoop = true; });
84-
}
85-
return v;
86-
}
87-
8854
static bool isEvaluateInMemoryBlockArg(mlir::Value v) {
8955
if (auto evalInMem = llvm::dyn_cast_or_null<hlfir::EvaluateInMemoryOp>(
9056
v.getParentRegion()->getParentOp()))
@@ -621,38 +587,34 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
621587
if (mlir::isa<fir::PointerType>(boxTy.getEleTy()))
622588
attributes.set(Attribute::Pointer);
623589

624-
auto def = getOriginalDef(op.getMemref(), attributes,
625-
isCapturedInInternalProcedure,
626-
approximateSource);
627-
if (auto addrOfOp = def.template getDefiningOp<fir::AddrOfOp>()) {
628-
global = addrOfOp.getSymbol();
629-
630-
if (hasGlobalOpTargetAttr(def, addrOfOp))
631-
attributes.set(Attribute::Target);
590+
auto boxSrc = getSource(op.getMemref());
591+
attributes |= boxSrc.attributes;
592+
approximateSource |= boxSrc.approximateSource;
593+
isCapturedInInternalProcedure |=
594+
boxSrc.isCapturedInInternalProcedure;
632595

596+
global = llvm::dyn_cast<mlir::SymbolRefAttr>(boxSrc.origin.u);
597+
if (global) {
633598
type = SourceKind::Global;
634-
}
635-
// TODO: Add support to fir.allocmem
636-
else if (auto allocOp =
637-
def.template getDefiningOp<fir::AllocaOp>()) {
638-
v = def;
639-
defOp = v.getDefiningOp();
640-
type = SourceKind::Allocate;
641-
} else if (isDummyArgument(def)) {
642-
defOp = nullptr;
643-
v = def;
644599
} else {
645-
type = SourceKind::Indirect;
600+
auto def = llvm::cast<mlir::Value>(boxSrc.origin.u);
601+
// TODO: Add support to fir.allocmem
602+
if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
603+
v = def;
604+
defOp = v.getDefiningOp();
605+
type = SourceKind::Allocate;
606+
} else if (isDummyArgument(def)) {
607+
defOp = nullptr;
608+
v = def;
609+
} else {
610+
type = SourceKind::Indirect;
611+
}
646612
}
647-
// TODO: This assignment is redundant but somehow works around an
648-
// apparent MSVC bug reporting "undeclared identifier" at the next
649-
// "breakFromLoop = true;". See
650-
// <https://github.com/llvm/llvm-project/pull/127845#issuecomment-2669829610>.
651613
breakFromLoop = true;
652-
} else {
653-
// No further tracking for addresses loaded from memory for now.
654-
type = SourceKind::Indirect;
614+
return;
655615
}
616+
// No further tracking for addresses loaded from memory for now.
617+
type = SourceKind::Indirect;
656618
breakFromLoop = true;
657619
})
658620
.Case<fir::AddrOfOp>([&](auto op) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: fir-opt %s -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis))' -debug-only=fir-alias-analysis 2>&1 | FileCheck %s
2+
3+
// CHECK-LABEL: Testing : "_QFPtest"
4+
5+
// Checking that the source kind of a load of a load is SourceKind::Indirect
6+
// CHECK: {test.ptr = "load_load"}
7+
// CHECK-NEXT: SourceKind: Indirect
8+
9+
// Checking that the source kind of a load of an arg is SourceKind::Argument
10+
// CHECK: {test.ptr = "load_arg"}
11+
// CHECK-NEXT: SourceKind: Argument
12+
13+
func.func @_QFPtest(%arg0: !fir.ref<!fir.box<!fir.ptr<f32>>> ) attributes {test.ptr = "func"} {
14+
15+
%0 = fir.alloca !fir.llvm_ptr<!fir.box<!fir.ptr<f32>>>
16+
%1 = fir.convert %arg0 : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.llvm_ptr<!fir.box<!fir.ptr<f32>>>
17+
fir.store %1 to %0 : !fir.ref<!fir.llvm_ptr<!fir.box<!fir.ptr<f32>>>>
18+
%2 = fir.load %0 : !fir.ref<!fir.llvm_ptr<!fir.box<!fir.ptr<f32>>>>
19+
%3 = fir.convert %2 : (!fir.llvm_ptr<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>
20+
%15 = fir.load %3 : !fir.ref<!fir.box<!fir.ptr<f32>>>
21+
%16 = fir.box_addr %15 {test.ptr = "load_load"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
22+
%17 = fir.load %arg0 : !fir.ref<!fir.box<!fir.ptr<f32>>>
23+
%18 = fir.box_addr %17 {test.ptr = "load_arg"} : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
24+
return
25+
}

lld/COFF/Chunks.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Chunk {
5959
SectionKind,
6060
SectionECKind,
6161
OtherKind,
62-
ImportThunkKind
62+
ImportThunkKind,
63+
ECExportThunkKind
6364
};
6465
Kind kind() const { return chunkKind; }
6566

@@ -827,7 +828,10 @@ static const uint8_t ECExportThunkCode[] = {
827828

828829
class ECExportThunkChunk : public NonSectionCodeChunk {
829830
public:
830-
explicit ECExportThunkChunk(Defined *targetSym) : target(targetSym) {}
831+
explicit ECExportThunkChunk(Defined *targetSym)
832+
: NonSectionCodeChunk(ECExportThunkKind), target(targetSym) {}
833+
static bool classof(const Chunk *c) { return c->kind() == ECExportThunkKind; }
834+
831835
size_t getSize() const override { return sizeof(ECExportThunkCode); };
832836
void writeTo(uint8_t *buf) const override;
833837
MachineTypes getMachine() const override { return AMD64; }

lld/test/COFF/build-id-sym.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: x86
22
# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
3-
# RUN: lld-link -debug:symtab -entry:main %t.obj -build-id -Brepro -out:%t.exe
3+
# RUN: lld-link -debug:symtab -entry:main %t.obj -build-id -Brepro -out:%t.exe -guard:cf
44
# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
55

66
# Check __buildid points to 0x14000203c which is after the signature RSDS.
@@ -21,3 +21,6 @@ main:
2121
.section .bss,"bw",discard,__buildid
2222
.global __buildid
2323
__buildid:
24+
25+
.data
26+
.quad __buildid

llvm/include/llvm/ExecutionEngine/Orc/MemoryMapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class SharedMemoryMapper final : public MemoryMapper {
157157
struct Reservation {
158158
void *LocalAddr;
159159
size_t Size;
160+
int SharedMemoryId;
160161
};
161162

162163
ExecutorProcessControl &EPC;

0 commit comments

Comments
 (0)