Skip to content

Commit 8df40b4

Browse files
committed
Enforce opaque IR pointers
1 parent 94af2f8 commit 8df40b4

File tree

10 files changed

+17
-141
lines changed

10 files changed

+17
-141
lines changed

driver/cl_options.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,6 @@ cl::opt<bool> dynamicCompileTlsWorkaround(
710710
cl::Hidden);
711711
#endif
712712

713-
#if LDC_LLVM_VER >= 1700
714-
bool enableOpaqueIRPointers = true; // typed pointers are no longer supported from LLVM 17
715-
#else
716-
bool enableOpaqueIRPointers = false;
717-
#endif
718-
719713
static cl::extrahelp
720714
footer("\n"
721715
"-d-debug can also be specified without options, in which case it "
@@ -775,9 +769,6 @@ void createClashingOptions() {
775769
"Hardware floating-point ABI and instructions")));
776770

777771
renameAndHide("opaque-pointers", nullptr); // remove
778-
new cl::opt<bool, true>(
779-
"opaque-pointers", cl::ZeroOrMore, cl::location(enableOpaqueIRPointers),
780-
cl::desc("Use opaque IR pointers (experimental!)"), cl::Hidden);
781772
}
782773

783774
/// Hides command line options exposed from within LLVM that are unlikely
@@ -865,7 +856,7 @@ void hideLLVMOptions() {
865856
"no-discriminators", "no-integrated-as", "no-type-check", "no-xray-index",
866857
"nozero-initialized-in-bss", "nvptx-sched4reg",
867858
"objc-arc-annotation-target-identifier",
868-
"object-size-offset-visitor-max-visit-instructions", "opaque-pointers",
859+
"object-size-offset-visitor-max-visit-instructions",
869860
"pgo-block-coverage", "pgo-temporal-instrumentation",
870861
"pgo-view-block-coverage-graph",
871862
"pie-copy-relocations", "poison-checking-function-local",

driver/cl_options.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,4 @@ extern cl::opt<bool> dynamicCompileTlsWorkaround;
150150
#else
151151
constexpr bool enableDynamicCompile = false;
152152
#endif
153-
154-
extern bool enableOpaqueIRPointers;
155153
}

driver/main.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,13 @@ void parseCommandLine(Strings &sourceFiles) {
558558
global.params.dihdr.fullOutput = opts::hdrKeepAllBodies;
559559
global.params.disableRedZone = opts::disableRedZone();
560560

561+
// enforce opaque IR pointers
561562
#if LDC_LLVM_VER >= 1700
562-
if (!opts::enableOpaqueIRPointers)
563-
error(Loc(),
564-
"LLVM version 17 or above only supports --opaque-pointers=true");
563+
// supports opaque IR pointers only
565564
#elif LDC_LLVM_VER >= 1500
566-
getGlobalContext().setOpaquePointers(opts::enableOpaqueIRPointers);
567-
#else
568-
if (opts::enableOpaqueIRPointers)
569-
getGlobalContext().enableOpaquePointers();
565+
getGlobalContext().setOpaquePointers(true);
566+
#else // LLVM 14
567+
getGlobalContext().enableOpaquePointers();
570568
#endif
571569
}
572570

@@ -1023,16 +1021,6 @@ void registerPredefinedVersions() {
10231021
VersionCondition::addPredefinedGlobalIdent("LDC_ThreadSanitizer");
10241022
}
10251023

1026-
// Set a version identifier for whether opaque pointers are enabled or not. (needed e.g. for intrinsic mangling)
1027-
#if LDC_LLVM_VER >= 1700
1028-
// Since LLVM 17, IR pointers are always opaque.
1029-
VersionCondition::addPredefinedGlobalIdent("LDC_LLVM_OpaquePointers");
1030-
#else
1031-
if (!getGlobalContext().supportsTypedPointers()) {
1032-
VersionCondition::addPredefinedGlobalIdent("LDC_LLVM_OpaquePointers");
1033-
}
1034-
#endif
1035-
10361024
// Expose LLVM version to runtime
10371025
#define STR(x) #x
10381026
#define XSTR(x) STR(x)

gen/dvalue.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,7 @@ DRValue *DLValue::getRVal() {
159159
////////////////////////////////////////////////////////////////////////////////
160160

161161
DSpecialRefValue::DSpecialRefValue(Type *t, LLValue *v) : DLValue(v, t) {
162-
#if LDC_LLVM_VER >= 1700 // LLVM >= 17 uses opaque pointers, type check boils
163-
// down to pointer check only.
164162
assert(v->getType()->isPointerTy());
165-
#else
166-
assert(v->getType() == DtoPtrToType(t)->getPointerTo());
167-
#endif
168163
}
169164

170165
DRValue *DSpecialRefValue::getRVal() {

gen/functions.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,7 @@ void defineParameters(IrFuncTy &irFty, VarDeclarations &parameters) {
808808
if (irparam->arg->byref) {
809809
// The argument is an appropriate lvalue passed by reference.
810810
// Use the passed pointer as parameter storage.
811-
#if LDC_LLVM_VER >= 1700 // LLVM >= 17 uses opaque pointers, type check boils
812-
// down to pointer check only.
813811
assert(irparam->value->getType()->isPointerTy());
814-
#else
815-
assert(irparam->value->getType() == DtoPtrToType(paramType));
816-
#endif
817812
} else {
818813
// Let the ABI transform the parameter back to an lvalue.
819814
irparam->value =

gen/tollvm.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,27 +595,7 @@ LLType *stripAddrSpaces(LLType *t)
595595
if (!pt)
596596
return t;
597597

598-
#if LDC_LLVM_VER >= 1700
599598
return getVoidPtrType();
600-
#else
601-
if (pt->isOpaque())
602-
return getVoidPtrType();
603-
else {
604-
int indirections = 0;
605-
while (t->isPointerTy()) {
606-
indirections++;
607-
// Disable [[deprecated]] warning on getPointerElementType. We solved the
608-
// deprecation for versions >= LLVM 16 above (8 lines up).
609-
#pragma GCC diagnostic push
610-
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
611-
t = t->getPointerElementType();
612-
#pragma GCC diagnostic pop
613-
}
614-
while (indirections-- != 0)
615-
t = t->getPointerTo(0);
616-
}
617-
return t;
618-
#endif
619599
}
620600

621601
LLValue *DtoBitCast(LLValue *v, LLType *t, const llvm::Twine &name) {

runtime/druntime/src/ldc/intrinsics.di

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ enum LLVM_atleast(int major) = (LLVM_version >= major * 100);
3636
nothrow:
3737
@nogc:
3838

39-
version(LDC_LLVM_OpaquePointers)
40-
private enum p0i8 = "p0";
41-
else
42-
private enum p0i8 = "p0i8";
43-
4439
//
4540
// CODE GENERATOR INTRINSICS
4641
//
@@ -53,7 +48,7 @@ pragma(LDC_intrinsic, "llvm.returnaddress")
5348

5449
/// The 'llvm.frameaddress' intrinsic attempts to return the target-specific
5550
/// frame pointer value for the specified stack frame.
56-
pragma(LDC_intrinsic, "llvm.frameaddress."~p0i8)
51+
pragma(LDC_intrinsic, "llvm.frameaddress.p0")
5752
void* llvm_frameaddress(uint level);
5853

5954
/// The 'llvm.stacksave' intrinsic is used to remember the current state of the
@@ -80,7 +75,7 @@ pragma(LDC_intrinsic, "llvm.stackrestore")
8075
/// keep in cache. The cache type specifies whether the prefetch is performed on
8176
/// the data (1) or instruction (0) cache. The rw, locality and cache type
8277
/// arguments must be constant integers.
83-
pragma(LDC_intrinsic, "llvm.prefetch."~p0i8)
78+
pragma(LDC_intrinsic, "llvm.prefetch.p0")
8479
void llvm_prefetch(const(void)* ptr, uint rw, uint locality, uint cachetype) pure @safe;
8580

8681
/// The 'llvm.pcmarker' intrinsic is a method to export a Program Counter (PC)
@@ -144,7 +139,7 @@ pure:
144139
/// location to the destination location.
145140
/// Note that, unlike the standard libc function, the llvm.memcpy.* intrinsics do
146141
/// not return a value.
147-
pragma(LDC_intrinsic, "llvm.memcpy."~p0i8~"."~p0i8~".i#")
142+
pragma(LDC_intrinsic, "llvm.memcpy.p0.p0.i#")
148143
void llvm_memcpy(T)(void* dst, const(void)* src, T len, bool volatile_ = false)
149144
if (__traits(isIntegral, T));
150145

@@ -154,15 +149,15 @@ pragma(LDC_intrinsic, "llvm.memcpy."~p0i8~"."~p0i8~".i#")
154149
/// intrinsic but allows the two memory locations to overlap.
155150
/// Note that, unlike the standard libc function, the llvm.memmove.* intrinsics
156151
/// do not return a value.
157-
pragma(LDC_intrinsic, "llvm.memmove."~p0i8~"."~p0i8~".i#")
152+
pragma(LDC_intrinsic, "llvm.memmove.p0.p0.i#")
158153
void llvm_memmove(T)(void* dst, const(void)* src, T len, bool volatile_ = false)
159154
if (__traits(isIntegral, T));
160155

161156
/// The 'llvm.memset.*' intrinsics fill a block of memory with a particular byte
162157
/// value.
163158
/// Note that, unlike the standard libc function, the llvm.memset intrinsic does
164159
/// not return a value.
165-
pragma(LDC_intrinsic, "llvm.memset."~p0i8~".i#")
160+
pragma(LDC_intrinsic, "llvm.memset.p0.i#")
166161
void llvm_memset(T)(void* dst, ubyte val, T len, bool volatile_ = false)
167162
if (__traits(isIntegral, T));
168163

tests/codegen/dcompute_cl_addrspaces_new.d renamed to tests/codegen/dcompute_cl_addrspaces.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// UNSUPPORTED: atleast_llvm1800 && atmost_llvm1809
55

66
// REQUIRES: target_SPIRV && atleast_llvm1600
7-
// RUN: %ldc -c -opaque-pointers -mdcompute-targets=ocl-220 -m64 -mdcompute-file-prefix=addrspace_new -output-ll -output-o %s && FileCheck %s --check-prefix=LL < addrspace_new_ocl220_64.ll \
7+
// RUN: %ldc -c -mdcompute-targets=ocl-220 -m64 -mdcompute-file-prefix=addrspace_new -output-ll -output-o %s && FileCheck %s --check-prefix=LL < addrspace_new_ocl220_64.ll \
88
// RUN: && %llc addrspace_new_ocl220_64.ll -mtriple=spirv64-unknown-unknown -O0 -o - | FileCheck %s --check-prefix=SPT
9-
@compute(CompileFor.deviceOnly) module dcompute_cl_addrspaces_new;
9+
@compute(CompileFor.deviceOnly) module dcompute_cl_addrspaces;
1010
import ldc.dcompute;
1111

1212
// LL: %"ldc.dcompute.Pointer!(AddrSpace.Private, float).Pointer" = type { ptr }

tests/codegen/dcompute_cl_addrspaces_old.d

Lines changed: 0 additions & 60 deletions
This file was deleted.

tests/codegen/inline_ir.d

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
import ldc.llvmasm;
44
import ldc.intrinsics;
5-
version (LDC_LLVM_OpaquePointers)
6-
{
7-
alias __irEx!("", "store i32 %1, ptr %0, !nontemporal !0", "!0 = !{i32 1}", void, int*, int) nontemporalStore;
8-
alias __irEx!("!0 = !{i32 1}", "%i = load i32, ptr %0, !nontemporal !0\nret i32 %i", "", int, const int*) nontemporalLoad;
9-
}
10-
else
11-
{
12-
alias __irEx!("", "store i32 %1, i32* %0, !nontemporal !0", "!0 = !{i32 1}", void, int*, int) nontemporalStore;
13-
alias __irEx!("!0 = !{i32 1}", "%i = load i32, i32* %0, !nontemporal !0\nret i32 %i", "", int, const int*) nontemporalLoad;
14-
}
5+
6+
alias __irEx!("", "store i32 %1, ptr %0, !nontemporal !0", "!0 = !{i32 1}", void, int*, int) nontemporalStore;
7+
alias __irEx!("!0 = !{i32 1}", "%i = load i32, ptr %0, !nontemporal !0\nret i32 %i", "", int, const int*) nontemporalLoad;
8+
159
int foo(const int* src)
1610
{
1711
// CHECK: %{{.*}} = load i32, {{i32\*|ptr}} {{.*}} !nontemporal ![[METADATA:[0-9]+]]

0 commit comments

Comments
 (0)